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

Re: Problem with SPI1 read on STM32F4

Post by xlh1460 »

I had a peek at board.h and changing that seems a bit daunting.

Shouldn't the pin configuration applied in my code be sufficient to override what is defined in board.h?
xlh1460
Posts: 25
Joined: Wed May 22, 2013 6:48 pm

Re: Problem with SPI1 read on STM32F4

Post by xlh1460 »

On, second thought, it sounds like the problem might be with the pins that I am not using and noth with the ones that i am using.

I'll play with this some more.
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,

You should not change board.h and board.c manually, in the ./cfg subdirectory there is a .chcfg file (XML), you can change it and then generate the board files using the generator tool included in ChibiStudio (select the .chcfg file and look in the toolbar, a button should appear there).
The .chcfg file has a schema guiding you if you use the Eclipse XML editor.

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

Re: Problem with SPI1 read on STM32F4

Post by xlh1460 »

You and mculover definitely nailed down the problem and pointed me in the right direction.

I didn't touch the board definition files but I changed my code slightly and now it works fine.

Code: Select all

  palSetPadMode(GPIOA, 4, 0 );
  palSetPadMode(GPIOA, 5, 0 );
  palSetPadMode(GPIOA, 6, 0 );
  palSetPadMode(GPIOA, 7, 0 );

  palSetPadMode(GPIOB, 3, PAL_MODE_ALTERNATE(5) |
                           PAL_STM32_OSPEED_HIGHEST);       /* New SCK.     */
  palSetPadMode(GPIOB, 4, PAL_MODE_ALTERNATE(5) |
                           PAL_STM32_OSPEED_HIGHEST);       /* New MISO.    */
  palSetPadMode(GPIOB, 5, PAL_MODE_ALTERNATE(5) |
                           PAL_STM32_OSPEED_HIGHEST);       /* New MOSI.    */
  palSetPadMode(GPIOA, 15, PAL_MODE_OUTPUT_PUSHPULL |
                           PAL_STM32_OSPEED_HIGHEST);       /* New CS.      */
  palSetPad(GPIOA, 15);

  spiStart(&SPID1, &spicfg);



I needed to "disconnect" the "standard" pins from the SPI peripheral.

This now loops back correctly, regardless of which set of pins I use on SPI1.

Thank you!
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 »

I suggest to put the unused pins as "input with pull up", this will prevent noise and extra consumption.

Giovanni
Post Reply