cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f107 - SPI ''reinit'' not working

darekfilip
Associate II
Posted on February 14, 2016 at 21:24

Hi,

i write bootloader with sdcard upgrade option. During first bootloader start (after power on, or MCU programming using stm-vldiscovery programmer) everything works well. When I restart MCU using NVIC_SystemReset() SPI stops to work. Both times application executes same source code, but after SPI init after reset there is no clock on SPI3_CLK and communication does not work correctly. SPI initiazliation source code:


RCC_APB2PeriphClockCmd(SPI_APB2, ENABLE);

RCC_APB1PeriphClockCmd(SPI_APB1, ENABLE);


gpio_init(GPIO_Mode_AF_PP, SPI_SCK_GPIO, SPI_SCK_GPIO_PIN);

gpio_init(GPIO_Mode_IPU, SPI_MISO_GPIO, SPI_MISO_GPIO_PIN);

gpio_init(GPIO_Mode_AF_PP, SPI_MOSI_GPIO, SPI_MOSI_GPIO_PIN);

gpio_init(GPIO_Mode_Out_PP, SPI_SDCS_GPIO, SPI_SDCS_GPIO_PIN);

gpio_init(GPIO_Mode_Out_PP, SPI_EXTCS_GPIO, SPI_EXTCS_GPIO_PIN);


spi_cs(SPI_USE_EXT);


SPI_I2S_DeInit(SPI_SPI);

SPI_InitTypeDef SPI_InitStructure;

SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;

SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;

SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;

SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;

SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

SPI_InitStructure.SPI_CRCPolynomial = 7;

SPI_Init(SPI_SPI, &SPI_InitStructure);

SPI_I2S_ClearFlag(SPI_SPI, SPI_FLAG_CRCERR);

SPI_Cmd(SPI_SPI, ENABLE);


spi_decs();

When works communication works very stable without any problems. Tried adding SPI_I2S_DeInit before Resting CPU, but didn't help. Darek
5 REPLIES 5
Posted on February 15, 2016 at 01:06

Ok, but understand that you resetting the SPI peripheral, or the processor, doesn't reset or change he state of the external peripherals *attached* to the SPI bus. Either your external peripherals need to get feed the NRST signal, or you need that to gate the supply to your SD Card, for them the get back into a reset state.

Failing that you'll have to walk the attached devices out of whatever state they are in, so you can reinitialize them, or perhaps you can skip steps/commands/modes that they might already be in.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
darekfilip
Associate II
Posted on February 15, 2016 at 11:46

I think problem is not with SD Card state.

1. Reseting MCU with st-link solves the problem. During such reset  SD card is not being reseted.

2. MCU works as SPI master. There is not clock signal on line after reset. Clock does not depend on slave state.

In my opinion it's problem with MCU or configuration.

Posted on February 15, 2016 at 12:33

In my opinion it's problem with MCU or configuration. 

And I'm not here to argue with you, or spend hours debugging it.

Not sure why the ST-LINK reset would do something the NVIC_SystemReset() wouldn't, are you doing something odd with the NRST signal on your board, like driving it with a push-pull driver?

I have a very narrow perspective on what exactly your design is doing.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
darekfilip
Associate II
Posted on February 15, 2016 at 13:53

NRST pin connection schema: http://imgur.com/JuNdAK1

There is no R1 resistor on board. There is no connection made with JP2. Reset done using S1 switch also creates problems with SPI CLK pin.

Are there some requirements for SPI lines? MISO/MOSI/SCK - should they be pulled down/up?

I've made additional test - used watchdog to reset. No results.

tuxxas
Associate
Posted on September 22, 2016 at 12:28

Hi, have you managed to solve this problem?

I have the same problem: if I use NVIC_SystemReset(), SPI works with errors after reset though UART is OK. I have serial SRAM connected to SSP1 and SD - to SSP2. Reset button doesn't help. It is necessary to power off my device.

Thank you.