⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spi_flash.txt

📁 stm32.rar
💻 TXT
📖 第 1 页 / 共 3 页
字号:
; generated by ARM/Thumb C/C++ Compiler with , RVCT3.1 [Build 942] for uVision
; commandline ArmCC [--split_sections --debug -c --asm --interleave -o.\Int_Flash\spi_flash.o --depend=.\Int_Flash\spi_flash.d --device=DARMSTM --apcs=interwork -O3 -I..\include -I..\..\..\..\..\INC\ST\STM32F10x\USB -Id:\Keil\ARM\INC\ST\STM32F10x -D__MICROLIB --omf_browse=.\Int_Flash\spi_flash.crf ..\source\spi_flash.c]
                          THUMB

                          AREA ||i.SPI_FLASH_Init||, CODE, READONLY, ALIGN=2

                  SPI_FLASH_Init PROC
;;;50     void SPI_FLASH_Init(void)
;;;51     {
000000  b530              PUSH     {r4,r5,lr}
000002  b087              SUB      sp,sp,#0x1c
;;;52       SPI_InitTypeDef  SPI_InitStructure;
;;;53       GPIO_InitTypeDef GPIO_InitStructure;
;;;54        
;;;55       /* Enable SPI1, GPIOA and GPIOBclocks */
;;;56       RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
000004  2101              MOVS     r1,#1
000006  f241000c          MOV      r0,#0x100c
00000a  f7fffffe          BL       RCC_APB2PeriphClockCmd
;;;57       
;;;58       /* Configure SPI1 pins: SCK, MISO and MOSI */
;;;59       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
00000e  20e0              MOVS     r0,#0xe0
000010  f8ad0004          STRH     r0,[sp,#4]
;;;60       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
000014  2503              MOVS     r5,#3
000016  f88d5006          STRB     r5,[sp,#6]
;;;61       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00001a  2018              MOVS     r0,#0x18
00001c  f88d0007          STRB     r0,[sp,#7]
;;;62       GPIO_Init(GPIOA, &GPIO_InitStructure);
000020  a901              ADD      r1,sp,#4
000022  481c              LDR      r0,|L1.148|
000024  f7fffffe          BL       GPIO_Init
;;;63     
;;;64       /* Configure PB.2 as Output push-pull, used as Flash Chip select */
;;;65       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
000028  2401              MOVS     r4,#1
00002a  f8ad4004          STRH     r4,[sp,#4]
;;;66       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00002e  f88d5006          STRB     r5,[sp,#6]
;;;67       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
000032  2010              MOVS     r0,#0x10
;;;68       GPIO_Init(GPIOB, &GPIO_InitStructure);
000034  4d18              LDR      r5,|L1.152|
000036  f88d0007          STRB     r0,[sp,#7]            ;67
00003a  a901              ADD      r1,sp,#4
00003c  4628              MOV      r0,r5
00003e  f7fffffe          BL       GPIO_Init
;;;69     
;;;70       /* Deselect the FLASH: Chip Select high */
;;;71       SPI_FLASH_CS_HIGH();
000042  2101              MOVS     r1,#1
000044  4628              MOV      r0,r5
000046  f7fffffe          BL       GPIO_SetBits
;;;72     
;;;73       /* SPI1 configuration */ 
;;;74       SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
00004a  2000              MOVS     r0,#0
00004c  f8ad0008          STRH     r0,[sp,#8]
;;;75       SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
000050  f44f7182          MOV      r1,#0x104
000054  f8ad100a          STRH     r1,[sp,#0xa]
;;;76       SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
000058  f8ad000c          STRH     r0,[sp,#0xc]
;;;77       SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
00005c  2102              MOVS     r1,#2
00005e  f8ad100e          STRH     r1,[sp,#0xe]
;;;78       SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
000062  f8ad4010          STRH     r4,[sp,#0x10]
;;;79       SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
000066  0209              LSLS     r1,r1,#8
000068  f8ad1012          STRH     r1,[sp,#0x12]
;;;80       SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
00006c  2108              MOVS     r1,#8
00006e  f8ad1014          STRH     r1,[sp,#0x14]
;;;81       SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
000072  f8ad0016          STRH     r0,[sp,#0x16]
;;;82       SPI_InitStructure.SPI_CRCPolynomial = 7;
000076  2007              MOVS     r0,#7
;;;83       SPI_Init(SPI1, &SPI_InitStructure);
000078  4c08              LDR      r4,|L1.156|
00007a  f8ad0018          STRH     r0,[sp,#0x18]         ;82
00007e  a902              ADD      r1,sp,#8
000080  4620              MOV      r0,r4
000082  f7fffffe          BL       SPI_Init
;;;84       
;;;85       /* Enable SPI1  */
;;;86       SPI_Cmd(SPI1, ENABLE);   
000086  2101              MOVS     r1,#1
000088  4620              MOV      r0,r4
00008a  f7fffffe          BL       SPI_Cmd
;;;87     }
00008e  b007              ADD      sp,sp,#0x1c
000090  bd30              POP      {r4,r5,pc}
;;;88     
                          ENDP

000092  0000              DCW      0x0000
                  |L1.148|
000094  40010800          DCD      0x40010800
                  |L1.152|
000098  40010c00          DCD      0x40010c00
                  |L1.156|
00009c  40013000          DCD      0x40013000

                          AREA ||i.SPI_FLASH_SendByte||, CODE, READONLY, ALIGN=2

                  SPI_FLASH_SendByte PROC
;;;392    u8 SPI_FLASH_SendByte(u8 byte)
;;;393    {
000000  b570              PUSH     {r4-r6,lr}
000002  4c0b              LDR      r4,|L2.48|
000004  4605              MOV      r5,r0
                  |L2.6|
;;;394      /* Loop while DR register in not emplty */
;;;395      while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
000006  2102              MOVS     r1,#2
000008  4620              MOV      r0,r4
00000a  f7fffffe          BL       SPI_I2S_GetFlagStatus
00000e  2800              CMP      r0,#0
000010  d0f9              BEQ      |L2.6|
;;;396    
;;;397      /* Send byte through the SPI1 peripheral */
;;;398      SPI_I2S_SendData(SPI1, byte);
000012  4629              MOV      r1,r5
000014  4620              MOV      r0,r4
000016  f7fffffe          BL       SPI_I2S_SendData
                  |L2.26|
;;;399    
;;;400      /* Wait to receive a byte */
;;;401      while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
00001a  2101              MOVS     r1,#1
00001c  4620              MOV      r0,r4
00001e  f7fffffe          BL       SPI_I2S_GetFlagStatus
000022  2800              CMP      r0,#0
000024  d0f9              BEQ      |L2.26|
;;;402    
;;;403      /* Return the byte read from the SPI bus */
;;;404      return SPI_I2S_ReceiveData(SPI1);
000026  4620              MOV      r0,r4
000028  f7fffffe          BL       SPI_I2S_ReceiveData
00002c  b2c0              UXTB     r0,r0
;;;405    }
00002e  bd70              POP      {r4-r6,pc}
;;;406    
                          ENDP

                  |L2.48|
000030  40013000          DCD      0x40013000

                          AREA ||i.SPI_FLASH_WaitForWriteEnd||, CODE, READONLY, ALIGN=2

                  SPI_FLASH_WaitForWriteEnd PROC
000000  b510              PUSH     {r4,lr}
000002  4c09              LDR      r4,|L3.40|
000004  2101              MOVS     r1,#1
000006  4620              MOV      r0,r4
000008  f7fffffe          BL       GPIO_ResetBits
00000c  2005              MOVS     r0,#5
00000e  f7fffffe          BL       SPI_FLASH_SendByte
                  |L3.18|
000012  20a5              MOVS     r0,#0xa5
000014  f7fffffe          BL       SPI_FLASH_SendByte
000018  07c0              LSLS     r0,r0,#31
00001a  d1fa              BNE      |L3.18|
00001c  4620              MOV      r0,r4
00001e  e8bd4010          POP      {r4,lr}
000022  2101              MOVS     r1,#1
000024  f7ffbffe          B.W      GPIO_SetBits
                          ENDP

                  |L3.40|
000028  40010c00          DCD      0x40010c00

                          AREA ||i.SPI_FLASH_WriteEnable||, CODE, READONLY, ALIGN=2

                  SPI_FLASH_WriteEnable PROC
000000  b510              PUSH     {r4,lr}
000002  4c07              LDR      r4,|L4.32|
000004  2101              MOVS     r1,#1
000006  4620              MOV      r0,r4
000008  f7fffffe          BL       GPIO_ResetBits
00000c  2006              MOVS     r0,#6
00000e  f7fffffe          BL       SPI_FLASH_SendByte
000012  4620              MOV      r0,r4
000014  e8bd4010          POP      {r4,lr}
000018  2101              MOVS     r1,#1
00001a  f7ffbffe          B.W      GPIO_SetBits
                          ENDP

00001e  0000              DCW      0x0000
                  |L4.32|
000020  40010c00          DCD      0x40010c00

                          AREA ||i.SPI_FLASH_SectorErase||, CODE, READONLY, ALIGN=2

                  SPI_FLASH_SectorErase PROC
;;;96     void SPI_FLASH_SectorErase(u32 SectorAddr)
;;;97     {
000000  b570              PUSH     {r4-r6,lr}
000002  4604              MOV      r4,r0
;;;98       /* Send write enable instruction */
;;;99       SPI_FLASH_WriteEnable();
000004  f7fffffe          BL       SPI_FLASH_WriteEnable
;;;100    
;;;101      /* Sector Erase */ 
;;;102      /* Select the FLASH: Chip Select low */
;;;103      SPI_FLASH_CS_LOW();
000008  4d0d              LDR      r5,|L5.64|
00000a  2101              MOVS     r1,#1
00000c  4628              MOV      r0,r5
00000e  f7fffffe          BL       GPIO_ResetBits
;;;104      /* Send Sector Erase instruction */
;;;105      SPI_FLASH_SendByte(SE);
000012  20d8              MOVS     r0,#0xd8
000014  f7fffffe          BL       SPI_FLASH_SendByte
;;;106      /* Send SectorAddr high nibble address byte */
;;;107      SPI_FLASH_SendByte((SectorAddr & 0xFF0000) >> 16);
000018  f3c44007          UBFX     r0,r4,#16,#8
00001c  f7fffffe          BL       SPI_FLASH_SendByte
;;;108      /* Send SectorAddr medium nibble address byte */
;;;109      SPI_FLASH_SendByte((SectorAddr & 0xFF00) >> 8);
000020  f3c42007          UBFX     r0,r4,#8,#8
000024  f7fffffe          BL       SPI_FLASH_SendByte
;;;110      /* Send SectorAddr low nibble address byte */
;;;111      SPI_FLASH_SendByte(SectorAddr & 0xFF);
000028  b2e0              UXTB     r0,r4
00002a  f7fffffe          BL       SPI_FLASH_SendByte
;;;112      /* Deselect the FLASH: Chip Select high */
;;;113      SPI_FLASH_CS_HIGH();
00002e  2101              MOVS     r1,#1
000030  4628              MOV      r0,r5
000032  f7fffffe          BL       GPIO_SetBits
;;;114    
;;;115      /* Wait the end of Flash writing */
;;;116      SPI_FLASH_WaitForWriteEnd();
000036  e8bd4070          POP      {r4-r6,lr}
00003a  f7ffbffe          B.W      SPI_FLASH_WaitForWriteEnd
;;;117    }
;;;118    
                          ENDP

00003e  0000              DCW      0x0000
                  |L5.64|

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -