FreeRTOS stuck at "svc 0" in function of prvPortStartFirstTask in debug mode

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

FreeRTOS stuck at "svc 0" in function of prvPortStartFirstTask in debug mode

9,948 次查看
zjldabing
Contributor II

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.

 

标记 (1)
0 项奖励
回复
21 回复数

9,706 次查看
dduminy
Contributor I

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

0 项奖励
回复

9,486 次查看
zjldabing
Contributor II

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

0 项奖励
回复

9,480 次查看
dduminy
Contributor I

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

 

 

0 项奖励
回复

9,314 次查看
zjldabing
Contributor II

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 

0 项奖励
回复

9,049 次查看
nxf78987
NXP Employee
NXP Employee

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

0 项奖励
回复

9,479 次查看
dduminy
Contributor I

You have also to comment the line #define vPortSVCHandler SVC_Handler of the FreeRTOSCOnfig.h file

0 项奖励
回复

9,688 次查看
zjldabing
Contributor II

Thanks,David

It's a very clear explanation.I will try it

0 项奖励
回复

9,800 次查看
zjldabing
Contributor II

I found some simliar topics and almost all end without unambiguous solution.

Can anyone help on this?It stops me from in-depth working as the debug mode is not work..

标记 (3)
0 项奖励
回复

9,817 次查看
sobo
Contributor III

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

0 项奖励
回复

9,845 次查看
sobo
Contributor III

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

 

0 项奖励
回复

9,798 次查看
zjldabing
Contributor II

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

0 项奖励
回复

9,830 次查看
zjldabing
Contributor II

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?

0 项奖励
回复

9,796 次查看
nxf78987
NXP Employee
NXP Employee

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

0 项奖励
回复

9,784 次查看
zjldabing
Contributor II

Hi , Dan

 

Actually,I am using PE debugger with this issue.I does not have the trace 32 in my hand.

0 项奖励
回复

9,771 次查看
nxf78987
NXP Employee
NXP Employee
0 项奖励
回复

9,763 次查看
zjldabing
Contributor II

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

0 项奖励
回复

9,759 次查看
nxf78987
NXP Employee
NXP Employee

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

0 项奖励
回复

9,732 次查看
zjldabing
Contributor II

Hi, Dan

Attach the project as I do not have the S32 trace.If you also have a PE debugger,you can double check debugging with it.Thanks a lot.

9,723 次查看
nxf78987
NXP Employee
NXP Employee

Hi @zjldabing,

I ran your example successfully on both PE and Trace 32 debugger.

I'm using PE 5.1.7 version.

nxf78987_0-1682667317102.png

Best regards,

Dan

标记 (1)
0 项奖励
回复

9,698 次查看
zjldabing
Contributor II

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.

0 项奖励
回复