LPC54628 MemFault not raised when calling function via pointer

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC54628 MemFault not raised when calling function via pointer

Jump to solution
842 Views
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,

Labels (1)
Tags (1)
0 Kudos
1 Solution
826 Views
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

View solution in original post

0 Kudos
4 Replies
827 Views
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 Kudos
819 Views
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 Kudos
810 Views
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 Kudos
800 Views
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 Kudos