HCS08 Flash Erase/Write Routines.

Showing results for 
Search instead for 
Did you mean: 

HCS08 Flash Erase/Write Routines.

Contributor I
I attached the AN2295 and Standard Software SGF Driver for HCS08 flash routines prepared for simple use.
What you need to do:
-Add FlashRoutines.asm to your user modules.
-Include flash.h in the file where you are to use the routines.
-Modify BUS_CLK value to the programed bus in your application.
-Modify INCLUDE "9s08gb60.inc" in FlashRoutines.asm to accommodate the derivative in your application.
This is some example code:
const unsigned char text[]="This is some text";
  asm sei;
  returnCode = FlashInit(FLASH_CLK);
  Erase_Page((unsigned char *)0x8000);
  Write_Flash((unsigned char *)0x8000,17,&text[0]);
  asm cli;
Message Edited by t.dowe on 2009-09-04 02:21 PM
Labels (1)
0 Kudos
6 Replies

Contributor I
I tried to compile this code into one of my projects for a HCS08GT60 device.  However, I keep getting the following error message in the compiler:
Error: A1104: Undelared user defined symbol: mFCCF
Error: A1104: Undelared user defined symbol: mPageErase
Error: A1104: Undelared user defined symbol: mBurstProg
Error: A1104: Undelared user defined symbol: mFACCERR
Error: A1104: Undelared user defined symbol: mFCBEF
Error: A1104: Undelared user defined symbol: mFPVIOL
Error: A1104: Undelared user defined symbol: NVPROT
Is there some switch I need to give the compiler or is there something else I need to include?
0 Kudos

Contributor IV
I received those same errors.

I am using an AW32 chip, and it seems that most of those are not defined in my include file.

You need to modify the code so that instead of mFPVIOL you have mFSTAT_FPVIOL, the others are the same.

I commented out the line with NVPROT in it, since I will not be using it....

I have to say I was extremely disappointed in the SGF software. I would say that it is unusable for anything in its distributed form. Without the copy-to-ram provisions, and with extremely sketchy documentation it is a nightmare.

I did get it to sort of work, but it had an extremely odd side-effect of shutting off my main timer (it worked if I stepped thru the code, but not when running). So I punted and implemented this.

SGF should have been a complete suite of functions like this gentleman has contributed.
An EEPROM emulator like the HC08AP has would be a killer feature as well.


0 Kudos

Contributor I
Where you have FlashInit, I think you mean Flash_Init. 
I have a quick question.  Do you have any examples where you use your routines to store and retreive an unsigned short variable?

Message Edited by shiloh on 05-05-200603:26 PM

0 Kudos

Contributor I
You really don't need subroutines to do this(although,it's a very good idea), all you need is some casting:
unsigned short example[SIZE] @ 0x8000;
void main void
 unsigned short vol1=0,vol2=0;//Our variable in volatile memory;
  /*This will store the "variable" value at 0x8000*/
  asm sei;
  returnCode = Flash_Init(FLASH_CLK);
 Erase_Page((unsigned char*)example);
 vol1=16384;//example value.
 Write_Flash((unsigned char*)example,sizeof(unsigned short),(unsigned char*)&vol1);
 asm cli;
 /*This should retreive it*/
I don't have the tools to test this code just now, but I'm pretty sure it should do the job.
Cheers =D.
0 Kudos

Contributor V
Tequila, thanks for your simplified SGF Driver. But I'm having troubles with the Write_Flash routine, specifically when that routine is running on the stack and checking the FCBEF bit in FSTAT. That's where my demoboard hangs, with a value of $D0 and therefore looping forever.

According to page 45 of the datasheet, step three in the command execution steps, there's a simple procedure for clearing that flag. I'm really surprised the SGF driver doesn't attempt that.

I put in a simple check for that bit in my main.c with a bit clear (writing a 1 to that bit clears it). Strangely, that bit write isn't working and I can't change the FSTAT register manually either.

Erase_Page isn't working either. I have a page of flash that I'm pre-configuring with some sample bytes to test it. Erase_Page is running off of the stack without hanging, but nothing gets erased.

Hmm, indeed.
0 Kudos

Contributor I
I downloaded and successfully used the driver listed above on a HCS09GB60.  A couple of notes:
1) The code is a expanded mix of the examples in the data book and the "Standard Software SGF Driver for HCS08". Don't let the comments at the top of the source code think you are using the SGF (which is available).
2) For  the HCS08, the correct call from C would be as follows. Note the order of the parameters differs from the example above. (sorry, I renamed the functions):
 byte Flash_Init(byte fcdiv);                   
 byte Flash_Erase(char* dest);
 byte Flash_Write(char* dest, char* source, byte length);

3) For the Flash_Write, note the length is of type byte. This means you can only write 255 bytes at a time (This could be fixed but the 255 byte limit works for me).
4) The include file "9s08gb60.inc" is out dated: Use "mc9s08gb60.inc" located in the
 {compiler}\lib\hc08c\device\asm_include directory. I had to put this into  my project "User" paths so it would not find the wrong one.
5) Perhaps obvious but, don't for get that you must erase the block of data (512 bytes) before you can write it. So if you want to update one byte, you must read then entire block from FLASH to RAM, update your byte in RAM, erase the FLASH and write the block back to FLASH.
6) The Flash_Init function should only be called once at power up.
7) Make sure you have enough stack for the loaded code to run in RAM. (I get 51 bytes)
0 Kudos