2014-01-20 10:43 AM
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:
//GPIO B
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIOB_InitStructure;
GPIOB_InitStructure.GPIO_Pin = ( GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 );
GPIOB_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIOB_InitStructure.GPIO_Speed = GPIO_Speed_Level_1;
//2MHz is enough for us
GPIOB_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIOB_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIOB_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
//SysTick
NVIC_SetPriority(SysTick_IRQn,0);
/* set Priority for Systick Interrupt */
SysTick->VAL = 0;
/* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
/* Enable SysTick IRQ and SysTick Timer */
SysTick_CTRL_TICKINT_Msk;
SysTick->LOAD = (250 * 96) - 1;
//IRHandler
NVIC_SetPriority(EXTI0_1_IRQn,2);
NVIC_EnableIRQ(EXTI0_1_IRQn);
NVIC_SetPriority(EXTI2_3_IRQn,3);
NVIC_EnableIRQ(EXTI2_3_IRQn);
EXTI->IMR = (EXTI_IMR_MR0 | EXTI_IMR_MR2);
EXTI->EMR = (EXTI_EMR_MR0 | EXTI_EMR_MR2);
//SPI1 + DMA1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource5, GPIO_AF_5);
//SCK
GPIO_PinAFConfig(GPIOA,GPIO_PinSource6, GPIO_AF_5);
//MISO
GPIO_PinAFConfig(GPIOA,GPIO_PinSource7, GPIO_AF_5);
//MOSI
GPIO_InitTypeDef GPIOA_InitStructure;
GPIOA_InitStructure.GPIO_Pin = ( GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 );
GPIOA_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Init(GPIOB, &GPIOA_InitStructure);
SPI_InitTypeDef SPI1_InitStructure;
SPI1_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI1_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI1_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI1_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI1_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI1_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI1_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
SPI1_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_Init(SPI1, &SPI1_InitStructure);
SPI_RxFIFOThresholdConfig(SPI1,SPI_RxFIFOThreshold_QF);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_InitTypeDef DMA1Rx_InitStructure;
DMA_InitTypeDef DMA1Tx_InitStructure;
DMA1Rx_InitStructure.DMA_PeripheralBaseAddr = SPI1->DR;
DMA1Tx_InitStructure.DMA_PeripheralBaseAddr = SPI1->DR;
DMA1Rx_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SPIRxBuffer;
DMA1Tx_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SPITxBuffer;
DMA1Rx_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA1Tx_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA1Rx_InitStructure.DMA_BufferSize = SPIBUFFERSIZE;
DMA1Tx_InitStructure.DMA_BufferSize = SPIBUFFERSIZE;
DMA1Rx_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA1Tx_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA1Rx_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA1Tx_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA1Rx_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA1Tx_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA1Rx_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA1Tx_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA1Rx_InitStructure.DMA_Priority = DMA_Priority_Medium;
DMA1Tx_InitStructure.DMA_Priority = DMA_Priority_Medium;
DMA1Rx_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA1Tx_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel2, &DMA1Rx_InitStructure);
DMA_Init(DMA1_Channel3, &DMA1Tx_InitStructure);
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Rx, ENABLE);
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE);
SPI_Cmd(SPI1, ENABLE);
DMA_Cmd(DMA1_Channel2, ENABLE);
DMA_Cmd(DMA1_Channel3, ENABLE);
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
2014-01-20 02:11 PM
DMA has been known to lock out debuggers.
BOOT0 = High at reset will stop broke user code from running.
DMA1Rx_InitStructure.DMA_PeripheralBaseAddr = SPI1->DR;
DMA1Tx_InitStructure.DMA_PeripheralBaseAddr = SPI1->DR;
Some how I don't think the content of the data register is what you're looking for?
The ADDRESS of &SPI1->DR perhaps?
2014-01-21 03:57 AM
2014-01-21 09:19 AM
Setting Boot0 to 3,3V perfectly solves my problem. Big THX for this hint!