stm32: Add option to put ISR, flash and UART code in RAM.

This allows UART RX to function while flash erase/writes operations are
under way, preventing lost serial data so long as it fits in the UART RX
buffer.

This enables (among other things) mpremote to successfully copy files to
boards that use a UART REPL.

Enable via the following option placed in `mpconfigboard.mk`:

    MICROPY_HW_ENABLE_ISR_UART_FLASH_FUNCS_IN_RAM = 1

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This commit is contained in:
Andrew Leech
2022-08-15 14:21:47 +10:00
committed by Damien George
parent 35b6a66b0b
commit 1f5cab9edb
28 changed files with 109 additions and 48 deletions

View File

@@ -303,10 +303,21 @@ void stm32_main(uint32_t reset_mode) {
// Low-level MCU initialisation.
stm32_system_init();
#if !defined(STM32F0) && defined(MICROPY_HW_VTOR)
#if !defined(STM32F0)
#if MICROPY_HW_ENABLE_ISR_UART_FLASH_FUNCS_IN_RAM
// Copy IRQ vector table to RAM and point VTOR there
extern uint32_t __isr_vector_flash_addr, __isr_vector_ram_start, __isr_vector_ram_end;
size_t __isr_vector_size = (&__isr_vector_ram_end - &__isr_vector_ram_start) * sizeof(uint32_t);
memcpy(&__isr_vector_ram_start, &__isr_vector_flash_addr, __isr_vector_size);
SCB->VTOR = (uint32_t)&__isr_vector_ram_start;
#else
#if defined(MICROPY_HW_VTOR)
// Change IRQ vector table if configured differently
SCB->VTOR = MICROPY_HW_VTOR;
#endif
#endif
#endif
#if __CORTEX_M != 33
// Enable 8-byte stack alignment for IRQ handlers, in accord with EABI