S12X read paged flash 78 ( 0x780000 0x783FFF)

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

S12X read paged flash 78 ( 0x780000 0x783FFF)

Jump to solution
2,783 Views
firefox0005
Contributor I

Hi All,

 

I m trying to read the page  0x00780000 to 0x00783FFF ( global Address ) and calculate the CRC16 of the flash memory

 

 

#define FLASH_START_ADDR     0x00780000
#define FLASH_END_ADDR      0x00783FFF

 the function calculate every 64 bytes the crc and go out from the function again

 

void Flash_CalcCRC(void)
{
 // Puffer Zeiger auf aktuelles Byte mit Startadresse initialisieren

        static T_UC08* pucBuffer = (T_UC08*) FLASH_START_ADDR; // <-- wrong content

 // berechne nur ein Teil des Flashes
 T_UI16 uiBytesCounter = 0;
 // Temporäre Variable
 T_UI16 uiCryptPos = 0;

 // nur eine gewisse Anzahl an Byte berechnen und die Funktion wieder verlassen
 for (ulNumLoops ; (ulNumLoops <= FLASH_END_ADDR) && (uiBytesCounter < 64 ); ulNumLoops++)
 {
  // Bytes Zähler inkrementieren
  uiBytesCounter++;
  // Word aus Puffer in uiCryptPos kopieren
  uiCryptPos = (T_UI16) *pucBuffer; // also wrong
  // Pufferzeiger inkrementieren
  pucBuffer++;
  // EXOR mit RückgabeCRC
  uiCryptPos ^= uiFlashCRC16;
  // CryptArrays einrechnen
  uiFlashCRC16 = *(T_UI16*)(uiCRC16l + (uiCryptPos & 0x000F)) ^
       *(T_UI16*)(uiCRC16h + ((uiCryptPos & 0x00F0) >> 4)) ^
       (uiFlashCRC16 >> 8);
 }

 if ( ulNumLoops == FLASH_END_ADDR )
 {
  ucFinishFlag = 1;
  Flash_SetCRC16(uiFlashCRC16);
 }
}

 MY PROBLEM is, when I try to read the flash memory, see uiCryptPos or *pucBuffer, in the debug modus, the content of memory is wrong! 

 

My function works very good, when I calculate the page  at start address 0x007F4000 to 0x007F7FFF

 

I dont know what to do and there is no help in the web concerning my problem.

 

thanks for help in advance

 

best regards

Labels (1)
0 Kudos
1 Solution
776 Views
Pedro_
Contributor III

Hi,

global addresses in Cosmic require the modifier @gpage, you can try something like this:

 

/* gpage pointer allows accessing any area of global map, paged and non paged */ 

@far @gpage unsigned int uiMP @0x00FB8000;

@far @gpage unsigned int *puiMP;

 

*puiMP = &uiMP; 

 

while (puiMP < (@far @gpage unsigned int*) 0x00FBBFFF)

{

   uiCryptPos = *puiMP;

 

   /* Here you calculate your CRC and then increment the pointer */

 

   puiMP ++;
}

 

I hope it works.

 

View solution in original post

0 Kudos
9 Replies
776 Views
CrasyCat
Specialist III

Hello

 

if the address you specify is a global address you need to define and cast the pointer as a far pointer.

 

static T_UC08 *far pucBuffer = (T_UC08 *far) FLASH_START_ADDR;

 

This should work better

 

CrasyCat

0 Kudos
776 Views
firefox0005
Contributor I

hello CarsyCat,

 

thanks for reply, I change it but It doesnt wor, now I get the content of the address 4000

 

While creating the S19 File, I get the error

 

S2060F800000006AError:(9) S-Record Data Not In Specified Memory Map

 

 

maybe the is something wrong with the address F80000

I dont really know

 

another question, what about if I m working with the pages address E08000 - E0BFFF

 

thanks a lot for the answer

Message Edited by firefox0005 on 2009-10-26 02:26 PM
0 Kudos
776 Views
kef
Specialist I

Hm, with CraseCat suggestion my CW5.0 copy properly reads from global 0x780000.

 

What tool gives you error about S-Record not in specified memory map? Is it Sreccvt?

 

Don't understand you question about paged (logical) E08000. Do you want to read data from there? Then convert paged E08000 to global as E0*4000 + 8000-8000 + 400000 = 780000

 

where *4000 is mul by page size

-8000 is remove page window ofset

+400000 - start of PPAGE-memory in global memory map

0 Kudos
776 Views
firefox0005
Contributor I

 

 

Hi Kef, Hi CrasyCat,

 

first thanks so much for your answer!!!

 

to Kef:

I m working with the cosmic Compiler Ver 4.7.10 and the codewarior debugger with the IndartOne

the s19 File is creating with the SRecCvt v1.0.26 and the command in the Makefile is:

 

$(SRECCVT) -gmb 400000 -m 780000 7FFFFF 8 -ob -o List/BANKED.s19 List/$(PROJEKT_NAME).s19

here is the Error:

 

 

SRecCvt v1.0.26

Converting S-Record File: List/Gallenschuetz.s19

S2060F8000C000AA
Error:(9) S-Record Data Not In Specified Memory Map

 the s19file is shown like:

 

 
