This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
I'm having issues performing F021 API flash writes. I initialize the flash banks clock successfully, set the active flash bank, enable the bank sectors all as described by the flash API, but when I get to performing the flash write, using Fapi_issueAsyncCommandWithAddress, the program gets stuck in prefetchEntry.
I'm suspecting it's related to the mode I'm in. I'm using HalCoGen generated code and based on my understanding it puts you into User mode after initialization. The flash API explicitly says that flash operations must be performed in Privileged mode, and I know you can set the mode through the CPSR register. The issue is that not so strong with assembly, and can't seem to find good TI examples on how to do that. All the responses I've seen so far point me to the ARM reference manual, which is not really helpful in my case. I saw CPSR Register and Interrupt Intrinsics section in the ARM Optimizing C/C++ Compiler v18.12.0.LTS User Guide, but I didn't see an intrinsic for setting the mode.
Could someone please show me an example on how to do it? Again, I'm just suspecting that this is the issue, so I'll take any pointers from anyone else here about what the issue could be.
Thanks!
Hi,
You are right, the flash operations must be performed in Privileged mode. If you use the HALCogen generated code, the CPU is in system mode after startup:
; Switch to System Mode ( Shares User Mode registers ) (M = 11111)
cps #31
mov lr, r0
mrs r1,cpsr
msr spsr_cxsf, r1
_coreInitRegisters_() in sys_core.asm is a good example to change the device mode.
What is the CPSR value after the code gets stuck?
Please refer to the bootloader about the flash operation: erase, and write.
Thanks for the response.
So for testing purposes I stuck another assembly function in sys_core.asm, I know it shouldn't be there, so once it works I will move it elsewhere. Anyway, I added the following code:
.def _setPrivilege_ .asmfunc _setPrivilege_ ; Switch to Privilege Instruction Mode (M = 10011) cps #19 mov lr, r0 mrs r1,cpsr msr spsr_cxsf, r1 .endasmfunc
I call that function right after Main, but that does not do anything to the M bits in the CPSR register.
To answer your other question, after the code gets stuck the CPSR value is 10111 (Abort).
Ok, rookie mistake.
I changed the assembly code to the following:
.def _setPrivilege_ .asmfunc _setPrivilege_ ; Switch to Privilege Instruction Mode (M = 10011) mov r0, lr cps #19 mrs r1,cpsr msr spsr_cxsf, r1 bx r0 .endasmfunc
And now I'm able to enter Privilege Mode.
Looks like I'm still having issues writing to flash though, stay tuned. Just wanted to give this quick update so you don't waste keystrokes correcting my mistake.
Thanks.
Alright, so it seems that there's very unstable behavior with Fapi_setActiveFlashBank command.
All that's different in the code now is that I added my _setPrivilege_(); function after calling Fapi_enableMainBankSectors (which is called after Fapi_setActiveFlashBank). With this added, I am NOT getting out of Fapi_setActiveFlashBank it's stuck in prefetchEntry with CPSR register at value 0x80000397.
Hello,
When you program the data to flash using flash API, do you program the ECC at the same time? Please refer to the flash API example code in TI CAN/UART bootloader.