; generated by ARM C/C++ Compiler, 5.03 [Build 24]
; commandline ArmCC [--list --split_sections --debug -c --asm --interleave -o.\obj\massstorage.o --asm_dir=.\lst\ --list_dir=.\lst\ --depend=.\obj\massstorage.d --cpu=Cortex-M0 --apcs=interwork -I.\ -I..\..\..\..\Library\CMSIS\Include -I..\..\..\..\Library\Device\Nuvoton\NUC200Series\Include -I..\..\..\..\Library\StdDriver\inc -IC:\Keil\ARM\RV31\INC -IC:\Keil\ARM\CMSIS\Include -IC:\Keil\ARM\Inc\?ST\STM32F10x -D__MICROLIB --omf_browse=.\obj\massstorage.crf ..\MassStorage.c]
                          THUMB

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

                  EP2_Handler PROC
;;;204    
;;;205    void EP2_Handler(void)
000000  b510              PUSH     {r4,lr}
;;;206    {
;;;207        g_u8EP2Ready = 1;
000002  4903              LDR      r1,|L1.16|
000004  2001              MOVS     r0,#1
000006  7008              STRB     r0,[r1,#0]
;;;208        MSC_AckCmd();
000008  f7fffffe          BL       MSC_AckCmd
;;;209    }
00000c  bd10              POP      {r4,pc}
;;;210    
                          ENDP

00000e  0000              DCW      0x0000
                  |L1.16|
                          DCD      ||.data||

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

                  EP3_Handler PROC
;;;211    
;;;212    void EP3_Handler(void)
000000  4901              LDR      r1,|L2.8|
;;;213    {
;;;214        /* Bulk OUT */
;;;215        g_u8EP3Ready = 1;
000002  2001              MOVS     r0,#1
000004  7048              STRB     r0,[r1,#1]
;;;216    }
000006  4770              BX       lr
;;;217    
                          ENDP

                  |L2.8|
                          DCD      ||.data||

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

                          REQUIRE _printf_percent
                          REQUIRE _printf_d
                          REQUIRE _printf_int_dec
                  MSC_AckCmd PROC
;;;856    
;;;857    void MSC_AckCmd(void)
000000  b5f8              PUSH     {r3-r7,lr}
;;;858    {
;;;859        /* Bulk IN */
;;;860        int32_t volatile idx;
;;;861        uint32_t u32CurBuf;
;;;862    
;;;863        if (g_u8BulkState == BULK_CBW)
000002  4c32              LDR      r4,|L3.204|
000004  78e0              LDRB     r0,[r4,#3]  ; g_u8BulkState
000006  2800              CMP      r0,#0
000008  d018              BEQ      |L3.60|
;;;864        {
;;;865            /* Why Host do this?? */
;;;866            DBG_PRINTF("Unknow. return zero pkt\n");
;;;867        }
;;;868        else if (g_u8BulkState == BULK_CSW) {
00000a  78e0              LDRB     r0,[r4,#3]  ; g_u8BulkState
00000c  2600              MOVS     r6,#0
;;;869            /* Prepare to receive the CBW */
;;;870            g_u8BulkState = BULK_CBW;
;;;871    
;;;872            USBD_SET_EP_BUF_ADDR(EP3, g_u32BulkBuf0);
00000e  4f30              LDR      r7,|L3.208|
000010  2804              CMP      r0,#4                 ;868
000012  d017              BEQ      |L3.68|
;;;873            USBD_SET_PAYLOAD_LEN(EP3, 31);
;;;874            
;;;875            /* Avoid Host miss status */
;;;876            USBD_SET_PAYLOAD_LEN(EP2, 13);
;;;877            
;;;878        } else if (g_u8BulkState == BULK_IN) {
000014  78e0              LDRB     r0,[r4,#3]  ; g_u8BulkState
000016  2801              CMP      r0,#1
000018  d113              BNE      |L3.66|
;;;879            switch (g_sCBW.u8OPCode) {
00001a  482e              LDR      r0,|L3.212|
;;;880            case UFI_READ_FORMAT_CAPACITY:
;;;881            case UFI_READ_CAPACITY:
;;;882            case UFI_MODE_SENSE_10: {
;;;883                if (g_u32Length > 0) {
;;;884                    MSC_Read();
;;;885                    return;
;;;886                }
;;;887            }
;;;888            case UFI_READ_10: {
;;;889              DBG_PRINTF("r10,g_u32Length=%d\n",g_u32Length);
;;;890                if (g_u32Length > 0) {
;;;891                    MSC_ReadTrig();
;;;892                    return;
;;;893                }
;;;894            }
;;;895            case UFI_REQUEST_SENSE:
;;;896            case UFI_INQUIRY: {
;;;897                g_sCSW.dCSWDataResidue = 0;
00001c  4d2d              LDR      r5,|L3.212|
00001e  492d              LDR      r1,|L3.212|
000020  7bc0              LDRB     r0,[r0,#0xf]          ;879  ; g_sCBW
000022  3520              ADDS     r5,r5,#0x20
;;;898                g_sCSW.bCSWStatus = 0;
;;;899                break;
;;;900            }
;;;901    
;;;902            case UFI_PREVENT_ALLOW_MEDIUM_REMOVAL:
;;;903            case UFI_VERIFY_10:
;;;904            case UFI_START_STOP:
;;;905            case UFI_WRITE_10: {
;;;906                int32_t tmp;
;;;907    
;;;908                tmp = g_sCBW.dCBWDataTransferLength - STORAGE_BUFFER_SIZE;
000024  6889              LDR      r1,[r1,#8]
000026  2823              CMP      r0,#0x23              ;879
000028  d036              BEQ      |L3.152|
00002a  dc16              BGT      |L3.90|
00002c  2812              CMP      r0,#0x12              ;879
00002e  d04b              BEQ      |L3.200|
000030  dc0e              BGT      |L3.80|
000032  2800              CMP      r0,#0                 ;879
000034  d048              BEQ      |L3.200|
000036  2803              CMP      r0,#3                 ;879
000038  d11b              BNE      |L3.114|
00003a  e045              B        |L3.200|
                  |L3.60|
00003c  a026              ADR      r0,|L3.216|
00003e  f7fffffe          BL       __2printf
                  |L3.66|
;;;909                if (tmp < 0)
;;;910                    tmp = 0;
;;;911    
;;;912                g_sCSW.dCSWDataResidue = tmp;
;;;913                g_sCSW.bCSWStatus = 0;
;;;914                break;
;;;915            }
;;;916            case UFI_TEST_UNIT_READY: {
;;;917                g_sCSW.dCSWDataResidue = 0;
;;;918                g_sCSW.bCSWStatus = 0;
;;;919                break;
;;;920            }
;;;921            default: {
;;;922                /* Unsupported commmand. Return command fail status */
;;;923                g_sCSW.dCSWDataResidue = g_sCBW.dCBWDataTransferLength;
;;;924                g_sCSW.bCSWStatus = 0x01;
;;;925                break;
;;;926            }
;;;927            }
;;;928    
;;;929            /* Return the CSW */
;;;930            USBD_SET_EP_BUF_ADDR(EP2, g_u32BulkBuf1);
;;;931    
;;;932            /* Bulk IN buffer */
;;;933            USBD_MemCopy((uint8_t *)(USBD_BUF_BASE + g_u32BulkBuf1), (uint8_t *)&g_sCSW.dCSWSignature, 16);
;;;934    
;;;935            g_u8BulkState = BULK_CSW;
;;;936            USBD_SET_PAYLOAD_LEN(EP2, 13);
;;;937        }
;;;938    }
000042  bdf8              POP      {r3-r7,pc}
                  |L3.68|
000044  70e6              STRB     r6,[r4,#3]            ;870
000046  6a60              LDR      r0,[r4,#0x24]         ;872  ; g_u32BulkBuf0
000048  6138              STR      r0,[r7,#0x10]         ;872
00004a  201f              MOVS     r0,#0x1f              ;873
00004c  6178              STR      r0,[r7,#0x14]         ;873
00004e  e020              B        |L3.146|
                  |L3.80|
000050  281b              CMP      r0,#0x1b              ;879
000052  d031              BEQ      |L3.184|
000054  281e              CMP      r0,#0x1e              ;879
000056  d10c              BNE      |L3.114|
000058  e02e              B        |L3.184|
                  |L3.90|
00005a  282a              CMP      r0,#0x2a              ;879
00005c  d02c              BEQ      |L3.184|
00005e  dc04              BGT      |L3.106|
000060  2825              CMP      r0,#0x25              ;879
000062  d019              BEQ      |L3.152|
000064  2828              CMP      r0,#0x28              ;879
000066  d104              BNE      |L3.114|
000068  e01c              B        |L3.164|
                  |L3.106|
00006a  282f              CMP      r0,#0x2f              ;879
00006c  d024              BEQ      |L3.184|
00006e  285a              CMP      r0,#0x5a              ;879
000070  d012              BEQ      |L3.152|
                  |L3.114|
000072  2001              MOVS     r0,#1                 ;924
000074  60a9              STR      r1,[r5,#8]            ;924  ; g_sCSW
000076  7328              STRB     r0,[r5,#0xc]          ;924
                  |L3.120|
000078  6aa0              LDR      r0,[r4,#0x28]         ;930  ; g_u32BulkBuf1
00007a  6038              STR      r0,[r7,#0]            ;930
00007c  4915              LDR      r1,|L3.212|
00007e  2210              MOVS     r2,#0x10              ;933
000080  6aa0              LDR      r0,[r4,#0x28]         ;933  ; g_u32BulkBuf1
000082  3120              ADDS     r1,r1,#0x20           ;933
000084  4b12              LDR      r3,|L3.208|
000086  33c0              ADDS     r3,r3,#0xc0           ;933
000088  18c0              ADDS     r0,r0,r3              ;933
00008a  f7fffffe          BL       USBD_MemCopy
00008e  2004              MOVS     r0,#4                 ;935
000090  70e0              STRB     r0,[r4,#3]            ;935
                  |L3.146|
000092  200d              MOVS     r0,#0xd               ;876
000094  6078              STR      r0,[r7,#4]            ;876
000096  bdf8              POP      {r3-r7,pc}
                  |L3.152|
000098  69a0              LDR      r0,[r4,#0x18]         ;883  ; g_u32Length
00009a  2800              CMP      r0,#0                 ;883
00009c  d002              BEQ      |L3.164|
00009e  f7fffffe          BL       MSC_Read
0000a2  bdf8              POP      {r3-r7,pc}
                  |L3.164|
0000a4  69a1              LDR      r1,[r4,#0x18]         ;889  ; g_u32Length
0000a6  a013              ADR      r0,|L3.244|
0000a8  f7fffffe          BL       __2printf
0000ac  69a0              LDR      r0,[r4,#0x18]         ;890  ; g_u32Length
0000ae  2800              CMP      r0,#0                 ;890
0000b0  d00a              BEQ      |L3.200|
0000b2  f7fffffe          BL       MSC_ReadTrig
0000b6  bdf8              POP      {r3-r7,pc}
                  |L3.184|
0000b8  39ff              SUBS     r1,r1,#0xff           ;908
0000ba  39ff              SUBS     r1,r1,#0xff           ;908
0000bc  3902              SUBS     r1,#2                 ;908
0000be  d500              BPL      |L3.194|
0000c0  2100              MOVS     r1,#0                 ;910
                  |L3.194|
0000c2  60a9              STR      r1,[r5,#8]            ;912  ; g_sCSW
                  |L3.196|
0000c4  732e              STRB     r6,[r5,#0xc]          ;898
0000c6  e7d7              B        |L3.120|
                  |L3.200|
0000c8  60ae              STR      r6,[r5,#8]            ;919  ; g_sCSW
0000ca  e7fb              B        |L3.196|
;;;939    
                          ENDP

                  |L3.204|
                          DCD      ||.data||
                  |L3.208|
                          DCD      0x40060040
                  |L3.212|
                          DCD      ||.bss||
                  |L3.216|
0000d8  556e6b6e          DCB      "Unknow. return zero pkt\n",0
0000dc  6f772e20
0000e0  72657475
0000e4  726e207a
0000e8  65726f20
0000ec  706b740a
0000f0  00      
0000f1  00                DCB      0
0000f2  00                DCB      0
0000f3  00                DCB      0
                  |L3.244|
0000f4  7231302c          DCB      "r10,g_u32Length=%d\n",0
0000f8  675f7533
0000fc  324c656e
000100  6774683d
000104  25640a00

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

                  MSC_ClassRequest PROC
;;;257    
;;;258    void MSC_ClassRequest(void)
000000  b51c              PUSH     {r2-r4,lr}
;;;259    {
;;;260        uint8_t buf[8];
;;;261    
;;;262        USBD_GetSetupPacket(buf);
000002  4668              MOV      r0,sp
000004  f7fffffe          BL       USBD_GetSetupPacket
;;;263    
;;;264        if (buf[0] & 0x80) { /* request data transfer direction */
000008  4668              MOV      r0,sp
00000a  7800              LDRB     r0,[r0,#0]
00000c  2100              MOVS     r1,#0
00000e  0603              LSLS     r3,r0,#24
;;;265            // Device to host
;;;266            switch (buf[1]) {
;;;267            case GET_MAX_LUN: {
;;;268                M8(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP0)) = 0;
;;;269                /* Data stage */
;;;270                USBD_SET_DATA1(EP0);
000010  2280              MOVS     r2,#0x80
000012  2b00              CMP      r3,#0                 ;264
;;;271                USBD_SET_PAYLOAD_LEN(EP0, 1);
;;;272                /* Status stage */
;;;273                USBD_PrepareCtrlOut(0,0);
;;;274                break;
;;;275            }
;;;276            default: {
;;;277                /* Setup error, stall the device */
;;;278                USBD_SetStall(0);
;;;279                break;
;;;280            }
;;;281            }
;;;282        } else {
;;;283            // Host to device
;;;284            switch (buf[1]) {
000014  466b              MOV      r3,sp
000016  480f              LDR      r0,|L4.84|
000018  785b              LDRB     r3,[r3,#1]
00001a  da13              BGE      |L4.68|
00001c  2bfe              CMP      r3,#0xfe              ;266
00001e  d10d              BNE      |L4.60|
000020  6a03              LDR      r3,[r0,#0x20]         ;268
000022  4c0d              LDR      r4,|L4.88|
000024  191b              ADDS     r3,r3,r4              ;268
000026  7019              STRB     r1,[r3,#0]            ;268
000028  6a81              LDR      r1,[r0,#0x28]         ;270
00002a  4311              ORRS     r1,r1,r2              ;270
00002c  6281              STR      r1,[r0,#0x28]         ;270
00002e  2101              MOVS     r1,#1                 ;271
000030  6241              STR      r1,[r0,#0x24]         ;271
000032  2100              MOVS     r1,#0                 ;273
000034  4608              MOV      r0,r1                 ;273
000036  f7fffffe          BL       USBD_PrepareCtrlOut
;;;285            case BULK_ONLY_MASS_STORAGE_RESET: {
;;;286                /* Status stage */
;;;287                USBD_SET_DATA1(EP0);
;;;288                USBD_SET_PAYLOAD_LEN(EP0, 0);
;;;289    
;;;290                /* TODO: reset channel ? or trigger CBW? */
;;;291    
;;;292                break;
;;;293            }
;;;294            default: {
;;;295                // Stall
;;;296                /* Setup error, stall the device */
;;;297                USBD_SetStall(0);
;;;298                break;
;;;299            }
;;;300            }
;;;301        }
;;;302    }
00003a  bd1c              POP      {r2-r4,pc}
                  |L4.60|
00003c  2000              MOVS     r0,#0                 ;278
00003e  f7fffffe          BL       USBD_SetStall
000042  bd1c              POP      {r2-r4,pc}
                  |L4.68|
000044  2bff              CMP      r3,#0xff              ;284
000046  d1f9              BNE      |L4.60|
000048  6a83              LDR      r3,[r0,#0x28]         ;287
00004a  4313              ORRS     r3,r3,r2              ;287
00004c  6283              STR      r3,[r0,#0x28]         ;287
00004e  6241              STR      r1,[r0,#0x24]         ;288
000050  bd1c              POP      {r2-r4,pc}
;;;303    
                          ENDP

000052  0000              DCW      0x0000
                  |L4.84|
                          DCD      0x40060000
                  |L4.88|
                          DCD      0x40060100

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

                  MSC_Init PROC
;;;218    
;;;219    void MSC_Init(void)
000000  4810              LDR      r0,|L5.68|
;;;220    {
;;;221        /* Init setup packet buffer */
;;;222        /* Buffer range for setup packet -> [0 ~ 0x7] */
;;;223        USBD->STBUFSEG = SETUP_BUF_BASE;
000002  2100              MOVS     r1,#0
000004  6181              STR      r1,[r0,#0x18]
;;;224    
;;;225        /*****************************************************/
;;;226        /* EP0 ==> control IN endpoint, address 0 */
;;;227        USBD_CONFIG_EP(EP0, USBD_CFG_CSTALL | USBD_CFG_EPMODE_IN | 0);
000006  2109              MOVS     r1,#9
000008  0189              LSLS     r1,r1,#6
00000a  6281              STR      r1,[r0,#0x28]
;;;228        /* Buffer range for EP0 */
;;;229        USBD_SET_EP_BUF_ADDR(EP0, EP0_BUF_BASE);
00000c  2108              MOVS     r1,#8
00000e  6201              STR      r1,[r0,#0x20]
;;;230    
;;;231        /* EP1 ==> control OUT endpoint, address 0 */
;;;232        USBD_CONFIG_EP(EP1, USBD_CFG_CSTALL | USBD_CFG_EPMODE_OUT | 0);
000010  2211              MOVS     r2,#0x11
000012  0152              LSLS     r2,r2,#5
000014  6382              STR      r2,[r0,#0x38]
;;;233        /* Buffer range for EP1 */
;;;234        USBD_SET_EP_BUF_ADDR(EP1, EP1_BUF_BASE);
000016  6301              STR      r1,[r0,#0x30]
;;;235    
;;;236        /*****************************************************/
;;;237        /* EP2 ==> Bulk IN endpoint, address 2 */
;;;238        USBD_CONFIG_EP(EP2, USBD_CFG_EPMODE_IN | BULK_IN_EP_NUM);
000018  480a              LDR      r0,|L5.68|
00001a  2142              MOVS     r1,#0x42
00001c  3040              ADDS     r0,r0,#0x40
00001e  6081              STR      r1,[r0,#8]
;;;239        /* Buffer range for EP2 */
;;;240        USBD_SET_EP_BUF_ADDR(EP2, EP2_BUF_BASE);
000020  2148              MOVS     r1,#0x48
000022  6001              STR      r1,[r0,#0]
;;;241    
;;;242        /* EP3 ==> Bulk Out endpoint, address 3 */
;;;243        USBD_CONFIG_EP(EP3, USBD_CFG_EPMODE_OUT | BULK_OUT_EP_NUM);
000024  2223              MOVS     r2,#0x23
000026  6182              STR      r2,[r0,#0x18]
;;;244        /* Buffer range for EP3 */
;;;245        USBD_SET_EP_BUF_ADDR(EP3, EP3_BUF_BASE);
000028  2288              MOVS     r2,#0x88
00002a  6102              STR      r2,[r0,#0x10]
;;;246    
;;;247        /* trigger to receive OUT data */
;;;248        USBD_SET_PAYLOAD_LEN(EP3, EP3_MAX_PKT_SIZE);
00002c  2340              MOVS     r3,#0x40
00002e  6143              STR      r3,[r0,#0x14]
;;;249    
;;;250        /*****************************************************/
;;;251        g_u32BulkBuf0 = EP3_BUF_BASE;
000030  4805              LDR      r0,|L5.72|
000032  6242              STR      r2,[r0,#0x24]  ; g_u32BulkBuf0
;;;252        g_u32BulkBuf1 = EP2_BUF_BASE;
000034  6281              STR      r1,[r0,#0x28]  ; g_u32BulkBuf1
;;;253    
;;;254        g_sCSW.dCSWSignature = CSW_SIGNATURE;
000036  4a06              LDR      r2,|L5.80|
000038  4904              LDR      r1,|L5.76|
;;;255        g_TotalSectors = DATA_FLASH_STORAGE_SIZE / UDC_SECTOR_SIZE;
00003a  6011              STR      r1,[r2,#0]  ; g_sCSW
00003c  2180              MOVS     r1,#0x80
00003e  6081              STR      r1,[r0,#8]  ; g_TotalSectors
;;;256    }
000040  4770              BX       lr
;;;257    
                          ENDP

000042  0000              DCW      0x0000
                  |L5.68|
                          DCD      0x40060000
                  |L5.72|
                          DCD      ||.data||
                  |L5.76|
                          DCD      0x53425355
                  |L5.80|
                          DCD      ||.bss||+0x20

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

                  MSC_ModeSense10 PROC
;;;484    
;;;485    void MSC_ModeSense10(void)
000000  b5f0              PUSH     {r4-r7,lr}
;;;486    {
;;;487        uint8_t i,j;
;;;488        uint8_t NumHead,NumSector;
;;;489        uint16_t NumCyl=0;
;;;490    
;;;491        /* Clear the command buffer */
;;;492        *((uint32_t *)MassCMD_BUF  ) = 0;
000002  4a4d              LDR      r2,|L6.312|
;;;493        *((uint32_t *)MassCMD_BUF + 1) = 0;
;;;494    
;;;495        switch (g_sCBW.au8Data[0]) {
;;;496        case 0x01:
;;;497            *((uint8_t *)MassCMD_BUF) = 19;
;;;498            i = 8;
;;;499            for (j = 0; j<12; j++, i++)
;;;500                *((uint8_t *)(MassCMD_BUF+i)) = g_au8ModePage_01[j];
000004  4e4d              LDR      r6,|L6.316|
000006  2300              MOVS     r3,#0                 ;492
000008  6013              STR      r3,[r2,#0]            ;493  ; MassBlock
00000a  4610              MOV      r0,r2                 ;495
;;;501            break;
;;;502    
;;;503        case 0x05:
;;;504            *((uint8_t *)MassCMD_BUF) = 39;
;;;505            i = 8;
;;;506            for (j = 0; j<32; j++, i++)
;;;507                *((uint8_t *)(MassCMD_BUF+i)) = g_au8ModePage_05[j];
00000c  4634              MOV      r4,r6
00000e  3830              SUBS     r0,r0,#0x30           ;495
000010  6053              STR      r3,[r2,#4]            ;495  ; MassBlock
000012  340c              ADDS     r4,r4,#0xc
000014  7c40              LDRB     r0,[r0,#0x11]         ;495  ; g_sCBW
;;;508    
;;;509            NumHead = 2;
;;;510            NumSector = 64;
;;;511            NumCyl = g_TotalSectors / 128;
;;;512    
;;;513            *((uint8_t *)(MassCMD_BUF+12)) = NumHead;
;;;514            *((uint8_t *)(MassCMD_BUF+13)) = NumSector;
;;;515            *((uint8_t *)(MassCMD_BUF+16)) = (uint8_t)(NumCyl >> 8);
;;;516            *((uint8_t *)(MassCMD_BUF+17)) = (uint8_t)(NumCyl & 0x00ff);
;;;517            break;
;;;518    
;;;519        case 0x1B:
;;;520            *((uint8_t *)MassCMD_BUF) = 19;
;;;521            i = 8;
;;;522            for (j = 0; j<12; j++, i++)
;;;523                *((uint8_t *)(MassCMD_BUF+i)) = g_au8ModePage_1B[j];
000016  4625              MOV      r5,r4
000018  2113              MOVS     r1,#0x13              ;497
00001a  3520              ADDS     r5,r5,#0x20
00001c  281b              CMP      r0,#0x1b              ;495
00001e  d03b              BEQ      |L6.152|
000020  dc04              BGT      |L6.44|
000022  2801              CMP      r0,#1                 ;495
000024  d010              BEQ      |L6.72|
000026  2805              CMP      r0,#5                 ;495
000028  d106              BNE      |L6.56|
00002a  e019              B        |L6.96|
                  |L6.44|
;;;524            break;
;;;525    
;;;526        case 0x1C:
;;;527            *((uint8_t *)MassCMD_BUF) = 15;
;;;528            i = 8;
;;;529            for (j = 0; j<8; j++, i++)
;;;530                *((uint8_t *)(MassCMD_BUF+i)) = g_au8ModePage_1C[j];
00002c  4f43              LDR      r7,|L6.316|
00002e  3f2c              SUBS     r7,r7,#0x2c
000030  281c              CMP      r0,#0x1c              ;495
000032  d03d              BEQ      |L6.176|
000034  283f              CMP      r0,#0x3f              ;495
000036  d048              BEQ      |L6.202|
                  |L6.56|
;;;531            break;
;;;532    
;;;533        case 0x3F:
;;;534            *((uint8_t *)MassCMD_BUF) = 0x47;
;;;535            i = 8;
;;;536            for (j = 0; j<12; j++, i++)
;;;537                *((uint8_t *)(MassCMD_BUF+i)) = g_au8ModePage_01[j];
;;;538            for (j = 0; j<32; j++, i++)
;;;539                *((uint8_t *)(MassCMD_BUF+i)) = g_au8ModePage_05[j];
;;;540            for (j = 0; j<12; j++, i++)
;;;541                *((uint8_t *)(MassCMD_BUF+i)) = g_au8ModePage_1B[j];
;;;542            for (j = 0; j<8; j++, i++)
;;;543                *((uint8_t *)(MassCMD_BUF+i)) = g_au8ModePage_1C[j];
;;;544    
;;;545            NumHead = 2;
;;;546            NumSector = 64;
;;;547            NumCyl = g_TotalSectors / 128;
;;;548    
;;;549            *((uint8_t *)(MassCMD_BUF+24)) = NumHead;
;;;550            *((uint8_t *)(MassCMD_BUF+25)) = NumSector;
;;;551            *((uint8_t *)(MassCMD_BUF+28)) = (uint8_t)(NumCyl >> 8);
;;;552            *((uint8_t *)(MassCMD_BUF+29)) = (uint8_t)(NumCyl & 0x00ff);
;;;553            break;
;;;554    
;;;555        default:
;;;556            g_au8SenseKey[0] = 0x05;
000038  4840              LDR      r0,|L6.316|
00003a  2105              MOVS     r1,#5
00003c  384c              SUBS     r0,r0,#0x4c
00003e  7001              STRB     r1,[r0,#0]
;;;557            g_au8SenseKey[1] = 0x24;
000040  2124              MOVS     r1,#0x24
000042  7041              STRB     r1,[r0,#1]
;;;558            g_au8SenseKey[2] = 0x00;
000044  7083              STRB     r3,[r0,#2]
;;;559        }
;;;560    }
000046  bdf0              POP      {r4-r7,pc}
                  |L6.72|
000048  7011              STRB     r1,[r2,#0]            ;497
00004a  2108              MOVS     r1,#8                 ;498
00004c  2000              MOVS     r0,#0                 ;499
                  |L6.78|
00004e  5c33              LDRB     r3,[r6,r0]            ;500
000050  5453              STRB     r3,[r2,r1]            ;500
000052  1c40              ADDS     r0,r0,#1              ;499
000054  1c49              ADDS     r1,r1,#1              ;499
000056  b2c0              UXTB     r0,r0                 ;499
000058  b2c9              UXTB     r1,r1                 ;499
00005a  280c              CMP      r0,#0xc               ;499
00005c  d3f7              BCC      |L6.78|
00005e  bdf0              POP      {r4-r7,pc}
                  |L6.96|
000060  2027              MOVS     r0,#0x27              ;504
000062  7010              STRB     r0,[r2,#0]            ;504
000064  2108              MOVS     r1,#8                 ;505
000066  2000              MOVS     r0,#0                 ;506
                  |L6.104|
000068  5c23              LDRB     r3,[r4,r0]            ;507
00006a  5453              STRB     r3,[r2,r1]            ;507
00006c  1c40              ADDS     r0,r0,#1              ;506
00006e  1c49              ADDS     r1,r1,#1              ;506
000070  b2c0              UXTB     r0,r0                 ;506
000072  b2c9              UXTB     r1,r1                 ;506
000074  2820              CMP      r0,#0x20              ;506
000076  d3f7              BCC      |L6.104|
000078  4830              LDR      r0,|L6.316|
00007a  2302              MOVS     r3,#2                 ;509
00007c  2140              MOVS     r1,#0x40              ;510
00007e  3858              SUBS     r0,r0,#0x58           ;511
000080  6880              LDR      r0,[r0,#8]            ;511  ; g_TotalSectors
000082  7313              STRB     r3,[r2,#0xc]          ;513
000084  17c4              ASRS     r4,r0,#31             ;511
000086  0e64              LSRS     r4,r4,#25             ;511
000088  1820              ADDS     r0,r4,r0              ;511
00008a  0240              LSLS     r0,r0,#9              ;511
00008c  0c00              LSRS     r0,r0,#16             ;511
00008e  7351              STRB     r1,[r2,#0xd]          ;514
000090  0a01              LSRS     r1,r0,#8              ;515
000092  7411              STRB     r1,[r2,#0x10]         ;515
000094  7450              STRB     r0,[r2,#0x11]         ;516
000096  bdf0              POP      {r4-r7,pc}
                  |L6.152|
000098  7011              STRB     r1,[r2,#0]            ;520
00009a  2108              MOVS     r1,#8                 ;521
00009c  2000              MOVS     r0,#0                 ;522
                  |L6.158|
00009e  5c2b              LDRB     r3,[r5,r0]            ;523
0000a0  5453              STRB     r3,[r2,r1]            ;523
0000a2  1c40              ADDS     r0,r0,#1              ;522
0000a4  1c49              ADDS     r1,r1,#1              ;522
0000a6  b2c0              UXTB     r0,r0                 ;522
0000a8  b2c9              UXTB     r1,r1                 ;522
0000aa  280c              CMP      r0,#0xc               ;522
0000ac  d3f7              BCC      |L6.158|
0000ae  bdf0              POP      {r4-r7,pc}
                  |L6.176|
0000b0  200f              MOVS     r0,#0xf               ;527
0000b2  7010              STRB     r0,[r2,#0]            ;527
0000b4  2108              MOVS     r1,#8                 ;528
0000b6  2000              MOVS     r0,#0                 ;529
                  |L6.184|
0000b8  5c3b              LDRB     r3,[r7,r0]            ;530
0000ba  5453              STRB     r3,[r2,r1]            ;530
0000bc  1c40              ADDS     r0,r0,#1              ;529
0000be  1c49              ADDS     r1,r1,#1              ;529
0000c0  b2c0              UXTB     r0,r0                 ;529
0000c2  b2c9              UXTB     r1,r1                 ;529
0000c4  2808              CMP      r0,#8                 ;529
0000c6  d3f7              BCC      |L6.184|
0000c8  bdf0              POP      {r4-r7,pc}
                  |L6.202|
0000ca  2047              MOVS     r0,#0x47              ;534
0000cc  7010              STRB     r0,[r2,#0]            ;534
0000ce  2008              MOVS     r0,#8                 ;535
0000d0  2100              MOVS     r1,#0                 ;536
                  |L6.210|
0000d2  5c73              LDRB     r3,[r6,r1]            ;537
0000d4  5413              STRB     r3,[r2,r0]            ;537
0000d6  1c49              ADDS     r1,r1,#1              ;536
0000d8  1c40              ADDS     r0,r0,#1              ;536
0000da  b2c9              UXTB     r1,r1                 ;536
0000dc  b2c0              UXTB     r0,r0                 ;536
0000de  290c              CMP      r1,#0xc               ;536
0000e0  d3f7              BCC      |L6.210|
0000e2  2100              MOVS     r1,#0                 ;538
                  |L6.228|
0000e4  5c63              LDRB     r3,[r4,r1]            ;539
0000e6  5413              STRB     r3,[r2,r0]            ;539
0000e8  1c49              ADDS     r1,r1,#1              ;538
0000ea  1c40              ADDS     r0,r0,#1              ;538
0000ec  b2c9              UXTB     r1,r1                 ;538
0000ee  b2c0              UXTB     r0,r0                 ;538
0000f0  2920              CMP      r1,#0x20              ;538
0000f2  d3f7              BCC      |L6.228|
0000f4  2100              MOVS     r1,#0                 ;540
                  |L6.246|
0000f6  5c6b              LDRB     r3,[r5,r1]            ;541
0000f8  5413              STRB     r3,[r2,r0]            ;541
0000fa  1c49              ADDS     r1,r1,#1              ;540
0000fc  1c40              ADDS     r0,r0,#1              ;540
0000fe  b2c9              UXTB     r1,r1                 ;540
000100  b2c0              UXTB     r0,r0                 ;540
000102  290c              CMP      r1,#0xc               ;540
000104  d3f7              BCC      |L6.246|
000106  2100              MOVS     r1,#0                 ;542
                  |L6.264|
000108  5c7b              LDRB     r3,[r7,r1]            ;543
00010a  5413              STRB     r3,[r2,r0]            ;543
00010c  1c49              ADDS     r1,r1,#1              ;542
00010e  1c40              ADDS     r0,r0,#1              ;542
000110  b2c9              UXTB     r1,r1                 ;542
000112  b2c0              UXTB     r0,r0                 ;542
000114  2908              CMP      r1,#8                 ;542
000116  d3f7              BCC      |L6.264|
000118  4808              LDR      r0,|L6.316|
00011a  2302              MOVS     r3,#2                 ;545
00011c  2140              MOVS     r1,#0x40              ;546
00011e  3858              SUBS     r0,r0,#0x58           ;547
000120  6880              LDR      r0,[r0,#8]            ;547  ; g_TotalSectors
000122  7613              STRB     r3,[r2,#0x18]         ;549
000124  17c4              ASRS     r4,r0,#31             ;547
000126  0e64              LSRS     r4,r4,#25             ;547
000128  1820              ADDS     r0,r4,r0              ;547
00012a  0240              LSLS     r0,r0,#9              ;547
00012c  0c00              LSRS     r0,r0,#16             ;547
00012e  7651              STRB     r1,[r2,#0x19]         ;550
000130  0a01              LSRS     r1,r0,#8              ;551
000132  7711              STRB     r1,[r2,#0x1c]         ;551
000134  7750              STRB     r0,[r2,#0x1d]         ;552
000136  bdf0              POP      {r4-r7,pc}
;;;561    
                          ENDP

                  |L6.312|
                          DCD      ||.bss||+0x30
                  |L6.316|
                          DCD      ||.data||+0x58

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

                          REQUIRE _printf_pre_padding
                          REQUIRE _printf_percent
                          REQUIRE _printf_flags
                          REQUIRE _printf_widthprec
                          REQUIRE _printf_d
                          REQUIRE _printf_x
                          REQUIRE _printf_int_dec
                          REQUIRE _printf_longlong_hex
                  MSC_ProcessCmd PROC
;;;609    
;;;610    void MSC_ProcessCmd(void)
000000  b5f8              PUSH     {r3-r7,lr}
;;;611    {
;;;612        uint8_t u8Len;
;;;613        int32_t i;
;;;614    
;;;615        if (g_u8EP3Ready) {
000002  4c96              LDR      r4,|L7.604|
000004  7860              LDRB     r0,[r4,#1]  ; g_u8EP3Ready
000006  2800              CMP      r0,#0
000008  d00f              BEQ      |L7.42|
;;;616            g_u8EP3Ready = 0;
00000a  2200              MOVS     r2,#0
00000c  7062              STRB     r2,[r4,#1]
;;;617            if (g_u8BulkState == BULK_CBW) {
00000e  78e0              LDRB     r0,[r4,#3]  ; g_u8BulkState
000010  2800              CMP      r0,#0
000012  d00b              BEQ      |L7.44|
;;;618                
;;;619                USBD_STOP_TRANSACTION(EP2);
;;;620              
;;;621                u8Len = USBD_GET_PAYLOAD_LEN(EP3);
;;;622    
;;;623                /* Check Signature & length of CBW */
;;;624                /* Bulk Out buffer */
;;;625                if ((*(uint32_t *) ((uint32_t)USBD_BUF_BASE + g_u32BulkBuf0) != CBW_SIGNATURE) || (u8Len != 31)) {
;;;626                    return;
;;;627                }
;;;628    
;;;629                /* Get the CBW */
;;;630                for (i = 0; i < u8Len; i++)
;;;631                    *((uint8_t *) (&g_sCBW.dCBWSignature) + i) = *(uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf0 + i);
;;;632    
;;;633                /* Prepare to echo the tag from CBW to CSW */
;;;634                g_sCSW.dCSWTag = g_sCBW.dCBWTag;
;;;635    
;;;636                /* Parse Op-Code of CBW */
;;;637                switch (g_sCBW.u8OPCode) {
;;;638                case UFI_PREVENT_ALLOW_MEDIUM_REMOVAL: {
;;;639                    if (g_sCBW.au8Data[2] & 0x01) {
;;;640                        g_au8SenseKey[0] = 0x05;  //INVALID COMMAND
;;;641                        g_au8SenseKey[1] = 0x24;
;;;642                        g_au8SenseKey[2] = 0;
;;;643                        g_u8Prevent = 1;
;;;644                    } else
;;;645                        g_u8Prevent = 0;
;;;646                    g_u8BulkState = BULK_IN;
;;;647                    MSC_AckCmd();
;;;648                    return;
;;;649                }
;;;650                case UFI_VERIFY_10:
;;;651                case UFI_START_STOP:
;;;652                case UFI_TEST_UNIT_READY: {
;;;653                    g_u8BulkState = BULK_IN;
;;;654                    MSC_AckCmd();
;;;655                    return;
;;;656                }
;;;657                case UFI_REQUEST_SENSE: {
;;;658                    MSC_RequestSense();
;;;659                    g_u8BulkState = BULK_IN;
;;;660                    USBD_SET_PAYLOAD_LEN(EP2, 18);
;;;661                    return;
;;;662                }
;;;663                case UFI_READ_FORMAT_CAPACITY: {
;;;664                    if (g_u32Length == 0) {
;;;665                        g_u32Length = g_sCBW.dCBWDataTransferLength;
;;;666                        g_u32Address = MassCMD_BUF;
;;;667                    }
;;;668                    MSC_ReadFormatCapacity();
;;;669                    g_u8BulkState = BULK_IN;
;;;670                    if (g_u32Length > 0) {
;;;671                        if (g_u32Length > EP2_MAX_PKT_SIZE)
;;;672                            g_u8Size = EP2_MAX_PKT_SIZE;
;;;673                        else
;;;674                            g_u8Size = g_u32Length;
;;;675    
;;;676                        /* Bulk IN buffer */
;;;677                        USBD_MemCopy((uint8_t *)(USBD_BUF_BASE + g_u32BulkBuf1), (uint8_t *)g_u32Address, g_u8Size);
;;;678    
;;;679                        g_u32Address += g_u8Size;
;;;680                        USBD_SET_EP_BUF_ADDR(EP2, g_u32BulkBuf0);
;;;681                        MSC_Read();
;;;682                    }
;;;683    //                     else
;;;684    //                         MSC_AckCmd();
;;;685                    return;
;;;686                }
;;;687                case UFI_READ_CAPACITY: {
;;;688                    if (g_u32Length == 0) {
;;;689                        g_u32Length = g_sCBW.dCBWDataTransferLength;
;;;690                        g_u32Address = MassCMD_BUF;
;;;691                    }
;;;692    
;;;693                    MSC_ReadCapacity();
;;;694                    g_u8BulkState = BULK_IN;
;;;695                    if (g_u32Length > 0) {
;;;696                        if (g_u32Length > EP2_MAX_PKT_SIZE)
;;;697                            g_u8Size = EP2_MAX_PKT_SIZE;
;;;698                        else
;;;699                            g_u8Size = g_u32Length;
;;;700    
;;;701                        /* Bulk IN buffer */
;;;702                        USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf1), (uint8_t *)g_u32Address, g_u8Size);
;;;703    
;;;704                        g_u32Address += g_u8Size;
;;;705                        USBD_SET_EP_BUF_ADDR(EP2, g_u32BulkBuf0);
;;;706                        MSC_Read();
;;;707                    }
;;;708    //                     else
;;;709    //                         MSC_AckCmd();
;;;710                    return;
;;;711                }
;;;712                case UFI_MODE_SELECT_10: {
;;;713                    g_u32Length = g_sCBW.dCBWDataTransferLength;
;;;714                    g_u32Address = MassCMD_BUF;
;;;715    
;;;716                    if (g_u32Length > 0) {
;;;717                        USBD_SET_PAYLOAD_LEN(EP3, EP3_MAX_PKT_SIZE);
;;;718                        g_u8BulkState = BULK_OUT;
;;;719                    }
;;;720                    return;
;;;721                }
;;;722                case UFI_MODE_SENSE_10: {
;;;723                    if (g_u32Length == 0) {
;;;724                        g_u32Length = g_sCBW.dCBWDataTransferLength;
;;;725                        g_u32Address = MassCMD_BUF;
;;;726                    }
;;;727    
;;;728                    MSC_ModeSense10();
;;;729                    g_u8BulkState = BULK_IN;
;;;730                    if (g_u32Length > 0) {
;;;731                        if (g_u32Length > EP2_MAX_PKT_SIZE)
;;;732                            g_u8Size = EP2_MAX_PKT_SIZE;
;;;733                        else
;;;734                            g_u8Size = g_u32Length;
;;;735                        /* Bulk IN buffer */
;;;736                        USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf1), (uint8_t *)g_u32Address, g_u8Size);
;;;737    
;;;738                        g_u32Address += g_u8Size;
;;;739    
;;;740                        USBD_SET_EP_BUF_ADDR(EP2, g_u32BulkBuf0);
;;;741                        MSC_Read();
;;;742                    }
;;;743    //                     else
;;;744    //                         MSC_AckCmd();
;;;745                    return;
;;;746                }
;;;747                case UFI_INQUIRY: {
;;;748                    /* Bulk IN buffer */
;;;749                    USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf1), (uint8_t *)g_au8InquiryID, 36);
;;;750                    USBD_SET_PAYLOAD_LEN(EP2, 36);
;;;751                    g_u8BulkState = BULK_IN;
;;;752    
;;;753                    return;
;;;754                }
;;;755                case UFI_READ_10: {
;;;756                    /* Check if it is a new transfer */
;;;757                    if(g_u32Length == 0) {
;;;758                        /* Prepare the data for Bulk IN transfer */
;;;759    
;;;760                        /* Get LBA address */
;;;761                        g_u32Address = get_be32(&g_sCBW.au8Data[0]);
;;;762                        g_u32LbaAddress = g_u32Address * UDC_SECTOR_SIZE;
;;;763                        g_u32Length = g_sCBW.dCBWDataTransferLength;
;;;764                        g_u32BytesInStorageBuf = g_u32Length;
;;;765    
;;;766                        i = g_u32Length;
;;;767                        if (i > STORAGE_BUFFER_SIZE)
;;;768                            i = STORAGE_BUFFER_SIZE;
;;;769    
;;;770                        DBG_PRINTF("media read A:0x%08x S:%d\n", g_u32Address * UDC_SECTOR_SIZE, g_u32Length);
;;;771    
;;;772                        MSC_ReadMedia(g_u32Address * UDC_SECTOR_SIZE, i, (uint8_t *)STORAGE_DATA_BUF);
;;;773                        g_u32BytesInStorageBuf = i;
;;;774                        g_u32LbaAddress += i;
;;;775                        
;;;776                        
;;;777                    }
;;;778                    g_u32Address = STORAGE_DATA_BUF;
;;;779    
;;;780                    /* Indicate the next packet should be Bulk IN Data packet */
;;;781                    g_u8BulkState = BULK_IN;
;;;782    
;;;783                    if (g_u32BytesInStorageBuf > 0) {
;;;784                        /* Set the packet size */
;;;785                        if (g_u32BytesInStorageBuf > EP2_MAX_PKT_SIZE)
;;;786                            g_u8Size = EP2_MAX_PKT_SIZE;
;;;787                        else
;;;788                            g_u8Size = g_u32BytesInStorageBuf;
;;;789    
;;;790                        /* Prepare the first data packet (DATA1) */
;;;791                        /* Bulk IN buffer */
;;;792                        USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf1), (uint8_t *)g_u32Address, g_u8Size);
;;;793                        g_u32Address += g_u8Size;
;;;794    
;;;795                        DBG_PRINTF("bulk in start buf %d, size %d\n", 1, g_u8Size);
;;;796    
;;;797                        /* kick - start */
;;;798                        USBD_SET_EP_BUF_ADDR(EP2, g_u32BulkBuf1);
;;;799                        /* Trigger to send out the data packet */
;;;800                        USBD_SET_PAYLOAD_LEN(EP2, g_u8Size);
;;;801                        g_u32Length -= g_u8Size;
;;;802                        g_u32BytesInStorageBuf -= g_u8Size;
;;;803                        
;;;804                    }
;;;805    //                     else
;;;806    //                         MSC_AckCmd();
;;;807    
;;;808                    return;
;;;809                }
;;;810                case UFI_WRITE_10: {
;;;811                    if (g_u32Length == 0) {
;;;812                        g_u32Length = g_sCBW.dCBWDataTransferLength;
;;;813                        g_u32Address = STORAGE_DATA_BUF;
;;;814                        g_u32DataFlashStartAddr = get_be32(&g_sCBW.au8Data[0]) * UDC_SECTOR_SIZE;
;;;815                    }
;;;816    
;;;817                    if ((g_u32Length > 0)) {
;;;818                        USBD_SET_PAYLOAD_LEN(EP3, EP3_MAX_PKT_SIZE);
;;;819                        g_u8BulkState = BULK_OUT;
;;;820                    }
;;;821                    return;
;;;822                }
;;;823                default: {
;;;824                    /* Unsupported command */
;;;825                    g_au8SenseKey[0] = 0x05;
;;;826                    g_au8SenseKey[1] = 0x20;
;;;827                    g_au8SenseKey[2] = 0x00;
;;;828    
;;;829                    /* If CBW request for data phase, just return zero packet to end data phase */
;;;830                    if (g_sCBW.dCBWDataTransferLength > 0) {
;;;831                        /* Data Phase, zero/short packet */
;;;832                        if ((g_sCBW.bmCBWFlags & 0x80) != 0) {
;;;833                            /* Data-In */
;;;834                            g_u8BulkState = BULK_IN;
;;;835                            USBD_SET_PAYLOAD_LEN(EP2, 0);
;;;836                        }
;;;837                    } else {
;;;838                        /* Status Phase */
;;;839                        g_u8BulkState = BULK_IN;
;;;840                        MSC_AckCmd();
;;;841                    }
;;;842                    return;
;;;843                }
;;;844                }
;;;845            } else if (g_u8BulkState == BULK_OUT) {
000014  78e0              LDRB     r0,[r4,#3]  ; g_u8BulkState
000016  2802              CMP      r0,#2
000018  d107              BNE      |L7.42|
;;;846                switch (g_sCBW.u8OPCode) {
00001a  4891              LDR      r0,|L7.608|
00001c  7bc0              LDRB     r0,[r0,#0xf]  ; g_sCBW
00001e  282a              CMP      r0,#0x2a
000020  d001              BEQ      |L7.38|
000022  2855              CMP      r0,#0x55
000024  d101              BNE      |L7.42|
                  |L7.38|
;;;847                case UFI_WRITE_10:
;;;848                case UFI_MODE_SELECT_10: {
;;;849                    MSC_Write();
000026  f7fffffe          BL       MSC_Write
                  |L7.42|
;;;850                    return;
;;;851                }
;;;852                }
;;;853            }
;;;854        }
;;;855    }
00002a  bdf8              POP      {r3-r7,pc}
                  |L7.44|
00002c  4e8d              LDR      r6,|L7.612|
00002e  68f0              LDR      r0,[r6,#0xc]          ;619
000030  2501              MOVS     r5,#1                 ;619
000032  4328              ORRS     r0,r0,r5              ;619
000034  60f0              STR      r0,[r6,#0xc]          ;619
000036  6970              LDR      r0,[r6,#0x14]         ;621
000038  b2c1              UXTB     r1,r0                 ;621
00003a  6a60              LDR      r0,[r4,#0x24]         ;625  ; g_u32BulkBuf0
00003c  4b89              LDR      r3,|L7.612|
00003e  4f8a              LDR      r7,|L7.616|
000040  33c0              ADDS     r3,r3,#0xc0           ;625
000042  18c0              ADDS     r0,r0,r3              ;625
000044  6800              LDR      r0,[r0,#0]            ;625
000046  42b8              CMP      r0,r7                 ;625
000048  d1ef              BNE      |L7.42|
00004a  291f              CMP      r1,#0x1f              ;625
00004c  d1ed              BNE      |L7.42|
00004e  2000              MOVS     r0,#0                 ;630
                  |L7.80|
000050  6a63              LDR      r3,[r4,#0x24]         ;631  ; g_u32BulkBuf0
000052  181f              ADDS     r7,r3,r0              ;631
000054  4b83              LDR      r3,|L7.612|
000056  33c0              ADDS     r3,r3,#0xc0           ;631
000058  18fb              ADDS     r3,r7,r3              ;631
00005a  781f              LDRB     r7,[r3,#0]            ;631
00005c  4b80              LDR      r3,|L7.608|
00005e  541f              STRB     r7,[r3,r0]            ;631
000060  1c40              ADDS     r0,r0,#1              ;630
000062  4288              CMP      r0,r1                 ;630
000064  dbf4              BLT      |L7.80|
000066  461f              MOV      r7,r3                 ;634
000068  4619              MOV      r1,r3                 ;634
00006a  3120              ADDS     r1,r1,#0x20           ;634
00006c  6878              LDR      r0,[r7,#4]            ;634  ; g_sCBW
00006e  6048              STR      r0,[r1,#4]            ;637  ; g_sCSW
000070  7bf9              LDRB     r1,[r7,#0xf]          ;637  ; g_sCBW
000072  4638              MOV      r0,r7                 ;666
000074  2305              MOVS     r3,#5                 ;640
000076  3030              ADDS     r0,r0,#0x30           ;666
000078  2925              CMP      r1,#0x25              ;637
00007a  d060              BEQ      |L7.318|
00007c  dc0e              BGT      |L7.156|
00007e  291b              CMP      r1,#0x1b              ;637
000080  d034              BEQ      |L7.236|
000082  dc06              BGT      |L7.146|
000084  2900              CMP      r1,#0                 ;637
000086  d031              BEQ      |L7.236|
000088  2903              CMP      r1,#3                 ;637
00008a  d033              BEQ      |L7.244|
00008c  2912              CMP      r1,#0x12              ;637
00008e  d112              BNE      |L7.182|
000090  e071              B        |L7.374|
                  |L7.146|
000092  291e              CMP      r1,#0x1e              ;637
000094  d01e              BEQ      |L7.212|
000096  2923              CMP      r1,#0x23              ;637
000098  d10d              BNE      |L7.182|
00009a  e031              B        |L7.256|
                  |L7.156|
00009c  292f              CMP      r1,#0x2f              ;637
00009e  d025              BEQ      |L7.236|
0000a0  dc05              BGT      |L7.174|
0000a2  4872              LDR      r0,|L7.620|
0000a4  2928              CMP      r1,#0x28              ;637
0000a6  d074              BEQ      |L7.402|
0000a8  292a              CMP      r1,#0x2a              ;637
0000aa  d104              BNE      |L7.182|
0000ac  e0c1              B        |L7.562|
                  |L7.174|
0000ae  2955              CMP      r1,#0x55              ;637
0000b0  d04e              BEQ      |L7.336|
0000b2  295a              CMP      r1,#0x5a              ;637
0000b4  d050              BEQ      |L7.344|
                  |L7.182|
0000b6  4869              LDR      r0,|L7.604|
0000b8  2120              MOVS     r1,#0x20              ;826
0000ba  300c              ADDS     r0,r0,#0xc            ;825
0000bc  7003              STRB     r3,[r0,#0]            ;825
0000be  7041              STRB     r1,[r0,#1]            ;826
0000c0  7082              STRB     r2,[r0,#2]            ;827
0000c2  68b8              LDR      r0,[r7,#8]            ;830  ; g_sCBW
0000c4  2800              CMP      r0,#0                 ;830
0000c6  d011              BEQ      |L7.236|
0000c8  7b38              LDRB     r0,[r7,#0xc]          ;832  ; g_sCBW
0000ca  0600              LSLS     r0,r0,#24             ;832
0000cc  d5ad              BPL      |L7.42|
0000ce  70e5              STRB     r5,[r4,#3]            ;834
0000d0  6072              STR      r2,[r6,#4]            ;835
0000d2  bdf8              POP      {r3-r7,pc}
                  |L7.212|
0000d4  7cf8              LDRB     r0,[r7,#0x13]         ;639  ; g_sCBW
0000d6  07c0              LSLS     r0,r0,#31             ;639
0000d8  d007              BEQ      |L7.234|
0000da  4860              LDR      r0,|L7.604|
0000dc  300c              ADDS     r0,r0,#0xc            ;640
0000de  7003              STRB     r3,[r0,#0]            ;640
0000e0  2124              MOVS     r1,#0x24              ;641
0000e2  7041              STRB     r1,[r0,#1]            ;641
0000e4  7082              STRB     r2,[r0,#2]            ;642
0000e6  70a5              STRB     r5,[r4,#2]            ;643
0000e8  e000              B        |L7.236|
                  |L7.234|
0000ea  70a2              STRB     r2,[r4,#2]            ;645
                  |L7.236|
0000ec  70e5              STRB     r5,[r4,#3]            ;839
0000ee  f7fffffe          BL       MSC_AckCmd
0000f2  bdf8              POP      {r3-r7,pc}
                  |L7.244|
0000f4  f7fffffe          BL       MSC_RequestSense
0000f8  70e5              STRB     r5,[r4,#3]            ;659
0000fa  2012              MOVS     r0,#0x12              ;660
0000fc  6070              STR      r0,[r6,#4]            ;660
0000fe  bdf8              POP      {r3-r7,pc}
                  |L7.256|
000100  69a1              LDR      r1,[r4,#0x18]         ;664  ; g_u32Length
000102  2900              CMP      r1,#0                 ;664
000104  d102              BNE      |L7.268|
000106  68b9              LDR      r1,[r7,#8]            ;665  ; g_sCBW
000108  61a1              STR      r1,[r4,#0x18]         ;665  ; g_u32Length
00010a  6160              STR      r0,[r4,#0x14]         ;666  ; g_u32Address
                  |L7.268|
00010c  f7fffffe          BL       MSC_ReadFormatCapacity
000110  e02a              B        |L7.360|
                  |L7.274|
000112  69a0              LDR      r0,[r4,#0x18]         ;671  ; g_u32Length
000114  2840              CMP      r0,#0x40              ;671
000116  d92c              BLS      |L7.370|
000118  2040              MOVS     r0,#0x40              ;732
                  |L7.282|
00011a  7120              STRB     r0,[r4,#4]            ;674
00011c  7922              LDRB     r2,[r4,#4]            ;736  ; g_u8Size
00011e  6961              LDR      r1,[r4,#0x14]         ;736  ; g_u32Address
000120  6aa3              LDR      r3,[r4,#0x28]         ;736  ; g_u32BulkBuf1
000122  4850              LDR      r0,|L7.612|
000124  30c0              ADDS     r0,r0,#0xc0           ;736
000126  1818              ADDS     r0,r3,r0              ;736
000128  f7fffffe          BL       USBD_MemCopy
00012c  6960              LDR      r0,[r4,#0x14]         ;738  ; g_u32Address
00012e  7921              LDRB     r1,[r4,#4]            ;738  ; g_u8Size
000130  1840              ADDS     r0,r0,r1              ;738
000132  6160              STR      r0,[r4,#0x14]         ;738  ; g_u32Address
000134  6a60              LDR      r0,[r4,#0x24]         ;740  ; g_u32BulkBuf0
000136  6030              STR      r0,[r6,#0]            ;740
000138  f7fffffe          BL       MSC_Read
00013c  bdf8              POP      {r3-r7,pc}
                  |L7.318|
00013e  69a1              LDR      r1,[r4,#0x18]         ;688  ; g_u32Length
000140  2900              CMP      r1,#0                 ;688
000142  d102              BNE      |L7.330|
000144  68b9              LDR      r1,[r7,#8]            ;689  ; g_sCBW
000146  61a1              STR      r1,[r4,#0x18]         ;689  ; g_u32Length
000148  6160              STR      r0,[r4,#0x14]         ;690  ; g_u32Address
                  |L7.330|
00014a  f7fffffe          BL       MSC_ReadCapacity
00014e  e00b              B        |L7.360|
                  |L7.336|
000150  68b9              LDR      r1,[r7,#8]            ;713  ; g_sCBW
000152  61a1              STR      r1,[r4,#0x18]         ;713  ; g_u32Length
000154  6160              STR      r0,[r4,#0x14]         ;714  ; g_u32Address
000156  e078              B        |L7.586|
                  |L7.344|
000158  69a1              LDR      r1,[r4,#0x18]         ;723  ; g_u32Length
00015a  2900              CMP      r1,#0                 ;723
00015c  d102              BNE      |L7.356|
00015e  68b9              LDR      r1,[r7,#8]            ;724  ; g_sCBW
000160  61a1              STR      r1,[r4,#0x18]         ;724  ; g_u32Length
000162  6160              STR      r0,[r4,#0x14]         ;725  ; g_u32Address
                  |L7.356|
000164  f7fffffe          BL       MSC_ModeSense10
                  |L7.360|
000168  70e5              STRB     r5,[r4,#3]            ;729
00016a  69a0              LDR      r0,[r4,#0x18]         ;730  ; g_u32Length
00016c  2800              CMP      r0,#0                 ;730
00016e  d1d0              BNE      |L7.274|
000170  bdf8              POP      {r3-r7,pc}
                  |L7.370|
000172  69a0              LDR      r0,[r4,#0x18]         ;734  ; g_u32Length
000174  e7d1              B        |L7.282|
                  |L7.374|
000176  4939              LDR      r1,|L7.604|
000178  2224              MOVS     r2,#0x24              ;749
00017a  6aa3              LDR      r3,[r4,#0x28]         ;749  ; g_u32BulkBuf1
00017c  3134              ADDS     r1,r1,#0x34           ;749
00017e  4839              LDR      r0,|L7.612|
000180  30c0              ADDS     r0,r0,#0xc0           ;749
000182  1818              ADDS     r0,r3,r0              ;749
000184  f7fffffe          BL       USBD_MemCopy
000188  2024              MOVS     r0,#0x24              ;750
00018a  6070              STR      r0,[r6,#4]            ;750
00018c  70e5              STRB     r5,[r4,#3]            ;751
                  |L7.398|
00018e  bdf8              POP      {r3-r7,pc}
000190  e7ff              B        |L7.402|
                  |L7.402|
000192  69a1              LDR      r1,[r4,#0x18]         ;757  ; g_u32Length
000194  2900              CMP      r1,#0                 ;757
000196  d120              BNE      |L7.474|
000198  f7fffffe          BL       get_be32
00019c  6160              STR      r0,[r4,#0x14]         ;761  ; g_u32Address
00019e  6960              LDR      r0,[r4,#0x14]         ;762  ; g_u32Address
0001a0  0240              LSLS     r0,r0,#9              ;762
0001a2  61e0              STR      r0,[r4,#0x1c]         ;762  ; g_u32LbaAddress
0001a4  68b8              LDR      r0,[r7,#8]            ;763  ; g_sCBW
0001a6  61a0              STR      r0,[r4,#0x18]         ;763  ; g_u32Length
0001a8  69a0              LDR      r0,[r4,#0x18]         ;764  ; g_u32Length
0001aa  6220              STR      r0,[r4,#0x20]         ;764  ; g_u32BytesInStorageBuf
0001ac  69a7              LDR      r7,[r4,#0x18]         ;766  ; g_u32Length
0001ae  2001              MOVS     r0,#1                 ;767
0001b0  0240              LSLS     r0,r0,#9              ;767
0001b2  4287              CMP      r7,r0                 ;767
0001b4  dd00              BLE      |L7.440|
0001b6  4607              MOV      r7,r0                 ;768
                  |L7.440|
0001b8  6960              LDR      r0,[r4,#0x14]         ;770  ; g_u32Address
0001ba  69a2              LDR      r2,[r4,#0x18]         ;770  ; g_u32Length
0001bc  0241              LSLS     r1,r0,#9              ;770
0001be  a02c              ADR      r0,|L7.624|
0001c0  f7fffffe          BL       __2printf
0001c4  6960              LDR      r0,[r4,#0x14]         ;772  ; g_u32Address
0001c6  4a29              LDR      r2,|L7.620|
0001c8  0240              LSLS     r0,r0,#9              ;772
0001ca  324f              ADDS     r2,r2,#0x4f           ;772
0001cc  4639              MOV      r1,r7                 ;772
0001ce  f7fffffe          BL       MSC_ReadMedia
0001d2  6227              STR      r7,[r4,#0x20]         ;773  ; g_u32BytesInStorageBuf
0001d4  69e0              LDR      r0,[r4,#0x1c]         ;774  ; g_u32LbaAddress
0001d6  19c0              ADDS     r0,r0,r7              ;774
0001d8  61e0              STR      r0,[r4,#0x1c]         ;774  ; g_u32LbaAddress
                  |L7.474|
0001da  4824              LDR      r0,|L7.620|
0001dc  304f              ADDS     r0,r0,#0x4f           ;778
0001de  6160              STR      r0,[r4,#0x14]         ;778  ; g_u32Address
0001e0  70e5              STRB     r5,[r4,#3]            ;781
0001e2  6a20              LDR      r0,[r4,#0x20]         ;783  ; g_u32BytesInStorageBuf
0001e4  2800              CMP      r0,#0                 ;783
0001e6  d0d2              BEQ      |L7.398|
0001e8  6a20              LDR      r0,[r4,#0x20]         ;785  ; g_u32BytesInStorageBuf
0001ea  2840              CMP      r0,#0x40              ;785
0001ec  d901              BLS      |L7.498|
0001ee  2040              MOVS     r0,#0x40              ;786
0001f0  e000              B        |L7.500|
                  |L7.498|
0001f2  6a20              LDR      r0,[r4,#0x20]         ;788  ; g_u32BytesInStorageBuf
                  |L7.500|
0001f4  7120              STRB     r0,[r4,#4]            ;788
0001f6  7922              LDRB     r2,[r4,#4]            ;792  ; g_u8Size
0001f8  6961              LDR      r1,[r4,#0x14]         ;792  ; g_u32Address
0001fa  6aa3              LDR      r3,[r4,#0x28]         ;792  ; g_u32BulkBuf1
0001fc  4819              LDR      r0,|L7.612|
0001fe  30c0              ADDS     r0,r0,#0xc0           ;792
000200  1818              ADDS     r0,r3,r0              ;792
000202  f7fffffe          BL       USBD_MemCopy
000206  6960              LDR      r0,[r4,#0x14]         ;793  ; g_u32Address
000208  7921              LDRB     r1,[r4,#4]            ;793  ; g_u8Size
00020a  1840              ADDS     r0,r0,r1              ;793
00020c  6160              STR      r0,[r4,#0x14]         ;793  ; g_u32Address
00020e  7922              LDRB     r2,[r4,#4]            ;795  ; g_u8Size
000210  2101              MOVS     r1,#1                 ;795
000212  a01e              ADR      r0,|L7.652|
000214  f7fffffe          BL       __2printf
000218  6aa0              LDR      r0,[r4,#0x28]         ;798  ; g_u32BulkBuf1
00021a  6030              STR      r0,[r6,#0]            ;798
00021c  7920              LDRB     r0,[r4,#4]            ;800  ; g_u8Size
00021e  6070              STR      r0,[r6,#4]            ;800
000220  69a0              LDR      r0,[r4,#0x18]         ;801  ; g_u32Length
000222  7921              LDRB     r1,[r4,#4]            ;801  ; g_u8Size
000224  1a40              SUBS     r0,r0,r1              ;801
000226  61a0              STR      r0,[r4,#0x18]         ;801  ; g_u32Length
000228  6a20              LDR      r0,[r4,#0x20]         ;802  ; g_u32BytesInStorageBuf
00022a  7921              LDRB     r1,[r4,#4]            ;802  ; g_u8Size
00022c  1a40              SUBS     r0,r0,r1              ;802
00022e  6220              STR      r0,[r4,#0x20]         ;802  ; g_u32BytesInStorageBuf
000230  e7ad              B        |L7.398|
                  |L7.562|
000232  69a1              LDR      r1,[r4,#0x18]         ;811  ; g_u32Length
000234  2900              CMP      r1,#0                 ;811
000236  d108              BNE      |L7.586|
000238  68b9              LDR      r1,[r7,#8]            ;812  ; g_sCBW
00023a  61a1              STR      r1,[r4,#0x18]         ;812  ; g_u32Length
00023c  490b              LDR      r1,|L7.620|
00023e  314f              ADDS     r1,r1,#0x4f           ;813
000240  6161              STR      r1,[r4,#0x14]         ;813  ; g_u32Address
000242  f7fffffe          BL       get_be32
000246  0240              LSLS     r0,r0,#9              ;814
000248  6120              STR      r0,[r4,#0x10]         ;814  ; g_u32DataFlashStartAddr
                  |L7.586|
00024a  69a0              LDR      r0,[r4,#0x18]         ;817  ; g_u32Length
00024c  2800              CMP      r0,#0                 ;817
00024e  d09e              BEQ      |L7.398|
000250  2040              MOVS     r0,#0x40              ;818
000252  6170              STR      r0,[r6,#0x14]         ;818
000254  2002              MOVS     r0,#2                 ;819
000256  70e0              STRB     r0,[r4,#3]            ;819
000258  e799              B        |L7.398|
;;;856    
                          ENDP

00025a  0000              DCW      0x0000
                  |L7.604|
                          DCD      ||.data||
                  |L7.608|
                          DCD      ||.bss||
                  |L7.612|
                          DCD      0x40060040
                  |L7.616|
                          DCD      0x43425355
                  |L7.620|
                          DCD      ||.bss||+0x11
                  |L7.624|
000270  6d656469          DCB      "media read A:0x%08x S:%d\n",0
000274  61207265
000278  61642041
00027c  3a307825
000280  30387820
000284  533a2564
000288  0a00    
00028a  00                DCB      0
00028b  00                DCB      0
                  |L7.652|
00028c  62756c6b          DCB      "bulk in start buf %d, size %d\n",0
000290  20696e20
000294  73746172
000298  74206275
00029c  66202564
0002a0  2c207369
0002a4  7a652025
0002a8  640a00  
0002ab  00                DCB      0

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

                  MSC_Read PROC
;;;344    
;;;345    void MSC_Read(void)
000000  b5f8              PUSH     {r3-r7,lr}
;;;346    {
;;;347        uint32_t u32Len;
;;;348    
;;;349        if (USBD_GET_EP_BUF_ADDR(EP2) == g_u32BulkBuf1)
000002  4f24              LDR      r7,|L8.148|
000004  6838              LDR      r0,[r7,#0]
000006  4d24              LDR      r5,|L8.152|
000008  6aa9              LDR      r1,[r5,#0x28]  ; g_u32BulkBuf1
00000a  4288              CMP      r0,r1
00000c  d101              BNE      |L8.18|
;;;350            USBD_SET_EP_BUF_ADDR(EP2, g_u32BulkBuf0);
00000e  6a68              LDR      r0,[r5,#0x24]  ; g_u32BulkBuf0
000010  e000              B        |L8.20|
                  |L8.18|
;;;351        else
;;;352            USBD_SET_EP_BUF_ADDR(EP2, g_u32BulkBuf1);
000012  6aa8              LDR      r0,[r5,#0x28]  ; g_u32BulkBuf1
                  |L8.20|
000014  6038              STR      r0,[r7,#0]
;;;353    
;;;354        /* Trigger to send out the data packet */
;;;355        USBD_SET_PAYLOAD_LEN(EP2, g_u8Size);
000016  7928              LDRB     r0,[r5,#4]  ; g_u8Size
000018  6078              STR      r0,[r7,#4]
;;;356    
;;;357        g_u32Length -= g_u8Size;
00001a  69a8              LDR      r0,[r5,#0x18]  ; g_u32Length
00001c  7929              LDRB     r1,[r5,#4]  ; g_u8Size
00001e  1a40              SUBS     r0,r0,r1
000020  61a8              STR      r0,[r5,#0x18]  ; g_u32Length
;;;358        g_u32BytesInStorageBuf -= g_u8Size;
000022  6a28              LDR      r0,[r5,#0x20]  ; g_u32BytesInStorageBuf
000024  7929              LDRB     r1,[r5,#4]  ; g_u8Size
000026  1a40              SUBS     r0,r0,r1
000028  6228              STR      r0,[r5,#0x20]  ; g_u32BytesInStorageBuf
;;;359    
;;;360        if (g_u32Length) {
00002a  69a8              LDR      r0,[r5,#0x18]  ; g_u32Length
00002c  2800              CMP      r0,#0
00002e  d018              BEQ      |L8.98|
;;;361            if (g_u32BytesInStorageBuf) {
000030  6a28              LDR      r0,[r5,#0x20]  ; g_u32BytesInStorageBuf
;;;362                /* Prepare next data packet */
;;;363                g_u8Size = EP2_MAX_PKT_SIZE;
;;;364                if (g_u8Size > g_u32Length)
;;;365                    g_u8Size = g_u32Length;
;;;366    
;;;367                if (USBD_GET_EP_BUF_ADDR(EP2) == g_u32BulkBuf1)
;;;368                    USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf0), (uint8_t *)g_u32Address, g_u8Size);
000032  4e18              LDR      r6,|L8.148|
000034  36c0              ADDS     r6,r6,#0xc0
000036  2800              CMP      r0,#0                 ;361
000038  d014              BEQ      |L8.100|
                  |L8.58|
00003a  2040              MOVS     r0,#0x40              ;363
00003c  7128              STRB     r0,[r5,#4]            ;363
00003e  7928              LDRB     r0,[r5,#4]            ;364  ; g_u8Size
000040  69a9              LDR      r1,[r5,#0x18]         ;364  ; g_u32Length
000042  4288              CMP      r0,r1                 ;364
000044  d820              BHI      |L8.136|
                  |L8.70|
000046  6838              LDR      r0,[r7,#0]            ;367
000048  6aa9              LDR      r1,[r5,#0x28]         ;367  ; g_u32BulkBuf1
;;;369                else
;;;370                    USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf1), (uint8_t *)g_u32Address, g_u8Size);
;;;371                g_u32Address += g_u8Size;
;;;372            } else {
;;;373                u32Len = g_u32Length;
;;;374                if (u32Len > STORAGE_BUFFER_SIZE)
;;;375                    u32Len = STORAGE_BUFFER_SIZE;
;;;376    
;;;377                MSC_ReadMedia(g_u32LbaAddress, u32Len, (uint8_t *)STORAGE_DATA_BUF);
;;;378                g_u32BytesInStorageBuf = u32Len;
;;;379                g_u32LbaAddress += u32Len;
;;;380                g_u32Address = STORAGE_DATA_BUF;
;;;381    
;;;382                /* Prepare next data packet */
;;;383                g_u8Size = EP2_MAX_PKT_SIZE;
;;;384                if (g_u8Size > g_u32Length)
;;;385                    g_u8Size = g_u32Length;
;;;386    
;;;387                if (USBD_GET_EP_BUF_ADDR(EP2) == g_u32BulkBuf1)
;;;388                    USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf0), (uint8_t *)g_u32Address, g_u8Size);
;;;389                else
;;;390                    USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf1), (uint8_t *)g_u32Address, g_u8Size);
00004a  792a              LDRB     r2,[r5,#4]  ; g_u8Size
00004c  4288              CMP      r0,r1                 ;367
00004e  6969              LDR      r1,[r5,#0x14]  ; g_u32Address
000050  d11d              BNE      |L8.142|
000052  6a68              LDR      r0,[r5,#0x24]         ;388  ; g_u32BulkBuf0
                  |L8.84|
000054  1980              ADDS     r0,r0,r6              ;370
000056  f7fffffe          BL       USBD_MemCopy
;;;391                g_u32Address += g_u8Size;
00005a  6968              LDR      r0,[r5,#0x14]  ; g_u32Address
00005c  7929              LDRB     r1,[r5,#4]  ; g_u8Size
00005e  1840              ADDS     r0,r0,r1
000060  6168              STR      r0,[r5,#0x14]  ; g_u32Address
                  |L8.98|
;;;392            }
;;;393        }
;;;394    }
000062  bdf8              POP      {r3-r7,pc}
                  |L8.100|
000064  69ac              LDR      r4,[r5,#0x18]         ;373  ; g_u32Length
000066  2001              MOVS     r0,#1                 ;374
000068  0240              LSLS     r0,r0,#9              ;374
00006a  4284              CMP      r4,r0                 ;374
00006c  d900              BLS      |L8.112|
00006e  4604              MOV      r4,r0                 ;375
                  |L8.112|
000070  4a0a              LDR      r2,|L8.156|
000072  4621              MOV      r1,r4                 ;377
000074  69e8              LDR      r0,[r5,#0x1c]         ;377  ; g_u32LbaAddress
000076  f7fffffe          BL       MSC_ReadMedia
00007a  622c              STR      r4,[r5,#0x20]         ;378  ; g_u32BytesInStorageBuf
00007c  69e8              LDR      r0,[r5,#0x1c]         ;379  ; g_u32LbaAddress
00007e  1900              ADDS     r0,r0,r4              ;379
000080  61e8              STR      r0,[r5,#0x1c]         ;379  ; g_u32LbaAddress
000082  4806              LDR      r0,|L8.156|
000084  6168              STR      r0,[r5,#0x14]         ;380  ; g_u32Address
000086  e7d8              B        |L8.58|
                  |L8.136|
000088  69a8              LDR      r0,[r5,#0x18]         ;385  ; g_u32Length
00008a  7128              STRB     r0,[r5,#4]            ;385
00008c  e7db              B        |L8.70|
                  |L8.142|
00008e  6aa8              LDR      r0,[r5,#0x28]         ;390  ; g_u32BulkBuf1
000090  e7e0              B        |L8.84|
;;;395    
                          ENDP

000092  0000              DCW      0x0000
                  |L8.148|
                          DCD      0x40060040
                  |L8.152|
                          DCD      ||.data||
                  |L8.156|
                          DCD      ||.bss||+0x60

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

                  MSC_ReadCapacity PROC
;;;470    
;;;471    void MSC_ReadCapacity(void)
000000  b508              PUSH     {r3,lr}
;;;472    {
;;;473        uint32_t tmp;
;;;474    
;;;475        memset((uint8_t *)MassCMD_BUF, 0, 36);
000002  2124              MOVS     r1,#0x24
000004  480b              LDR      r0,|L9.52|
000006  f7fffffe          BL       __aeabi_memclr4
;;;476    
;;;477        tmp = g_TotalSectors - 1;
00000a  480b              LDR      r0,|L9.56|
00000c  6880              LDR      r0,[r0,#8]  ; g_TotalSectors
;;;478        *((uint8_t *)(MassCMD_BUF+0)) = *((uint8_t *)&tmp+3);
00000e  4669              MOV      r1,sp
000010  1e40              SUBS     r0,r0,#1              ;477
000012  9000              STR      r0,[sp,#0]
000014  4807              LDR      r0,|L9.52|
000016  78c9              LDRB     r1,[r1,#3]
000018  7001              STRB     r1,[r0,#0]
;;;479        *((uint8_t *)(MassCMD_BUF+1)) = *((uint8_t *)&tmp+2);
00001a  4669              MOV      r1,sp
00001c  7889              LDRB     r1,[r1,#2]
00001e  7041              STRB     r1,[r0,#1]
;;;480        *((uint8_t *)(MassCMD_BUF+2)) = *((uint8_t *)&tmp+1);
000020  4669              MOV      r1,sp
000022  7849              LDRB     r1,[r1,#1]
000024  7081              STRB     r1,[r0,#2]
;;;481        *((uint8_t *)(MassCMD_BUF+3)) = *((uint8_t *)&tmp+0);
000026  4669              MOV      r1,sp
000028  7809              LDRB     r1,[r1,#0]
00002a  70c1              STRB     r1,[r0,#3]
;;;482        *((uint8_t *)(MassCMD_BUF+6)) = 0x02;
00002c  2102              MOVS     r1,#2
00002e  7181              STRB     r1,[r0,#6]
;;;483    }
000030  bd08              POP      {r3,pc}
;;;484    
                          ENDP

000032  0000              DCW      0x0000
                  |L9.52|
                          DCD      ||.bss||+0x30
                  |L9.56|
                          DCD      ||.data||

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

                  MSC_ReadFormatCapacity PROC
;;;326    
;;;327    void MSC_ReadFormatCapacity(void)
000000  b570              PUSH     {r4-r6,lr}
;;;328    {
;;;329        memset((uint8_t *)MassCMD_BUF, 0, 36);
000002  2124              MOVS     r1,#0x24
000004  480b              LDR      r0,|L10.52|
000006  f7fffffe          BL       __aeabi_memclr4
;;;330    
;;;331        *((uint8_t *)(MassCMD_BUF+3)) = 0x10;
00000a  480a              LDR      r0,|L10.52|
00000c  2110              MOVS     r1,#0x10
;;;332        *((uint8_t *)(MassCMD_BUF+4)) = *((uint8_t *)&g_TotalSectors+3);
00000e  4c0a              LDR      r4,|L10.56|
000010  70c1              STRB     r1,[r0,#3]            ;331
000012  78e1              LDRB     r1,[r4,#3]  ; g_TotalSectors
000014  7101              STRB     r1,[r0,#4]
;;;333        *((uint8_t *)(MassCMD_BUF+5)) = *((uint8_t *)&g_TotalSectors+2);
000016  78a2              LDRB     r2,[r4,#2]  ; g_TotalSectors
000018  7142              STRB     r2,[r0,#5]
;;;334        *((uint8_t *)(MassCMD_BUF+6)) = *((uint8_t *)&g_TotalSectors+1);
00001a  7863              LDRB     r3,[r4,#1]  ; g_TotalSectors
00001c  7183              STRB     r3,[r0,#6]
;;;335        *((uint8_t *)(MassCMD_BUF+7)) = *((uint8_t *)&g_TotalSectors+0);
00001e  7825              LDRB     r5,[r4,#0]  ; g_TotalSectors
000020  71c5              STRB     r5,[r0,#7]
;;;336        *((uint8_t *)(MassCMD_BUF+8)) = 0x02;
000022  2402              MOVS     r4,#2
000024  7204              STRB     r4,[r0,#8]
;;;337        *((uint8_t *)(MassCMD_BUF+10)) = 0x02;
000026  7284              STRB     r4,[r0,#0xa]
;;;338        *((uint8_t *)(MassCMD_BUF+12)) = *((uint8_t *)&g_TotalSectors+3);
000028  7301              STRB     r1,[r0,#0xc]
;;;339        *((uint8_t *)(MassCMD_BUF+13)) = *((uint8_t *)&g_TotalSectors+2);
00002a  7342              STRB     r2,[r0,#0xd]
;;;340        *((uint8_t *)(MassCMD_BUF+14)) = *((uint8_t *)&g_TotalSectors+1);
00002c  7383              STRB     r3,[r0,#0xe]
;;;341        *((uint8_t *)(MassCMD_BUF+15)) = *((uint8_t *)&g_TotalSectors+0);
00002e  73c5              STRB     r5,[r0,#0xf]
;;;342        *((uint8_t *)(MassCMD_BUF+18)) = 0x02;
000030  7484              STRB     r4,[r0,#0x12]
;;;343    }
000032  bd70              POP      {r4-r6,pc}
;;;344    
                          ENDP

                  |L10.52|
                          DCD      ||.bss||+0x30
                  |L10.56|
                          DCD      ||.data||+0x8

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

                  MSC_ReadMedia PROC
;;;939    
;;;940    void MSC_ReadMedia(uint32_t addr, uint32_t size, uint8_t *buffer)
000000  b510              PUSH     {r4,lr}
;;;941    {
;;;942        DataFlashRead( addr, size, (uint32_t)buffer);
000002  f7fffffe          BL       DataFlashRead
;;;943    }
000006  bd10              POP      {r4,pc}
;;;944    
                          ENDP


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

                  MSC_ReadTrig PROC
;;;395    
;;;396    void MSC_ReadTrig(void)
000000  b5f8              PUSH     {r3-r7,lr}
;;;397    {
;;;398        uint32_t u32Len;
;;;399        uint32_t u32CurBuf;
;;;400    
;;;401        u32CurBuf = USBD_GET_EP_BUF_ADDR(EP2);
000002  4f26              LDR      r7,|L12.156|
000004  683e              LDR      r6,[r7,#0]
;;;402        
;;;403        if (g_u32Length) {
000006  4d26              LDR      r5,|L12.160|
000008  69a8              LDR      r0,[r5,#0x18]  ; g_u32Length
00000a  2800              CMP      r0,#0
00000c  d040              BEQ      |L12.144|
;;;404            if (g_u32BytesInStorageBuf) {
00000e  6a28              LDR      r0,[r5,#0x20]  ; g_u32BytesInStorageBuf
000010  2800              CMP      r0,#0
000012  d019              BEQ      |L12.72|
                  |L12.20|
;;;405                /* Prepare next data packet */
;;;406                g_u8Size = EP2_MAX_PKT_SIZE;
000014  2040              MOVS     r0,#0x40
000016  7128              STRB     r0,[r5,#4]
;;;407                if (g_u8Size > g_u32Length)
000018  7928              LDRB     r0,[r5,#4]  ; g_u8Size
00001a  69a9              LDR      r1,[r5,#0x18]  ; g_u32Length
00001c  4288              CMP      r0,r1
00001e  d825              BHI      |L12.108|
                  |L12.32|
;;;408                    g_u8Size = g_u32Length;
;;;409    
;;;410                if (u32CurBuf == g_u32BulkBuf1)
000020  6aa8              LDR      r0,[r5,#0x28]  ; g_u32BulkBuf1
;;;411                    USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf0), (uint8_t *)g_u32Address, g_u8Size);
;;;412                else
;;;413                    USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf1), (uint8_t *)g_u32Address, g_u8Size);
;;;414                g_u32Address += g_u8Size;
;;;415                
;;;416                //DBG_PRINTF("%d ready\n", g_u8Size);
;;;417                
;;;418            } else {
;;;419                u32Len = g_u32Length;
;;;420                if (u32Len > STORAGE_BUFFER_SIZE)
;;;421                    u32Len = STORAGE_BUFFER_SIZE;
;;;422    
;;;423                MSC_ReadMedia(g_u32LbaAddress, u32Len, (uint8_t *)STORAGE_DATA_BUF);
;;;424                g_u32BytesInStorageBuf = u32Len;
;;;425                g_u32LbaAddress += u32Len;
;;;426                g_u32Address = STORAGE_DATA_BUF;
;;;427                
;;;428                //DBG_PRINTF("Update buf from media A:0x%08x S:%d\n",g_u32LbaAddress, u32Len);
;;;429    
;;;430                /* Prepare next data packet */
;;;431                g_u8Size = EP2_MAX_PKT_SIZE;
;;;432                if (g_u8Size > g_u32Length)
;;;433                    g_u8Size = g_u32Length;
;;;434    
;;;435                if (u32CurBuf == g_u32BulkBuf1)
;;;436                    USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf0), (uint8_t *)g_u32Address, g_u8Size);
;;;437                else
;;;438                    USBD_MemCopy((uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf1), (uint8_t *)g_u32Address, g_u8Size);
000022  792a              LDRB     r2,[r5,#4]  ; g_u8Size
000024  4286              CMP      r6,r0                 ;410
000026  6969              LDR      r1,[r5,#0x14]  ; g_u32Address
000028  d123              BNE      |L12.114|
00002a  6a6b              LDR      r3,[r5,#0x24]         ;436  ; g_u32BulkBuf0
                  |L12.44|
00002c  481b              LDR      r0,|L12.156|
00002e  30c0              ADDS     r0,r0,#0xc0           ;413
000030  1818              ADDS     r0,r3,r0              ;413
000032  f7fffffe          BL       USBD_MemCopy
;;;439                g_u32Address += g_u8Size;
000036  6968              LDR      r0,[r5,#0x14]  ; g_u32Address
000038  7929              LDRB     r1,[r5,#4]  ; g_u8Size
00003a  1840              ADDS     r0,r0,r1
00003c  6168              STR      r0,[r5,#0x14]  ; g_u32Address
;;;440                
;;;441                //DBG_PRINTF("%d ready\n", g_u8Size);
;;;442                
;;;443            }
;;;444    
;;;445            /* DATA0/DATA1 Toggle */
;;;446            if (u32CurBuf == g_u32BulkBuf1)
00003e  6aa8              LDR      r0,[r5,#0x28]  ; g_u32BulkBuf1
000040  4286              CMP      r6,r0
000042  d118              BNE      |L12.118|
;;;447                USBD_SET_EP_BUF_ADDR(EP2, g_u32BulkBuf0);
000044  6a68              LDR      r0,[r5,#0x24]  ; g_u32BulkBuf0
000046  e017              B        |L12.120|
                  |L12.72|
000048  69ac              LDR      r4,[r5,#0x18]         ;419  ; g_u32Length
00004a  2001              MOVS     r0,#1                 ;420
00004c  0240              LSLS     r0,r0,#9              ;420
00004e  4284              CMP      r4,r0                 ;420
000050  d900              BLS      |L12.84|
000052  4604              MOV      r4,r0                 ;421
                  |L12.84|
000054  4a13              LDR      r2,|L12.164|
000056  4621              MOV      r1,r4                 ;423
000058  69e8              LDR      r0,[r5,#0x1c]         ;423  ; g_u32LbaAddress
00005a  f7fffffe          BL       MSC_ReadMedia
00005e  622c              STR      r4,[r5,#0x20]         ;424  ; g_u32BytesInStorageBuf
000060  69e8              LDR      r0,[r5,#0x1c]         ;425  ; g_u32LbaAddress
000062  1900              ADDS     r0,r0,r4              ;425
000064  61e8              STR      r0,[r5,#0x1c]         ;425  ; g_u32LbaAddress
000066  480f              LDR      r0,|L12.164|
000068  6168              STR      r0,[r5,#0x14]         ;426  ; g_u32Address
00006a  e7d3              B        |L12.20|
                  |L12.108|
00006c  69a8              LDR      r0,[r5,#0x18]         ;433  ; g_u32Length
00006e  7128              STRB     r0,[r5,#4]            ;433
000070  e7d6              B        |L12.32|
                  |L12.114|
000072  6aab              LDR      r3,[r5,#0x28]         ;438  ; g_u32BulkBuf1
000074  e7da              B        |L12.44|
                  |L12.118|
;;;448            else
;;;449                USBD_SET_EP_BUF_ADDR(EP2, g_u32BulkBuf1);
000076  6aa8              LDR      r0,[r5,#0x28]  ; g_u32BulkBuf1
                  |L12.120|
000078  6038              STR      r0,[r7,#0]
;;;450    
;;;451            /* Trigger to send out the data packet */
;;;452            USBD_SET_PAYLOAD_LEN(EP2, g_u8Size);
00007a  7928              LDRB     r0,[r5,#4]  ; g_u8Size
00007c  6078              STR      r0,[r7,#4]
;;;453    
;;;454            g_u32Length -= g_u8Size;
00007e  69a8              LDR      r0,[r5,#0x18]  ; g_u32Length
000080  7929              LDRB     r1,[r5,#4]  ; g_u8Size
000082  1a40              SUBS     r0,r0,r1
000084  61a8              STR      r0,[r5,#0x18]  ; g_u32Length
;;;455            g_u32BytesInStorageBuf -= g_u8Size;
000086  6a28              LDR      r0,[r5,#0x20]  ; g_u32BytesInStorageBuf
000088  7929              LDRB     r1,[r5,#4]  ; g_u8Size
00008a  1a40              SUBS     r0,r0,r1
00008c  6228              STR      r0,[r5,#0x20]  ; g_u32BytesInStorageBuf
;;;456    
;;;457            //DBG_PRINTF("In Buf size:%d (%d) buf %d\n", g_u32BytesInStorageBuf,g_u32Length,(u32CurBuf==g_u32BulkBuf0)?1:0);
;;;458            
;;;459            
;;;460            
;;;461        } else
;;;462        {
;;;463            USBD_SET_PAYLOAD_LEN(EP2, 0);
;;;464            DBG_PRINTF("g_u32Length=0, send zero pkt\n");
;;;465        }
;;;466        
;;;467        
;;;468    }
00008e  bdf8              POP      {r3-r7,pc}
                  |L12.144|
000090  2000              MOVS     r0,#0                 ;463
000092  6078              STR      r0,[r7,#4]            ;463
000094  a004              ADR      r0,|L12.168|
000096  f7fffffe          BL       __2printf
00009a  bdf8              POP      {r3-r7,pc}
;;;469    
                          ENDP

                  |L12.156|
                          DCD      0x40060040
                  |L12.160|
                          DCD      ||.data||
                  |L12.164|
                          DCD      ||.bss||+0x60
                  |L12.168|
0000a8  675f7533          DCB      "g_u32Length=0, send zero pkt\n",0
0000ac  324c656e
0000b0  6774683d
0000b4  302c2073
0000b8  656e6420
0000bc  7a65726f
0000c0  20706b74
0000c4  0a00    
0000c6  00                DCB      0
0000c7  00                DCB      0

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

                  MSC_RequestSense PROC
;;;304    
;;;305    void MSC_RequestSense(void)
000000  b530              PUSH     {r4,r5,lr}
;;;306    {
000002  b085              SUB      sp,sp,#0x14
;;;307        uint8_t tmp[20];
;;;308    
;;;309        memset(tmp, 0, 18);
000004  2112              MOVS     r1,#0x12
000006  4668              MOV      r0,sp
000008  f7fffffe          BL       __aeabi_memclr4
;;;310        if (g_u8Prevent) {
00000c  4812              LDR      r0,|L13.88|
00000e  7881              LDRB     r1,[r0,#2]  ; g_u8Prevent
000010  2500              MOVS     r5,#0
000012  2900              CMP      r1,#0
000014  d004              BEQ      |L13.32|
;;;311            g_u8Prevent = 0;
000016  7085              STRB     r5,[r0,#2]
;;;312            tmp[0]= 0x70;
000018  2070              MOVS     r0,#0x70
00001a  4669              MOV      r1,sp
00001c  7008              STRB     r0,[r1,#0]
00001e  e002              B        |L13.38|
                  |L13.32|
;;;313        } else
;;;314            tmp[1] = 0xf0;
000020  20f0              MOVS     r0,#0xf0
000022  4669              MOV      r1,sp
000024  7048              STRB     r0,[r1,#1]
                  |L13.38|
;;;315    
;;;316        tmp[2] = g_au8SenseKey[0];
000026  4c0c              LDR      r4,|L13.88|
000028  340c              ADDS     r4,r4,#0xc
00002a  7820              LDRB     r0,[r4,#0]  ; g_au8SenseKey
00002c  7088              STRB     r0,[r1,#2]
;;;317        tmp[7] = 0x0a;
00002e  200a              MOVS     r0,#0xa
000030  71c8              STRB     r0,[r1,#7]
;;;318        tmp[12] = g_au8SenseKey[1];
000032  7860              LDRB     r0,[r4,#1]  ; g_au8SenseKey
000034  7308              STRB     r0,[r1,#0xc]
;;;319        tmp[13] = g_au8SenseKey[2];
000036  78a0              LDRB     r0,[r4,#2]  ; g_au8SenseKey
000038  7348              STRB     r0,[r1,#0xd]
;;;320        USBD_MemCopy((uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP2)), tmp, 20);
00003a  4808              LDR      r0,|L13.92|
00003c  6800              LDR      r0,[r0,#0]
00003e  4907              LDR      r1,|L13.92|
000040  2214              MOVS     r2,#0x14
000042  31c0              ADDS     r1,r1,#0xc0
000044  1840              ADDS     r0,r0,r1
000046  4669              MOV      r1,sp
000048  f7fffffe          BL       USBD_MemCopy
;;;321    
;;;322        g_au8SenseKey[0] = 0;
00004c  7025              STRB     r5,[r4,#0]
;;;323        g_au8SenseKey[1] = 0;
00004e  7065              STRB     r5,[r4,#1]
;;;324        g_au8SenseKey[2] = 0;
000050  70a5              STRB     r5,[r4,#2]
;;;325    }
000052  b005              ADD      sp,sp,#0x14
000054  bd30              POP      {r4,r5,pc}
;;;326    
                          ENDP

000056  0000              DCW      0x0000
                  |L13.88|
                          DCD      ||.data||
                  |L13.92|
                          DCD      0x40060040

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

                  MSC_Write PROC
;;;561    
;;;562    void MSC_Write(void)
000000  b570              PUSH     {r4-r6,lr}
;;;563    {
;;;564        uint32_t lba, len;
;;;565    
;;;566        if (g_u32Length > EP3_MAX_PKT_SIZE) {
000002  4c2e              LDR      r4,|L14.188|
000004  69a2              LDR      r2,[r4,#0x18]  ; g_u32Length
;;;567            if (USBD_GET_EP_BUF_ADDR(EP3) == g_u32BulkBuf0) {
000006  492e              LDR      r1,|L14.192|
;;;568                USBD_SET_EP_BUF_ADDR(EP3, g_u32BulkBuf1);
;;;569                USBD_SET_PAYLOAD_LEN(EP3, EP3_MAX_PKT_SIZE);
;;;570                USBD_MemCopy((uint8_t *)g_u32Address, (uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf0), EP3_MAX_PKT_SIZE);
000008  482d              LDR      r0,|L14.192|
00000a  39c0              SUBS     r1,r1,#0xc0           ;567
00000c  2a40              CMP      r2,#0x40              ;566
00000e  d92a              BLS      |L14.102|
000010  690b              LDR      r3,[r1,#0x10]         ;567
000012  6a65              LDR      r5,[r4,#0x24]         ;567  ; g_u32BulkBuf0
000014  2240              MOVS     r2,#0x40              ;569
000016  42ab              CMP      r3,r5                 ;567
000018  d104              BNE      |L14.36|
00001a  6aa3              LDR      r3,[r4,#0x28]         ;568  ; g_u32BulkBuf1
00001c  610b              STR      r3,[r1,#0x10]         ;568
00001e  614a              STR      r2,[r1,#0x14]         ;569
000020  6a61              LDR      r1,[r4,#0x24]  ; g_u32BulkBuf0
000022  e004              B        |L14.46|
                  |L14.36|
;;;571            } else {
;;;572                USBD_SET_EP_BUF_ADDR(EP3, g_u32BulkBuf0);
000024  6a63              LDR      r3,[r4,#0x24]  ; g_u32BulkBuf0
000026  610b              STR      r3,[r1,#0x10]
;;;573                USBD_SET_PAYLOAD_LEN(EP3, EP3_MAX_PKT_SIZE);
000028  614a              STR      r2,[r1,#0x14]
;;;574                USBD_MemCopy((uint8_t *)g_u32Address, (uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf1), EP3_MAX_PKT_SIZE);
00002a  6aa1              LDR      r1,[r4,#0x28]  ; g_u32BulkBuf1
00002c  2240              MOVS     r2,#0x40
                  |L14.46|
00002e  1809              ADDS     r1,r1,r0
000030  6960              LDR      r0,[r4,#0x14]  ; g_u32Address
000032  f7fffffe          BL       USBD_MemCopy
;;;575            }
;;;576    
;;;577            g_u32Address += EP3_MAX_PKT_SIZE;
000036  6960              LDR      r0,[r4,#0x14]  ; g_u32Address
000038  3040              ADDS     r0,r0,#0x40
00003a  6160              STR      r0,[r4,#0x14]  ; g_u32Address
;;;578            g_u32Length -= EP3_MAX_PKT_SIZE;
00003c  69a0              LDR      r0,[r4,#0x18]  ; g_u32Length
00003e  3840              SUBS     r0,r0,#0x40
000040  61a0              STR      r0,[r4,#0x18]  ; g_u32Length
;;;579    
;;;580            /* Buffer full. Writer it to storage first. */
;;;581            if (g_u32Address >= (STORAGE_DATA_BUF + STORAGE_BUFFER_SIZE)) {
000042  6961              LDR      r1,[r4,#0x14]  ; g_u32Address
000044  481f              LDR      r0,|L14.196|
000046  4281              CMP      r1,r0
000048  d30c              BCC      |L14.100|
;;;582                DataFlashWrite(g_u32DataFlashStartAddr, STORAGE_BUFFER_SIZE, (uint32_t)STORAGE_DATA_BUF);
00004a  2101              MOVS     r1,#1
00004c  4a1e              LDR      r2,|L14.200|
00004e  0249              LSLS     r1,r1,#9
000050  6920              LDR      r0,[r4,#0x10]  ; g_u32DataFlashStartAddr
000052  f7fffffe          BL       DataFlashWrite
;;;583    
;;;584                g_u32Address = STORAGE_DATA_BUF;
000056  481c              LDR      r0,|L14.200|
000058  6160              STR      r0,[r4,#0x14]  ; g_u32Address
;;;585                g_u32DataFlashStartAddr += STORAGE_BUFFER_SIZE;
00005a  6920              LDR      r0,[r4,#0x10]  ; g_u32DataFlashStartAddr
00005c  30ff              ADDS     r0,r0,#0xff
00005e  30ff              ADDS     r0,r0,#0xff
000060  3002              ADDS     r0,#2
000062  6120              STR      r0,[r4,#0x10]  ; g_u32DataFlashStartAddr
                  |L14.100|
;;;586            }
;;;587        } else {
;;;588            if (USBD_GET_EP_BUF_ADDR(EP3) == g_u32BulkBuf0)
;;;589                USBD_MemCopy((uint8_t *)g_u32Address, (uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf0), g_u32Length);
;;;590            else
;;;591                USBD_MemCopy((uint8_t *)g_u32Address, (uint8_t *)((uint32_t)USBD_BUF_BASE + g_u32BulkBuf1), g_u32Length);
;;;592            g_u32Address += g_u32Length;
;;;593            g_u32Length = 0;
;;;594    
;;;595    
;;;596            if (g_sCBW.u8OPCode == UFI_WRITE_10) {
;;;597                lba = get_be32(&g_sCBW.au8Data[0]);
;;;598                len = g_sCBW.dCBWDataTransferLength;
;;;599    
;;;600                len = lba * UDC_SECTOR_SIZE + g_sCBW.dCBWDataTransferLength - g_u32DataFlashStartAddr;
;;;601                if (len)
;;;602                    DataFlashWrite(g_u32DataFlashStartAddr, len, (uint32_t)STORAGE_DATA_BUF);
;;;603            }
;;;604    
;;;605            g_u8BulkState = BULK_IN;
;;;606            MSC_AckCmd();
;;;607        }
;;;608    }
000064  bd70              POP      {r4-r6,pc}
                  |L14.102|
000066  6909              LDR      r1,[r1,#0x10]         ;588
000068  6a62              LDR      r2,[r4,#0x24]         ;588  ; g_u32BulkBuf0
00006a  4291              CMP      r1,r2                 ;588
00006c  69a2              LDR      r2,[r4,#0x18]         ;591  ; g_u32Length
00006e  d101              BNE      |L14.116|
000070  6a61              LDR      r1,[r4,#0x24]         ;589  ; g_u32BulkBuf0
000072  e000              B        |L14.118|
                  |L14.116|
000074  6aa1              LDR      r1,[r4,#0x28]         ;591  ; g_u32BulkBuf1
                  |L14.118|
000076  1809              ADDS     r1,r1,r0              ;591
000078  6960              LDR      r0,[r4,#0x14]         ;591  ; g_u32Address
00007a  f7fffffe          BL       USBD_MemCopy
00007e  6960              LDR      r0,[r4,#0x14]         ;592  ; g_u32Address
000080  69a1              LDR      r1,[r4,#0x18]         ;592  ; g_u32Length
000082  1840              ADDS     r0,r0,r1              ;592
000084  6160              STR      r0,[r4,#0x14]         ;592  ; g_u32Address
000086  2000              MOVS     r0,#0                 ;593
000088  61a0              STR      r0,[r4,#0x18]         ;593  ; g_u32Length
00008a  4d0f              LDR      r5,|L14.200|
00008c  3d60              SUBS     r5,r5,#0x60           ;596
00008e  7be8              LDRB     r0,[r5,#0xf]          ;596  ; g_sCBW
000090  282a              CMP      r0,#0x2a              ;596
000092  d10d              BNE      |L14.176|
000094  4628              MOV      r0,r5                 ;597
000096  3011              ADDS     r0,r0,#0x11           ;597
000098  f7fffffe          BL       get_be32
00009c  68a9              LDR      r1,[r5,#8]            ;600  ; g_sCBW
00009e  0240              LSLS     r0,r0,#9              ;600
0000a0  1840              ADDS     r0,r0,r1              ;600
0000a2  6921              LDR      r1,[r4,#0x10]         ;600  ; g_u32DataFlashStartAddr
0000a4  1a41              SUBS     r1,r0,r1              ;600
0000a6  d003              BEQ      |L14.176|
0000a8  4a07              LDR      r2,|L14.200|
0000aa  6920              LDR      r0,[r4,#0x10]         ;602  ; g_u32DataFlashStartAddr
0000ac  f7fffffe          BL       DataFlashWrite
                  |L14.176|
0000b0  2001              MOVS     r0,#1                 ;605
0000b2  70e0              STRB     r0,[r4,#3]            ;605
0000b4  f7fffffe          BL       MSC_AckCmd
0000b8  bd70              POP      {r4-r6,pc}
;;;609    
                          ENDP

0000ba  0000              DCW      0x0000
                  |L14.188|
                          DCD      ||.data||
                  |L14.192|
                          DCD      0x40060100
                  |L14.196|
                          DCD      ||.bss||+0x260
                  |L14.200|
                          DCD      ||.bss||+0x60

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

                  MSC_WriteMedia PROC
;;;944    
;;;945    void MSC_WriteMedia(uint32_t addr, uint32_t size, uint8_t *buffer)
000000  4770              BX       lr
;;;946    {
;;;947    }
;;;948    
                          ENDP


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

                  USBD_IRQHandler PROC
;;;94     
;;;95     void USBD_IRQHandler(void)
000000  b5f8              PUSH     {r3-r7,lr}
;;;96     {
;;;97         uint32_t u32IntSts = USBD_GET_INT_FLAG();
000002  4d36              LDR      r5,|L16.220|
000004  686c              LDR      r4,[r5,#4]
;;;98         uint32_t u32State = USBD_GET_BUS_STATE();
000006  6928              LDR      r0,[r5,#0x10]
;;;99     
;;;100    //------------------------------------------------------------------
;;;101        if (u32IntSts & USBD_INTSTS_FLDET) {
;;;102            // Floating detect
;;;103            USBD_CLR_INT_FLAG(USBD_INTSTS_FLDET);
;;;104    
;;;105            if (USBD_IS_ATTACHED()) {
;;;106                /* USB Plug In */
;;;107                USBD_ENABLE_USB();
000008  2790              MOVS     r7,#0x90
00000a  0706              LSLS     r6,r0,#28             ;98
00000c  0f36              LSRS     r6,r6,#28             ;98
00000e  0760              LSLS     r0,r4,#29             ;101
000010  2800              CMP      r0,#0                 ;101
000012  da0a              BGE      |L16.42|
000014  2004              MOVS     r0,#4                 ;103
000016  6068              STR      r0,[r5,#4]            ;103
000018  6968              LDR      r0,[r5,#0x14]         ;105
00001a  07c0              LSLS     r0,r0,#31             ;105
;;;108            } else {
;;;109                /* USB Un-plug */
;;;110                USBD_DISABLE_USB();
00001c  6928              LDR      r0,[r5,#0x10]
00001e  d001              BEQ      |L16.36|
000020  4338              ORRS     r0,r0,r7              ;107
000022  e001              B        |L16.40|
                  |L16.36|
000024  2180              MOVS     r1,#0x80
000026  4388              BICS     r0,r0,r1
                  |L16.40|
000028  6128              STR      r0,[r5,#0x10]         ;107
                  |L16.42|
;;;111            }
;;;112        }
;;;113    
;;;114    //------------------------------------------------------------------
;;;115        if (u32IntSts & USBD_INTSTS_BUS) {
00002a  07e0              LSLS     r0,r4,#31
00002c  d013              BEQ      |L16.86|
;;;116            /* Clear event flag */
;;;117            USBD_CLR_INT_FLAG(USBD_INTSTS_BUS);
00002e  2001              MOVS     r0,#1
000030  6068              STR      r0,[r5,#4]
;;;118    
;;;119            if (u32State & USBD_STATE_USBRST) {
000032  07f0              LSLS     r0,r6,#31
000034  d004              BEQ      |L16.64|
;;;120                /* Bus reset */
;;;121                USBD_ENABLE_USB();
000036  6928              LDR      r0,[r5,#0x10]
000038  4338              ORRS     r0,r0,r7
00003a  6128              STR      r0,[r5,#0x10]
;;;122                USBD_SwReset();
00003c  f7fffffe          BL       USBD_SwReset
                  |L16.64|
;;;123            }
;;;124            if (u32State & USBD_STATE_SUSPEND) {
000040  07b0              LSLS     r0,r6,#30
000042  d503              BPL      |L16.76|
;;;125                /* Enable USB but disable PHY */
;;;126                USBD_DISABLE_PHY();
000044  6928              LDR      r0,[r5,#0x10]
000046  2110              MOVS     r1,#0x10
000048  4388              BICS     r0,r0,r1
00004a  6128              STR      r0,[r5,#0x10]
                  |L16.76|
;;;127            }
;;;128            if (u32State & USBD_STATE_RESUME) {
00004c  0770              LSLS     r0,r6,#29
00004e  d502              BPL      |L16.86|
;;;129                /* Enable USB and enable PHY */
;;;130                USBD_ENABLE_USB();
000050  6928              LDR      r0,[r5,#0x10]
000052  4338              ORRS     r0,r0,r7
000054  6128              STR      r0,[r5,#0x10]
                  |L16.86|
;;;131            }
;;;132        }
;;;133    
;;;134    //------------------------------------------------------------------
;;;135        if (u32IntSts & USBD_INTSTS_USB) {
000056  07a0              LSLS     r0,r4,#30
000058  d53e              BPL      |L16.216|
;;;136            // USB event
;;;137            if (u32IntSts & USBD_INTSTS_SETUP) {
00005a  2c00              CMP      r4,#0
00005c  da0b              BGE      |L16.118|
;;;138                // Setup packet
;;;139                /* Clear event flag */
;;;140                USBD_CLR_INT_FLAG(USBD_INTSTS_SETUP);
00005e  2001              MOVS     r0,#1
000060  07c0              LSLS     r0,r0,#31
000062  6068              STR      r0,[r5,#4]
;;;141    
;;;142                /* Clear the data IN/OUT ready flag of control end-points */
;;;143                USBD_STOP_TRANSACTION(EP0);
000064  6ae9              LDR      r1,[r5,#0x2c]
000066  2001              MOVS     r0,#1
000068  4301              ORRS     r1,r1,r0
00006a  62e9              STR      r1,[r5,#0x2c]
;;;144                USBD_STOP_TRANSACTION(EP1);
00006c  6be9              LDR      r1,[r5,#0x3c]
00006e  4301              ORRS     r1,r1,r0
000070  63e9              STR      r1,[r5,#0x3c]
;;;145    
;;;146                USBD_ProcessSetupPacket();
000072  f7fffffe          BL       USBD_ProcessSetupPacket
                  |L16.118|
;;;147            }
;;;148    
;;;149            // EP events
;;;150            if (u32IntSts & USBD_INTSTS_EP0) {
000076  03e0              LSLS     r0,r4,#15
000078  d504              BPL      |L16.132|
;;;151                /* Clear event flag */
;;;152                USBD_CLR_INT_FLAG(USBD_INTSTS_EP0);
00007a  2001              MOVS     r0,#1
00007c  0400              LSLS     r0,r0,#16
00007e  6068              STR      r0,[r5,#4]
;;;153                // control IN
;;;154                USBD_CtrlIn();
000080  f7fffffe          BL       USBD_CtrlIn
                  |L16.132|
;;;155            }
;;;156    
;;;157            if (u32IntSts & USBD_INTSTS_EP1) {
000084  03a0              LSLS     r0,r4,#14
000086  d504              BPL      |L16.146|
;;;158                /* Clear event flag */
;;;159                USBD_CLR_INT_FLAG(USBD_INTSTS_EP1);
000088  2001              MOVS     r0,#1
00008a  0440              LSLS     r0,r0,#17
00008c  6068              STR      r0,[r5,#4]
;;;160    
;;;161                // control OUT
;;;162                USBD_CtrlOut();
00008e  f7fffffe          BL       USBD_CtrlOut
                  |L16.146|
;;;163            }
;;;164    
;;;165            if (u32IntSts & USBD_INTSTS_EP2) {
000092  0360              LSLS     r0,r4,#13
000094  d504              BPL      |L16.160|
;;;166                /* Clear event flag */
;;;167                USBD_CLR_INT_FLAG(USBD_INTSTS_EP2);
000096  2001              MOVS     r0,#1
000098  0480              LSLS     r0,r0,#18
00009a  6068              STR      r0,[r5,#4]
;;;168                
;;;169                // Bulk IN
;;;170                EP2_Handler();
00009c  f7fffffe          BL       EP2_Handler
                  |L16.160|
;;;171            }
;;;172    
;;;173            if (u32IntSts & USBD_INTSTS_EP3) {
0000a0  0320              LSLS     r0,r4,#12
0000a2  d505              BPL      |L16.176|
;;;174                /* Clear event flag */
;;;175                USBD_CLR_INT_FLAG(USBD_INTSTS_EP3);
0000a4  2001              MOVS     r0,#1
0000a6  04c0              LSLS     r0,r0,#19
0000a8  6068              STR      r0,[r5,#4]
0000aa  490d              LDR      r1,|L16.224|
0000ac  2001              MOVS     r0,#1
0000ae  7048              STRB     r0,[r1,#1]
                  |L16.176|
;;;176                // Bulk OUT
;;;177                EP3_Handler();
;;;178            }
;;;179    
;;;180            if (u32IntSts & USBD_INTSTS_EP4) {
0000b0  02e0              LSLS     r0,r4,#11
0000b2  d502              BPL      |L16.186|
;;;181                /* Clear event flag */
;;;182                USBD_CLR_INT_FLAG(USBD_INTSTS_EP4);
0000b4  2001              MOVS     r0,#1
0000b6  0500              LSLS     r0,r0,#20
0000b8  6068              STR      r0,[r5,#4]
                  |L16.186|
;;;183            }
;;;184    
;;;185            if (u32IntSts & USBD_INTSTS_EP5) {
0000ba  02a0              LSLS     r0,r4,#10
0000bc  d502              BPL      |L16.196|
;;;186                /* Clear event flag */
;;;187                USBD_CLR_INT_FLAG(USBD_INTSTS_EP5);
0000be  2001              MOVS     r0,#1
0000c0  0540              LSLS     r0,r0,#21
0000c2  6068              STR      r0,[r5,#4]
                  |L16.196|
;;;188            }
;;;189    
;;;190            if (u32IntSts & USBD_INTSTS_EP6) {
0000c4  0260              LSLS     r0,r4,#9
0000c6  d502              BPL      |L16.206|
;;;191                /* Clear event flag */
;;;192                USBD_CLR_INT_FLAG(USBD_INTSTS_EP6);
0000c8  2001              MOVS     r0,#1
0000ca  0580              LSLS     r0,r0,#22
0000cc  6068              STR      r0,[r5,#4]
                  |L16.206|
;;;193            }
;;;194    
;;;195            if (u32IntSts & USBD_INTSTS_EP7) {
0000ce  0220              LSLS     r0,r4,#8
0000d0  d502              BPL      |L16.216|
;;;196                /* Clear event flag */
;;;197                USBD_CLR_INT_FLAG(USBD_INTSTS_EP7);
0000d2  2001              MOVS     r0,#1
0000d4  05c0              LSLS     r0,r0,#23
0000d6  6068              STR      r0,[r5,#4]
                  |L16.216|
;;;198            }
;;;199        }
;;;200        /* clear unknown event */
;;;201        USBD_CLR_INT_FLAG(u32IntSts);
0000d8  606c              STR      r4,[r5,#4]
;;;202    }
0000da  bdf8              POP      {r3-r7,pc}
;;;203    
                          ENDP

                  |L16.220|
                          DCD      0x40060000
                  |L16.224|
                          DCD      ||.data||

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

                  USBD_MemCopy PROC
;;;341      */
;;;342    static __INLINE void USBD_MemCopy(uint8_t *dest, uint8_t *src, int32_t size)
000000  e003              B        |L17.10|
                  |L17.2|
;;;343    {
;;;344        while (size--) *dest++ = *src++;
000002  780b              LDRB     r3,[r1,#0]
000004  1c49              ADDS     r1,r1,#1
000006  7003              STRB     r3,[r0,#0]
000008  1c40              ADDS     r0,r0,#1
                  |L17.10|
00000a  1e52              SUBS     r2,r2,#1
00000c  d2f9              BCS      |L17.2|
;;;345    }
00000e  4770              BX       lr
;;;346    
                          ENDP


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

                  USBD_SetStall PROC
;;;355     */
;;;356    static __INLINE void USBD_SetStall(uint8_t ep)
000000  4b0a              LDR      r3,|L18.44|
;;;357    {
;;;358    	uint32_t u32CfgAddr;
;;;359    	uint32_t u32Cfg;
;;;360        int i;
;;;361    
;;;362        for (i=0; i<USBD_MAX_EP; i++)
000002  2100              MOVS     r1,#0
                  |L18.4|
;;;363        {
;;;364            u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFG; /* USBD_CFG0 */
000004  010a              LSLS     r2,r1,#4
000006  18d2              ADDS     r2,r2,r3
;;;365            u32Cfg = *((__IO uint32_t *) (u32CfgAddr));
000008  6812              LDR      r2,[r2,#0]
;;;366    
;;;367            if ((u32Cfg & 0xf) == ep)
00000a  0712              LSLS     r2,r2,#28
00000c  0f12              LSRS     r2,r2,#28
00000e  4282              CMP      r2,r0
000010  d108              BNE      |L18.36|
;;;368            {
;;;369                u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFGP; /* USBD_CFGP0 */
000012  0108              LSLS     r0,r1,#4
000014  4905              LDR      r1,|L18.44|
000016  1d09              ADDS     r1,r1,#4
000018  1840              ADDS     r0,r0,r1
;;;370                u32Cfg = *((__IO uint32_t *) (u32CfgAddr));
00001a  6801              LDR      r1,[r0,#0]
;;;371    
;;;372                *((__IO uint32_t *) (u32CfgAddr)) = (u32Cfg | USBD_CFGP_SSTALL);
00001c  2202              MOVS     r2,#2
00001e  4311              ORRS     r1,r1,r2
000020  6001              STR      r1,[r0,#0]
;;;373                break;
;;;374            }
;;;375        }
;;;376    }
000022  4770              BX       lr
                  |L18.36|
000024  1c49              ADDS     r1,r1,#1              ;362
000026  2908              CMP      r1,#8                 ;362
000028  dbec              BLT      |L18.4|
00002a  4770              BX       lr
;;;377    
                          ENDP

                  |L18.44|
                          DCD      0x40060028

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

                  get_be32 PROC
;;;76     
;;;77     static __INLINE uint32_t get_be32(uint8_t *buf)
000000  b510              PUSH     {r4,lr}
;;;78     {
000002  4604              MOV      r4,r0
;;;79         return ((uint32_t) buf[0] << 24) | ((uint32_t) buf[1] << 16) |
000004  f7fffffe          BL       __aeabi_uread4
000008  ba00              REV      r0,r0
00000a  0a00              LSRS     r0,r0,#8
00000c  78e1              LDRB     r1,[r4,#3]
00000e  0200              LSLS     r0,r0,#8
000010  4308              ORRS     r0,r0,r1
;;;80                ((uint32_t) buf[2] << 8) | ((uint32_t) buf[3]);
;;;81     }
000012  bd10              POP      {r4,pc}
;;;82     
                          ENDP


                          AREA ||.bss||, DATA, NOINIT, ALIGN=2

                  g_sCBW
                          %        32
                  g_sCSW
                          %        16
                  MassBlock
                          %        48
                  Storage_Block
                          %        512

                          AREA ||.data||, DATA, ALIGN=2

                  g_u8EP2Ready
000000  00                DCB      0x00
                  g_u8EP3Ready
000001  00                DCB      0x00
                  g_u8Prevent
000002  00                DCB      0x00
                  g_u8BulkState
000003  00                DCB      0x00
                  g_u8Size
000004  00000000          DCB      0x00,0x00,0x00,0x00
                  g_TotalSectors
                          DCD      0x00000000
                  g_au8SenseKey
                          DCD      0x00000000
                  g_u32DataFlashStartAddr
                          DCD      0x00000000
                  g_u32Address
                          DCD      0x00000000
                  g_u32Length
                          DCD      0x00000000
                  g_u32LbaAddress
                          DCD      0x00000000
                  g_u32BytesInStorageBuf
                          DCD      0x00000000
                  g_u32BulkBuf0
                          DCD      0x00000000
                  g_u32BulkBuf1
                          DCD      0x00000000
                  g_au8ModePage_1C
00002c  1c060005          DCB      0x1c,0x06,0x00,0x05
000030  00000000          DCB      0x00,0x00,0x00,0x00
                  g_au8InquiryID
000034  00800000          DCB      0x00,0x80,0x00,0x00
000038  1f000000          DCB      0x1f,0x00,0x00,0x00
00003c  4e75766f          DCB      0x4e,0x75,0x76,0x6f
000040  746f6e20          DCB      0x74,0x6f,0x6e,0x20
000044  55534220          DCB      0x55,0x53,0x42,0x20
000048  4d617373          DCB      0x4d,0x61,0x73,0x73
00004c  2053746f          DCB      0x20,0x53,0x74,0x6f
000050  72616765          DCB      0x72,0x61,0x67,0x65
000054  312e3030          DCB      0x31,0x2e,0x30,0x30
                  g_au8ModePage_01
000058  010a0003          DCB      0x01,0x0a,0x00,0x03
00005c  00000000          DCB      0x00,0x00,0x00,0x00
000060  03000000          DCB      0x03,0x00,0x00,0x00
                  g_au8ModePage_05
000064  051e1388          DCB      0x05,0x1e,0x13,0x88
000068  08200200          DCB      0x08,0x20,0x02,0x00
00006c  01f40000          DCB      0x01,0xf4,0x00,0x00
000070  00000000          DCB      0x00,0x00,0x00,0x00
000074  00000005          DCB      0x00,0x00,0x00,0x05
000078  1e000000          DCB      0x1e,0x00,0x00,0x00
00007c  00000000          DCB      0x00,0x00,0x00,0x00
000080  01680000          DCB      0x01,0x68,0x00,0x00
                  g_au8ModePage_1B
000084  1b0a0001          DCB      0x1b,0x0a,0x00,0x01
000088  00000000          DCB      0x00,0x00,0x00,0x00
00008c  00000000          DCB      0x00,0x00,0x00,0x00

;*** Start embedded assembler ***

#line 1 "..\\MassStorage.c"
	AREA ||.rev16_text||, CODE, READONLY
	THUMB
	EXPORT |__asm___13_MassStorage_c_3ebb586c____REV16|
#line 118 "..\\..\\..\\..\\Library\\CMSIS\\Include\\core_cmInstr.h"
|__asm___13_MassStorage_c_3ebb586c____REV16| PROC
#line 119

 rev16 r0, r0
 bx lr
	ENDP
	AREA ||.revsh_text||, CODE, READONLY
	THUMB
	EXPORT |__asm___13_MassStorage_c_3ebb586c____REVSH|
#line 132
|__asm___13_MassStorage_c_3ebb586c____REVSH| PROC
#line 133

 revsh r0, r0
 bx lr
	ENDP

;*** End   embedded assembler ***
