comparison src/external_flash.asm @ 414:35bdfd89323c

support for new flash memory
author heinrichsweikamp
date Tue, 29 Mar 2016 12:35:47 +0200
parents eb758a5b44eb
children 4389fe9673b2
comparison
equal deleted inserted replaced
413:12e85930d95c 414:35bdfd89323c
197 bsf flash_ncs ; CS=1 197 bsf flash_ncs ; CS=1
198 return 198 return
199 199
200 global ext_flash_disable_protection ; Disable write protection 200 global ext_flash_disable_protection ; Disable write protection
201 ext_flash_disable_protection: 201 ext_flash_disable_protection:
202 ; unlock old memory
202 bsf flash_ncs ; CS=1 203 bsf flash_ncs ; CS=1
203 movlw 0x50 ; EWSR command 204 movlw 0x50 ; EWSR command
204 rcall write_spi 205 rcall write_spi
205 bsf flash_ncs ; CS=1 206 bsf flash_ncs ; CS=1
206 207
207 movlw 0x01 ; WRSR command 208 movlw 0x01 ; WRSR command
208 rcall write_spi 209 rcall write_spi
209 movlw b'00000000' ; New status 210 movlw b'00000000' ; New status
211 rcall write_spi
212 bsf flash_ncs ; CS=1
213
214 ; unlock new memory
215 bsf flash_ncs ; CS=1
216 movlw 0x06 ; WREN command
217 rcall write_spi
218 bsf flash_ncs ; CS=1
219 movlw 0x98 ; ULBPR command
210 rcall write_spi 220 rcall write_spi
211 bsf flash_ncs ; CS=1 221 bsf flash_ncs ; CS=1
212 return 222 return
213 223
214 global ext_flash_enable_protection 224 global ext_flash_enable_protection
215 ext_flash_enable_protection: 225 ext_flash_enable_protection:
226 ; lock old memory
216 bsf flash_ncs ; CS=1 227 bsf flash_ncs ; CS=1
217 movlw 0x50 ; EWSR command 228 movlw 0x50 ; EWSR command
218 rcall write_spi 229 rcall write_spi
219 bsf flash_ncs ; CS=1 230 bsf flash_ncs ; CS=1
220 231
221 movlw 0x01 ; WRSR command 232 movlw 0x01 ; WRSR command
222 rcall write_spi 233 rcall write_spi
223 movlw b'00011100' ; New status (Write protect on) 234 movlw b'00011100' ; New status (Write protect on)
224 rcall write_spi 235 rcall write_spi
225 bsf flash_ncs ; CS=1 236 bsf flash_ncs ; CS=1
237
238 ; lock new memory
239 bsf flash_ncs ; CS=1
240 movlw 0x06 ; WREN command
241 rcall write_spi
242 bsf flash_ncs ; CS=1
243 movlw 0x42 ; WBPR command
244 rcall write_spi
245 movlw .18
246 movwf temp1
247 ext_flash_enable_protection2:
248 movlw 0xFF
249 rcall write_spi
250 decfsz temp1,F ; 18 bytes with 0xFF
251 bra ext_flash_enable_protection2
252 bsf flash_ncs ; CS=1
226 return 253 return
227 254
228 255
229 global ext_flash_erase4kB ; Erases 4kB sector 256 global ext_flash_erase4kB ; Erases 4kB sector
230 ext_flash_erase4kB: 257 ext_flash_erase4kB:
245 bsf flash_ncs ; CS=1 272 bsf flash_ncs ; CS=1
246 btfsc SSP2BUF,0 ; Write operation in process? 273 btfsc SSP2BUF,0 ; Write operation in process?
247 bra ext_flash_wait_write ; Yes, wait more.. 274 bra ext_flash_wait_write ; Yes, wait more..
248 return 275 return
249 276
250 global ext_flash_erase_logbook ; erases logbook memory (000000h -> 2FFFFFh -> 3MByte) 277 global ext_flash_erase_logbook ; erases logbook memory (000000h -> 2FFFFFh -> 3MByte -> 3145728 Bytes)
251 ext_flash_erase_logbook: 278 ext_flash_erase_logbook:
252 bsf flash_ncs ; CS=1 279 bsf flash_ncs ; CS=1
253 clrf ext_flash_address+0 280 clrf ext_flash_address+0
254 clrf ext_flash_address+1 281 clrf ext_flash_address+1
255 clrf ext_flash_address+2 282 clrf ext_flash_address+2
256 283
257 movlw d'48' 284 setf temp1 ; 256*12kB=3145728 Bytes
258 movwf temp1 ; 48*64kB=917504 Bytes
259 ext_flash_erase_logbook_loop: 285 ext_flash_erase_logbook_loop:
260 movlw 0x06 ; WREN command 286 rcall ext_flash_erase4kB ; 4kB
261 rcall write_spi 287 rcall ext_flash_add_4kB ; Increase ext_flash_address:3 by 4kB
262 bsf flash_ncs ; CS=1 288 rcall ext_flash_erase4kB ; 4kB
263 movlw 0xD8 ; 64kB erase command 289 rcall ext_flash_add_4kB ; Increase ext_flash_address:3 by 4kB
264 rcall write_spi 290 rcall ext_flash_erase4kB ; 4kB
265 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI 291 rcall ext_flash_add_4kB ; Increase ext_flash_address:3 by 4kB
266 bsf flash_ncs ; CS=1
267 rcall ext_flash_wait_write ; Wait for write...
268
269 incf ext_flash_address+2,F ; 64kB ahead
270 decfsz temp1,F 292 decfsz temp1,F
271 bra ext_flash_erase_logbook_loop 293 bra ext_flash_erase_logbook_loop
272 return 294 return
295
296 ext_flash_add_4kB:
297 movlw 0x10
298 addwf ext_flash_address+1,F
299 movlw d'0'
300 addwfc ext_flash_address+2,F
301 return
273 302
274 303
275 write_spi: ; With data in WREG... 304 write_spi: ; With data in WREG...
276 bcf flash_ncs ; CS 305 bcf flash_ncs ; CS
277 global write_spi1 306 global write_spi1