Dear Sirs,
I'm facing a strange behaviour using the WRITECODE statement.
Basically I've done a bootloader that starts at $17680 (using PBP) and when it detect it is time for a firmware upgrade it does, copying the new firmware from a FRAM to the chip's memory address from $0000 to $1767F.
At bootloader side, I've set the proper type of variables for using with ERASECODE/WRITECODE (Long for address and Word for the argument).
I'm respecting the rule of the 64 bytes.
Everything looks as it's working perfectly, EXCEPT that only the FIRST 2 BYTE Sat the address $0000 are both kept at the value of $00.
In other words, I can't REALLY MODIFY the value of the first word that is located at the adress $0000.
I've correctly used the ERASECODE (otherwise the first page never will be filled-in with the proper values).
I've double and triple checked if I'm getting the right values from the FRAM and if (of course) I'm correctly starting the filling from the address $0000. Data are correct from the FRAM and I'm actually starting the filling from $0000.
But still the same issue.
I'm using PBP 2.60c and the micro is a 18F4685. Also the great DT interrupts are used here, but I'm switching it off interrupts using:
@ INT_DISABLE RX_UART
GIE = 0
PEIE = 0
RCIE = 0
T1ON = 0 'Disable Timer1
I do the above, before letting the bootloader doing any action on the program memory.
For additional explanation, please look at the attached pictures.
Is there any reason why the WRITECODE act this way or I'm doing something wrong?
Thank you in advance for your help.


Here is a code snippet that show the main stuffs.
Any idea?
Code:
' Don't care for Ports and Pin assignment.
' I've removed it for code best reading
DEFINE RESET_ORG 17680h
INCLUDE "modedefs.bas"
DEFINE OSC 20
DEFINE I2C_SLOW 1
DEFINE SHIFT_PAUSEUS 1
Flash var long
x var long
FW_Bytes var word
FW_Words var long
y var long
programStart var word
BUFF var byte[7]
CLEAR
programStart = 0
FW_Words = $1767E
for x = programStart to $1767F step 64
Flash = x
ERASECODE Flash
next
for x = 0 to FW_Words step 2
RAMCS = 0 'SRAM Chip Selected
SHIFTOUT RAMSI, RAMCLK, MSBFIRST, [$03, x.BYTE2, x.BYTE1, x.BYTE0] ; Send read cmd and address to FRAM
SHIFTIN RAMSO, RAMCLK, MSBPRE, [BUFF(4)] ; Read data HighByte
RAMCS = 1 'SRAM Chip NOT Selected
y = x + 1
RAMCS = 0 'SRAM Chip Selected
SHIFTOUT RAMSI, RAMCLK, MSBFIRST, [$03, y.BYTE2, y.BYTE1, y.BYTE0] ; Send read cmd and address
SHIFTIN RAMSO, RAMCLK, MSBPRE, [BUFF(3)] ; Read data LowByte
RAMCS = 1 'SRAM Chip NOT Selected
FW_Bytes.lowbyte = BUFF[3]
FW_Bytes.highbyte = BUFF[4] 'Store the current Word of the new Firmware Code
Flash = x + programstart
writecode flash, fw_bytes
next x
Thank you.
Bookmarks