TC397 STM Interrupt and Pflash operation conflict

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
JexJiang
Level 3
Level 3
25 replies posted 5 questions asked First solution authored

Hi,

  I am going to write a bootloader project, the project has STM Interrupt function and pflash read and write functions. Before operating Pflash, call IfxCpu_disableInterrupts, after the operation, call IfxCpu_restoreInterrupts; then STM Interrupt cannot enter ISR again, and CPU0 enters the trap (IfxCpu_Trap_contextManagementError) state.

Trap state:

JexJiang_0-1641548678426.png

 

Pflash Code:

JexJiang_1-1641548739292.png

Pflash Code run PSPRAM.

0 Likes
1 Solution
JexJiang
Level 3
Level 3
25 replies posted 5 questions asked First solution authored

I found a bug. Because the operation pflsh is in CPU2, CPU0 still has code to execute, and then it enters this trap state, and the Pflash-related operations are moved into CPU0, and this trap is no longer generated.

View solution in original post

0 Likes
8 Replies
µC_Wrangler
Employee
Employee
50 solutions authored 100 sign-ins 25 likes received

Are you sure that writeFlash completes before it returns (FLASH0_FSR.BUSY=0)?  This type of problem is often due to PFLASH still being busy, which leads to a bus error, which causes a fetch from BTV (pointing to PFLASH), which causes another bus error, etc., etc.

0 Likes

Hi

     I sure that  eraseFlash and writeFlash completes defore it returns(FLASH0_FSR.BUSY=0).

     There is my code.

JexJiang_0-1641779134184.png

and i copy them to PSPRAM.

JexJiang_1-1641779179398.png

 

0 Likes
µC_Wrangler
Employee
Employee
50 solutions authored 100 sign-ins 25 likes received

Isn't the writePFLASH function still in PFLASH though?  That means that in between programming steps that are writing/erasing PFLASH, the code is still fetching instructions from PFLASH, which will result in a bus error.

Can you move writePFLASH into PSPR too? 

0 Likes

Hi:

          I don't understand why the writePflash function is in Pflash, because I copied it to PSPRAM using memcpy.

0 Likes
µC_Wrangler
Employee
Employee
50 solutions authored 100 sign-ins 25 likes received

I may have missed it, but I didn't see in the snippets you've provided that writePFLASH() was in PSPR.

If you step through it in a debugger, are you certain that the program counter is actually in PSPR, and not in PFLASH?  Sometimes the linker directives aren't quite right, and although the code is copied to PSPR, it's still being executed from PFLASH.

0 Likes
JexJiang
Level 3
Level 3
25 replies posted 5 questions asked First solution authored

I found a bug. Because the operation pflsh is in CPU2, CPU0 still has code to execute, and then it enters this trap state, and the Pflash-related operations are moved into CPU0, and this trap is no longer generated.

0 Likes
µC_Wrangler
Employee
Employee
50 solutions authored 100 sign-ins 25 likes received

Nice work figuring that out.  Developers also often miss the fact that other bus masters (CPUs, DMA, Ethernet, HSM) may be accessing PFLASH in the background.

0 Likes
JexJiang
Level 3
Level 3
25 replies posted 5 questions asked First solution authored

Yes,thanks for your reply.

0 Likes