S01900004C6973742F47616C6C656E7363687565747A2E783132B9
S2060F8000C000AA
S2247EC0000A722004F62004C10A2609CC04001662CF7920040A1D21431FFC21418C000A2572
S2247EC020081C2143011879214118722141FC213F8C003225081C2143021879213F187221B0
S2247EC0403FFC213D8C006425081C2143041879213D1872213DFC213B8C03E825081C2143D0
S2247EC060081879213B1872213BFC21398C177025081C2143101879213918722139CC0001A0
S2247EC0801662CF0A1C0002401D0000400A0A0AF62005260B1C000040C6017B200520071DA0
S2137EC0A0000040792005F60000C4407B21460A4A
S2247F4000CF3FFF180BFD0016180B200011180BFF0030CEC104ED31A63427372A021A02857D
S2247F4020602604ED1E20F034972B10B764A31EEE1C180A703004B4F93020DCEC1E3B180D62
S2247F40401B0010EE1CE670186B30AD8025F7303020C5CE2137C720026C318E2E6625F9180C
...
...
...

concerning the memory Error in the CRC function:

I have tried it both with the paged and global adress an no one works

 

/// Flash Start Adresse
//#define FLASH_START_ADDR   0x00FB8000 // paged
#define FLASH_START_ADDR    0x007EC000 // global

/// Flash End Adresse
//#define FLASH_END_ADDR   0x00FBBFFF // paged
#define FLASH_END_ADDR    0x007EFFFF // global

 and the function is:

 

void Flash_CalcCRC(void)
{
 // Puffer Zeiger auf aktuelles Byte mit Startadresse initialisieren

 // for paged addressing
 //static T_UC08* pucBuffer = (T_UC08*) FLASH_START_ADDR;

 // for global addressing
 static T_UC08 *_atfar pucBuffer = (T_UC08 *_atfar) FLASH_START_ADDR;

 // calculate only a part of flash
 T_UI16 uiBytesCounter = 0;
 // Temp Var
 T_UI16 uiCryptPos = 0;

 // calculate just 64 bytes every time and go out from function
 for (ulNumLoops ; (ulNumLoops <= FLASH_END_ADDR) && (uiBytesCounter < 64 ); ulNumLoops++)
 {
 // increment counter
  uiBytesCounter++;
  // copy Word from buffer in uiCryptPos
  uiCryptPos = (T_UI16) *pucBuffer;
  // increment buffer pointer
  pucBuffer++;
  // EXOR with retrun CRC
  uiCryptPos ^= uiFlashCRC16;
  // calc CryptArrays
  uiFlashCRC16 = *(T_UI16*)(uiCRC16l + (uiCryptPos & 0x000F)) ^
       *(T_UI16*)(uiCRC16h + ((uiCryptPos & 0x00F0) >> 4)) ^
       (uiFlashCRC16 >> 8);
 }

 if ( ulNumLoops == FLASH_END_ADDR )
 {
  ucFinishFlag = 1;
  Flash_SetCRC16(uiFlashCRC16);
 }

}

 now if I debug the function in the codewarior with iondart one

 it shown, that he is taking the content of the address 0L
see codewarior.jpg

 

I m sorry for posting this, I m a very beginner with embedded systems and S12X, this is my first  experience with it.

 

I m still trying and serching in google and this forum!!

 

thanks soo much friends

 

 

codewarior.jpg


 

 

 

Message Edited by t.dowe on 2009-10-27 11:33 AM
0 Kudos
777 Views
Pedro_
Contributor III

Hi,

global addresses in Cosmic require the modifier @gpage, you can try something like this:

 

/* gpage pointer allows accessing any area of global map, paged and non paged */ 

@far @gpage unsigned int uiMP @0x00FB8000;

@far @gpage unsigned int *puiMP;

 

*puiMP = &uiMP; 

 

while (puiMP < (@far @gpage unsigned int*) 0x00FBBFFF)

{

   uiCryptPos = *puiMP;

 

   /* Here you calculate your CRC and then increment the pointer */

 

   puiMP ++;
}

 

I hope it works.

 

0 Kudos
776 Views
kef
Specialist I

I can't help you with Cosmic. CrasyCat suggestion works in CodeWarrior.

 

Regarding SrecCvt error.

 

S2060F8000C000AA

Highlighted address doesn't fit global memory range specified in sreccvt -m switch -m 780000 7FFFFF.

Global 0F8000 points to RAM, not flash. Do you have some initialized variable in "far" RAM? Maybe Cosmic doesn't support initialization of far variables and puts them directly to S-records?

0 Kudos
776 Views
firefox0005
Contributor I

ups sorry I sended you the not banked s19 File!

sorry sorry 

here the command:

 

CHEX_OUT_MOT = -o List/$(PROJEKT_NAME).s19..$(LINK) $(LDFLAGS) -o List/$(PROJEKT_NAME).x12 $(LINKFILE)$(S19) -s $(CHEX_OPT_MOT) $(CHEX_OUT_MOT) List/$(PROJEKT_NAME).x12

 

this is not a big problem, because the not banked S19 file is not needed, only the banked is needed

so the error is not critical

the error happens when I add the @far pointer

 

 

no I dont have any initialized variables in RAM

 

I will send an email direktly to Cosmic, and post the response here

 

thank you Kef for answer! I m still looking for a solution

0 Kudos
775 Views
firefox0005
Contributor I

I got it!!!!!

 

const _atfar @gpage T_UC08* pucBuffer = (const _atfar @gpage T_UC08 *) FLASH_START_ADDR;

 

and it works fine!!

 

thanks for help friends!

and have a nice day,night!!

0 Kudos
776 Views
firefox0005
Contributor I

now I m really stumped

I change the line to T_UI16

 

static T_UI16 *_atfar pucBuffer = (T_UI16 *_atfar) FLASH_START_ADDR;

and now I read the adress 4000L, see codewarior2.jpg

 

Sorry friends, if I m taking your time, I hope I can help you too in the future

 

codewarior2.jpg

Message Edited by t.dowe on 2009-10-27 11:34 AM
0 Kudos