Quantcast

Executing code from RAM

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Executing code from RAM

Tomek Lorek
Hi,
I'd like to make some functions to be executed from RAM. There are
some nice examples of how this can be done in CCS (e.g
http://embedded-funk.blogspot.com/2013/11/running-c-function-in-ram-on-msp430.html)
but the syntax of TI linker's .cmd file is not compatibile with GNU ld
(specifically the load and run parts of ".ram_code : load =
FLASH_RAM_CODE, run = RAM_CODE" makes ld to raise the syntax error).

Suppose you have a app() function:

__attribute__((section(".app_main")))
void app() {
  // body
}

The code needs to be copied from flash (position forced with
__attribute__((section(".mysection")))) to RAM (with memcpy), but
assuming they have the same name how to make the microcontroller run
the copied function from RAM not the original one from flash when
called app();
?

Thanks in advance!

Best Regareds,
Tomek

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Executing code from RAM

Tomek Lorek
> Suppose you have a app() function:
>
> __attribute__((section(".app_main")))
> void app() {
>   // body
> }

Copy-paste error: it should be
__attribute__((section(".mysection")))
void app() {
  // body
}

this is aligned with "position forced with
__attribute__((section(".mysection")))"

Best Regards,
Tomek

2014-04-18 10:53 GMT+02:00 Tomek Lorek <[hidden email]>:

> Hi,
> I'd like to make some functions to be executed from RAM. There are
> some nice examples of how this can be done in CCS (e.g
> http://embedded-funk.blogspot.com/2013/11/running-c-function-in-ram-on-msp430.html)
> but the syntax of TI linker's .cmd file is not compatibile with GNU ld
> (specifically the load and run parts of ".ram_code : load =
> FLASH_RAM_CODE, run = RAM_CODE" makes ld to raise the syntax error).
>
> Suppose you have a app() function:
>
> __attribute__((section(".app_main")))
> void app() {
>   // body
> }
>
> The code needs to be copied from flash (position forced with
> __attribute__((section(".mysection")))) to RAM (with memcpy), but
> assuming they have the same name how to make the microcontroller run
> the copied function from RAM not the original one from flash when
> called app();
> ?
>
> Thanks in advance!
>
> Best Regareds,
> Tomek

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Executing code from RAM

Peter Bigot-4
On Fri, Apr 18, 2014 at 3:55 AM, Tomek Lorek <[hidden email]> wrote:

>> Suppose you have a app() function:
>>
>> __attribute__((section(".app_main")))
>> void app() {
>>   // body
>> }
>
> Copy-paste error: it should be
> __attribute__((section(".mysection")))
> void app() {
>   // body
> }
>
> this is aligned with "position forced with
> __attribute__((section(".mysection")))"
>
> Best Regards,
> Tomek
>
> 2014-04-18 10:53 GMT+02:00 Tomek Lorek <[hidden email]>:
>> Hi,
>> I'd like to make some functions to be executed from RAM. There are
>> some nice examples of how this can be done in CCS (e.g
>> http://embedded-funk.blogspot.com/2013/11/running-c-function-in-ram-on-msp430.html)
>> but the syntax of TI linker's .cmd file is not compatibile with GNU ld
>> (specifically the load and run parts of ".ram_code : load =
>> FLASH_RAM_CODE, run = RAM_CODE" makes ld to raise the syntax error).
>>
>> Suppose you have a app() function:
>>
>> __attribute__((section(".app_main")))
>> void app() {
>>   // body
>> }
>>
>> The code needs to be copied from flash (position forced with
>> __attribute__((section(".mysection")))) to RAM (with memcpy), but
>> assuming they have the same name how to make the microcontroller run
>> the copied function from RAM not the original one from flash when
>> called app();

Without looking at the example code you cited: don't give them the same name.

In general, create a pointer-to-function and invoke through it.

  void (* fp)() = ram_where_code_copied;
  fp();

Peter

>> ?
>>
>> Thanks in advance!
>>
>> Best Regareds,
>> Tomek
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/NeoTech
> _______________________________________________
> Mspgcc-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Loading...