• AVR Freaks

Hot!Error in writing Flash of dsPIC33

Author
koneuser
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2019/10/25 04:07:28
  • Location: 0
  • Status: offline
2019/10/25 07:32:03 (permalink)
0

Error in writing Flash of dsPIC33

I want to write data bytes from a desired location in flash of dsPIC33.
For the same, I have written an API in assembly which looks as follows -
; In Flash.h file
Int16 HAL_flash_page_write(
Uint16 u16nvm_addru,
Uint16 u16nvm_addr,
Int16 *i16page_buff_ptr);
 
; In Flash.s file
_HAL_flash_page_write:
push TBLPAG
push.d W8
MOV W0, W9 ; Add loc to be written
MOV w1, w8
mov #0xFA, w0
mov w0, TBLPAG ;TBLPAG has to point to the SRAM latch section
mov #0, w1
mov #0,w6
mov #7,w5 ; w5=row counter
row_loop:
mov #64,w3
mov #0, w1 ;clear w1 - address is relative to the row start address
pinst_loop:

TBLWTL [w2++], [w1]
TBLWTH [w2++], [w1++] ; write 0 to high byte to be decoded as nop
TBLWTL [w2++], [w1]
TBLWTH [w2++], [w1++]
TBLWTL [w2++], [w1]
TBLWTH [w2++], [w1++] ; write 0 to high byte to be decoded as nop
TBLWTL [w2++], [w1]
TBLWTH [w2++], [w1++]
dec2 w1,w1
dec2 w1,w1
; dec w3, w3
; bra NZ, pinst_loop

MOV w9, NVMADRU ;point to the row to be written to
MOV w8, NVMADR
; ; Setup NVCON for row program
mov #FLASH_WORD_PROG_CODE,w7
mov w7, NVMCON
bset w7,#15
disi #5 ; Block all interrupt with priority <7 for next 5 instructions
mov #0x55, W0
mov W0, NVMKEY
mov #0xAA, W0
mov W0, NVMKEY
mov w7,NVMCON ; Start Program Operation
nop
nop
add w8,#4,w8
prog_wait:
btsc NVMCON, #WR
bra prog_wait
dec w3, w3
bra NZ, pinst_loop
; mov #256,w1 ; load with row size
; mov w8,w0 ; load previous row address
; add w1,w0,w0 ; compute new row address
; mov w0,w8 ; load new row address in w8

dec w5, w5
bra nz, row_loop ; test if all rows are written
clr w0
pop.d W8
pop TBLPAG
return
Further, the data is stored in a PageBuffer[1024]
Then, _HAL_flash_page_write function is called with the arguments passed as Upper_address, Lower_address and PageBuffer[].
 
Problem - 
1. Unable to write in 3 bytes (24 bits) in one memory cell.
2. Only FIRST TWO bytes from PageBuffer[] are repeatedly written in a complete single page of flash.
#1
Jump to:
© 2020 APG vNext Commercial Version 4.5