; generated by Component: ARM Compiler 5.05 update 2 (build 169) Tool: ArmCC [4d0f38]
; commandline ArmCC [--c99 --list --split_sections --debug -c --asm --interleave -o..\..\..\..\build\bootloader\mico-fire_f429\obj_rvmdk\spi_flash.o --asm_dir=..\..\..\..\Build\Bootloader\MICO-Fire_F429\list_RVMDK\ --list_dir=..\..\..\..\Build\Bootloader\MICO-Fire_F429\list_RVMDK\ --depend=..\..\..\..\build\bootloader\mico-fire_f429\obj_rvmdk\spi_flash.d --cpu=Cortex-M4.fp --apcs=interwork --diag_suppress=9931,1,1293 -I..\..\..\..\Bootloader -I..\..\..\..\Board\fire_F429 -I..\..\..\..\include -I..\..\..\..\libraries\utilities -I..\..\..\..\libraries\utilities\json_c -I..\..\..\..\MICO\core -I..\..\..\..\MICO\security -I..\..\..\..\MICO\system -I..\..\..\..\MICO\system\command_console -I..\..\..\..\Platform\include -I..\..\..\..\Platform\Cortex-M4 -I..\..\..\..\Platform\Cortex-M4\CMSIS -I..\..\..\..\Platform\MCU\STM32F4xx\peripherals -I..\..\..\..\Platform\MCU\STM32F4xx\peripherals\Libraries\STM32F4xx_StdPeriph_Driver\inc -I..\..\..\..\Platform\MCU\STM32F4xx\peripherals\Libraries -I..\..\..\..\Platform\MCU\STM32F4xx\wlan_bus_driver -I..\..\..\..\Platform\Drivers\spi_flash -I..\..\..\..\Platform\Drivers -IG:\GIT_OSC\F429_OV2640_MICO_SDRAM\Projects\STM32F429\bootloader\RVMDK\RTE -ID:\work\keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0\Drivers\CMSIS\Device\ST\STM32F4xx\Include -ID:\work\keil5\ARM\CMSIS\Include -ID:\work\keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0 -D__MICROLIB -D__UVISION_VERSION=516 -DSTM32F429xx -DUSE_STDPERIPH_DRIVER -DBOOTLOADER -DNO_MICO_RTOS -DHSE_VALUE=25000000 --omf_browse=..\..\..\..\build\bootloader\mico-fire_f429\obj_rvmdk\spi_flash.crf ..\..\..\..\Platform\Drivers\spi_flash\spi_flash.c]
                          THUMB

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

                  generic_sflash_command PROC
