QG8 - Programming a byte in Flash (C based)

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

QG8 - Programming a byte in Flash (C based)

3,198 Views
UtopiaTim
Contributor III
Hi Folks,
 
I've been searching a while in the archives to see if there is any
code on the forum to program a byte in a QG8 written in C.  Didn't
find any.
 
I saw some nice code from Peg in assembly, but there's a lot
of stack manipulation (to keep things in Ram).
 
I only need to keep 1 or 2 bytes of Flash (although I know I
need to 'waste' a page worth's of space to do it)!
 
Just wondered if there was any code floating around.
 
Thanks!
 
Tim
Labels (1)
0 Kudos
Reply
6 Replies

1,579 Views
Ake
Contributor III
Hi,
Here is a collection of Flash EPROM routines for the 9S08QG.
They are not guaranteed in any way, but believed to be OK.
 
Regards,
Ake
0 Kudos
Reply

1,579 Views
UtopiaTim
Contributor III
Thanks Ake!!
 
Tim
 
 
0 Kudos
Reply

1,579 Views
bigmac
Specialist III
Hello Tim,
 
The previously posted code above does require rather a lot of RAM that is permanently allocated to the flash programming function.  This may make it less suitable for low end devices such as the 'QG8.  It would also appear that the code does not disable interrupts whilst flash memory is inaccessible, which could be problematic (since the interrupt vectors are located within flash).
 
Provided burst programming is not required, which is likely not an issue if you need to program only a few bytes, the amount of permanently allocated RAM may be considerably reduced, to better suit smaller devices.
 
The following thread provides some discussion about some of these issues.
 
The attached code might also be of interest.
 
Regards,
Mac
0 Kudos
Reply

1,579 Views
UtopiaTim
Contributor III
Thanks Mac,
 
That's one thread that I hadn't seen. 

Also, thanks for the code - I'll be trying it out in a while.

Tim
 
 
0 Kudos
Reply

1,579 Views
UtopiaTim
Contributor III
Hi Mac,
 
In S08_Flash.c, the 3rd & 4th line references:
 
extern char __SEG_START_FLASH_ROUTINE[];
extern char __SEG_SIZE_FLASH_ROUTINE[];
 
Where are these defined?
 
When I run the program, the srcPtr and the dstPtr both = 0xe198.
I figure the dstPtr needs to point to ram.  Where is that defined?
 
Thanks,
 
Tim
0 Kudos
Reply

1,579 Views
bigmac
Specialist III
Hello Tim,
 
Sorry, I omitted the PRM file in my previous post.  The segment FLASH_ROUTINE  is defined there, and also the RAM address where it is re-located to (0x200).  This is assumed to be the bottom of the stack for the sample code.
 
And contrary to the comment within the .c file, the RAM requirement is actually 10 bytes - a COP reset was later added within the routine, but the byte count not updated.
 
Regards,
Mac


Message Edited by bigmac on 2008-10-21 08:39 AM
0 Kudos
Reply