cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 hangs when erasing page and receiving USART data

g239955_stm1
Associate II
Posted on March 11, 2015 at 10:19

I am currently working on a STM32F103, and I want to program the flash. However, it appear that programming the flash with an USART device receiving bytes in the same time make it hangs:

FLASH_BASE->CR |= FLASH_CR_PER; while (FLASH_BASE->SR & FLASH_SR_BSY); FLASH_BASE->AR = pageAddr; FLASH_BASE->CR |= FLASH_CR_STRT; // Hangs forever when receiving // data on USART2 in the same time while (FLASH_BASE->SR & FLASH_SR_BSY); FLASH_BASE->CR &= ~FLASH_CR_PER; 

Disabling the RE flag on USART2 before and re-enabling it after avoids the problem, but it prevent me from receiving data during the operation, which would be possible since the receive interrupt is in the RAM.

Actually, looks like it is not related to the interrupt itself, because it still hangs without the receive interrupt.

Any idea?

Thanks #flash
2 REPLIES 2
jpeacock
Associate II
Posted on March 11, 2015 at 18:46

Are you running your code from SRAM, not just the interrupt handler but your idle loop or any routines called from the handler?  Whenever you erase or update internal flash the CPU stalls when fetching an instruction from the flash array.  This can be a significant amount of time, long enough for interrupts to miss data. 

If you are already stalled it won't call the interrupt.  If the flash routine is in flash that while loop is actually a stalled CPU, no code fetches.

  Jack Peacock

Posted on March 11, 2015 at 19:11

Assume the vector table is also in RAM.

Is the USART interrupt doing anything that might be objectionable?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..