> Isaac Marino Bavaresco wrote: >> The boot-loader is not yet finished but I did some tests in the real >> hardware today, and they show that the word-programming works. > > I have done bootloaders for dsPIC parts. These have to erase a whole > erase > block at a time. My bootloaders then write whole write blocks within eac= h > erase block. So far that seems to have worked without incident. I don't > see why a bootloader would want to write individual words. > > I think that could wear out the flash faster too. It's possible that eac= h > word write effects the whole write block. If a write block is 32 words i= n > size, then writing each word individually may stress the flash as if the > whole block were written 32 times. I don't know if this is true, but I > can > certainly see how it could be. > > Again, word writes don't make much sense for a bootloader. > I've had a 24H bootloader working for several years. I wrote assembly routines that I call from C. The routines are: _ReadFlashLocal: ; 32 bit input passed in W1:W0, 32 bit result returned in W1:W0 mov W1,TBLPAG TBLRDH [W0],W1 ; high byte of contents into W1 TBLRDL [W0],W0 ; low word into W0 return _UnlockPM: ; Unlock Program Memory push w0 ; save it disi #5 ; disable interrupts for next 5 instructions mov #0x55,w0 mov w0,NVMKEY ; first part of magic number mov #0xaa,w0 mov w0,NVMKEY ; second part bset NVMCON,#15 ;start write nop nop btsc NVMCON,#15 bra $-2 ; write not done yet, go again pop w0 ; restore it return _EraseFlashPageLocal: ; Pass in a 32 bit address in w1:w0. This will erase 512 instruction locations (1024 addresses). For erase, the address bits are interpreted as ; pppp ppoo oooo oooo where p is page, and o is offset. Therefore, the 10lsb of the address passed in to this routine have no effect, but are ; used here to provide a consistent interface (always pass in a 32 bit address). mov W1, TBLPAG ; set up the page tblwtl W0,[W0] ; a dummy write in the page we are going to erase mov #0x4042,W0 mov W0,NVMCON ; set up for page erase call _UnlockPM ; go do the erase return _WriteFlashWordLocal: ; Pass a 32 bit address in W1:W0 and a 32 bit value in W3:W2. This writes the data to the write latch but does not actually program the chip. 64 24 bit words ; can be written before you have to do a WriteFlashRow. mov W1,TBLPAG ; select the page we're going to write to TBLWTL W2,[W0] ; write low byte of data in w2 to offset pointed to by w0 TBLWTH W3,[W0] ; write high byte of data in w3 to offset pointed to by w= 0 return _WriteFlashRowLocal: ; No arguments are passed in. The row to program is determined by the previous TBLWT instructions. mov #0x4001, W0 mov W0,NVMCON ; Tell NVMCON we're going to write a row call _UnlockPM ; go do the write return Harold --=20 FCC Rules Updated Daily at http://www.hallikainen.com - Advertising opportunities available! --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .