I had a question open which was perfectly solved in this Q&A .
As mentioned in my last comment, I didn't bring me a whole lot further. When I include freertos into my program, I get a mem fault when the first tasks is started when I compile with -fpic.
When I recompile without -fpic, the blink test runs fine.
I added two projects to this issue:
- MIMXRT1024_Project.zip : the project compiled WITH -fpic, which crashes on mem fault
- MIMXRT1024_Project.zip: the project compiled normally, without -fpic. Runs fine.
I would be very very grateful if you could help me and explain what I am doing wrong. I have tried so many things but I am getting nowhere. Moving got to ITC sram. DTC sram. Moving vector table into ITC/DTC sram. Leaving .got in flash. Nothing gives. I have the feeling that I am so close to a working solution, but I just can't find the culprit....
Solved! Go to Solution.
Hi @bp1979 ,
FreeRTOS will flush all CPU register by kernel, include R9. This is happened in first time start the task.
void vPortSVCHandler( void )
{
__asm volatile (
" ldr r3, pxCurrentTCBConst2 \n"/* Restore the context. */
" ldr r1, [r3] \n"/* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
" ldr r0, [r1] \n"/* The first item in pxCurrentTCB is the task top of stack. */
" ldmia r0!, {r4-r11, r14} \n"/* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */
" msr psp, r0 \n"/* Restore the task stack pointer. */
" isb \n"
" mov r0, #0 \n"
" msr basepri, r0 \n"
" bx r14 \n"
" \n"
" .align 4 \n"
"pxCurrentTCBConst2: .word pxCurrentTCB \n"
);
}
If without -fPIC, R9 is not used. So, this will not cause any problem. But if compile with -fPIC, R9 is used. So, you must recover R9.
Regards,
Jing
Hi @bp1979 ,
I haven't RT1024 board on hand. I only have a RT1064-EVK. So, I made a led-blinky demo. I put .got in flash. You can trace if R9 is really correct by stop at RestISR().
And please check if vector table is at right position.
Regards,
Jing
Hi @jingpan
The problem comes when i use freertos. Just blinking the pin already worked.
Could you try the project i attached and swap the cpu to whatever you have lying around there?
Hi @bp1979 ,
FreeRTOS will flush all CPU register by kernel, include R9. This is happened in first time start the task.
void vPortSVCHandler( void )
{
__asm volatile (
" ldr r3, pxCurrentTCBConst2 \n"/* Restore the context. */
" ldr r1, [r3] \n"/* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
" ldr r0, [r1] \n"/* The first item in pxCurrentTCB is the task top of stack. */
" ldmia r0!, {r4-r11, r14} \n"/* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */
" msr psp, r0 \n"/* Restore the task stack pointer. */
" isb \n"
" mov r0, #0 \n"
" msr basepri, r0 \n"
" bx r14 \n"
" \n"
" .align 4 \n"
"pxCurrentTCBConst2: .word pxCurrentTCB \n"
);
}
If without -fPIC, R9 is not used. So, this will not cause any problem. But if compile with -fPIC, R9 is used. So, you must recover R9.
Regards,
Jing
@jingpan thx. Already figured it out with help from freertos forum. Forgot to reply here. Thx though.!
The biggest problem i now have is debugging my app while offset in flash. I have another questions open for that. Would be really great if sonebody could help there.