Flash store

General discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Skydec
Posts: 39
Joined: 30 Jan 2009 12:38

Flash store

#1 Post by Skydec » 24 Feb 2009 22:23

I'm struggeling to store some variables in the flash memory.

I want to store a array of real into a part of the flash memory.

I tried to do this by declairing both an array of real an an array of word and set it to the same adress

Code: Select all

var
   LL : array [5] of real; absolute $80;
   LLW : array [11] of word; absolute $80;

But my question is, what adresses do I have to choose for LL and LLW, does $80 conflict something else?
and to store with write_flash what adress do I have to choose there?

How I can find a usable adres?

For now my application compiles, but when I read some flash the controller crashes.

Does anybody know where to find the info, or does anybody made a unit to do this?

I'm using a PIC 24HJ128GP202 btw.

Or is there a way to change and store a const during runtime?

Thanks in advance

goran.marinkovic
mikroElektronika team
Posts: 265
Joined: 25 Nov 2008 09:09

#2 Post by goran.marinkovic » 25 Feb 2009 17:12

Hi,
var
LL : array [5] of real; absolute $80;
LLW : array [11] of word; absolute $80;
If you use that, certainly will not cover with some piece of memory which our compiler reproduce, but it will certainly cover with some address for example:
the registers of compiler which are on fixed address

For more informations you should try to find on our forum.

Regards

FRM
Posts: 381
Joined: 20 May 2005 18:58
Location: UK

#3 Post by FRM » 25 Feb 2009 19:33

It's proabably easiest for you to determine the address where the free rom space starts after your program has been compiled. You can use the statistics tool in the ide for this. Pick the next block start address. It is not as easy as using eeprom I'm afriad. One can use pointers to reference RAM variables (or arrays of variables), then control block flash reads/writes using the pointer reference. Take care not to confuse RAM address space with ROM address space. Experiment by writing blocks to free rom and reading them back with the dsPICFlash tool.
Have a closer look in the help file about flash read/write routines for dsPIC compiler.
Here is part of some code from a dsPIC33FJ128GP710 project that may help you, unfortunately subject to IP so I cannot show all of it:

Code: Select all

const
CONF_CAL_FBS = $15200;        // last 1536 byte ROM block for configuration calibration etc

var
Byte_Mapped_Array : array [192] of byte; absolute $2800; // absolute declaration in RAM space
Config_Reg : word; absolute $2800;
Sin_MIN : word; absolute $2802;
Sin_MAX : word; absolute $2804;
SinRg : word; absolute $2806;
SinZ : word; absolute $2808;
Cos_MIN : word; absolute $280A;
Cos_MAX : word; absolute $280C;
CosRg : word; absolute $280E;
CosZ : word; absolute $2810;

A_Rotor : real; absolute $2812;
D_Rotor : real; absolute $2816;
PID_Rotor : real; absolute $281A;
Old_PID_rotor : real; absolute $281E;
pGain : real; absolute $2822;
iGain : real; absolute $2826;
dGain : real; absolute $282A;
Field_f : real; absolute $282E;
Fvi_R : real; absolute $2832;
Targ_f : real; absolute $2836;
hi_temp : short; absolute $283A;    // compensators high temp limit
lo_temp : short; absolute $283B;    // compensators low temp limit
temp_span : byte; absolute $283C;   // compensators calculated temp span
                                    // one extra byte???? why?
CHA_Temp : real; absolute $283E;    // Temperature1 (upper?)
CHB_Temp : real; absolute $2842;    // Temperature2 (lower?)
                                    // 70 bytes to here
//More variable references not shown

Procedure Store_config(diag : boolean);
begin
if diag then Dump_Flash_Data;        // Send cal variables to UART2
Flash_Erase(CONF_CAL_FBS);           // Erase storage block of flash memory at address xxxx
Flash_Write_Compact(CONF_CAL_FBS, Byte_Mapped_Array); // store calibration values to flash memory
//Vector_Set(Byte_Mapped_Array,192,0); // Reset Array for test
Flash_Read_Compact(CONF_CAL_FBS, Byte_Mapped_Array, 64); // Read in Config_Reg, PID constants & calibration data
if diag then Dump_Flash_Data;        // Send cal variables to UART2
end;

Hope this helps you.

Post Reply

Return to “mikroPascal for dsPIC30/33 and PIC24 General”