Bootloader - erase flash memory

Hi there,

I've got a C164CI and I have to write a bootloader in assembly to load my Hex-Files into the Flash memory. I've got a 32-Byte primary loop that loads another loop, refered to as secondary loop, which should load the main prog and write it into the flash memory. Everything seems to work fine, as I've inserted some LED controll codes, and the code seems to work, but when I've finshed sending the Hex-File and reseted the microcontroller it starts the prog that was (and obviously still is) in memory before. My secondary loop only temporarly stores the data in a register and then directly writes it into the flash starting on 00h.

I've got the disassembled code of an existing bootloader and there I found that it is deleting the flash memory before it writes the data to it. But I could not really find out how that works. The dissasembled code uses instructions like MEMMOV 0XAAAA, #0xAAAA, R3 but I havn't found out what this instruction does and the assembler I use (Reads166 - Rigel Cooperation) doesn't even know it. So could anybody tell me what MEMMOV does? (google didn't help :'-( )

Or/And

how you can erase the flash with assembly code? What exactly is the principle of erasing memory? Is it to set every bit to zero or exactly does that mean?

Thanks for your help

Thomas

Reply to
Thomas Baier
Loading thread data ...

Hi,you cant write to flash unles it's been earased first. If you can write to flash then you must allready know how to use the flash commands, so why has the earase command got you baffled? Writing a true bootloader is a problem because they but have to share the same reset vector.

Reply to
CBarn24050

Thomas, I'm not familiar with the C164CI, but the sequence above looks like the start of an embedded algorithm for an AMD flash chip. Basically, a CHIP ERASE consists of 6 cycles, where each cycle consists of a write to one of two command registers with a "magic" value. This value is documented in the datasheets for the flash. In order to perform a CHIP ERASE, the following sequence would be performed (these are 16-bit writes):

ADDRESS VALUE ---------------------------------- AAAA AAAA 5554 5555 AAAA 8080 AAAA AAAA 5554 5555 AAAA 1010

After the erase operation, all of the bits return to a "1" state, so any (16-bit) reads of memory will result in the value FFFF.

Programming a memory location consists of a 4 cycle operation. The following example would set the contents of address 4567 to C123:

ADDRESS VALUE ---------------------------------- AAAA AAAA 5554 5555 AAAA A0A0 4567 C123

Joe

Reply to
Joe Hagen

Erasing flash means setting every bit to 1. Programming flash means to set an arbitrary number of bits to 0. Bits cannot be "programmed" from

0 back to 1, except by erasing (possible only for a whole page at once).

So, to write your firmware into the flash, you have to first erase the flash, and then program your firmware.

To avoid accidential writes, most flash chips need a special programming sequence (and a special erase sequence as well). Usually the sequence begins with writing 0xAAAA to address 0xAAAA, followed by writing 0x5555 to address 0x5554, and then writing a command (eg "ERASE") to address

0xAAAA. These writes are purely virtual and dont overwrite your firmware addresses 0x5554 or 0xaaaa. They make the flash listen to your command.

Read the datasheet of your flash, or copy off a working flash driver to make your project going.

Marc

Reply to
jetmarc

I don't know Reads166, but it is defninitely not the fault of the assembler.

I am pretty sure, that there is no such instruction available on a C16x CPU. The correct version of the instruction would be something like mov 0xAAAA, R3 assuming that DPP2 contains the correct value. I don't know the meaning of the second operand in your example.

What disassembler are you using that produces these funny mnemonics? Are there any options to tell him that it should use the C16x instruction set?

Best regards Gerhard

Reply to
Gerhard Hempl

This has been known to work ....

; assuming r15 = segment address of FLASH address to be written to ; r14 = offset address of FLASH address to be written to

mov r12,#0AAAAh

exts r15,#1 ; extended segment sequence of len = 1 mov [r14],r12 ; [r15:r14] = r12

Casey

Reply to
Casey

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.