Page 1 of 2
Remapped SPI1_MOSI on STM32 doesn't seem to work
Posted: Tue Jun 07, 2011 3:34 pm
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.
Re: Remapped SPI1_MOSI on STM32 doesn't seem to work
Posted: Tue Jun 07, 2011 3:40 pm
by Giovanni
Hi,
Do you program the remapped pins as "alternate output"? You should do this in board.h.
Giovanni
Re: Remapped SPI1_MOSI on STM32 doesn't seem to work
Posted: Tue Jun 07, 2011 3:43 pm
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);
Re: Remapped SPI1_MOSI on STM32 doesn't seem to work
Posted: Tue Jun 07, 2011 4:19 pm
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.
Re: Remapped SPI1_MOSI on STM32 doesn't seem to work
Posted: Tue Jun 07, 2011 5:35 pm
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
Re: Remapped SPI1_MOSI on STM32 doesn't seem to work
Posted: Tue Jun 07, 2011 10:03 pm
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.
Re: Remapped SPI1_MOSI on STM32 doesn't seem to work
Posted: Wed Jun 08, 2011 7:25 am
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
Re: Remapped SPI1_MOSI on STM32 doesn't seem to work
Posted: Wed Jun 08, 2011 10:10 am
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

Re: Remapped SPI1_MOSI on STM32 doesn't seem to work
Posted: Wed Jun 08, 2011 10:24 am
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
Re: Remapped SPI1_MOSI on STM32 doesn't seem to work
Posted: Thu Jun 09, 2011 9:31 am
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!