Problem writting FLASH as an EEPROM

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Problem writting FLASH as an EEPROM

跳至解决方案
2,229 次查看
hernanEche
Contributor I

Hello, I did this question

 

https://community.freescale.com/thread/68126

 

Then I found AN3824 a library for MC9S08LG32

 

I am using MC9S08GT32 (LG and GT that's first difference)

 

then the code I downloaded have a demo that says : "This demo is designed to run only on MC9S08GB60 evaluation board. " I couldn't integrate that to my project there are too many files and things to touch like frecuencies.

 

A little lost back here for some light.

 

I am reading this is a very complex thing to do, it need the code to be executed at RAM?

 

I really would be glad with something like

 

  • writeByte2Flash(u08 byte, int address);
  • u08 readByte2Flash(int address);

 

:smileyindifferent:

标签 (1)
0 项奖励
1 解答
531 次查看
bigmac
Specialist III

Hello,

 

The code associated with AN3824 is rather complex because it appears to distribute the parameter storage over a number of flash sectors, presumably to increase the total number of erase/write cycles before flash "wearout" occurs.  If your application does not require frequent update of the non-volatile data, you can more simply write the data to a single dedicated sector.

 

The attached code extensively uses inline assembly, but would generally be applicable to most HCS08 devices, with minor variation, mainly to the PRM file.

 

You will need to define the bus clock frequency you are using (within the header file) so that the appropriate flash clock frequency is set when FlashInit() function is called.  A small RAM based function is used, and the function CopyInRAM() will transfer this code from flash.  The RAM block for this code must be defined within the PRM file, as must also the flash block for the non-volatile parameters.

 

The remaining functions are Flash_Erase() that erases a flash sector, and Flash_Program() that programs a single byte.  There is no need for a special read function where variables are allocated within the flash block - simply read the variable in the normal manner.

 

Regards,

Mac

 

在原帖中查看解决方案

0 项奖励
5 回复数
532 次查看
bigmac
Specialist III

Hello,

 

The code associated with AN3824 is rather complex because it appears to distribute the parameter storage over a number of flash sectors, presumably to increase the total number of erase/write cycles before flash "wearout" occurs.  If your application does not require frequent update of the non-volatile data, you can more simply write the data to a single dedicated sector.

 

The attached code extensively uses inline assembly, but would generally be applicable to most HCS08 devices, with minor variation, mainly to the PRM file.

 

You will need to define the bus clock frequency you are using (within the header file) so that the appropriate flash clock frequency is set when FlashInit() function is called.  A small RAM based function is used, and the function CopyInRAM() will transfer this code from flash.  The RAM block for this code must be defined within the PRM file, as must also the flash block for the non-volatile parameters.

 

The remaining functions are Flash_Erase() that erases a flash sector, and Flash_Program() that programs a single byte.  There is no need for a special read function where variables are allocated within the flash block - simply read the variable in the normal manner.

 

Regards,

Mac

 

0 项奖励
531 次查看
hernanEche
Contributor I

News:

 

A related error because data overlap

 

https://community.freescale.com/message/74836#74836

 

could be easily corrected (I hope) I will try it now

 

Bye!

0 项奖励
531 次查看
hernanEche
Contributor I

Hello, thanks for the answer! , I will try to make it works

 

What I made till now:

 

1-Modify project.prm adding this

SEGMENTS    ..    FLASH_TO_RAM             =  READ_ONLY    0xE000 TO 0xE00F RELOCATE_TO 0x0200;        ..ENDPLACEMENT    ..    FLASH_ROUTINE                       INTO  FLASH_TO_RAM;    ..END

2.Adding .h and .c to project

 

3.Define BUS_CLOCK in S08_Flash.h

//(in my project)#define BUS_CLOCK 4195200

4. Comment //#include "derivative.h" because this included MC9S08GT32A.h but my project uses MC9S08GT32.h

 

5.Run!

 

I watched FLASH memory with "True-Time Simulator & Real Time Debugger" connected to an Open Source BDM and to the microcontroller and..

 

It works!! I see in FLASH the data I've written..

 

Now the question is:

 

The Flash_Read function is missing?, How do I Read FLASH Data from source?

 

Thank you very much again

 

 

 

 

0 项奖励
531 次查看
bigmac
Specialist III

Hello,

 

Maybe the following function could be used to read a byte from a specific location in (flash) memory -

 

byte get_mem( const byte *addr)

{

   return (*addr);

}

 

 

 

Regards,

Mac

 

0 项奖励
531 次查看
hernanEche
Contributor I

Thank you very much! :smileyhappy:

0 项奖励