Hi all,
Recently i have made a flash driver and export it as a hex file,i take hexadecimal data in the file into a global array 'g_flashDriverRAM' and change the array g_flashDriverRAM to a function pointer.
Later i excute the function pointer to do erase flash and write flash funtion,it can work well.The flash memory can be modified as i want.However,when i copy the data in g_flashDriverRAM to a new array 'g_flashDriverRAM1' and change it to function pointer to excute,it case a hardfault. I have check that the data in g_flashDriverRAM is same as g_flashDriverRAM1,i can change g_flashDriverRAM to function pointer to excute erasing and writing flash function but can not work when i use g_flashDriverRAM1.
I also try to copy the data in g_flashDriverRAM to a assigned RAM address and change the assigned RAM address as a function pointer to excute,it also can not work.
The main different of g_flashDriverRAM and g_flashDriverRAM1 is that g_flashDriverRAM has initialized when declaration but g_flashDriverRAM1 does not initialize when declaration.I check the map file and found that g_flashDriverRAM is store in .data segment and g_flashDriverRAM1 is store in .bss segment.
Follow figure are some part of my code:
(1)define two array, g_flashDriverRAM is initialized and g_flashDriverRAM1 is not initialized
(2)check the map file after compliering,it can be found that g_flashDriverRAM is store in .data segment and g_flashDriverRAM1 is store in .bss segment.
(3)change the g_flashDriverRAM to function pointer and excute erasing and writing flash operation,it can work well,however when copy the data in g_flashDriverRAM to g_flashDriverRAM1 and do the same operation,it cause hardfault.
Is there anything i forget to configure or any fault operation i have made?Can you tell me how to solve this problem?
Thanks and Best Regard,
Leo
In your demo, the address pointed to by g_pFlashDriverAPIRAM is actually different, I think this is why the error occurred.
Hi Senlent,
By assigning different array pointer to g_pFlashDriverAPIRAM,i think it is right g_pFlashDriverAPIRAM have different address in this two situation.If you initialize g_flashDriverRAM1 like g_flashDriverRAM,it also can work normally.
please have a try below methods.
1.change pointer to same with g_flashDrvierRAM
g_pFlashDriverAPIRAM = (tFlashDriverAPIInfo *)g_flashDriverRAM1;
g_pFlashDriverAPIRAM->pfFLASH_DRV_EraseSector = (tpfFLASH_DRV_EraseSector) ((uint32)g_flashDriverRAM1-1+(uint32)(g_pFlashDriverAPIRAM->pfFLASH_DRV_EraseSector));
g_pFlashDriverAPIRAM->pfFLASH_DRV_Program = (tpfFLASH_DRV_Program) ((uint32)g_flashDriverRAM1-1+(uint32)(g_pFlashDriverAPIRAM->pfFLASH_DRV_Program));
2. try set g_flashDriverRAM to .data sector.
Define any initial value, which will allocate g_flashDriverRAM to the .data section
uint8_t g_flashDriverRAM1[1424] = {0,1,2,3,4};
I have tested the above two methods, but for some reason they are not successful every time.
could you please share this project so i can reproduce your problem.