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

📄 flasher.s

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 S
📖 第 1 页 / 共 4 页
字号:
_THUMB_LABEL_program_done _LABEL_    mov     r0, _CONST_ 0x2a // '*'    bl      SendChar    //    // Return to the caller.    //    pop     {pc}//****************************************************************************//// Checks the FLASH to determine if it is a device that we know how to program.////****************************************************************************_THUMB_LABEL_check_flash _LABEL_    //    // Load a pointer to the FLASH.    //    mov     r0, _CONST_ 0x70    lsl     r0, r0, _CONST_ 24    //    // Load the value of the system status register.    //    ldr     r1, =0x80000140    ldr     r1, [r1]    //    // Get the BOOTBIT field of the system status register.    //    mov     r2, _CONST_ 0x18    lsl     r2, r2, _CONST_ 24    and     r1, r1, r2    //    // See if the BOOTBIT field is zero, indicating that the FLASH connected to    // nCS0 is 32-bits wide.    //    mov     r2, _CONST_ 0x00    cmp     r1, r2    bne     check_flash_16    //    // The FLASH is 32-bits wide.    //_THUMB_LABEL_check_flash_32 _LABEL_    mov     r7, _CONST_ 0x00    //    // Write the read identifier command to the FLASH.    //    ldr     r1, =0x00900090    str     r1, [r0]    //    // Read back the manufacturer ID from each 16-bit wide FLASH.    //    ldr     r1, [r0]    //    // See if the IDs are Intel.    //    ldr     r2, =0x00890089    cmp     r1, r2    bne     unknown_device    //    // Load the device IDs from each 16-bit wide FLASH.    //    ldrh    r1, [r0, _CONST_ 4]    ldrh    r2, [r0, _CONST_ 6]    //    // See if the IDs are identical.    //    cmp     r1, r2    beq     id_is_ok    //    // This is a FLASH configuration we can not handle, either an unknown    // manufacturer, an unknown device ID, or the FLASH devices do not match.    // Return an error.    //_THUMB_LABEL_unknown_device _LABEL_    mov     r0, _CONST_ 0x00    mov     pc, lr    //    // The FLASH is 16-bits wide.    //_THUMB_LABEL_check_flash_16 _LABEL_    mov     r7, _CONST_ 0x01    //    // Write the read identifier command to the FLASH.    //    mov     r1, _CONST_ 0x90    strh    r1, [r0]    //    // Read back the manufacturer ID from the FLASH.    //    ldrh    r1, [r0]    //    // See if the ID is Intel.    //    cmp     r1, _CONST_ 0x89    beq     is_intel    //    // Rev. B of the EP7209 reference design board has the data bus to the    // FLASH reversed, so try the read identifier command bit reversed.    //    mov     r1, _CONST_ 0x09    lsl     r1, r1, _CONST_ 8    strh    r1, [r0]    //    // Re-load the manufacturer ID (bit reversed?).    //    ldrh    r1, [r0]    //    // See if the ID is Intel, bit reversed.    //    mov     r2, _CONST_ 0x91    lsl     r2, r2, _CONST_ 8    cmp     r1, r2    bne     unknown_device    //    // The data bus is reversed, so set the flag to indicate this condition.    //    mov     r1, _CONST_ 0x02    orr     r7, r7, r1    //    // We have an Intel FLASH, so read the device ID.    //_THUMB_LABEL_is_intel _LABEL_    ldrh    r1, [r0, _CONST_ 2]    //    // On the EP73XX evaluation board, the FLASH can be jumpered to be either    // 32 or 16 bits wide.  If it is jumpered to be 16 bits wide, the LSB of    // the FLASH (which must be high to read the device ID) is connected to A2    // of the processor.  In this case, the read at offset 2 will actually read    // the manufacturer ID.  So, read the manufacturer ID and see if it matches    // the device ID.    //    ldrh    r2, [r0]    cmp     r1, r2    bne     have_id    //    // The manufacturer ID matches the device ID, so read the device ID from    // from offset 4 (which will assert the LSB of the FLASH, giving the real    // device ID).    //    ldrh    r1, [r0, _CONST_ 4]    //    // We now have the device ID of the FLASH.  See if it is bit reversed.    //_THUMB_LABEL_have_id _LABEL_    mov     r2, _CONST_ 0x02    tst     r7, r2    beq     id_is_ok    //    // The device ID is bit reversed, so we need to reverse it.  We will go    // through a sequence of reversing sets of bits in a manner similar to a    // binary traversal.  If we consider the 16 bits to be as follows:    //    //     fedcba98 76543210    //    // Then we will reverse the bits in a sequence that will make the bits look    // as follows (if viewed at each step of the sequence):    //    //     76543210 fedcba98    //     32107654 ba98fedc    //     10325476 98badcfe    //     01234567 89abcdef    //    // At each step, a smaller set of bits is swapped, and the same swap is    // performed across the entire 16-bit word.    //    // Start by swapping the two bytes.    //    mov     r2, r1    lsl     r2, r2, _CONST_ 8    lsr     r1, r1, _CONST_ 8    orr     r1, r1, r2    //    // Now, swap the two nibbles of each byte.    //    mov     r2, r1    ldr     r3, =0x0000f0f0    lsl     r2, r2, _CONST_ 4    and     r1, r1, r3    and     r2, r2, r3    lsr     r1, r1, _CONST_ 4    orr     r1, r1, r2    //    // Now, swap the two halves of each nibble.    //    mov     r2, r1    ldr     r3, =0x0000cccc    lsl     r2, r2, _CONST_ 2    and     r1, r1, r3    and     r2, r2, r3    lsr     r1, r1, _CONST_ 2    orr     r1, r1, r2    //    // Finally, swap each pair of bits.    //    mov     r2, r1    ldr     r3, =0x0000aaaa    lsl     r2, r2, _CONST_ 1    and     r1, r1, r3    and     r2, r2, r3    lsr     r1, r1, _CONST_ 1    orr     r1, r1, r2    //    // We now have the device ID.  See if this is a 32Mb Intel J3 FLASH.    //_THUMB_LABEL_id_is_ok _LABEL_    cmp     r1, _CONST_ 0x16    beq     intel_j3_32Mb    //    // See if this is a 64Mb Intel J3 FLASH.    //    cmp     r1, _CONST_ 0x17    beq     intel_j3_64Mb    //    // See if this is a 128Mb Intel J3 FLASH.    //    cmp     r1, _CONST_ 0x18    beq     intel_j3_128Mb    //    // The remaining FLASH device IDs that we recognize are all 0x88.., so load    // 0x8800 into r3.    //    mov     r3, _CONST_ 0x88    lsl     r3, r3, _CONST_ 8    //    // See if this is a 16Mb Intel B3 FLASH.    //    mov     r2, _CONST_ 0x91    orr     r2, r2, r3    cmp     r1, r2    beq     intel_b3_16Mb    //    // See if this is a 8Mb Intel B3 FLASH.    //    mov     r2, _CONST_ 0x93    orr     r2, r2, r3    cmp     r1, r2    beq     intel_b3_8Mb    //    // See if this is a 4Mb Intel B3 FLASH.    //    mov     r2, _CONST_ 0x95    orr     r2, r2, r3    cmp     r1, r2    beq     intel_b3_4Mb    //    // See if this is a 32Mb Intel B3 FLASH.    //    mov     r2, _CONST_ 0x97    orr     r2, r2, r3    cmp     r1, r2    beq     intel_b3_32Mb    //    // See if this is a 8Mb Intel C3 FLASH.    //    mov     r2, _CONST_ 0xc1    orr     r2, r2, r3    cmp     r1, r2    beq     intel_c3_8Mb    //    // See if this is a 16Mb Intel C3 FLASH.    //    mov     r2, _CONST_ 0xc3    orr     r2, r2, r3    cmp     r1, r2    beq     intel_c3_16Mb    //    // See if this is a 32Mb Intel C3 FLASH.    //    mov     r2, _CONST_ 0xc5    orr     r2, r2, r3    cmp     r1, r2    beq     intel_c3_32Mb    //    // See if this is a 64Mb Intel C3 FLASH.    //    mov     r2, _CONST_ 0xcd    orr     r2, r2, r3    cmp     r1, r2    beq     intel_c3_64Mb    //    // We do not recognize the device ID, so this is an unknown device.    //    b       unknown_device    //    // This is a 4Mb Intel B3 FLASH.  Set the size to 1, which will get shifted    // by 19 to create 512KB.    //_THUMB_LABEL_intel_b3_4Mb _LABEL_    mov     r0, _CONST_ 0x01    //    // Shift the size by 19 bits.    //_THUMB_LABEL_intel_b3 _LABEL_    lsl     r0, r0, _CONST_ 19    //    // Save the size of the FLASH.    //    mov     r8, r0    //    // Save the pointer to the routine to erase an Intel B3 FLASH.    //    ldr     r0, =intel_b3_erase    mov     r9, r0    //    // Save the pointer to the routine to program an Intel B3 FLASH.    //    ldr     r0, =intel_b3_c3_program    mov     r10, r0    //    // Perform the size check.    //    b       check_size    //    // This is a 8Mb Intel B3 FLASH.  Set the size to 2, which will get shifted    // by 19 to create 1MB.    //_THUMB_LABEL_intel_b3_8Mb _LABEL_    mov     r0, _CONST_ 0x02    //    // The remainder of the handling is common.    //    b       intel_b3    //    // This is a 16Mb Intel B3 FLASH.  Set the size to 4, which will get    // shifted by 19 to create 2MB.    //_THUMB_LABEL_intel_b3_16Mb _LABEL_    mov     r0, _CONST_ 0x04    //    // The remainder of the handling is common.    //    b       intel_b3    //    // This is a 32Mb Intel B3 FLASH.  Set the size to 8, which will get    // shifted by 19 to create 4MB.    //_THUMB_LABEL_intel_b3_32Mb _LABEL_    mov     r0, _CONST_ 0x08    //    // The remainder of the handling is common.    //    b       intel_b3    //    // This is a 8Mb Intel C3 FLASH.  Set the size to 1, which will get shifted    // by 20 to create 1MB.    //_THUMB_LABEL_intel_c3_8Mb _LABEL_    mov     r0, _CONST_ 0x01    //    // Shift the size by 20 bits.    //_THUMB_LABEL_intel_c3 _LABEL_    lsl     r0, r0, _CONST_ 20    //    // Save the size of the FLASH.    //    mov     r8, r0    //    // Save the pointer to the routine to erase an Intel C3 FLASH.    //    ldr     r0, =intel_c3_erase    mov     r9, r0    //    // Save the pointer to the routine to program an Intel C3 FLASH.    //    ldr     r0, =intel_b3_c3_program    mov     r10, r0    //    // Perform the size check.    //    b       check_size    //    // This is a 16Mb Intel C3 FLASH.  Set the size to 2, which will get    // shifted by 20 to create 2MB.    //_THUMB_LABEL_intel_c3_16Mb _LABEL_    mov     r0, _CONST_ 0x02    //    // The remainder of the handling is common.    //    b       intel_c3    //    // This is a 32Mb Intel C3 FLASH.  Set the size to 4, which will get    // shifted by 20 to create 4MB.    //_THUMB_LABEL_intel_c3_32Mb _LABEL_    mov     r0, _CONST_ 0x04    //    // The remainder of the handling is common.    //    b       intel_c3    //    // This is a 64Mb Intel C3 FLASH.  Set the size to 4, which will get    // shifted by 20 to create 8MB.    //_THUMB_LABEL_intel_c3_64Mb _LABEL_    mov     r0, _CONST_ 0x08    //    // The remainder of the handling is common.    //    b       intel_c3    //    // This is a 32Mb Intel J3 FLASH.  Set the size to 1, which will get    // shifted by 22 to create 4MB.    //_THUMB_LABEL_intel_j3_32Mb _LABEL_    mov     r0, _CONST_ 0x01    //    // Shift the size by 22 bits.    //_THUMB_LABEL_intel_j3 _LABEL_    lsl     r0, r0, _CONST_ 22    //    // Save the size of the FLASH.    //    mov     r8, r0    //    // Get a pointer to the routines for erasing and program an Intel J3 FLASH.    //    ldr     r0, =intel_j3_erase    ldr     r1, =intel_j3_program    //    // See if we have a reversed data bus.    //    mov     r2, _CONST_ 2    tst     r7, r2    beq     save_j3    //    // Increment the address of the erase and program routines by 4, so that we    // will use the bit reversed versions.    //    add     r0, r0, _CONST_ 4    add     r1, r1, _CONST_ 4    //    // Save the pointers to the routines to erase and program an Intel J3    // FLASH.    //_THUMB_LABEL_save_j3 _LABEL_    mov     r9, r0    mov     r10, r1    //    // Perform the size check.    //    b       check_size    //    // This is a 64Mb Intel J3 FLASH.  Set the size to 2, which will get    // shifted by 22 to create 8MB.    //_THUMB_LABEL_intel_j3_64Mb _LABEL_    mov     r0, _CONST_ 0x02    //    // The remainder of the handling is common.    //    b       intel_j3    //    // This is a 128Mb Intel J3 FLASH.  Set the size to 4, which will get    // shifted by 22 to create 16MB.    //_THUMB_LABEL_intel_j3_128Mb _LABEL_    mov     r0, _CONST_ 0x04    //    // The remainder of the handling is common.    //    b       intel_j3    //    // We now have the size of the FLASH and pointers to the routines that will    // erase and program it.  See if we are in a 32-bit wide configuration, in    // which case we must double the size of the FLASH (since there are two 16    // bit wides devices creating the 32-bit wide "device").    //_THUMB_LABEL_check_size _LABEL_    mov     r0, _CONST_ 0x01    tst     r7, r0    bne     check_done    //    // The FLASH is 32-bits wide, so double the size.    //    mov     r0, r8    lsl     r0, r0, _CONST_ 1    mov     r8, r0    //    // Increment the address of the erase and program routines by 2, so that we    // will use the 32-bit wide versions instead of the 16-bit wide versions.    //    mov     r0, r9    add     r0, r0, _CONST_ 2    mov     r9, r0    mov     r0, r10    add     r0, r0, _CONST_ 2    mov     r10, r0    //    // We've completed our checking successfully.  Return success.    //_THUMB_LABEL_check_done _LABEL_    mov     r0, _CONST_ 0x01    mov     pc, lr//****************************************************************************//// The zero-initialized read-write data used by the application.////****************************************************************************    _BSS_//****************************************************************************//// A buffer to contain 1K bytes of data read from the serial port that is to be// programmed into the FLASH.////****************************************************************************DataBuffer _LABEL_    _SPACE_ 0x400    _END_

⌨️ 快捷键说明

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