relocating code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

relocating code

Jump to solution
752 Views
martinpi
Contributor III

Hello everyone!

 

I am trying to locate code partially in flash and partially in RAM.

I found AN4329 which explains how to do it.

 

There are two ways to do it:

  • __declspec()
  • #pragma section xxx begin / end

 

I copied the code examples from AN4329 into main.c and into the lcf-file of an empty bareboard project.

 

With the __declspec() I get a  compiler error "illegal type qualifier(s)", both in the function prototype and in the function itself.

Interestingly, in the kinetis_sysinit.c, __declspec() is used to tie the exception table to the vectortable section.

I can compile kinetis_sysinit.c without problems.

This is contary to AN4329, as it says that it is not possible to use __declspec() to relocate data (page 9).

 

 

When I tried the #pragma version, I was able to compile and link. But the code is placed into the .text section as usual, ignoring my section directive. I can see this in the xmap file. The function which I want to relocate is where it would normally be, and in the memory map I see that the section which should hold the function is empty (size=0).

 

Please help!

Regards, Martin

Labels (1)
0 Kudos
1 Solution
424 Views
martinpi
Contributor III

I found the answer!

As it might be interesting for other people as well, here is the solution:

1) Don't copy&paste code from a pdf document into your code.

I copied code from AN4329 into my code which did not work.

At some point, I noticed that the section definition ".MY_SECTION" was black instead of blue.

Erased the quotation marks and typed them manually, now they are blue.

The quotation marks are not recognized as quotation marks, and to make it worse, when they appear in a pragma statement there is no syntax error. The pragma statement is simply ignored and you get a totally uncomprehensible error message when you try to refer to that previous pragma.

In my case: the section definition had the wrong quotation marks

The __declspec referring to the previously (not) defined section produced an error

2) Don't put the function in main.c

It was just a little test program.

A small function which resides in the same file as the calling function is optimized away (function inlining).

The section definition is ignored without notice.

View solution in original post

0 Kudos
1 Reply
425 Views
martinpi
Contributor III

I found the answer!

As it might be interesting for other people as well, here is the solution:

1) Don't copy&paste code from a pdf document into your code.

I copied code from AN4329 into my code which did not work.

At some point, I noticed that the section definition ".MY_SECTION" was black instead of blue.

Erased the quotation marks and typed them manually, now they are blue.

The quotation marks are not recognized as quotation marks, and to make it worse, when they appear in a pragma statement there is no syntax error. The pragma statement is simply ignored and you get a totally uncomprehensible error message when you try to refer to that previous pragma.

In my case: the section definition had the wrong quotation marks

The __declspec referring to the previously (not) defined section produced an error

2) Don't put the function in main.c

It was just a little test program.

A small function which resides in the same file as the calling function is optimized away (function inlining).

The section definition is ignored without notice.

0 Kudos