annotate src/external_flash.asm @ 627:bf5fee575701

minor cleanup, reset rx circuity
author heinrichsweikamp
date Sun, 30 Jun 2019 23:22:32 +0200
parents c40025d8e750
children cd58f7fc86db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
3 ; File external_flash.asm combined next generation V3.0.1
0
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; External flash
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-08-12 : [mH] creation
heinrichsweikamp
parents:
diff changeset
11
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 167
diff changeset
12 #include "hwos.inc"
0
heinrichsweikamp
parents:
diff changeset
13 #include "wait.inc"
heinrichsweikamp
parents:
diff changeset
14
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
15 ext_flash CODE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
16
0
heinrichsweikamp
parents:
diff changeset
17 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
18
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
19 ; increase flash address by one
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
20 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
21 global incf_ext_flash_address_p1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
22 incf_ext_flash_address_p1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
23 movlw .1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
24 ;bra incf_ext_flash_address0
0
heinrichsweikamp
parents:
diff changeset
25
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
26
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
27 ; increase flash address by value in WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
28 ;
0
heinrichsweikamp
parents:
diff changeset
29 global incf_ext_flash_address0
heinrichsweikamp
parents:
diff changeset
30 incf_ext_flash_address0:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
31 addwf ext_flash_address+0,F ; increase address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
32 movlw d'0'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
33 addwfc ext_flash_address+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
34 addwfc ext_flash_address+2,F
0
heinrichsweikamp
parents:
diff changeset
35
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
36 movlw 0x40
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
37 cpfseq ext_flash_address+2 ; at address 40FFFF?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
38 return ; NO - return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
39 ; clrf ext_flash_address+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
40 ; clrf ext_flash_address+1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
41 clrf ext_flash_address+2 ; YES - rollover to 0x000000
0
heinrichsweikamp
parents:
diff changeset
42 return
heinrichsweikamp
parents:
diff changeset
43
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
44
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
45 ; increase flash address by one with roll-over at 0x200000 to 0x000000
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
46 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
47 global incf_ext_flash_address0_p1_0x20
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
48 incf_ext_flash_address0_p1_0x20: ; increase by one
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
49 movlw .1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
50 ;bra incf_ext_flash_address0_0x20
0
heinrichsweikamp
parents:
diff changeset
51
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
52
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
53 ; increase flash address by value in WREG with roll-over at 0x200000 to 0x000000
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
54 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
55 global incf_ext_flash_address0_0x20
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
56 incf_ext_flash_address0_0x20:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
57 addwf ext_flash_address+0,F ; increase address
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
58 movlw d'0'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
59 addwfc ext_flash_address+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
60 addwfc ext_flash_address+2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
61 movlw 0x20
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
62 cpfseq ext_flash_address+2 ; at address 0x200000?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
63 return ; NO - return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
64 ; clrf ext_flash_address+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
65 ; clrf ext_flash_address+1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
66 clrf ext_flash_address+2 ; YES - rollover to 0x000000
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
67 return
0
heinrichsweikamp
parents:
diff changeset
68
heinrichsweikamp
parents:
diff changeset
69
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
70 ; decrease flash address by value in WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
71 ;
0
heinrichsweikamp
parents:
diff changeset
72 global decf_ext_flash_address0
heinrichsweikamp
parents:
diff changeset
73 decf_ext_flash_address0:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
74 subwf ext_flash_address+0,F ; decrease address: do a 16-8bits subtract
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
75 movlw d'0'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
76 subwfb ext_flash_address+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
77 movlw d'0'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
78 subwfb ext_flash_address+2,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
79 btfss ext_flash_address+2,7 ; under-run?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
80 return ; NO - return
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
81 clrf ext_flash_address+2 ; YES - set to 0x00FFFFF
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
82 setf ext_flash_address+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
83 setf ext_flash_address+0
0
heinrichsweikamp
parents:
diff changeset
84 return
heinrichsweikamp
parents:
diff changeset
85
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
86
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
87 global ext_flash_byte_read_plus ; return data read in WREG and SSP2BUF and
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
88 ext_flash_byte_read_plus: ; increase address after read
0
heinrichsweikamp
parents:
diff changeset
89 rcall ext_flash_byte_read
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
90 movwf ext_flash_rw ; store received data
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
91 bra incf_ext_flash_address_p1 ; +1 and return
0
heinrichsweikamp
parents:
diff changeset
92
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
93
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
94 global ext_flash_byte_read_plus_0x20 ; return data read in WREG and SSP2BUF and
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
95 ext_flash_byte_read_plus_0x20: ; increase address after read with banking at 0x200000
0
heinrichsweikamp
parents:
diff changeset
96 rcall ext_flash_byte_read
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
97 movwf ext_flash_rw ; store received data
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
98 bra incf_ext_flash_address0_p1_0x20 ; +1 and return
0
heinrichsweikamp
parents:
diff changeset
99
heinrichsweikamp
parents:
diff changeset
100
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
101 global ext_flash_byte_read ; return data read in WREG
0
heinrichsweikamp
parents:
diff changeset
102 ext_flash_byte_read:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
103 movlw 0x03 ; read command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
104 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
105 rcall ext_flash_write_address ; write 24 bit address ext_flash_address:3 via SPI
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
106 rcall write_spi ; dummy write to read data into WREG
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
107 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
108 movwf ext_flash_rw
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
109 return ; return data read in WREG and ext_flash_rw
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
110
0
heinrichsweikamp
parents:
diff changeset
111
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
112 ext_flash_write_address: ; write 24 bit address ext_flash_address:3 via SPI
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
113 movf ext_flash_address+2,W ; 24 bit address
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
114 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
115 movf ext_flash_address+1,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
116 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
117 movf ext_flash_address+0,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
118 bra write_spi ; and return....
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
119
0
heinrichsweikamp
parents:
diff changeset
120
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
121 global ext_flash_read_block_start ; return data read in WREG
0
heinrichsweikamp
parents:
diff changeset
122 ext_flash_read_block_start:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
123 movlw 0x03 ; read command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
124 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
125 rcall ext_flash_write_address ; write 24 bit address ext_flash_address:3 via SPI
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
126 rcall write_spi ; dummy write to read data into WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
127 return ; return data read in WREG
0
heinrichsweikamp
parents:
diff changeset
128
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
129
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
130 global ext_flash_read_block ; return data read in WREG
0
heinrichsweikamp
parents:
diff changeset
131 ext_flash_read_block:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
132 rcall incf_ext_flash_address_p1 ; increase address +1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
133 bra write_spi1 ; dummy write to read data into WREG and return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
134
0
heinrichsweikamp
parents:
diff changeset
135
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
136 global ext_flash_read_block_stop ; return data read in WREG
0
heinrichsweikamp
parents:
diff changeset
137 ext_flash_read_block_stop:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
138 bsf flash_ncs ; CS=1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
139 return ; nO data in WREG
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
140
0
heinrichsweikamp
parents:
diff changeset
141
heinrichsweikamp
parents:
diff changeset
142 global write_byte_ext_flash_plus_header
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
143 write_byte_ext_flash_plus_header: ; write from WREG and increase address after write
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
144 movwf ext_flash_rw ; store data
0
heinrichsweikamp
parents:
diff changeset
145 ; test if write is done at first byte of 4kB block
heinrichsweikamp
parents:
diff changeset
146 ; if yes -> delete 4kB block first
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
147 tstfsz ext_flash_address+0 ; at 0x00?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
148 bra write_byte_ext_flash_plus_h1 ; NO - normal write
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
149 movf ext_flash_address+1,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
150 andlw 0x0F ; mask lower nibble
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
151 tstfsz WREG ; at 0x.0?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
152 bra write_byte_ext_flash_plus_h1 ; NO - normal write
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
153 ; YES - at beginning of 4kB block -> erase first!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
154 rcall ext_flash_erase4kB ; - erases 4kB sector @ext_flash_address:3
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
155 write_byte_ext_flash_plus_h1:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
156 movf ext_flash_rw,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
157 rcall ext_flash_byte_write ; write the byte
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
158 bra incf_ext_flash_address_p1 ; +1 and return
0
heinrichsweikamp
parents:
diff changeset
159
heinrichsweikamp
parents:
diff changeset
160
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
161 global write_byte_ext_flash_plus_nocnt ; no increase of ext_flash_dive_counter:3
279
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
162 write_byte_ext_flash_plus_nocnt:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
163 movwf ext_flash_rw ; store data
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
164 bra write_byte_ext_flash_plus2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
165
279
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
166
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
167 global write_byte_ext_flash_plus_nodel ; does NOT delete 4kB page when required
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
168 write_byte_ext_flash_plus_nodel: ; write from WREG and increase address after write with banking at 0x200000
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
169 movwf ext_flash_rw ; store data
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
170 bra write_byte_ext_flash_plus1 ; ignore possible begin of 4kB page, there have been written 0xFF already
6
13cda523891f bugfix: dive length in normal header
heinrichsweikamp
parents: 0
diff changeset
171
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
172 global write_byte_ext_flash_plus ; write from WREG and increase address after write with banking at 0x200000
0
heinrichsweikamp
parents:
diff changeset
173 write_byte_ext_flash_plus:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
174 movwf ext_flash_rw ; store data
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
175 ; First, increase dive length counter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
176 incf ext_flash_dive_counter+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
177 movlw .0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
178 addwfc ext_flash_dive_counter+1,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
179 addwfc ext_flash_dive_counter+2,F ; 24 bit ++
0
heinrichsweikamp
parents:
diff changeset
180
6
13cda523891f bugfix: dive length in normal header
heinrichsweikamp
parents: 0
diff changeset
181 write_byte_ext_flash_plus2:
0
heinrichsweikamp
parents:
diff changeset
182 ; Now test if write is done at first byte of 4kB block
heinrichsweikamp
parents:
diff changeset
183 ; if yes -> delete 4kB block first
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
184 tstfsz ext_flash_address+0 ; at 0x00?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
185 bra write_byte_ext_flash_plus1 ; NO - normal write
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
186 movf ext_flash_address+1,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
187 andlw 0x0F ; mask lower nibble
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
188 tstfsz WREG ; at 0x.0?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
189 bra write_byte_ext_flash_plus1 ; NO - normal write
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
190 ; YES - at beginning of 4kB block -> erase first!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
191 rcall ext_flash_erase4kB ; - erases 4kB sector @ext_flash_address:3
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
192 write_byte_ext_flash_plus1:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
193 movf ext_flash_rw,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
194 rcall ext_flash_byte_write ; write the byte
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
195 bra incf_ext_flash_address0_p1_0x20 ; +1 and roll over at 0x200000 to 0x000000 and return
0
heinrichsweikamp
parents:
diff changeset
196
heinrichsweikamp
parents:
diff changeset
197
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
198 global ext_flash_byte_write ; write from WREG
0
heinrichsweikamp
parents:
diff changeset
199 ext_flash_byte_write:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
200 movwf ext_flash_rw ; store data byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
201 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
202 movlw 0x06 ; WREN command
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
203 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
204 bsf flash_ncs ; CS=1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
205 movlw 0x02 ; write (PP, Page-Program) command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
206 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
207 rcall ext_flash_write_address ; write 24 bit address ext_flash_address:3 via SPI
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
208 movf ext_flash_rw,W ; load data byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
209 rcall write_spi ; write one byte of data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
210 bra ext_flash_wait_write ; and return...
423
ccaaac45b61a _another_ timing fix for firmware updates (2.07 was not published yet anyway)
heinrichsweikamp
parents: 421
diff changeset
211
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
212
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
213 global ext_flash_byte_write_comms ; without wait, ~86us fixed delay due to 115200 Baud
423
ccaaac45b61a _another_ timing fix for firmware updates (2.07 was not published yet anyway)
heinrichsweikamp
parents: 421
diff changeset
214 ext_flash_byte_write_comms:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
215 movwf ext_flash_rw ; store data byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
216 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
217 movlw 0x06 ; WREN command
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
218 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
219 bsf flash_ncs ; CS=1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
220 movlw 0x02 ; write PP (Page-Program) command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
221 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
222 rcall ext_flash_write_address ; write 24 bit address ext_flash_address:3 via SPI
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
223 movf ext_flash_rw,W ; load data byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
224 rcall write_spi ; write one byte of data
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
225 bsf flash_ncs ; CS=1
423
ccaaac45b61a _another_ timing fix for firmware updates (2.07 was not published yet anyway)
heinrichsweikamp
parents: 421
diff changeset
226 return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
227
0
heinrichsweikamp
parents:
diff changeset
228
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
229 global ext_flash_disable_protection ; disable write protection
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
230 ext_flash_disable_protection:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
231 ; unlock old memory
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
232 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
233 movlw 0x50 ; EWSR command
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
234 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
235 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
236 movlw 0x01 ; WRSR command
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
237 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
238 movlw b'00000000' ; new status
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
239 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
240 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
241 ; unlock new memory
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
242 movlw 0x06 ; WREN command
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
243 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
244 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
245 movlw 0x98 ; ULBPR command
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
246 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
247 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
248 movlw 0x06 ; WREN command
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
249 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
250 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
251 movlw 0x42 ; WBPR command
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
252 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
253 movlw .18
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
254 movwf lo
420
789230298511 fix handling for new flash memory chip
heinrichsweikamp
parents: 416
diff changeset
255 ext_flash_disable_protection2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
256 movlw 0x00
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
257 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
258 decfsz lo,F ; 18 bytes with 0x00
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
259 bra ext_flash_disable_protection2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
260 bsf flash_ncs ; CS=1
0
heinrichsweikamp
parents:
diff changeset
261 return
heinrichsweikamp
parents:
diff changeset
262
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
263
0
heinrichsweikamp
parents:
diff changeset
264 global ext_flash_enable_protection
heinrichsweikamp
parents:
diff changeset
265 ext_flash_enable_protection:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
266 ; lock old memory
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
267 bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
268 movlw 0x50 ; EWSR command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
269 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
270 bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
271 movlw 0x01 ; WRSR command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
272 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
273 movlw b'00011100' ; new status (write protection on)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
274 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
275 bsf flash_ncs ; CS=1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
276 ; lock new memory
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
277 ; movlw 0x06 ; WREN command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
278 ; rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
279 ; bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
280 ; movlw 0x8D ; LBPR command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
281 ; rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
282 ; bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
283 movlw 0x06 ; WREN command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
284 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
285 bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
286 movlw 0x42 ; WBPR command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
287 rcall write_spi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
288 movlw .18
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
289 movwf lo
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
290 ext_flash_enable_protection2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
291 movlw 0xFF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
292 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
293 decfsz lo,F ; 18 bytes with 0xFF
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
294 bra ext_flash_enable_protection2
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
295 bsf flash_ncs ; CS=1
0
heinrichsweikamp
parents:
diff changeset
296 return
heinrichsweikamp
parents:
diff changeset
297
heinrichsweikamp
parents:
diff changeset
298
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
299 global ext_flash_erase4kB ; erases 4kB sector
0
heinrichsweikamp
parents:
diff changeset
300 ext_flash_erase4kB:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
301 bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
302 movlw 0x06 ; WREN command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
303 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
304 bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
305 movlw 0x20 ; sector erase command
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
306 rcall write_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
307 rcall ext_flash_write_address ; write 24 bit address ext_flash_address:3 via SPI
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
308 ; bra ext_flash_wait_write ; wait for write... and return
0
heinrichsweikamp
parents:
diff changeset
309 ext_flash_wait_write:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
310 bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
311 ; WAITMS d'1' ; TBE/TSE=25ms...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
312 movlw 0x05 ; RDSR command
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
313 rcall write_spi ; read status
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
314 rcall write_spi ; read status into WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
315 bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
316 btfsc SSP2BUF,0 ; write operation in process?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
317 bra ext_flash_wait_write ; ES - loop waiting
0
heinrichsweikamp
parents:
diff changeset
318 return
heinrichsweikamp
parents:
diff changeset
319
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
320
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
321 global ext_flash_erase_logbook ; erases logbook memory (000000h -> 2FFFFFh -> 3MByte -> 3145728 Bytes)
0
heinrichsweikamp
parents:
diff changeset
322 ext_flash_erase_logbook:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
323 bsf flash_ncs ; CS=1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
324 clrf ext_flash_address+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
325 clrf ext_flash_address+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
326 clrf ext_flash_address+2
0
heinrichsweikamp
parents:
diff changeset
327
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
328 setf ext_flash_rw ; 256 * 12 kB = 3145728 bytes
0
heinrichsweikamp
parents:
diff changeset
329 ext_flash_erase_logbook_loop:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
330 rcall ext_flash_erase4kB ; 4kB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
331 rcall ext_flash_add_4kB ; increase ext_flash_address:3 by 4kB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
332 rcall ext_flash_erase4kB ; 4kB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
333 rcall ext_flash_add_4kB ; increase ext_flash_address:3 by 4kB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
334 rcall ext_flash_erase4kB ; 4kB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
335 rcall ext_flash_add_4kB ; increase ext_flash_address:3 by 4kB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
336 decfsz ext_flash_rw,F ; decrement loop counter, done?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
337 bra ext_flash_erase_logbook_loop ; NO - loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
338 return ; YES - done
0
heinrichsweikamp
parents:
diff changeset
339
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
340 ext_flash_add_4kB:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
341 movlw 0x10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
342 addwf ext_flash_address+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
343 movlw d'0'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
344 addwfc ext_flash_address+2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
345 return
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
346
0
heinrichsweikamp
parents:
diff changeset
347
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
348 write_spi: ; with data in WREG...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
349 bcf flash_ncs ; CS
0
heinrichsweikamp
parents:
diff changeset
350 global write_spi1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
351 write_spi1: ; with data in WREG...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
352 bcf SSP2STAT,WCOL ; clear flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
353 movwf SSP2BUF ; write to buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
354 btfsc SSP2STAT,WCOL ; was buffer full?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
355 bra write_spi1 ; YES - try again
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
356 write_spi2: ; wait for write command
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
357 btfss SSP2STAT, BF ; buffer full?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
358 bra write_spi2 ; NO - loop waiting
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
359 movf SSP2BUF,W ; YES - copy RX data to WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
360 return ; - return with RX data in WREG and SSP2BUF
0
heinrichsweikamp
parents:
diff changeset
361
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
362 END