📄 spi_flash.txt
字号:
000040 40010c00 DCD 0x40010c00
AREA ||i.SPI_FLASH_BulkErase||, CODE, READONLY, ALIGN=2
SPI_FLASH_BulkErase PROC
;;;126 void SPI_FLASH_BulkErase(void)
;;;127 {
000000 b510 PUSH {r4,lr}
;;;128 /* Send write enable instruction */
;;;129 SPI_FLASH_WriteEnable();
000002 f7fffffe BL SPI_FLASH_WriteEnable
;;;130
;;;131 /* Bulk Erase */
;;;132 /* Select the FLASH: Chip Select low */
;;;133 SPI_FLASH_CS_LOW();
000006 4c08 LDR r4,|L6.40|
000008 2101 MOVS r1,#1
00000a 4620 MOV r0,r4
00000c f7fffffe BL GPIO_ResetBits
;;;134 /* Send Bulk Erase instruction */
;;;135 SPI_FLASH_SendByte(BE);
000010 20c7 MOVS r0,#0xc7
000012 f7fffffe BL SPI_FLASH_SendByte
;;;136 /* Deselect the FLASH: Chip Select high */
;;;137 SPI_FLASH_CS_HIGH();
000016 2101 MOVS r1,#1
000018 4620 MOV r0,r4
00001a f7fffffe BL GPIO_SetBits
;;;138
;;;139 /* Wait the end of Flash writing */
;;;140 SPI_FLASH_WaitForWriteEnd();
00001e e8bd4010 POP {r4,lr}
000022 f7ffbffe B.W SPI_FLASH_WaitForWriteEnd
;;;141 }
;;;142
ENDP
000026 0000 DCW 0x0000
|L6.40|
000028 40010c00 DCD 0x40010c00
AREA ||i.SPI_FLASH_PageWrite||, CODE, READONLY, ALIGN=2
SPI_FLASH_PageWrite PROC
;;;156 void SPI_FLASH_PageWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite)
;;;157 {
000000 e92d41f0 PUSH {r4-r8,lr}
000004 4604 MOV r4,r0
000006 460f MOV r7,r1
000008 4615 MOV r5,r2
;;;158 /* Enable the write access to the FLASH */
;;;159 SPI_FLASH_WriteEnable();
00000a f7fffffe BL SPI_FLASH_WriteEnable
;;;160
;;;161 /* Select the FLASH: Chip Select low */
;;;162 SPI_FLASH_CS_LOW();
00000e 4e12 LDR r6,|L7.88|
000010 2101 MOVS r1,#1
000012 4630 MOV r0,r6
000014 f7fffffe BL GPIO_ResetBits
;;;163 /* Send "Write to Memory " instruction */
;;;164 SPI_FLASH_SendByte(WRITE);
000018 2002 MOVS r0,#2
00001a f7fffffe BL SPI_FLASH_SendByte
;;;165 /* Send WriteAddr high nibble address byte to write to */
;;;166 SPI_FLASH_SendByte((WriteAddr & 0xFF0000) >> 16);
00001e f3c74007 UBFX r0,r7,#16,#8
000022 f7fffffe BL SPI_FLASH_SendByte
;;;167 /* Send WriteAddr medium nibble address byte to write to */
;;;168 SPI_FLASH_SendByte((WriteAddr & 0xFF00) >> 8);
000026 f3c72007 UBFX r0,r7,#8,#8
00002a f7fffffe BL SPI_FLASH_SendByte
;;;169 /* Send WriteAddr low nibble address byte to write to */
;;;170 SPI_FLASH_SendByte(WriteAddr & 0xFF);
00002e b2f8 UXTB r0,r7
000030 f7fffffe BL SPI_FLASH_SendByte
;;;171
;;;172 /* while there is data to be written on the FLASH */
;;;173 while(NumByteToWrite--)
000034 e003 B |L7.62|
|L7.54|
;;;174 {
;;;175 /* Send the current byte */
;;;176 SPI_FLASH_SendByte(*pBuffer);
000036 7820 LDRB r0,[r4,#0]
000038 f7fffffe BL SPI_FLASH_SendByte
;;;177 /* Point on the next byte to be written */
;;;178 pBuffer++;
00003c 1c64 ADDS r4,r4,#1
|L7.62|
00003e 0028 MOVS r0,r5 ;173
000040 f1a50501 SUB r5,r5,#1 ;173
000044 b2ad UXTH r5,r5 ;173
000046 d1f6 BNE |L7.54|
;;;179 }
;;;180
;;;181 /* Deselect the FLASH: Chip Select high */
;;;182 SPI_FLASH_CS_HIGH();
000048 2101 MOVS r1,#1
00004a 4630 MOV r0,r6
00004c f7fffffe BL GPIO_SetBits
;;;183
;;;184 /* Wait the end of Flash writing */
;;;185 SPI_FLASH_WaitForWriteEnd();
000050 e8bd41f0 POP {r4-r8,lr}
000054 f7ffbffe B.W SPI_FLASH_WaitForWriteEnd
;;;186 }
;;;187
ENDP
|L7.88|
000058 40010c00 DCD 0x40010c00
AREA ||i.SPI_FLASH_BufferWrite||, CODE, READONLY, ALIGN=1
SPI_FLASH_BufferWrite PROC
;;;199 void SPI_FLASH_BufferWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite)
;;;200 {
000000 e92d47f0 PUSH {r4-r10,lr}
000004 4606 MOV r6,r0
000006 460d MOV r5,r1
;;;201 u8 NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0;
;;;202
;;;203 Addr = WriteAddr % SPI_FLASH_PageSize;
000008 f01100ff ANDS r0,r1,#0xff
;;;204 count = SPI_FLASH_PageSize - Addr;
00000c f1c00100 RSB r1,r0,#0
000010 b2cf UXTB r7,r1
;;;205 NumOfPage = NumByteToWrite / SPI_FLASH_PageSize;
000012 ea4f2412 LSR r4,r2,#8
;;;206 NumOfSingle = NumByteToWrite % SPI_FLASH_PageSize;
000016 f0020aff AND r10,r2,#0xff
00001a f44f7980 MOV r9,#0x100
;;;207
;;;208 if(Addr == 0) /* WriteAddr is SPI_FLASH_PageSize aligned */
00001e d113 BNE |L8.72|
;;;209 {
;;;210 if(NumOfPage == 0) /* NumByteToWrite < SPI_FLASH_PageSize */
000020 b95c CBNZ r4,|L8.58|
|L8.34|
;;;211 {
;;;212 SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumByteToWrite);
000022 4629 MOV r1,r5
000024 4630 MOV r0,r6
000026 e043 B |L8.176|
|L8.40|
;;;213 }
;;;214 else /* NumByteToWrite > SPI_FLASH_PageSize */
;;;215 {
;;;216 while(NumOfPage--)
;;;217 {
;;;218 SPI_FLASH_PageWrite(pBuffer, WriteAddr, SPI_FLASH_PageSize);
000028 464a MOV r2,r9
00002a 4629 MOV r1,r5
00002c 4630 MOV r0,r6
00002e f7fffffe BL SPI_FLASH_PageWrite
;;;219 WriteAddr += SPI_FLASH_PageSize;
000032 f5057580 ADD r5,r5,#0x100
;;;220 pBuffer += SPI_FLASH_PageSize;
000036 f5067680 ADD r6,r6,#0x100
|L8.58|
00003a 0020 MOVS r0,r4 ;216
00003c f1a40401 SUB r4,r4,#1 ;216
000040 b2e4 UXTB r4,r4 ;216
000042 d1f1 BNE |L8.40|
;;;221 }
;;;222
;;;223 SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumOfSingle);
000044 4652 MOV r2,r10
000046 e7ec B |L8.34|
|L8.72|
000048 b2e8 UXTB r0,r5
00004a 4240 RSBS r0,r0,#0
00004c b2c0 UXTB r0,r0
00004e eb050800 ADD r8,r5,r0
;;;224 }
;;;225 }
;;;226 else /* WriteAddr is not SPI_FLASH_PageSize aligned */
;;;227 {
;;;228 if(NumOfPage== 0) /* NumByteToWrite < SPI_FLASH_PageSize */
000052 b96c CBNZ r4,|L8.112|
;;;229 {
;;;230 if(NumOfSingle > count) /* (NumByteToWrite + WriteAddr) > SPI_FLASH_PageSize */
000054 45ba CMP r10,r7
000056 d9e4 BLS |L8.34|
;;;231 {
;;;232 temp = NumOfSingle - count;
000058 ebaa0007 SUB r0,r10,r7
00005c b2c4 UXTB r4,r0
;;;233
;;;234 SPI_FLASH_PageWrite(pBuffer, WriteAddr, count);
00005e 463a MOV r2,r7
000060 4629 MOV r1,r5
000062 4630 MOV r0,r6
000064 f7fffffe BL SPI_FLASH_PageWrite
000068 4641 MOV r1,r8
;;;235 WriteAddr += count;
;;;236 pBuffer += count;
00006a 19f0 ADDS r0,r6,r7
;;;237
;;;238 SPI_FLASH_PageWrite(pBuffer, WriteAddr, temp);
00006c 4622 MOV r2,r4
00006e e01f B |L8.176|
|L8.112|
;;;239 }
;;;240 else
;;;241 {
;;;242 SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumByteToWrite);
;;;243 }
;;;244 }
;;;245 else /* NumByteToWrite > SPI_FLASH_PageSize */
;;;246 {
;;;247 NumByteToWrite -= count;
000070 1bd0 SUBS r0,r2,r7
000072 b280 UXTH r0,r0
;;;248 NumOfPage = NumByteToWrite / SPI_FLASH_PageSize;
000074 0a04 LSRS r4,r0,#8
;;;249 NumOfSingle = NumByteToWrite % SPI_FLASH_PageSize;
000076 f0000aff AND r10,r0,#0xff
;;;250
;;;251 SPI_FLASH_PageWrite(pBuffer, WriteAddr, count);
00007a 463a MOV r2,r7
00007c 4629 MOV r1,r5
00007e 4630 MOV r0,r6
000080 f7fffffe BL SPI_FLASH_PageWrite
;;;252 WriteAddr += count;
;;;253 pBuffer += count;
000084 19f5 ADDS r5,r6,r7
;;;254
;;;255 while(NumOfPage--)
000086 e008 B |L8.154|
|L8.136|
;;;256 {
;;;257 SPI_FLASH_PageWrite(pBuffer, WriteAddr, SPI_FLASH_PageSize);
000088 464a MOV r2,r9
00008a 4641 MOV r1,r8
00008c 4628 MOV r0,r5
00008e f7fffffe BL SPI_FLASH_PageWrite
;;;258 WriteAddr += SPI_FLASH_PageSize;
000092 f5087880 ADD r8,r8,#0x100
;;;259 pBuffer += SPI_FLASH_PageSize;
000096 f5057580 ADD r5,r5,#0x100
|L8.154|
00009a 0020 MOVS r0,r4 ;255
00009c f1a40401 SUB r4,r4,#1 ;255
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -