Skip to content

cannot redirect flash's address to ram's address for execution in cc2650 launchpad #2725

@phituong

Description

@phituong

Hi guys,

I tried to copy a function from flash to ram in cc2650 launchpad. When it redirects to new address in RAM, the function is not called. Here is my code.
In linker script, RAM is configured with RWX, allowing code to be executed. I read document cc2650 and it allows RAM execution. https://www.ti.com/lit/ds/symlink/cc2650.pdf

This problem from Contiki-ng or MPU, MCU?

#include <stdio.h>
#include <string.h>
#include <stdint.h>

// Example function to be copied to RAM
void test_function(void) {
printf("Function running from RAM\n");
}

// Function to copy test_function to RAM and execute it
void run_from_ram(void) {
void (*ram_function)(void);
// Allocate space in RAM
uint32_t *ram_space = (uint32_t *)0x20000100; // Example RAM address

// Copy function to RAM
memcpy(ram_space, (void *)&test_function, 100);  // Adjust size as needed

// Cast RAM space to a function pointer and call it
ram_function = (void (*)(void))ram_space;
ram_function();  // **not redirecting to new address??????** 

}

int main(void) {
printf("Starting program...\n");

// Run the test function from RAM
run_from_ram();

printf("Program finished.\n");
return 0;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions