Problem with SPI1 read on STM32F4

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

xlh1460
Posts: 25
Joined: Wed May 22, 2013 6:48 pm

Problem with SPI1 read on STM32F4

Post by xlh1460 »

I am using ChibiOS 2.6.3 on an STM32F4-Discovery board.

When I use SPI1 wired to the following pins, it works correctly for read and write;

PA4 - SPI1_NSS (CS)
PA5 - SPI1_SCK
PA6 - SPI1_MISO
PA7 - SPI1_MOSI

The SPI1 functionality is allow available on these pins according to the AF table:

PA15 - SPI1_NSS (CS)
PB3 - SPI1_SCK
PB4 - SPI1_MISO
PB5 - SPI1_MOSI

When using those pins and adjusting the SPI1 configuration and wiring appropriately it doesn't appear to work.

When I investigate with a logic analyzer I saw that the SPI write was working correctly and the attached device was responding correctly but the SPI read was not returning the correct value.

I tested this using a simple bare metal program that worked fine under the same conditions. That program does its reading and writing via the SPI->DR directly.

Is this a known issue or limitation of the OS?

Not sure where to look next.

If necessary I can work out a simple demonstration program to upload.

Thanks in advance.

Dale.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with SPI1 read on STM32F4

Post by Giovanni »

Hi,

The SPI driver requires the CS line to be programmed as GPIO because it is handled in software, is this your case?

Giovanni
xlh1460
Posts: 25
Joined: Wed May 22, 2013 6:48 pm

Re: Problem with SPI1 read on STM32F4

Post by xlh1460 »

Yes, The CS pin is programmed as GPIO.

I suspect if that were the problem I would see different results since TX seems OK but RX is not working even though the SPI slave device is responding appropriately.
xlh1460
Posts: 25
Joined: Wed May 22, 2013 6:48 pm

Re: Problem with SPI1 read on STM32F4

Post by xlh1460 »

I'll try to work up a simple demo and upload it.

Thanks.
xlh1460
Posts: 25
Joined: Wed May 22, 2013 6:48 pm

Re: Problem with SPI1 read on STM32F4

Post by xlh1460 »

Here is the demo.

Compile it and connect terminal to USART3(PC10 - TX | PC11 - RX)

Jumper PA6 to PA7 to loopback SPI1 MISO and MOSI.

Execute the program and what is typed in the terminal should get looped back to the terminal via the SPI1 module.

Then comment out the line reading: #define TEST_WORKING_PINS

Recompile.

Jumper PB4 to PB5 to loopback SPI1 MISO and MOSI.

Now when you type in the terminal is not echoed correctly. The SPI1 read is always returning 0xFF.

I think that the problem is in the OS since a bare metal application seemed to work fine reading and writing on SPI1 regardless of which pins I used.

Thanks in advance for any help and don't hesitate to let me know if I can provide anything else.
Attachments
ARMCM4-STM32F407-DISCOVERY-SPI.zip
(11.37 KiB) Downloaded 569 times
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with SPI1 read on STM32F4

Post by Giovanni »

Hi,

I will give a try in the weekend, I will have no HW available until then.

Giovanni
mculover
Posts: 26
Joined: Fri Dec 10, 2010 2:27 pm

Re: Problem with SPI1 read on STM32F4

Post by mculover »

No board.h in your example
xlh1460
Posts: 25
Joined: Wed May 22, 2013 6:48 pm

Re: Problem with SPI1 read on STM32F4

Post by xlh1460 »

It can be found in the boards directory of the ChibiOS distro.
mculover
Posts: 26
Joined: Fri Dec 10, 2010 2:27 pm

Re: Problem with SPI1 read on STM32F4

Post by mculover »

File board.h need setting for operate with hardware module.
Default setting in ..\chibios\boards\ST_STM32F4_DISCOVERY\board.h not set pin PA15 / PB3 / PB4 / PB5 for SPI1.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with SPI1 read on STM32F4

Post by Giovanni »

Mcu lover could be right, you need to setup the alternate for SPI on port B but you also need to remove the alternate settings on port A inb board.h (if any).

You cannot put the SPI signals on two pins at the same time.

Giovanni
Post Reply