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,
Solved! Go to Solution.
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
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
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.
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
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.