The background is I simply run S32K3xx TCPIP STACK 1.0.2 Example Projects(lwip_s32k344).It works well in running mode and I can ping it correctly with PC.However, it stuck at "svc 0" in the function of prvPortStartFirstTask when I debug it with PME tools.
After some exploration,seems something is wrong with SVC_Handler interrupt.I tried different optimization and debug level and it does not work.The 3 interrupt handlers are defined in FreeRTOSConfig.h
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
Could anyome tell how to fix this when debugging?Attach the console log.
Hello,
The root cause of the issue is that RTD and FreeRTOS are both using SVC for different needs.
FreeRTOS uses SVC 0 only to start the first task, and does not use it after
RTD use SVC to switch between priviledged and user modes.
The first issue is they both implement a SVC Isr handler, and both use SVC 0.
The cleanest way to solve the issue is to merge the two SVC Isr handler into one that serves all SVC interrupts, and to change the FReeRTOS to use a SVC Id not used by RTD (RTD use SVC number 0 to 3).
A easiest work around can be to undefine MCAL_ENABLE_USER_MODE_SUPPORT. In this case, RTD do not use SVC anymore, but the whole software is run in priviledged mode.
Hope this will help !
Best regards,
David
Hello,David
I would like to try the easiest work around by undefining MCAL_ENABLE_USER_MODE_SUPPORT. Is it switched on/off by a button in configuration tools? I search the text such as "define MCAL_ENABLE_USER_MODE_SUPPORT" in .c and .h file and get no result.As for my demo project, I think the default setting should have aleady defined it.Could you tell the way to undine MCAL_ENABLE_USER_MODE_SUPPORT? Thanks
The MCAL_ENABLE_USER_MODE_SUPPORT is a symbol defined in the "C/C++ compiler" options of the project.
To implement the clean option :
- In the exceptions.c file (Platform RTD), add a case 4 in the SVCHandler main function as follow :
void SVCHandler_main(uint32 * svc_args)
{
uint32 svc_number; /* Stack contains: * r0, r1, r2, r3, r12, r14, the return address and xPSR */
/* First argument (r0) is svc_args[0] */
/* svc_args[6] = SP + 0x18 PC(r15) */
/* ((char *)svc_args[6])[-2]; = first two bytes, lsb, of the instruction which caused the SVC */
/* this will nto work if optimization compiler options are changed*/
svc_number = ((uint8 *)svc_args[6])[-2];
switch(svc_number)
{
case 1:
/* Handle SVC 01*/
ASM_KEYWORD("mov r0, #0x1"); /* Set User mode for Thread mode */
ASM_KEYWORD("msr CONTROL, r0");
break;
case 0:
/* Handle SVC 00*/
ASM_KEYWORD("mov r0, #0x0"); /* Set Supervisor mode for Thread mode */
ASM_KEYWORD("msr CONTROL, r0");
break;
case 2:
/* Handle SVC 02*/
Resume_Interrupts(); /* Resume all interrupts */
break;
case 3:
/* Handle SVC 03*/
Suspend_Interrupts(); /* Suspend all interrupts */
break;
case 4:
/* Handle SVC 04*/
vPortSVCHandler(); /* Suspend all interrupts */
break;
default:
/* Unknown SVC*/
break;
}
}
- At the beggining of the exceptions.c file (Platform RTD), add the prototype of vPortSVCHandler() as follow :
#ifdef MCAL_ENABLE_USER_MODE_SUPPORT
void SVCHandler_main(uint32 * svc_args);
extern void vPortSVCHandle (void);
void Suspend_Interrupts(void);
void Resume_Interrupts(void);
#endif
Then replace the "svc 0" line of the vPortStartFirstTask function of the portasm.s file by "svc 4".
Hi, dduminy
Thanks for your solution.I implement all steps in your solution.However,it failed to compile after "MCAL_ENABLE_USER_MODE_SUPPORT" is defined.It shows "startup_getControlRegisterValue is system.c is undefined".I attach the screenshot and the project I modified.Could you please tried the project? If possible, can you implement the solution in the project? Thanks a lot
Hi @zjldabing,
Could you try to re-test with the example attachment? (this is a Freertos example that was modified follow David's solution).
Best regards,
Dan
You have also to comment the line #define vPortSVCHandler SVC_Handler of the FreeRTOSCOnfig.h file
Thanks,David
It's a very clear explanation.I will try it
Hi,
I think it's on all demo project, the cause is that in the FreeRTOS we used (kernel 10.4.3 LTS patch 2) FreeRtos used the same SVC handler as the RTD so for now we just disable MCAL_ENABLE_USER_MODE_SUPPORT.
Another solution could be to modify FreeRTOS or RTD to used different SVC handler, but we don't try this solution can't help you more on this.
Sophie
Hello,
On our project we have some compatibility problem with Freertos and the RTD.
we have remove the define : MCAL_ENABLE_USER_MODE_SUPPORT from the compilation
and add a section in the linker file (*.icf)
define block codeBlock with fixed order { section .text, section .mcal_text, section .acmcu_code_rom, section CODE };
Sophie
Hi,Sophie
Does this mean adding MCAL_ENABLE_USER_MODE_SUPPORT can fix this debug issue?If so, what should I do step by step?I am a new leaner of S32DS and K344 chip
Thanks,Sophie
Is this a common issue with freertos demo project?I also tried FreeRTOS_Toggle_Led_Example_S32K344 and get the same problem when debugging.
I plan to integrate our product code based on a freertos demo.Is there a detailed solution so that I can debug?
Hi @zjldabing,
From my point of view, maybe this issue can due to the debugger.
Could you re-test with PE or Trace 32 debugger?
Best regards,
Dan
Hi @zjldabing,
You can refer to the same issues at those links:
https://community.nxp.com/t5/S32K/FreeRTOS-stuck-in-prvPortStartFirstTask/td-p/1418594
https://community.nxp.com/t5/S32K/FreeRTOS-Toggle-Led-Example-S32K344-stuck-in/m-p/1592950#M20422
Best regards,
Dan
Thanks, Dan
I have read these topics as soon as I met this issue.These topics does not point out the root cause.I tried some clues in it but get no luck.I have also tried Jlink debugger,but get the same issue...
Hi @zjldabing,
I remember that the FreeRTOS example was tested with Trace 32 debugger. Could you try to test the FreeRTOS example with this debugger? or if you don't have a Trace 32 debugger, could you send me your example?
Best regards,
Dan
Hi @zjldabing,
I ran your example successfully on both PE and Trace 32 debugger.
I'm using PE 5.1.7 version.
Best regards,
Dan
Hi, Dan
Your result reminds me if there is configuration difference between our PE debugger.I tried a lot of the setting one by one and get one setting at last.That's "Attach to Running Target" in the filed of runtime options.It can run well and the tasks switch as expected after enable that option.
It is a stange setting as it overwrite the option "set breakpoint at main".The program directly running instead of stop at the front of main as I usually debug.I am sure if your PE debugger have this option setting enabled.