LPC54628 MemFault not raised when calling function via pointer

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

LPC54628 MemFault not raised when calling function via pointer

跳至解决方案
872 次查看
mateuszkiełbasa
Contributor III

Hello, I'm working on NXP LPC54628 development board (ARM Cortex M4) and trying to configure MPU in a way that execute never (XN) flag is enabled on internal SRAM. I configured MPU and trying to call function from SRAM, e.g.

__RAMFUNC(SRAM_UPPER) static void function_to_be_executed(void)

{     

    /* do some nasty things here */

}

At this point everything works like a charm - MemFault is generated. But trying to call this function via pointer, e.g.

typedef void(*func)(void);

func f = function_to_be_executed;

f();

seems not to generate any exception. Is it normal? Am I missing something? From my POV in this case exception should also be generated,

标签 (1)
标记 (1)
0 项奖励
1 解答
856 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, mateusz

Regarding your question, I think the MPU functions no matter if you call it as a function as as a function pointer.

As you know that there is a backup or mirror in flash space for the void function_to_be_executed(void), pls check if the pointer f [which is defined as func f = function_to_be_executed] is located in flash address range or RAM range.

BR

Xiangjun Rong

在原帖中查看解决方案

0 项奖励
4 回复数
857 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, mateusz

Regarding your question, I think the MPU functions no matter if you call it as a function as as a function pointer.

As you know that there is a backup or mirror in flash space for the void function_to_be_executed(void), pls check if the pointer f [which is defined as func f = function_to_be_executed] is located in flash address range or RAM range.

BR

Xiangjun Rong

0 项奖励
849 次查看
mateuszkiełbasa
Contributor III

Hi,

According to debugger the function is actually running from SRAM. I've also tried to do second trial and moved the function to external flash (BOARD_SDRAM) via __TEXT() macro and result is the same... I mean running the function explicitly generates MemFault exception, but running the function via pointer doesn't.  That is really weird. How is it possible? I don't think there is MPU setting for that - it should simply work as is...

0 项奖励
840 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Regarding your question that the calling function can trigger MemManage Fault after MPU initialization, but calling function pointer can NOT trigger MemManage Fault, it is abnormal.

How about consulting ARM support? I have searched on google, no clue.

BR

XiangJun Rong

0 项奖励
830 次查看
mateuszkiełbasa
Contributor III

Hello,

It looks like setting correct TEX bits inside MPU->RASR register does the job. I have to study it further but basically it seems that everything works as expected. I'm marking your answer as a solution and going to invastigate it more deeply.

0 项奖励