S32K312 Flash Driver can not run in RAM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K312 Flash Driver can not run in RAM

1,151 Views
Leo_99
Contributor II

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

Leo_99_0-1695606146338.png

 

(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.

Leo_99_2-1695606293617.png

Leo_99_3-1695606324984.png

 

(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.

Leo_99_4-1695606597815.png

Leo_99_5-1695606617814.png

 

    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

 

 

 

 

Tags (3)
0 Kudos
Reply
5 Replies

1,101 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Leo_99

In your demo, the address pointed to by g_pFlashDriverAPIRAM is actually different, I think this is why the error occurred.

Senlent_2-1695629970259.png

 

Senlent_3-1695629975066.png

 

 

 

0 Kudos
Reply

1,097 Views
Leo_99
Contributor II

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.

0 Kudos
Reply

1,063 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Leo_99

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));

Senlent_2-1695690029991.png

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. 

0 Kudos
Reply

1,133 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Leo_99

could you please share this project so i can reproduce your problem.

0 Kudos
Reply

1,122 Views
Leo_99
Contributor II

Hi Senlent,

    The attachment of this message is my project,you can used it to reproduce the problem.

     You can use the three line code to operate flash normally.

Leo_99_0-1695612812685.png

 

     You can use the three line code to reproduce the problem.

Leo_99_1-1695612909103.png

 

0 Kudos
Reply