Mercurial > public > hwos_code
comparison src/external_flash.asm @ 423:ccaaac45b61a
_another_ timing fix for firmware updates (2.07 was not published yet anyway)
author | heinrichsweikamp |
---|---|
date | Mon, 02 May 2016 12:41:20 +0200 |
parents | 3895adc3477f |
children | 9c54849b8d3b |
comparison
equal
deleted
inserted
replaced
422:70e44a442689 | 423:ccaaac45b61a |
---|---|
185 movlw 0x02 ; Write (PP, Page-Program) command | 185 movlw 0x02 ; Write (PP, Page-Program) command |
186 rcall write_spi | 186 rcall write_spi |
187 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI | 187 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI |
188 movf temp1,W ; load data byte | 188 movf temp1,W ; load data byte |
189 rcall write_spi ; write one byte of data! | 189 rcall write_spi ; write one byte of data! |
190 bsf flash_ncs ; CS=1 | |
191 bra ext_flash_wait_write ; And return... | 190 bra ext_flash_wait_write ; And return... |
192 ; | 191 |
193 ; | 192 global ext_flash_byte_write_comms ; without wait, ~86us fixed delay due to 115200 Bauds |
194 ; return | 193 ext_flash_byte_write_comms: |
194 movwf temp1 ; store data byte | |
195 bsf flash_ncs ; CS=1 | |
196 movlw 0x06 ; WREN command | |
197 rcall write_spi | |
198 bsf flash_ncs ; CS=1 | |
199 movlw 0x02 ; Write (PP, Page-Program) command | |
200 rcall write_spi | |
201 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI | |
202 movf temp1,W ; load data byte | |
203 rcall write_spi ; write one byte of data! | |
204 bsf flash_ncs ; CS=1 | |
205 return | |
195 | 206 |
196 global ext_flash_disable_protection ; Disable write protection | 207 global ext_flash_disable_protection ; Disable write protection |
197 ext_flash_disable_protection: | 208 ext_flash_disable_protection: |
198 ; unlock old memory | 209 ; unlock old memory |
199 bsf flash_ncs ; CS=1 | 210 bsf flash_ncs ; CS=1 |
206 movlw b'00000000' ; New status | 217 movlw b'00000000' ; New status |
207 rcall write_spi | 218 rcall write_spi |
208 bsf flash_ncs ; CS=1 | 219 bsf flash_ncs ; CS=1 |
209 | 220 |
210 ; unlock new memory | 221 ; unlock new memory |
211 ; bsf flash_ncs ; CS=1 | 222 movlw 0x06 ; WREN command |
212 ; movlw 0x06 ; WREN command | 223 rcall write_spi |
213 ; rcall write_spi | 224 bsf flash_ncs ; CS=1 |
214 ; bsf flash_ncs ; CS=1 | 225 movlw 0x98 ; ULBPR command |
215 ; movlw 0x98 ; ULBPR command | 226 rcall write_spi |
216 ; rcall write_spi | 227 bsf flash_ncs ; CS=1 |
217 ; bsf flash_ncs ; CS=1 | 228 |
218 | |
219 ;bsf flash_ncs ; CS=1 | |
220 movlw 0x06 ; WREN command | 229 movlw 0x06 ; WREN command |
221 rcall write_spi | 230 rcall write_spi |
222 bsf flash_ncs ; CS=1 | 231 bsf flash_ncs ; CS=1 |
223 movlw 0x42 ; WBPR command | 232 movlw 0x42 ; WBPR command |
224 rcall write_spi | 233 rcall write_spi |
225 movlw .18 | 234 movlw .18 |
226 movwf temp1 | 235 movwf temp2 |
227 ext_flash_disable_protection2: | 236 ext_flash_disable_protection2: |
228 movlw 0x00 | 237 movlw 0x00 |
229 rcall write_spi | 238 rcall write_spi |
230 decfsz temp1,F ; 18 bytes with 0x00 | 239 decfsz temp2,F ; 18 bytes with 0x00 |
231 bra ext_flash_disable_protection2 | 240 bra ext_flash_disable_protection2 |
232 bsf flash_ncs ; CS=1 | 241 bsf flash_ncs ; CS=1 |
233 return | 242 return |
234 | 243 |
235 global ext_flash_enable_protection | 244 global ext_flash_enable_protection |
242 | 251 |
243 movlw 0x01 ; WRSR command | 252 movlw 0x01 ; WRSR command |
244 rcall write_spi | 253 rcall write_spi |
245 movlw b'00011100' ; New status (Write protect on) | 254 movlw b'00011100' ; New status (Write protect on) |
246 rcall write_spi | 255 rcall write_spi |
256 bsf flash_ncs ; CS=1 | |
257 | |
258 ; lock new memory | |
259 ; movlw 0x06 ; WREN command | |
260 ; rcall write_spi | |
247 ; bsf flash_ncs ; CS=1 | 261 ; bsf flash_ncs ; CS=1 |
248 | 262 ; movlw 0x8D ; LBPR command |
249 ; lock new memory | 263 ; rcall write_spi |
250 bsf flash_ncs ; CS=1 | 264 ; bsf flash_ncs ; CS=1 |
251 movlw 0x06 ; WREN command | 265 movlw 0x06 ; WREN command |
252 rcall write_spi | 266 rcall write_spi |
253 bsf flash_ncs ; CS=1 | 267 bsf flash_ncs ; CS=1 |
254 movlw 0x42 ; WBPR command | 268 movlw 0x42 ; WBPR command |
255 rcall write_spi | 269 rcall write_spi |
256 movlw .18 | 270 movlw .18 |
257 movwf temp1 | 271 movwf temp2 |
258 ext_flash_enable_protection2: | 272 ext_flash_enable_protection2: |
259 movlw 0xFF | 273 movlw 0xFF |
260 rcall write_spi | 274 rcall write_spi |
261 decfsz temp1,F ; 18 bytes with 0xFF | 275 decfsz temp2,F ; 18 bytes with 0xFF |
262 bra ext_flash_enable_protection2 | 276 bra ext_flash_enable_protection2 |
263 bsf flash_ncs ; CS=1 | 277 bsf flash_ncs ; CS=1 |
264 return | 278 return |
265 | 279 |
266 | 280 |
271 rcall write_spi | 285 rcall write_spi |
272 bsf flash_ncs ; CS=1 | 286 bsf flash_ncs ; CS=1 |
273 movlw 0x20 ; Sector erase command | 287 movlw 0x20 ; Sector erase command |
274 rcall write_spi | 288 rcall write_spi |
275 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI | 289 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI |
276 bsf flash_ncs ; CS=1 | |
277 ; bra ext_flash_wait_write ; Wait for write... and return | 290 ; bra ext_flash_wait_write ; Wait for write... and return |
278 ext_flash_wait_write: | 291 ext_flash_wait_write: |
279 WAITMS d'1' ; TBE/TSE=25ms... | 292 bsf flash_ncs ; CS=1 |
293 ; WAITMS d'1' ; TBE/TSE=25ms... | |
280 movlw 0x05 ; RDSR command | 294 movlw 0x05 ; RDSR command |
281 rcall write_spi ; Read status | 295 rcall write_spi ; Read status |
282 rcall write_spi ; Read status into WREG | 296 rcall write_spi ; Read status into WREG |
283 bsf flash_ncs ; CS=1 | 297 bsf flash_ncs ; CS=1 |
284 btfsc SSP2BUF,0 ; Write operation in process? | 298 btfsc SSP2BUF,0 ; Write operation in process? |