Writing a program to FLASH using the S08LC36/60

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

Writing a program to FLASH using the S08LC36/60

Jump to solution
1,240 Views
KerryMac
Contributor III

Greetings all,

 

We have a product based on the MC9S08LC36. Writing our program to FLASH uses a ORG $1870,$FFC0 to write the 9k bytes of code to the FLASH B block of the MCU. We also have to use the MC9S08LC60 for this product.

 

Question - Will the FLASH setup for the LC36 work successfully with the LC60, since both have a contiguous block of FLASH B ROM which exceeds the size of our program?

 

Thanks,

KM

Labels (1)
0 Kudos
Reply
1 Solution
1,056 Views
KerryMac
Contributor III

Thanks Mac,

 

Yes, using $1870 was problematic. $1900 seems to be working fine but I'll use $1A00 for EEPROM emulation per your suggestion.

 

Allow me to comment on how much I appreciate your knowledge and intellect. You're one of those special individuals who make things happen.

 

Thanks again,

KM

View solution in original post

0 Kudos
Reply
8 Replies
1,056 Views
KerryMac
Contributor III

Thanks Mac for the rapid response.

 

I wish to keep this thread open as I have just stumbled upon a possible problem of using nonvolatile  FLASH register, FFB0-FFBF, as my user defined EEPROM emulation!

 

I simply failed to pick up on this reservation. My only excuse is that it was not noted on there Memory Map.

 

After a review I plan to post more questions on my blunder.

 

Thanks,

KM

0 Kudos
Reply
1,056 Views
bigmac
Specialist III

Hello KM,

 

It may be better to place your program code within Flash A, and use the lower part of Flash B, at address 0x1870, for the non-volatile storage requirements.

 

You will then be able to implement write protection for your program code.  Additionally, the functions used for Flash B sector erase, and the programming of the non-volatile data from within your program, may reside in, and be executed from a Flash A location.  There is no necessity for RAM resident code, as for single flash array devices.

 

Regards,

Mac

 

0 Kudos
Reply
1,056 Views
KerryMac
Contributor III

Thanks Mac,

 

I will follow your advice and move my program to FLASH A, with my 16 bytes of end user data stored in FLASH B. I plan to use this on both the LC36 and the LC60.

 

************************************

EEstartEQU$1870; Beginning of FLASH B, registers used for EE

BytesInEE    EQU16; Used as a loop counter to prevent exceeding allocation

 

ORG $A000,MAX

************************************

 

Questions:

* Is $FFFF is the best value for MAX?

 

* Is FLASH protection only useful to prevent others from copying code or does it also prevent other scenarios?

 

* I know EEPROM Emulation has been beat to death but I have a two part question. If a MCU has a Double Flash Array can the PGM routine be executed in the opposite block of ROM, so the RAM is not used, and if so could you direct me to where you may have posted this code?

 

Thanks again,

KM

0 Kudos
Reply
1,056 Views
bigmac
Specialist III

Hello KM,

 

What assembler are you using?  For CW assembler, the syntax for the ORG directive is -

  ORG  <expression>   ; to define the new address.

 

In this context, flash block protection has no external security function, but provide protection against code corruption by a wayward flash erase or flash programming sub-routine.  Refer to section 4.4.6 of the datasheet.

 

Yes, you would locate the sector erase and the byte programming sub-routines within flash A, without the need to execute any code from RAM.  I have attached a relocatable assembly code example, that was originally intended to use a fixed block of RAM for a small part of the code.  This should be easily adaptable for your purpose.  Simply change the label F_FLASH_CMD to FLASH_CMD, and eliminate its special section.  Also eliminate the RAM_COPY sub-routine.

 

If you are using absolute assembly, instead of relocatable assembly, you will also need to INCLUDE the code file, and rename the file from .ASM, perhaps to .INC.  There will be some other file modifications for absolute assembly.

 

There is also a relevant Application Note AN3404.

 

Regards,

Mac

 

0 Kudos
Reply
1,056 Views
KerryMac
Contributor III

Thanks Mac,

 

I am doing absolute assembly using a fantastic text editor for Apple, BBEdit.

 

Your suggestion of locating my program into FLASH A works fine:

 ORG $A000; Start of FLASH A in LC36 and >FLASH A start in LC60 ($8000)

 

EEstartEQU$1900; +$30 into FLASH B, registers used for EE

 

But when the start of FLASH B ($1870) is used for EEPROM emulation it did not work.(?) However $1900 seems to be working fine.

 

I'm running out of time on this project. Should I stay with these settings or is there some cautions?

 

Once your reply is received I'll mark this thread as a Solved.

 

 

Thanks again,

KM

0 Kudos
Reply
1,056 Views
bigmac
Specialist III

Hello KM,

 

The first sector of flash B theoretically covers the address range $1800-$19FF.  However, this partly overlaps with the high page registers ($1800-$186F).  Perhaps there are some side effects with using this sector?  For non-volatile data storage, I might utilize the next sector ($1A00-$1BFF), as a precaution.

 

Regards,

Mac

 

0 Kudos
Reply
1,057 Views
KerryMac
Contributor III

Thanks Mac,

 

Yes, using $1870 was problematic. $1900 seems to be working fine but I'll use $1A00 for EEPROM emulation per your suggestion.

 

Allow me to comment on how much I appreciate your knowledge and intellect. You're one of those special individuals who make things happen.

 

Thanks again,

KM

0 Kudos
Reply
1,056 Views
bigmac
Specialist III

Hello KM,

 

The S19 file generated for a 'LC36 target should also be workable with a 'LC60 device.

 

Regards,

Mac

 

0 Kudos
Reply