AnsweredAssumed Answered

STM32F0 SWD Lockout

Question asked by walter.tom on Jan 20, 2014
Latest reply on Jan 21, 2014 by walter.tom
Hi Everybody,

i'm trying to get some of the STM32F0 peripherals (in this case GPIO, SysTick, NVIC, SPI, DMA) working. Im using IAR EW 6.7 + IAR I-Jet (which is connected via SWD to the Chip).

After creating a 'fresh' IAR project and do all the nessesary configuration (select the correct device, programmer etc) i can compile and download my empty project to the target (so im confident that my setup is working generally). But after doing some stuff with the STM32 peripheral library, i found myself locked out from the target:

Mon Jan 20, 2014 19:31:00: Failed to load flash loader: C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.5\arm\config\flashloader\ST\FlashSTM32F05xxxRAM4K.out

Mon Jan 20, 2014 19:31:00: Failed to load flash loader: C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.5\arm\config\flashloader\ST\FlashSTM32F05xx6.flash

All others cases of people complaining about this error i found were related to the programmer driver or stuff like that. Scince my setup does work in general, it is not very likely that i face a similar issue.

So i guess i locked myself out by configuration some of the peripheral and i would like to understand what happens there.

Here is my code:

001.//GPIO B
002.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
003.   
004.  GPIO_InitTypeDef GPIOB_InitStructure;
005.  GPIOB_InitStructure.GPIO_Pin          = ( GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 );
006.  GPIOB_InitStructure.GPIO_Mode         =   GPIO_Mode_OUT;
007.  GPIOB_InitStructure.GPIO_Speed        =   GPIO_Speed_Level_1; //2MHz is enough for us
008.  GPIOB_InitStructure.GPIO_OType        =   GPIO_OType_PP;
009.  GPIOB_InitStructure.GPIO_PuPd         =   GPIO_PuPd_NOPULL;
010.     
011.  GPIO_Init(GPIOB, &GPIOB_InitStructure);
012. 
013.  GPIO_SetBits(GPIOB, GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
014.   
015.   
016.  //SysTick
017.  NVIC_SetPriority(SysTick_IRQn,0);                     /* set Priority for Systick Interrupt */
018.  SysTick->VAL   = 0;                                   /* Load the SysTick Counter Value */
019.  SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |         /* Enable SysTick IRQ and SysTick Timer */
020.                   SysTick_CTRL_TICKINT_Msk;
021.  SysTick->LOAD = (250 * 96) - 1;
022.   
023.   
024.  //IRHandler
025.  NVIC_SetPriority(EXTI0_1_IRQn,2);
026.  NVIC_EnableIRQ(EXTI0_1_IRQn);
027.  NVIC_SetPriority(EXTI2_3_IRQn,3);
028.  NVIC_EnableIRQ(EXTI2_3_IRQn);
029.  
030.  EXTI->IMR = (EXTI_IMR_MR0 | EXTI_IMR_MR2);
031.  EXTI->EMR = (EXTI_EMR_MR0 | EXTI_EMR_MR2);
032.   
033.   
034.  //SPI1 + DMA1
035.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
036.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
037.   
038.  GPIO_PinAFConfig(GPIOA,GPIO_PinSource5, GPIO_AF_5);    //SCK
039.  GPIO_PinAFConfig(GPIOA,GPIO_PinSource6, GPIO_AF_5);    //MISO
040.  GPIO_PinAFConfig(GPIOA,GPIO_PinSource7, GPIO_AF_5);    //MOSI
041.   
042.  GPIO_InitTypeDef GPIOA_InitStructure;
043.  GPIOA_InitStructure.GPIO_Pin          = ( GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 );
044.  GPIOA_InitStructure.GPIO_Mode         =   GPIO_Mode_AF;
045.  GPIO_Init(GPIOB, &GPIOA_InitStructure);
046.   
047.  SPI_InitTypeDef SPI1_InitStructure;
048.  SPI1_InitStructure.SPI_Direction              = SPI_Direction_2Lines_FullDuplex;
049.  SPI1_InitStructure.SPI_Mode                   = SPI_Mode_Master;
050.  SPI1_InitStructure.SPI_DataSize               = SPI_DataSize_8b;
051.  SPI1_InitStructure.SPI_CPOL                   = SPI_CPOL_Low;
052.  SPI1_InitStructure.SPI_CPHA                   = SPI_CPHA_1Edge;
053.  SPI1_InitStructure.SPI_NSS                    = SPI_NSS_Soft;
054.  SPI1_InitStructure.SPI_BaudRatePrescaler      = SPI_BaudRatePrescaler_16;
055.  SPI1_InitStructure.SPI_FirstBit               = SPI_FirstBit_MSB;
056.  SPI_Init(SPI1, &SPI1_InitStructure);
057.   
058.  SPI_RxFIFOThresholdConfig(SPI1,SPI_RxFIFOThreshold_QF);
059.   
060.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
061.   
062.  DMA_InitTypeDef DMA1Rx_InitStructure;
063.  DMA_InitTypeDef DMA1Tx_InitStructure;
064.   
065.  DMA1Rx_InitStructure.DMA_PeripheralBaseAddr = SPI1->DR;
066.  DMA1Tx_InitStructure.DMA_PeripheralBaseAddr = SPI1->DR;
067.   
068.  DMA1Rx_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SPIRxBuffer;
069.  DMA1Tx_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SPITxBuffer;
070.   
071.  DMA1Rx_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
072.  DMA1Tx_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
073.   
074.  DMA1Rx_InitStructure.DMA_BufferSize = SPIBUFFERSIZE;
075.  DMA1Tx_InitStructure.DMA_BufferSize = SPIBUFFERSIZE;
076.   
077.  DMA1Rx_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
078.  DMA1Tx_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
079.   
080.  DMA1Rx_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
081.  DMA1Tx_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
082.   
083.  DMA1Rx_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
084.  DMA1Tx_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
085.   
086.  DMA1Rx_InitStructure.DMA_Mode = DMA_Mode_Circular;
087.  DMA1Tx_InitStructure.DMA_Mode = DMA_Mode_Circular;
088.   
089.  DMA1Rx_InitStructure.DMA_Priority = DMA_Priority_Medium;
090.  DMA1Tx_InitStructure.DMA_Priority = DMA_Priority_Medium;
091.   
092.  DMA1Rx_InitStructure.DMA_M2M = DMA_M2M_Disable;
093.  DMA1Tx_InitStructure.DMA_M2M = DMA_M2M_Disable;
094.   
095.  DMA_Init(DMA1_Channel2, &DMA1Rx_InitStructure);
096.  DMA_Init(DMA1_Channel3, &DMA1Tx_InitStructure);
097.    
098.  SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Rx, ENABLE);
099.  SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE);
100.   
101.  SPI_Cmd(SPI1, ENABLE);
102.  DMA_Cmd(DMA1_Channel2, ENABLE);
103.  DMA_Cmd(DMA1_Channel3, ENABLE);
104.   
105.   
106.  SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;

Does anybody have a suggestion what went wrong?

Despite the question what causes this behavior, i would be interested in information how to get access to the target again. But i guess i have to do some homework in reading documentation regarding Boot-Pins etc... That will be my task for tommorow :)

Regards,
Tom

Outcomes