My company has been using Freescale (HCS12X) parts for more than 10 years with CodeWarrior development.
We now want to use the Kinetis KE06Z part for a new lower code development. I have the FRDM-KE06Z board and have code running on it, using the CodeWarrior Development Studio V1.06. But as I progress I'm running into troubles.
My problem today started with the support or lack of support for #pragma. My research so far suggests there is NO SUPPORT for "#pragma DATA_SEG", for example. Is this true?
I want to place variables into specific memory locations so that both the normal project software, and the bootloader, can access the same data. How do I do this - in the past I used the DATA_SEG and then set up the linker to place that segment somewhere specific.
If no support for DATA_SEG, what is the alternative?
Documentation online is very confusing perhaps due to the Freescale / NXP business but also because there seems to be two separate development systems (the other is Kinetis Design Studio I think).
I wonder if I have chosen the wrong dev suite - where is any helpful information on which is the better choice, what the differences are, etc?
In any case does Kinetis Design Studio support "#pragma DATA_SEG"?
Thank you.
Ian Cull. PG Trionic Inc
Essex, MA, USA
Solved! Go to Solution.
Hi Ian,
things are a bit different in GNU/gcc/ld land. So yes, there is no such pragma CODE_SEG or DATA_SEG. Pragmas are very compiler specific.
But there is the very flexible __attribute__ in GNU land, e.g.:
static unsigned char __attribute__((section (".mySection"))) ucHeap[configTOTAL_HEAP_SIZE];
Additionally, you need to understand a bit the GNU linker file. Maybe have a look here which discusses a specific case how to allocate a variable in a special section:
FreeRTOS Heap with Segmented Kinetis K SRAM | MCU on Eclipse
Related on that topic, this might be helpful too: Defining Variables at Absolute Addresses with gcc | MCU on Eclipse
I hope this helps,
Erich
Hi Ian,
things are a bit different in GNU/gcc/ld land. So yes, there is no such pragma CODE_SEG or DATA_SEG. Pragmas are very compiler specific.
But there is the very flexible __attribute__ in GNU land, e.g.:
static unsigned char __attribute__((section (".mySection"))) ucHeap[configTOTAL_HEAP_SIZE];
Additionally, you need to understand a bit the GNU linker file. Maybe have a look here which discusses a specific case how to allocate a variable in a special section:
FreeRTOS Heap with Segmented Kinetis K SRAM | MCU on Eclipse
Related on that topic, this might be helpful too: Defining Variables at Absolute Addresses with gcc | MCU on Eclipse
I hope this helps,
Erich
Many thanks, and fast! That "Defining Variables at Absolute Addresses with gcc" looks like it might be very much what I need, I'll try modifying my pragmas to match and see how it goes.
With that help, I'm done :smileyhappy:
In the linker file, I split off 16 bytes of memory:
MEMORY
{
m_data (rwx) : ORIGIN = 0x1FFFF800, LENGTH = 8K - 16 /* SRAM */
m_fixedboot (rwx) : ORIGIN = 0x200017F0, LENGTH = 16 /* SRAM */
}
And I set up a new section to fill it:
.FIXEDBOOT_DATA :
{
*(.FIXEDBOOT_DATA1)
*(.FIXEDBOOT_DATA2)
*(.FIXEDBOOT_DATA3)
} > m_fixedboot
And in the memory definitions C code I labeled the variables (I did it this way in three section attributes since the order appeared unpredictable if I just put all in the same section):
byte __attribute__((section (".FIXEDBOOT_DATA1"))) ramFlashCodes[4];
byte __attribute__((section (".FIXEDBOOT_DATA2"))) ramResetData[4];
longword __attribute__((section (".FIXEDBOOT_DATA3"))) ramPowerUpCheck;
Perfect, thanks.
HI Ian
Like you, our company has used HSC12X for years and I am getting to grips with Kinetis for a new project (specifically the KL26).
As you noted, there is no direct equivalent of the #pragma DATA_SEG.
The downside of the method you have used is that you have to insert the __attribute__ ((section(".mydata"))) statement into every declaration for constants.
The alternative is to use the linker file to put all constant data from a given source file into the specified memory area as follows:
1. Put your constant data into a separate source file. In my project, it's called "changer_data.c"
It can be defined simply as "const byte ramFlashCodes[4];" etc.
2. in the MEMORY{} block define a segment of memory where the data will be stored.
E.g. m_changer_data (R) : ORIGIN = 0x00003600, LENGTH = 0x00001000
3. In the SECTIONS{} segment, add a statement that directs all output from the source file with the constant data to this segment. E.g.
.m_changer_data_seg :
{
. = ALIGN(4);
*changer_data.o (.rodata .rodata*)
. = ALIGN(4);
} > m_changer_data
This will take all the compiled output from "changer_data.c" and link it into the m_changer_data area of memory.
I got this from another post by Eric Styger at Putting Code of Files into Special Section with the GNU Linker | MCU on Eclipse
Hope this helps