;;;434    
;;;435    int generic_sflash_command(                                      const sflash_handle_t* const handle,
000000  e92d43ff          PUSH     {r0-r9,lr}
;;;436                                                                     sflash_command_t             cmd,
;;;437                                                                     unsigned long                num_initial_parameter_bytes,
;;;438                                /*@null@*/ /*@observer@*/            const void* const            parameter_bytes,
;;;439                                                                     unsigned long                num_data_bytes,
;;;440                                /*@null@*/ /*@observer@*/            const void* const            data_MOSI,
;;;441                                /*@null@*/ /*@out@*/ /*@dependent@*/ void* const                  data_MISO )
;;;442    {
000004  b08b              SUB      sp,sp,#0x2c
000006  4604              MOV      r4,r0
000008  a816              ADD      r0,sp,#0x58
00000a  4616              MOV      r6,r2
00000c  e8900380          LDM      r0,{r7-r9}
000010  461d              MOV      r5,r3
;;;443        int status;
;;;444        
;;;445        sflash_platform_message_segment_t segments[3] =
000012  2224              MOVS     r2,#0x24
000014  4916              LDR      r1,|L1.112|
000016  4668              MOV      r0,sp
000018  f7fffffe          BL       __aeabi_memcpy4
00001c  a80c              ADD      r0,sp,#0x30
00001e  9000              STR      r0,[sp,#0]
000020  9708              STR      r7,[sp,#0x20]
000022  a805              ADD      r0,sp,#0x14
000024  9503              STR      r5,[sp,#0xc]
000026  e8800340          STM      r0,{r6,r8,r9}
;;;446        {
;;;447                { &cmd,            NULL,       (unsigned long) 1 },
;;;448                { parameter_bytes, NULL,       num_initial_parameter_bytes },
;;;449                /*@-compdef@*/ /* Lint: Tell lint that it is OK that data_MISO is not completely defined */
;;;450                { data_MOSI,       data_MISO,  num_data_bytes }
;;;451                /*@+compdef@*/
;;;452        };
;;;453    
;;;454    
;;;455        status = sflash_platform_send_recv( handle->platform_peripheral, segments, (unsigned int) 3  );
00002a  2203              MOVS     r2,#3
00002c  4669              MOV      r1,sp
00002e  6860              LDR      r0,[r4,#4]
000030  f7fffffe          BL       sflash_platform_send_recv
;;;456    
;;;457        if ( status != 0 )
000034  2800              CMP      r0,#0
000036  d118              BNE      |L1.106|
;;;458        {
;;;459            /*@-mustdefine@*/ /* Lint: do not need to define data_MISO due to failure */
;;;460            return status;
;;;461            /*@+mustdefine@*/
;;;462        }
;;;463    
;;;464        if ( is_write_command( cmd ) == 1 )
000038  f89d0030          LDRB     r0,[sp,#0x30]
00003c  2802              CMP      r0,#2
00003e  d009              BEQ      |L1.84|
000040  2860              CMP      r0,#0x60
000042  d007              BEQ      |L1.84|
000044  28c7              CMP      r0,#0xc7
000046  d005              BEQ      |L1.84|
000048  2820              CMP      r0,#0x20
00004a  d003              BEQ      |L1.84|
00004c  2852              CMP      r0,#0x52
00004e  d001              BEQ      |L1.84|
000050  28d8              CMP      r0,#0xd8
000052  d109              BNE      |L1.104|
                  |L1.84|
;;;465        {
;;;466            unsigned char status_register;
;;;467            /* write commands require waiting until chip is finished writing */
;;;468    
;;;469            do
;;;470            {
;;;471                status = sflash_read_status_register( handle, &status_register );
000054  a909              ADD      r1,sp,#0x24
000056  4620              MOV      r0,r4
000058  f7fffffe          BL       sflash_read_status_register
;;;472                if ( status != 0 )
00005c  2800              CMP      r0,#0
00005e  d104              BNE      |L1.106|
;;;473                {
;;;474                    /*@-mustdefine@*/ /* Lint: do not need to define data_MISO due to failure */
;;;475                    return status;
;;;476                    /*@+mustdefine@*/
;;;477                }
;;;478            } while( ( status_register & SFLASH_STATUS_REGISTER_BUSY ) != (unsigned char) 0 );
000060  f89d0024          LDRB     r0,[sp,#0x24]
000064  07c0              LSLS     r0,r0,#31
000066  d1f5              BNE      |L1.84|
                  |L1.104|
;;;479    
;;;480        }
;;;481    
;;;482        /*@-mustdefine@*/ /* Lint: lint does not realise data_MISO was set by sflash_platform_send_recv */
;;;483        return 0;
000068  2000              MOVS     r0,#0
                  |L1.106|
;;;484        /*@+mustdefine@*/
;;;485    }
00006a  b00f              ADD      sp,sp,#0x3c
00006c  e8bd83f0          POP      {r4-r9,pc}
;;;486    
                          ENDP

                  |L1.112|
                          DCD      ||.constdata||

                          AREA ||i.init_sflash||, CODE, READONLY, ALIGN=1

                  init_sflash PROC
;;;386    
;;;387    int init_sflash( /*@out@*/ sflash_handle_t* const handle, /*@shared@*/ void* peripheral_id, sflash_write_allowed_t write_allowed_in )
000000  b538              PUSH     {r3-r5,lr}
;;;388    {
000002  4615              MOV      r5,r2
000004  460a              MOV      r2,r1
000006  4604              MOV      r4,r0
;;;389       int status;
;;;390        device_id_t tmp_device_id;
;;;391    
;;;392        status = sflash_platform_init( peripheral_id, &handle->platform_peripheral );
000008  1d01              ADDS     r1,r0,#4
00000a  4610              MOV      r0,r2
00000c  f7fffffe          BL       sflash_platform_init
;;;393        if ( status != 0 )
000010  2800              CMP      r0,#0
000012  d11a              BNE      |L2.74|
;;;394        {
;;;395            return status;
;;;396        }
;;;397    
;;;398        handle->write_allowed = write_allowed_in;
000014  7225              STRB     r5,[r4,#8]
;;;399        handle->device_id     = 0;
;;;400    
;;;401        status = sflash_read_ID( handle, &tmp_device_id );
000016  6020              STR      r0,[r4,#0]
000018  4669              MOV      r1,sp
00001a  4620              MOV      r0,r4
00001c  f7fffffe          BL       sflash_read_ID
;;;402        if ( status != 0 )
000020  2800              CMP      r0,#0
000022  d112              BNE      |L2.74|
;;;403        {
;;;404            return status;
;;;405        }
;;;406    
;;;407        handle->device_id = ( ((uint32_t) tmp_device_id.id[0]) << 16 ) +
000024  f89d0000          LDRB     r0,[sp,#0]
000028  f89d1001          LDRB     r1,[sp,#1]
00002c  0400              LSLS     r0,r0,#16
00002e  eb002001          ADD      r0,r0,r1,LSL #8
000032  f89d1002          LDRB     r1,[sp,#2]
;;;408                            ( ((uint32_t) tmp_device_id.id[1]) <<  8 ) +
;;;409                            ( ((uint32_t) tmp_device_id.id[2]) <<  0 );
;;;410    
;;;411    
;;;412        if ( write_allowed_in == SFLASH_WRITE_ALLOWED )
000036  2d01              CMP      r5,#1
000038  4408              ADD      r0,r0,r1              ;407
00003a  6020              STR      r0,[r4,#0]
00003c  d104              BNE      |L2.72|
;;;413        {
;;;414            /* Enable writing */
;;;415            if (0 != ( status = sflash_write_enable( handle ) ) )
00003e  4620              MOV      r0,r4
000040  f7fffffe          BL       sflash_write_enable
000044  2800              CMP      r0,#0
000046  d100              BNE      |L2.74|
                  |L2.72|
;;;416            {
;;;417                return status;
;;;418            }
;;;419        }
;;;420    
;;;421        return 0;
000048  2000              MOVS     r0,#0
                  |L2.74|
;;;422    }
00004a  bd38              POP      {r3-r5,pc}
;;;423    
                          ENDP


                          AREA ||i.sflash_chip_erase||, CODE, READONLY, ALIGN=1

                  sflash_chip_erase PROC
;;;85     
;;;86     int sflash_chip_erase( const sflash_handle_t* const handle )
000000  b53e              PUSH     {r1-r5,lr}
;;;87     {
000002  4604              MOV      r4,r0
;;;88         int status = sflash_write_enable( handle );
000004  f7fffffe          BL       sflash_write_enable
;;;89         if ( status != 0 )
000008  2800              CMP      r0,#0
00000a  d108              BNE      |L3.30|
;;;90         {
;;;91             return status;
;;;92         }
;;;93         return generic_sflash_command( handle, SFLASH_CHIP_ERASE1, 0, NULL, 0, NULL, NULL );
00000c  9000              STR      r0,[sp,#0]
00000e  9001              STR      r0,[sp,#4]
000010  4603              MOV      r3,r0
000012  4602              MOV      r2,r0
000014  9002              STR      r0,[sp,#8]
000016  2160              MOVS     r1,#0x60
000018  4620              MOV      r0,r4
00001a  f7fffffe          BL       generic_sflash_command
                  |L3.30|
;;;94     }
00001e  bd3e              POP      {r1-r5,pc}
;;;95     
                          ENDP


                          AREA ||i.sflash_get_size||, CODE, READONLY, ALIGN=1

                  sflash_get_size PROC
;;;157    
;;;158    int sflash_get_size( const sflash_handle_t* const handle, /*@out@*/ unsigned long* const size )
000000  2000              MOVS     r0,#0
;;;159    {
;;;160        *size = 0; /* Unknown size to start with */
000002  6008              STR      r0,[r1,#0]
;;;161    
;;;162    #ifdef SFLASH_SUPPORT_MACRONIX_PARTS
;;;163        if ( handle->device_id == SFLASH_ID_MX25L8006E )
;;;164        {
;;;165            *size = (unsigned long) 0x100000; /* 1MByte */
;;;166        }
;;;167        else if ( handle->device_id == SFLASH_ID_MX25L1606E )
;;;168        {
;;;169            *size = (unsigned long) 0x200000; /* 2MByte */
;;;170        }
;;;171    #endif /* ifdef SFLASH_SUPPORT_MACRONIX_PARTS */
;;;172    #ifdef SFLASH_SUPPORT_SST_PARTS
;;;173        if ( handle->device_id == SFLASH_ID_SST25VF080B )
;;;174        {
;;;175            *size = (unsigned long) 0x100000; /* 1MByte */
;;;176        }
;;;177    #endif /* ifdef SFLASH_SUPPORT_SST_PARTS */
;;;178    #ifdef SFLASH_SUPPORT_EON_PARTS
;;;179        if ( handle->device_id == SFLASH_ID_EN25QH16 )
;;;180        {
;;;181            *size = (unsigned long) 0x200000; /* 2MByte */
;;;182        }
;;;183    #endif /* ifdef SFLASH_SUPPORT_EON_PARTS */
;;;184    #ifdef SFLASH_SUPPORT_WINBOND_PARTS
;;;185        if ( handle->device_id == SFLASH_ID_W25X80AVSIG )
;;;186        {
;;;187            *size = (unsigned long) 0x100000; /* 1MByte */
;;;188        }
;;;189    #endif /* ifdef SFLASH_SUPPORT_WINBOND_PARTS */
;;;190        return 0;
;;;191    }
000004  4770              BX       lr
;;;192    
                          ENDP


                          AREA ||i.sflash_read||, CODE, READONLY, ALIGN=1

                  sflash_read PROC
;;;120    
;;;121    int sflash_read( const sflash_handle_t* const handle, unsigned long device_address, void* const data_addr, unsigned int size )
000000  b51f              PUSH     {r0-r4,lr}
;;;122    {
;;;123        char device_address_array[3] =  { ( ( device_address & 0x00FF0000 ) >> 16 ),
000002  0c0c              LSRS     r4,r1,#16
000004  f88d400c          STRB     r4,[sp,#0xc]
000008  0a0c              LSRS     r4,r1,#8
00000a  f88d400d          STRB     r4,[sp,#0xd]
00000e  f88d100e          STRB     r1,[sp,#0xe]
;;;124                                          ( ( device_address & 0x0000FF00 ) >>  8 ),
;;;125                                          ( ( device_address & 0x000000FF ) >>  0 ) };
;;;126    
;;;127        return generic_sflash_command( handle, SFLASH_READ, 3, device_address_array, size, NULL, data_addr );
000012  2100              MOVS     r1,#0
000014  e9cd3100          STRD     r3,r1,[sp,#0]
000018  9202              STR      r2,[sp,#8]
00001a  2203              MOVS     r2,#3
00001c  ab03              ADD      r3,sp,#0xc
00001e  4611              MOV      r1,r2
000020  f7fffffe          BL       generic_sflash_command
;;;128    }
000024  b004              ADD      sp,sp,#0x10
000026  bd10              POP      {r4,pc}
;;;129    
                          ENDP


                          AREA ||i.sflash_read_ID||, CODE, READONLY, ALIGN=1

                  sflash_read_ID PROC
;;;39     
;;;40     int sflash_read_ID( const sflash_handle_t* const handle, void* const data_addr )
000000  b50e              PUSH     {r1-r3,lr}
;;;41     {
;;;42         return generic_sflash_command( handle, SFLASH_READ_JEDEC_ID, 0, NULL, 3, NULL, data_addr );
000002  2200              MOVS     r2,#0
000004  2303              MOVS     r3,#3
000006  e9cd3200          STRD     r3,r2,[sp,#0]
00000a  9102              STR      r1,[sp,#8]
00000c  4613              MOV      r3,r2
00000e  219f              MOVS     r1,#0x9f
000010  f7fffffe          BL       generic_sflash_command
;;;43     }
000014  bd0e              POP      {r1-r3,pc}
;;;44     
                          ENDP


                          AREA ||i.sflash_read_status_register||, CODE, READONLY, ALIGN=1

                  sflash_read_status_register PROC
;;;113    
;;;114    int sflash_read_status_register( const sflash_handle_t* const handle, void* const dest_addr )
000000  b50e              PUSH     {r1-r3,lr}
;;;115    {
;;;116        return generic_sflash_command( handle, SFLASH_READ_STATUS_REGISTER, 0, NULL, 1, NULL, dest_addr );
000002  2200              MOVS     r2,#0
000004  2301              MOVS     r3,#1
000006  e9cd3200          STRD     r3,r2,[sp,#0]
00000a  9102              STR      r1,[sp,#8]
00000c  4613              MOV      r3,r2
00000e  2105              MOVS     r1,#5
000010  f7fffffe          BL       generic_sflash_command
;;;117    }
000014  bd0e              POP      {r1-r3,pc}
;;;118    
                          ENDP


                          AREA ||i.sflash_sector_erase||, CODE, READONLY, ALIGN=1

                  sflash_sector_erase PROC
;;;95     
;;;96     int sflash_sector_erase ( const sflash_handle_t* const handle, unsigned long device_address )
000000  b51f              PUSH     {r0-r4,lr}
;;;97     {
000002  4604              MOV      r4,r0
;;;98     
;;;99         char device_address_array[3] =  { ( ( device_address & 0x00FF0000 ) >> 16 ),
000004  0c08              LSRS     r0,r1,#16
000006  f88d000c          STRB     r0,[sp,#0xc]
00000a  0a08              LSRS     r0,r1,#8
00000c  f88d000d          STRB     r0,[sp,#0xd]
000010  f88d100e          STRB     r1,[sp,#0xe]
;;;100                                          ( ( device_address & 0x0000FF00 ) >>  8 ),
;;;101                                          ( ( device_address & 0x000000FF ) >>  0 ) };
;;;102    
;;;103        int retval;
;;;104        int status = sflash_write_enable( handle );
000014  4620              MOV      r0,r4
000016  f7fffffe          BL       sflash_write_enable
;;;105        if ( status != 0 )
00001a  2800              CMP      r0,#0
00001c  d10b              BNE      |L8.54|
;;;106        {
;;;107            return status;
;;;108        }
;;;109        retval = generic_sflash_command( handle, SFLASH_SECTOR_ERASE, 3, device_address_array, 0, NULL, NULL );
00001e  9000              STR      r0,[sp,#0]
000020  9001              STR      r0,[sp,#4]
000022  9002              STR      r0,[sp,#8]
000024  ab03              ADD      r3,sp,#0xc
000026  2203              MOVS     r2,#3
000028  2120              MOVS     r1,#0x20
00002a  4620              MOV      r0,r4
00002c  f7fffffe          BL       generic_sflash_command
;;;110        check_string(retval == 0, "SPI Flash erase error");
000030  2800              CMP      r0,#0
000032  d000              BEQ      |L8.54|
000034  be00              BKPT     #0
                  |L8.54|
;;;111        return retval;
;;;112    }
000036  b004              ADD      sp,sp,#0x10
000038  bd10              POP      {r4,pc}
;;;113    
                          ENDP


                          AREA ||i.sflash_write||, CODE, READONLY, ALIGN=1

                  sflash_write PROC
;;;288      */
;;;289    int sflash_write( const sflash_handle_t* const handle, unsigned long device_address, const void* const data_addr, unsigned int size )
000000  e92d5ff0          PUSH     {r4-r12,lr}
;;;290    {
000004  4683              MOV      r11,r0
000006  460f              MOV      r7,r1
;;;291      int status;
;;;292      uint8_t NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0;
;;;293      unsigned char* data_addr_ptr = (unsigned char*) data_addr;
;;;294    
;;;295      Addr = device_address % sFLASH_SPI_PAGESIZE;
000008  f01100ff          ANDS     r0,r1,#0xff
;;;296      count = sFLASH_SPI_PAGESIZE - Addr;
00000c  f1c00100          RSB      r1,r0,#0
000010  4614              MOV      r4,r2                 ;290
000012  b2ce              UXTB     r6,r1
;;;297      NumOfPage =  size / sFLASH_SPI_PAGESIZE;
000014  f3c32507          UBFX     r5,r3,#8,#8
;;;298      NumOfSingle = size % sFLASH_SPI_PAGESIZE;
000018  f00309ff          AND      r9,r3,#0xff
;;;299    
;;;300      if (Addr == 0) /*!< WriteAddr is sFLASH_PAGESIZE aligned  */
;;;301      {
;;;302        if (NumOfPage == 0) /*!< NumByteToWrite < sFLASH_PAGESIZE */
;;;303        {
;;;304          status = sflash_write_page( handle, device_address, data_addr_ptr, size );
;;;305          //sFLASH_WritePage(pBuffer, WriteAddr, NumByteToWrite);
;;;306        }
;;;307        else /*!< NumByteToWrite > sFLASH_PAGESIZE */
;;;308        {
;;;309          while (NumOfPage--)
;;;310          {
;;;311            status = sflash_write_page( handle, device_address, data_addr_ptr, sFLASH_SPI_PAGESIZE );
00001c  f44f7a80          MOV      r10,#0x100
000020  d013              BEQ      |L9.74|
000022  b2f8              UXTB     r0,r7                 ;295
000024  4240              RSBS     r0,r0,#0              ;296
000026  b2c0              UXTB     r0,r0                 ;296
;;;312            //sFLASH_WritePage(pBuffer, WriteAddr, sFLASH_SPI_PAGESIZE);
;;;313            device_address +=  sFLASH_SPI_PAGESIZE;
;;;314            data_addr_ptr += sFLASH_SPI_PAGESIZE;
;;;315          }
;;;316    
;;;317          status = sflash_write_page( handle, device_address, data_addr_ptr, NumOfSingle);
;;;318        }
;;;319      }
;;;320      else /*!< WriteAddr is not sFLASH_PAGESIZE aligned  */
;;;321      {
;;;322        if (NumOfPage == 0) /*!< NumByteToWrite < sFLASH_PAGESIZE */
;;;323        {
;;;324          if (NumOfSingle > count) /*!< (NumByteToWrite + WriteAddr) > sFLASH_PAGESIZE */
;;;325          {
;;;326            temp = NumOfSingle - count;
;;;327    
;;;328            status = sflash_write_page( handle, device_address, data_addr_ptr, count );
;;;329            //sFLASH_WritePage(pBuffer, WriteAddr, count);
;;;330            device_address +=  count;
000028  eb070800          ADD      r8,r7,r0
00002c  b30d              CBZ      r5,|L9.114|
;;;331            data_addr_ptr += count;
;;;332    
;;;333            status = sflash_write_page( handle, device_address, data_addr_ptr, temp);
;;;334          }
;;;335          else
;;;336          {
;;;337            status = sflash_write_page(handle, device_address, data_addr_ptr, size);
;;;338          }
;;;339        }
;;;340        else /*!< NumByteToWrite > sFLASH_PAGESIZE */
;;;341        {
;;;342          size -= count;
00002e  1b98              SUBS     r0,r3,r6
;;;343          NumOfPage =  size / sFLASH_SPI_PAGESIZE;
000030  f3c02507          UBFX     r5,r0,#8,#8
;;;344          NumOfSingle = size % sFLASH_SPI_PAGESIZE;
000034  f00009ff          AND      r9,r0,#0xff
;;;345    
;;;346          status = sflash_write_page( handle, device_address, data_addr_ptr, count );
000038  4633              MOV      r3,r6
00003a  4639              MOV      r1,r7
00003c  4658              MOV      r0,r11
00003e  f7fffffe          BL       sflash_write_page
;;;347          //sFLASH_WritePage(pBuffer, WriteAddr, count);
;;;348          device_address +=  count;
;;;349          data_addr_ptr += count;
000042  4434              ADD      r4,r4,r6
000044  4647              MOV      r7,r8                 ;346
000046  4656              MOV      r6,r10                ;311
;;;350    
;;;351          while (NumOfPage--)
000048  e02f              B        |L9.170|
                  |L9.74|
00004a  b175              CBZ      r5,|L9.106|
00004c  4656              MOV      r6,r10                ;311
                  |L9.78|
00004e  1e6d              SUBS     r5,r5,#1              ;309
000050  b2ed              UXTB     r5,r5                 ;309
000052  d30c              BCC      |L9.110|
000054  4633              MOV      r3,r6                 ;311
000056  4622              MOV      r2,r4                 ;311
000058  4639              MOV      r1,r7                 ;311
00005a  4658              MOV      r0,r11                ;311
00005c  f7fffffe          BL       sflash_write_page
000060  f5047480          ADD      r4,r4,#0x100          ;311
000064  f5077780          ADD      r7,r7,#0x100          ;311
000068  e7f1              B        |L9.78|
                  |L9.106|
00006a  4639              MOV      r1,r7                 ;304
00006c  e00e              B        |L9.140|
                  |L9.110|
00006e  464b              MOV      r3,r9                 ;317
000070  e022              B        |L9.184|
                  |L9.114|
000072  45b1              CMP      r9,r6                 ;324
000074  d9f9              BLS      |L9.106|
000076  eba90006          SUB      r0,r9,r6              ;326
00007a  b2c5              UXTB     r5,r0                 ;326
00007c  4633              MOV      r3,r6                 ;328
00007e  4639              MOV      r1,r7                 ;328
000080  4658              MOV      r0,r11                ;328
000082  f7fffffe          BL       sflash_write_page
000086  4641              MOV      r1,r8                 ;328
000088  19a2              ADDS     r2,r4,r6              ;331
00008a  462b              MOV      r3,r5                 ;333
                  |L9.140|
00008c  4658              MOV      r0,r11                ;337
00008e  e8bd5ff0          POP      {r4-r12,lr}           ;337
000092  f7ffbffe          B.W      sflash_write_page
                  |L9.150|
;;;352          {
;;;353            status = sflash_write_page( handle, device_address, data_addr_ptr, sFLASH_SPI_PAGESIZE );
000096  4633              MOV      r3,r6
000098  4622              MOV      r2,r4
00009a  4639              MOV      r1,r7
00009c  4658              MOV      r0,r11
00009e  f7fffffe          BL       sflash_write_page
0000a2  f5047480          ADD      r4,r4,#0x100
0000a6  f5077780          ADD      r7,r7,#0x100
                  |L9.170|
0000aa  1e6d              SUBS     r5,r5,#1              ;351
0000ac  b2ed              UXTB     r5,r5                 ;351
0000ae  d2f2              BCS      |L9.150|
;;;354            //sFLASH_WritePage(pBuffer, WriteAddr, sFLASH_SPI_PAGESIZE);
;;;355            device_address +=  sFLASH_SPI_PAGESIZE;
;;;356            data_addr_ptr += sFLASH_SPI_PAGESIZE;
;;;357          }
;;;358    
;;;359          if (NumOfSingle != 0)
0000b0  ea5f0109          MOVS     r1,r9
0000b4  d002              BEQ      |L9.188|
;;;360          {
;;;361            status = sflash_write_page( handle, device_address, data_addr_ptr, NumOfSingle );
0000b6  460b              MOV      r3,r1
                  |L9.184|
0000b8  4622              MOV      r2,r4
0000ba  e7d6              B        |L9.106|
                  |L9.188|
;;;362            //sFLASH_WritePage(pBuffer, WriteAddr, NumOfSingle);
;;;363          }
;;;364        }
;;;365      }
;;;366      return status;
;;;367    }
0000bc  e8bd9ff0          POP      {r4-r12,pc}
;;;368    
                          ENDP


                          AREA ||i.sflash_write_enable||, CODE, READONLY, ALIGN=1

                  sflash_write_enable PROC
;;;44     
;;;45     int sflash_write_enable( const sflash_handle_t* const handle )
000000  b57f              PUSH     {r0-r6,lr}
;;;46     {
000002  4605              MOV      r5,r0
;;;47         if ( handle->write_allowed == SFLASH_WRITE_ALLOWED )
000004  7a00              LDRB     r0,[r0,#8]
000006  2801              CMP      r0,#1
000008  d003              BEQ      |L10.18|
;;;48         {
;;;49             /* Send write-enable command */
;;;50             int status = generic_sflash_command( handle, SFLASH_WRITE_ENABLE, 0, NULL, 0, NULL, NULL );
;;;51             if ( status != 0 )
;;;52             {
;;;53                 return status;
;;;54             }
;;;55     
;;;56             /* Check status register */
;;;57             unsigned char status_register;
;;;58             if ( 0 != ( status = sflash_read_status_register( handle, &status_register ) ) )
;;;59             {
;;;60                 return status;
;;;61             }
;;;62     
;;;63             /* Check if Block protect bits are set */
;;;64             if ( status_register != SFLASH_STATUS_REGISTER_WRITE_ENABLED )
;;;65             {
;;;66                 /* Disable protection for all blocks */
;;;67                 if (0 != ( status = sflash_write_status_register( handle, 0 ) ) )
;;;68                 {
;;;69                     return status;
;;;70                 }
;;;71     
;;;72                 /* Re-Enable writing */
;;;73                 if (0 != ( status = generic_sflash_command( handle, SFLASH_WRITE_ENABLE, 0, NULL, 0, NULL, NULL ) ) )
;;;74                 {
;;;75                     return status;
;;;76                 }
;;;77             }
;;;78             return 0;
;;;79         }
;;;80         else
;;;81         {
;;;82             return -1;
00000a  f04f30ff          MOV      r0,#0xffffffff
                  |L10.14|
;;;83         }
;;;84     }
00000e  b004              ADD      sp,sp,#0x10
000010  bd70              POP      {r4-r6,pc}
                  |L10.18|
000012  2400              MOVS     r4,#0                 ;50
000014  9400              STR      r4,[sp,#0]            ;50
000016  9401              STR      r4,[sp,#4]            ;50
000018  4623              MOV      r3,r4                 ;50
00001a  4622              MOV      r2,r4                 ;50
00001c  2106              MOVS     r1,#6                 ;50
00001e  4628              MOV      r0,r5                 ;50
000020  9402              STR      r4,[sp,#8]            ;50
000022  f7fffffe          BL       generic_sflash_command
000026  2800              CMP      r0,#0                 ;51
000028  d1f1              BNE      |L10.14|
00002a  a903              ADD      r1,sp,#0xc            ;58
00002c  4628              MOV      r0,r5                 ;58
00002e  f7fffffe          BL       sflash_read_status_register
000032  2800              CMP      r0,#0                 ;58
000034  d1eb              BNE      |L10.14|
000036  f89d000c          LDRB     r0,[sp,#0xc]          ;64
00003a  2802              CMP      r0,#2                 ;64
00003c  d010              BEQ      |L10.96|
00003e  2100              MOVS     r1,#0                 ;67
000040  4628              MOV      r0,r5                 ;67
000042  f7fffffe          BL       sflash_write_status_register
000046  2800              CMP      r0,#0                 ;67
000048  d1e1              BNE      |L10.14|
00004a  2300              MOVS     r3,#0                 ;73
00004c  9400              STR      r4,[sp,#0]            ;73
00004e  9401              STR      r4,[sp,#4]            ;73
000050  461a              MOV      r2,r3                 ;73
000052  2106              MOVS     r1,#6                 ;73
000054  4628              MOV      r0,r5                 ;73
000056  9402              STR      r4,[sp,#8]            ;73
000058  f7fffffe          BL       generic_sflash_command
00005c  2800              CMP      r0,#0                 ;73
00005e  d1d6              BNE      |L10.14|
                  |L10.96|
000060  2000              MOVS     r0,#0                 ;78
000062  e7d4              B        |L10.14|
;;;85     
                          ENDP


                          AREA ||i.sflash_write_page||, CODE, READONLY, ALIGN=1

                  sflash_write_page PROC
;;;193    
;;;194    int sflash_write_page( const sflash_handle_t* const handle, unsigned long device_address, const void* const data_addr, int size )
000000  e92d47ff          PUSH     {r0-r10,lr}
;;;195    {
000004  4682              MOV      r10,r0
;;;196        int status;
;;;197        int write_size;
;;;198        int max_write_size = 256;
;;;199        unsigned char enable_before_every_write = 1;
;;;200        unsigned char* data_addr_ptr = (unsigned char*) data_addr;
;;;201        unsigned char curr_device_address[3];
;;;202    
;;;203        if ( handle->write_allowed == SFLASH_WRITE_ALLOWED )
000006  7a00              LDRB     r0,[r0,#8]
000008  461e              MOV      r6,r3                 ;195
00000a  4617              MOV      r7,r2                 ;195
00000c  460c              MOV      r4,r1                 ;195
00000e  f44f7880          MOV      r8,#0x100             ;198
000012  f04f0901          MOV      r9,#1                 ;199
000016  2801              CMP      r0,#1
000018  d029              BEQ      |L11.110|
;;;204        {
;;;205        }
;;;206        else
;;;207        {
;;;208            return -1;
00001a  f04f30ff          MOV      r0,#0xffffffff
                  |L11.30|
;;;209        }
;;;210    
;;;211        /* Some manufacturers support programming an entire page in one command. */
;;;212    
;;;213    #ifdef SFLASH_SUPPORT_MACRONIX_PARTS
;;;214        if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_MACRONIX )
;;;215        {
;;;216            max_write_size = 256;  /* TODO: this should be 256, but that causes write errors */
;;;217            enable_before_every_write = 1;
;;;218        }
;;;219    #endif /* ifdef SFLASH_SUPPORT_MACRONIX_PARTS */
;;;220    
;;;221    #ifdef SFLASH_SUPPORT_WINBOND_PARTS
;;;222        if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_WINBOND )
;;;223        {
;;;224            max_write_size = 256;  /* TODO: this should be 256, but that causes write errors */
;;;225            enable_before_every_write = 1;
;;;226        }
;;;227    #endif /* ifdef SFLASH_SUPPORT_MACRONIX_PARTS */
;;;228    
;;;229    #ifdef SFLASH_SUPPORT_SST_PARTS
;;;230        if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_SST )
;;;231        {
;;;232            max_write_size = 1;
;;;233            enable_before_every_write = 1;
;;;234        }
;;;235    #endif /* ifdef SFLASH_SUPPORT_SST_PARTS */
;;;236    #ifdef SFLASH_SUPPORT_EON_PARTS
;;;237        if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_EON )
;;;238        {
;;;239            max_write_size = (unsigned int) 1;
;;;240            enable_before_every_write = 1;
;;;241        }
;;;242    #endif /* ifdef SFLASH_SUPPORT_EON_PARTS */
;;;243    
;;;244    
;;;245        if ( ( enable_before_every_write == 0 ) &&
;;;246             ( 0 != ( status = sflash_write_enable( handle ) ) ) )
;;;247        {
;;;248            return status;
;;;249        }
;;;250    
;;;251        /* Generic x-bytes-at-a-time write */
;;;252    
;;;253        while ( size > 0 )
;;;254        {
;;;255            write_size = ( size > max_write_size )? max_write_size : size;
;;;256            curr_device_address[0] = ( ( device_address & 0x00FF0000 ) >> 16 );
;;;257            curr_device_address[1] = ( ( device_address & 0x0000FF00 ) >>  8 );
;;;258            curr_device_address[2] = ( ( device_address & 0x000000FF ) >>  0 );
;;;259    
;;;260            if ( ( enable_before_every_write == 1 ) &&
;;;261                 ( 0 != ( status = sflash_write_enable( handle ) ) ) )
;;;262            {
;;;263                return status;
;;;264            }
;;;265    
;;;266            if ( 0 != ( status = generic_sflash_command( handle, SFLASH_WRITE, 3, curr_device_address, write_size, data_addr_ptr, NULL ) ) )
;;;267            {
;;;268                return status;
;;;269            }
;;;270    
;;;271            data_addr_ptr += write_size;
;;;272            device_address += write_size;
;;;273            size -= write_size;
;;;274    
;;;275        }
;;;276    
;;;277        return 0;
;;;278    }
00001e  b004              ADD      sp,sp,#0x10
000020  e8bd87f0          POP      {r4-r10,pc}
                  |L11.36|
000024  4640              MOV      r0,r8                 ;255
000026  4546              CMP      r6,r8                 ;255
000028  dd01              BLE      |L11.46|
00002a  4605              MOV      r5,r0                 ;255
00002c  e000              B        |L11.48|
                  |L11.46|
00002e  4635              MOV      r5,r6                 ;255
                  |L11.48|
000030  0c20              LSRS     r0,r4,#16             ;256
000032  f88d000c          STRB     r0,[sp,#0xc]          ;256
000036  0a20              LSRS     r0,r4,#8              ;257
000038  f88d000d          STRB     r0,[sp,#0xd]          ;257
00003c  f88d400e          STRB     r4,[sp,#0xe]          ;258
000040  f1b90f00          CMP      r9,#0                 ;260
000044  d004              BEQ      |L11.80|
000046  4650              MOV      r0,r10                ;261
000048  f7fffffe          BL       sflash_write_enable
00004c  2800              CMP      r0,#0                 ;261
00004e  d1e6              BNE      |L11.30|
                  |L11.80|
000050  2000              MOVS     r0,#0                 ;266
000052  9500              STR      r5,[sp,#0]            ;266
000054  e9cd7001          STRD     r7,r0,[sp,#4]         ;266
000058  ab03              ADD      r3,sp,#0xc            ;266
00005a  2203              MOVS     r2,#3                 ;266
00005c  2102              MOVS     r1,#2                 ;266
00005e  4650              MOV      r0,r10                ;266
000060  f7fffffe          BL       generic_sflash_command
000064  2800              CMP      r0,#0                 ;266
000066  d1da              BNE      |L11.30|
000068  442f              ADD      r7,r7,r5              ;271
00006a  442c              ADD      r4,r4,r5              ;272
00006c  1b76              SUBS     r6,r6,r5              ;273
                  |L11.110|
00006e  2e00              CMP      r6,#0                 ;253
000070  dcd8              BGT      |L11.36|
000072  2000              MOVS     r0,#0                 ;277
000074  e7d3              B        |L11.30|
;;;279    
                          ENDP


                          AREA ||i.sflash_write_status_register||, CODE, READONLY, ALIGN=1

                  sflash_write_status_register PROC
;;;368    
;;;369    int sflash_write_status_register( const sflash_handle_t* const handle, char value )
000000  b51f              PUSH     {r0-r4,lr}
;;;370    {
;;;371        char status_register_val = value;
;;;372    #ifdef SFLASH_SUPPORT_SST_PARTS
;;;373        /* SST parts require enabling writing to the status register */
;;;374        if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_SST )
;;;375        {
;;;376            int status;
;;;377            if ( 0 != ( status = generic_sflash_command( handle, SFLASH_ENABLE_WRITE_STATUS_REGISTER, 0, NULL, 0, NULL, NULL ) ) )
;;;378            {
;;;379                return status;
;;;380            }
;;;381        }
;;;382    #endif /* ifdef SFLASH_SUPPORT_SST_PARTS */
;;;383    
;;;384        return generic_sflash_command( handle, SFLASH_WRITE_STATUS_REGISTER, 0, NULL, 1, &status_register_val, NULL );
000002  2300              MOVS     r3,#0
000004  f88d100c          STRB     r1,[sp,#0xc]          ;371
000008  aa03              ADD      r2,sp,#0xc
00000a  2101              MOVS     r1,#1
00000c  e88d000e          STM      sp,{r1-r3}
000010  461a              MOV      r2,r3
000012  f7fffffe          BL       generic_sflash_command
;;;385    }
000016  b004              ADD      sp,sp,#0x10
000018  bd10              POP      {r4,pc}
;;;386    
                          ENDP


                          AREA ||.constdata||, DATA, READONLY, ALIGN=2

                          DCD      0x00000000
                          DCD      0x00000000
                          DCD      0x00000001
                          DCD      0x00000000
                          DCD      0x00000000
                          DCD      0x00000000
                          DCD      0x00000000
                          DCD      0x00000000
                          DCD      0x00000000
