Remapped SPI1_MOSI on STM32 doesn't seem to work

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Remapped SPI1_MOSI on STM32 doesn't seem to work

Post by Badger »

I'm using a custom board I've designed with an STM32F103CBT6. The default mapping of SPI1_MOSI to PA7 works fine and data is output correctly (I'm sending an easily distinguishable byte 0x55 which is 01010101). Once I remap SPI1 to PB3:5, SPI1_SCLK works but SPI1_MOSI does not output anything. I've checked that everything is connected to the correct pins but can't find any problems. Do I need to change anything with the DMA configuration to get it to work on the remapped pins?

I have set my board.h appropriately for the remapped outputs:

Code: Select all

#define VAL_GPIOBCRL            0xDDB4B888      /*  PB7...PB0 */


and disabled JTAG and remapped SPI1:

Code: Select all

   halInit();
   chSysInit();
   // disable JTAG and remap spi1
   AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
   AFIO->MAPR |= AFIO_MAPR_SPI1_REMAP;


I'm trying to use the MMC over SPI driver. Commenting out the last line in the above code block disables the SPI remap and I see the expected output using my logic probe with no other changes.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Remapped SPI1_MOSI on STM32 doesn't seem to work

Post by Giovanni »

Hi,

Do you program the remapped pins as "alternate output"? You should do this in board.h.

Giovanni
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: Remapped SPI1_MOSI on STM32 doesn't seem to work

Post by Badger »

Hi Giovanni,

Yes I do set PB5 and PB3 as alternate output in board.h (the first code block shows this, although the numbers are somewhat cryptic!)

I've also tried manually setting the port type after remapping the pins to no success:

Code: Select all

palSetPadMode(IOPORT2, 3, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(IOPORT2, 5, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: Remapped SPI1_MOSI on STM32 doesn't seem to work

Post by Badger »

I tried the SPI demo with remapped pins and it worked, so something different with the MMC/SPI driver must be causing a problem.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Remapped SPI1_MOSI on STM32 doesn't seem to work

Post by Giovanni »

Hi,

The MMC_SPI driver just uses the SPI but should not affect it, the MMC_SPI driver does not touch any hardware directly so it should not be affected or affect remapping, there must be something else.
Try sending a pattern directly through the SPI while the MMC_SPI is enabled.

Giovanni
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: Remapped SPI1_MOSI on STM32 doesn't seem to work

Post by Badger »

Hi,

The problem was solved by turning off my other threads, including stuff like i2c processing. Not sure why it is only a problem with the remapped output, but I'll gradually add stuff back in and see if I can find the cause somewhere.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Remapped SPI1_MOSI on STM32 doesn't seem to work

Post by Giovanni »

If you had an active I2C you should download the STM32 errata document, there is an errata about remapped SPI1 when I2C clock is active, probably you hit exactly that scenario.

Giovanni
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: Remapped SPI1_MOSI on STM32 doesn't seem to work

Post by Badger »

Thanks for pointing that out, I found the errata, which has definitely saved me a lot of headaches! unfortunately the work around wasn't very useful:
Do not use SPI1 remapped in master mode and I2C1 together

Luckily in the current stage of my application I only need to record i2c data for a short period of time so can buffer in memory before writing to the card. Something to consider for the next prototype! but hopefully I'll have moved onto STM32F2 by then :D
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Remapped SPI1_MOSI on STM32 doesn't seem to work

Post by Giovanni »

You may consider to implement a bit-bang I2C implementation using the GPT driver for timings, probably it would a good idea to include something like this in the OS as a standard driver, hardware based I2C for some reason is always troublesome.

Giovanni
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: Remapped SPI1_MOSI on STM32 doesn't seem to work

Post by Badger »

I got around the problem by simply disabling the I2C1 clock before writing to the card, and re-enabling it at the end:

Code: Select all

RCC->APB1ENR &= ~RCC_APB1ENR_I2C1EN;
// write data to sd card..
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;

And thankfully the write is quick enough that i don't even need to buffer anything!
Post Reply