AnsweredAssumed Answered

stm32f107 - SPI "reinit" not working

Question asked by darek on Feb 14, 2016
Latest reply on Sep 22, 2016 by tuxxas
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:
01.RCC_APB2PeriphClockCmd(SPI_APB2, ENABLE);
02.RCC_APB1PeriphClockCmd(SPI_APB1, ENABLE);
03. 
04.gpio_init(GPIO_Mode_AF_PP, SPI_SCK_GPIO, SPI_SCK_GPIO_PIN);
05.gpio_init(GPIO_Mode_IPU, SPI_MISO_GPIO, SPI_MISO_GPIO_PIN);
06.gpio_init(GPIO_Mode_AF_PP, SPI_MOSI_GPIO, SPI_MOSI_GPIO_PIN);
07.gpio_init(GPIO_Mode_Out_PP, SPI_SDCS_GPIO, SPI_SDCS_GPIO_PIN);
08.gpio_init(GPIO_Mode_Out_PP, SPI_EXTCS_GPIO, SPI_EXTCS_GPIO_PIN);
09. 
10.spi_cs(SPI_USE_EXT);
11. 
12.SPI_I2S_DeInit(SPI_SPI);
13.SPI_InitTypeDef SPI_InitStructure;
14.SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
15.SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
16.SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
17.SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
18.SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
19.SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
20.SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
21.SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
22.SPI_InitStructure.SPI_CRCPolynomial = 7;
23.SPI_Init(SPI_SPI, &SPI_InitStructure);
24.SPI_I2S_ClearFlag(SPI_SPI, SPI_FLAG_CRCERR);
25.SPI_Cmd(SPI_SPI, ENABLE);
26. 
27. spi_decs();

When works communication works very stable without any problems. Tried adding SPI_I2S_DeInit before Resting CPU, but didn't help.

Darek
 

Outcomes