FRDM-K64F Context switching MSP & PSP

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

FRDM-K64F Context switching MSP & PSP

跳至解决方案
2,784 次查看
luisgarabo
Contributor II

Hi,

Do you have an example of FRDM-K64F Context switching MSP & PSP?

Thanks for your help,

标签 (1)
0 项奖励
回复
1 解答
1,965 次查看
CCandido
Contributor V

Hi Luis,

I tested it code not run, you can test.

stm32f4 - scheduler and stack - Electrical Engineering Stack Exchange 

thanks,

Carlos.

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,965 次查看
miduo
NXP Employee
NXP Employee

Hi,

Please make reference the MQX RTCS code, where in boot.s, the active stack pointer is set to PSP (set bit 1 of the CONTROL register). Then no need  do any manipulation of this bit. Cortex m4 itself automatically switches the active stack pointer to MSP in handler mode and switches back to PSP with exception return.

Here is the stack pointer switch code at <boot.s>

   /* Prepare process stack pointer */
   mrs r0, MSP
   msr PSP, r0

 

   /* Switch to proccess stack (PSP) */
   mrs r0, CONTROL
   orr r0, r0, #2
   msr CONTROL, r0
   isb #15
1,966 次查看
CCandido
Contributor V

Hi Luis,

I tested it code not run, you can test.

stm32f4 - scheduler and stack - Electrical Engineering Stack Exchange 

thanks,

Carlos.

0 项奖励
回复
1,965 次查看
luisgarabo
Contributor II

Thank you Carlos, Fang and Mark,

Your suggestions helped a lot. I implemented the code suggested by Carlos and I found that the priority for the PendSV call is set differently for the K64. I used the following:

NVIC_SetPriority(PendSV_IRQn, 0xF); //   Set PendSV to lowest possible priority

It works great!

Thanks!

Luis

0 项奖励
回复
1,965 次查看
mjbcswitzerland
Specialist V

Hi

You can study the FreeRTOS file /source/portable/GCC/ARM_MC4F/port.c to get some examples of such context switching.

Regards

Mark


uTasker developer and supporter (+5'000 hours experience on +60 Kinetis derivatives in +80 product developments)
Kinetis: http://www.utasker.com/kinetis.html