Jumping to RAM and executing function

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

Jumping to RAM and executing function

531 次查看
ED8500
Contributor I

Hi all,

Running on a LPC55S69JBD100. The application is running fine, but as soon as I want to jump to a function residing in RAM I get a bus fault.

The RAM section is created in the linker file, the function resides in that section says the .map file, and checking the function address at runtime is indeed in that RAM section. Defined a function pointer to that function but as soon as code wants to jump to that address, I get:

[ERROR] (           startup.c)(              BusFault_Handler @105) : Busfault! f0002

So I'm missing something or doing things wrong.

Just to keep it simple, the function in RAM only sets a variable, no more than that. So that I can focus on the jump to a RAM function.

Would there be any example in the SDK? Already searched for it, but couldn't find something related...

Thanks in advance!

0 项奖励
回复
3 回复数

504 次查看
frank_m
Senior Contributor III

First, I don't know the LPC55S69 particularly well, nor do I have an eval board with this MCU.

But I suppose you have checked the MCU reference manual, and confirmed that the RAM section in question is really connected to the I-Bus, haven't you ?
I know of MCUs were some RAM sections are connected to I- and D-Bus, and others are only to the D-Bus.

0 项奖励
回复

508 次查看
ED8500
Contributor I

Great, thank you Paval. Here's what I did: in the memmap linker file I created a new section:

MEMORY
{
...
ramfunction (rwx) : ORIGIN = 0x20043000, LENGTH = 0x01000  /* 4K bytes for storing functions */
}
...
__ramfunction_start__ = ORIGIN(ramfunction);
__ramfunction_length__ = LENGTH(ramfunction);
__ramfunction_end__ = __ramfunction_start__ + __ramfunction_length__; /* 4KB */
 
The map file says all is well:
0x0000000020043000 __ramfunction_start__ = ORIGIN (ramfunction)
0x0000000000001000 __ramfunction_length__ = LENGTH (ramfunction)
0x0000000020044000 __ramfunction_end__ = (__ramfunction_start__ + __ramfunction_length__)
...
.ramfunction_sect
0x0000000020043000 0x1c
*(.ramfunction_sect)
.ramfunction_sect
0x0000000020043000 0x1c CMakeFiles/.../myfile.c.obj
0x0000000020043000 ramFunction
...
Created a simple function just to have a bit of body:
__attribute__((section(".ramfunction_sect"))) void ramFunction(void) {

    uint32_t cnt = 0;
    while(cnt < 50000) {
        cnt++;
    }
    while (1) {
        ;;
    }
}
And then I call it from (flash) code to that function:
            LOG_INFO("Leaving flash area...");
            LOG_INFO("++ramFunction: 0x%08x", &ramFunction);
            func_ptr = ramFunction;
            func_ptr();
            // We should never get here...
 
That results in this output:
[ INFO] (managestoragespace.c)(handleRequest @258) : Leaving flash area...
[ INFO] (managestoragespace.c)(handleRequest @259) : ++ramFunction: 0x20043001
[ERROR] ( startup.c)( BusFault_Handler @105) : Busfault! f0002
 
The datasheet says I'm in SRAM4, and the function is not accessing anything outside that bank (at this point):
ED8500_0-1706776204641.png

FYI: toolchain is gcc and cmake, I'm not using MCUXpresso. But if there would be some kind of example somewhere, encapsulated in a MCUXpresso project, that would be neat.

Thanks in advance!

0 项奖励
回复

516 次查看
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello, my name is Pavel, and I will be supporting your case, I need more information, what is the location you need to get access? could you elaborate further about it? consider using an image if necessary.

Best regards,
Pavel

0 项奖励
回复