AnsweredAssumed Answered

Unable use Segments, flash varibles

Question asked by Carl Norman on Aug 4, 2007
Latest reply on Aug 4, 2007 by CompilerGuru

This is confusing me, so i thought i would ask for some help.
I have to write some code to use a flash table for variables, and want to be able to address them using their names, and put the data in the required segment.

(forgive me, i am reasonably new to C programming and Codewarrior, my background is 99% assembly code)

I do want to stay away from using actual address references due to the complex nature of the data that will be stored in flash.

I have modified the PRM file to this:

/* This is a linker parameter file for the GP32 */

NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */

    ROM             =  READ_ONLY    0x9000 TO 0xFDFF;      //Moved from 0x8000 to 0x9000 to make room for flash data storage
    F_RAM           =  READ_ONLY    0x8000 TO 0x8FFF;      //Added read write block for flash data storage
    Z_RAM           =  READ_WRITE   0x0040 TO 0x00FF;
    RAM             =  READ_WRITE   0x0100 TO 0x023F;
    ROM_IMAGE       =  READ_ONLY    0xF000 TO 0xF2FF RELOCATE_TO 0x0180;

PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */
    DEFAULT_RAM                         INTO  RAM;
    DEFAULT_ROM, ROM_VAR, STRINGS       INTO  ROM; /*  In case you want to use  as well, be sure the option -OnB=b is passed to the compiler. */
    UserFlashData                       INTO  F_RAM;
ToCopyToRAM                         INTO  ROM_IMAGE;


VECTOR 0 _Startup /* Reset vector: this is the default entry point for an application. */
C Code

#include <hidef.h>                /* for EnableInterrupts macro */
#include "derivative.h"           /* include peripheral declarations */

#pragma DATA_SEG UserFlashData
char FlashByte1 = 0x08;                  //Byte to be stored in UserFlashData, initialise to 0x08

void main(void) {

 char* pFlash = (char*)&__SEG_START_UserFlashData

 //two ways of writing the same byte of flash to PTA (0x0000)

    PTA = *pFlash;  
PTA = FlashByte1;

//I realize this code is completely useless and doesn’t do anything, but just wanted to illustrate what i am having problems with

When i compile this code, the assemble code is (PTA is at address 0x0000 on 68HC908GP32)
mov #0x08,0x00
(i want) it to be:
lda   0x8000
sta   0x00

I have tried many variants to this idea, and cannot get it to compile with the right assembly code.

I am only using the simulator at this point for testing, I have simulated my write/erase flash routines running from RAM with no problems, but now that im trying to actually modify data and use it from flash, i am having all sorts of problems.

All i want to be able to do is use the references to address varibles in flash (segments) using references, to create a table of variables in Flash, but not having and luck understanding how this all works.