cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G4, interrupt function delayed during flash write operation, interrupt vector table in ram, and interrupt function in ram. what am i doing wrong ?

Pchau.3
Associate II

I developed virtual eeprom function that is running fine. But when i write my interrupts are delayed. To avoid this delay, i decided to move all the code of the interrupt from flash to ram using linker script (i currently just toggle a pin in the interrupt):

 /* Initialized data sections into "RAM" Ram type memory */

 .data :

 {

   . = ALIGN(4);

   _sdata = .;       /* create a global symbol at data start */

   *(.data)          /* .data sections */

   *(.data*)         /* .data* sections */

   *(.RamFunc)       /* .RamFunc sections */ <------------

   *(.RamFunc*)      /* .RamFunc* sections */ <------------

   . = ALIGN(4);

   _edata = .;       /* define a global symbol at data end */

 } >RAM AT> FLASH

Also i moved interrupt vector table from flash to ram at the beginning of the code so i declared :

#define VECTORTABLE_SIZE       (118)   /* size of the used vector tables, see startup file  */
#define VECTORTABLE_ALIGNMENT  (0x200U) /* see programming manual */
 
/* externals from startup file */
extern u32 g_pfnVectors[VECTORTABLE_SIZE];       /* vector table ROM */
 
/* new vector table in RAM, same size as vector table in ROM */
u32 vectorTable_RAM[VECTORTABLE_SIZE] __attribute__(( aligned (VECTORTABLE_ALIGNMENT) ));

and then the code to copy the IVT called at beginning of main:

u32 i;
 for (i = 0; i < VECTORTABLE_SIZE; i++) {
   vectorTable_RAM[i] = g_pfnVectors[i];      /* copy vector table to RAM */
 }
 
 /* relocate vector table */
 __disable_irq();
   SCB->VTOR = (uint32_t)&vectorTable_RAM;
 __DSB();
 __enable_irq();

when i debug i can see that bit 29 of VTOR is 1 so it seems to work fine. When i stop i see that my interrupt is at a ram address in disassembly.

everything is running, no error but i have still the delay like i did nothing

i am stuck :expressionless_face: , i guess i am missing something

at the moment i just have an interrupt on timer update to toggle a pin and my virtual eeprom function in the main infinite loop, this function code is still running from flash.

1 ACCEPTED SOLUTION

Accepted Solutions
Pchau.3
Associate II

I finally found a solution here:

https://community.st.com/s/question/0D50X00009XkeYxSAJ/cpu-stalling-when-erasing-flash-on-stm32f405

All code related to flash operation must be located in ram too. So my virtual eeprom function is now in ram and also all HAL function like

HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data) __attribute__((section(".RamFunc")));
 
static void         FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data) __attribute__((section(".RamFunc")));
 
static void         FLASH_Program_Fast(uint32_t Address, uint32_t DataAddress) __attribute__((section(".RamFunc")));

i just put them all. i don't know which one are mandatory yet.

View solution in original post

1 REPLY 1
Pchau.3
Associate II

I finally found a solution here:

https://community.st.com/s/question/0D50X00009XkeYxSAJ/cpu-stalling-when-erasing-flash-on-stm32f405

All code related to flash operation must be located in ram too. So my virtual eeprom function is now in ram and also all HAL function like

HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data) __attribute__((section(".RamFunc")));
 
static void         FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data) __attribute__((section(".RamFunc")));
 
static void         FLASH_Program_Fast(uint32_t Address, uint32_t DataAddress) __attribute__((section(".RamFunc")));

i just put them all. i don't know which one are mandatory yet.