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.
Problem with SPI1 read on STM32F4
Moderator: RoccoMarco
- 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
Hi,
The SPI driver requires the CS line to be programmed as GPIO because it is handled in software, is this your case?
Giovanni
The SPI driver requires the CS line to be programmed as GPIO because it is handled in software, is this your case?
Giovanni
Re: Problem with SPI1 read on STM32F4
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.
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.
Re: Problem with SPI1 read on STM32F4
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.
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 571 times
- 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
Hi,
I will give a try in the weekend, I will have no HW available until then.
Giovanni
I will give a try in the weekend, I will have no HW available until then.
Giovanni
Re: Problem with SPI1 read on STM32F4
It can be found in the boards directory of the ChibiOS distro.
Re: Problem with SPI1 read on STM32F4
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.
Default setting in ..\chibios\boards\ST_STM32F4_DISCOVERY\board.h not set pin PA15 / PB3 / PB4 / PB5 for SPI1.
- 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
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
You cannot put the SPI signals on two pins at the same time.
Giovanni