Hi,
I'm trying to place a variable in an absolute flash location. Target is S12ZVM and I'm using codewarrior.
For this, I modified the .prm file as below:
In “SEGMENTS” defined “ROM_VAR_SPACE” (I selected small part of FLASH);
Then in “PLACEMENT” told linker, ROM_VAR data must be placed to ROM_VAR_SPACE.
Then in main.c ,
When I am trying to access the buffer[0] from main function, I am getting the below error.
But I am able to access buffer[1]. No issues are occurring at that time. Could you please tell me why this is happening.
I have attached my .prm and main.c.
Hi AjRj14,
This is caused by internal CodeWarrior compiler – it wants to optimize the organization of the code in FLASH.
If the CONST_SEG is used the compiler can’t optimize this section and musts write the constant (your variable in fact) into FLASH to specified place.
I have tested the next format how to set-up this feature:
------------------------------------------
SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
RAM = READ_WRITE 0x001000 TO 0x001FFF;
ROM = READ_ONLY 0xFF8000 TO 0xFFFCFF;
MY_ROM_VAR_SPACE = READ_ONLY 0xFFFD00 TO 0xFFFDFF;
END
PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */
_PRESTART, /* Used in HIWARE format: jump to _Startup at the code start */
STARTUP, /* startup data structures */
ROM_VAR, /* constant variables */
STRINGS, /* string literals */
NON_BANKED, /* runtime routines which must not be banked */
DEFAULT_ROM,
COPY INTO ROM;
MY_ROM_VAR INTO MY_ROM_VAR_SPACE;
DEFAULT_RAM /* all variables, the default RAM location */
INTO RAM;
END
-------------------------------
And in main.c:
----------------------------------
/* MODULE main */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
/* User includes (#include below this line is not maintained by Processor Expert) */
volatile dword my_Variable;
/* Write your local variable definition here */
#pragma CONST_SEG MY_ROM_VAR
const volatile dword ROM_Volatile = {0x12341234};
#pragma CONST_SEG DEFAULT
void main(void)
{
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
my_Variable = ROM_Volatile;
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
-------------------------------
The changes are implemented in the PE example project – the yellow marked rows.
Please use it as example for your settings.
I hope it could help you.
Best Regards,
Stano.