Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
phituong opened this issue Aug 26, 2024 · 0 comments

Comments

@phituong
Copy link

phituong commented Aug 26, 2024

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;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@phituong and others