Write into flash while USART interrupt executed
Hello,
I have some trouble to write into the flash of my stm32f I can send via usart a lot of commands to the µC, interprete and execute them finally. One command is to write some data into the flash but if I write and the usart is still receiving data, the communication is totally dead - only mcu reset helps.
The only 'solution' which doesn't crash the communication is to deactivate the usart with USART1->CR1 &= ~USART_CR1_UE; before I write into flash and re-enable it after the flash operation - but that's not a real solution cause I will lose data/commands.
What I tried:
- Moving the vector table into SRAM
- Disable the usart interrupt (NVIC_DisableIRQ(USART1_IRQn);)
-
__disable_irq
(
)
;
before the flash operationWithout any effect. The linker script has the following settings:
MEMORY
{ FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K UNUSED (rx) : ORIGIN = 0x8020000, LENGTH = 128K RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 32K - 0xC0 }I always write into the UNUSED section, not the FLASH where the running firmware is stored.
The best solution would be to disable the interrupt for the flash-write-time, the mcu buffering all incoming packages for the moment and after re-enabling the interrupt I receive the buffered data. Is that somehow possible or you have any other useful hints for me?
Thanks
Note: this post was migrated and contained many threaded conversations, some content may be missing.