📄 flasher.s
字号:
// configuration.////****************************************************************************_THUMB_LABEL_intel_c3_erase_32 _LABEL_ // // Save the link register to the stack. // push {r4-r7, lr} // // Save the length of the FLASH to be erased. // mov r4, r0 // // Load a pointer to the FLASH. // mov r0, _CONST_ 0x70 lsl r0, r0, _CONST_ 24 // // Get the command to unlock a block of the FLASH. // mov r5, _CONST_ 0x60 mov r3, r5 lsl r3, r3, _CONST_ 16 orr r3, r3, r5 // // Get the commands to erase a block of the FLASH. // mov r5, _CONST_ 0x20 mov r6, r5 lsl r6, r6, _CONST_ 16 orr r6, r6, r5 mov r5, _CONST_ 0xd0 mov r7, r5 lsl r7, r7, _CONST_ 16 orr r7, r7, r5 // // Start erasing the FLASH from block zero. // mov r5, _CONST_ 0x00_THUMB_LABEL_intel_c3_erase_32_block _LABEL_ // // See if we have erased all the required blocks. // cmp r5, r4 bge intel_c3_erase_32_done // // Unlock this block. // str r3, [r0, r5] str r7, [r0, r5] // // Erase this block. // str r6, [r0, r5] str r7, [r0, r5] // // Wait until the erase has completed. // bl intel_wait_32 // // Increment the block address. The first 8 blocks of the FLASH have a // block size of 16K and the remaining blocks have a size of 128K. So, // if the offset is less than 128K, increment it by 16K, otherwise // increment it by 128K. // mov r1, _CONST_ 0x02 lsl r1, r1, _CONST_ 16 cmp r5, r1 blt intel_c3_erase_32_small mov r1, _CONST_ 0x20 b intel_c3_erase_32_increment_THUMB_LABEL_intel_c3_erase_32_small _LABEL_ mov r1, _CONST_ 0x04_THUMB_LABEL_intel_c3_erase_32_increment _LABEL_ lsl r1, r1, _CONST_ 12 add r5, r5, r1 // // Loop back. // b intel_c3_erase_32_block // // We're done erasing the FLASH, so return to the caller. //_THUMB_LABEL_intel_c3_erase_32_done _LABEL_ pop {r4-r7, pc}//****************************************************************************//// The routine for erasing a single 16-bit wide Intel C3 FLASH.////****************************************************************************_THUMB_LABEL_intel_c3_erase_16 _LABEL_ // // Save the link register to the stack. // push {r4-r7, lr} // // Save the length of the FLASH to be erased. // mov r4, r0 // // Load a pointer to the FLASH. // mov r0, _CONST_ 0x70 lsl r0, r0, _CONST_ 24 // // Get the command to unlock a block of the FLASH. // mov r3, _CONST_ 0x60 // // Get the commands to erase a block of the FLASH. // mov r6, _CONST_ 0x20 mov r7, _CONST_ 0xd0 // // Start erasing the FLASH from block zero. // mov r5, _CONST_ 0x00_THUMB_LABEL_intel_c3_erase_16_block _LABEL_ // // See if we have erased all the required blocks. // cmp r5, r4 bge intel_c3_erase_16_done // // Unlock this block. // strh r3, [r0, r5] strh r7, [r0, r5] // // Erase this block. // strh r6, [r0, r5] strh r7, [r0, r5] // // Wait until the erase has completed. // bl intel_wait_16 // // Increment the block address. The first 8 blocks of the FLASH have a // block size of 8K and the remaining blocks have a size of 64K. So, // if the offset is less than 64K, increment it by 8K, otherwise // increment it by 64K. // mov r1, _CONST_ 0x01 lsl r1, r1, _CONST_ 16 cmp r5, r1 blt intel_c3_erase_16_small mov r1, _CONST_ 0x10 b intel_c3_erase_16_increment_THUMB_LABEL_intel_c3_erase_16_small _LABEL_ mov r1, _CONST_ 0x02_THUMB_LABEL_intel_c3_erase_16_increment _LABEL_ lsl r1, r1, _CONST_ 12 add r5, r5, r1 // // Loop back. // b intel_c3_erase_16_block // // We're done erasing the FLASH, so return to the caller. //_THUMB_LABEL_intel_c3_erase_16_done _LABEL_ pop {r4-r7, pc}//****************************************************************************//// The routine to erase a Intel J3 FLASH. This must be a branch to the routine// for a single 16-bit wide FLASH, immediately followed by a branch to the// routine for a 32-bit wide FLASH (i.e. two 16-bit wide FLASHes), immediately// followed by the routien for a single 16-bit wide FLASH with a reversed data// bus.////****************************************************************************_THUMB_LABEL_intel_j3_erase _LABEL_ b intel_j3_erase_16 b intel_j3_erase_32//****************************************************************************//// The routine for erasing a 16-bit wide Intel J3 FLASH with a reversed data// bus.////****************************************************************************_THUMB_LABEL_intel_j3_erase_16_rev _LABEL_ // // Save the link register to the stack. // push {r4-r7, lr} // // Save the length of the FLASH to be erased. // mov r4, r0 // // Load a pointer to the FLASH. // mov r0, _CONST_ 0x70 lsl r0, r0, _CONST_ 24 // // Get the commands to erase a block of the FLASH. // mov r6, _CONST_ 0x04 lsl r6, r6, _CONST_ 8 mov r7, _CONST_ 0x0b lsl r7, r7, _CONST_ 8 // // Start erasing the FLASH from block zero. // mov r5, _CONST_ 0x00_THUMB_LABEL_intel_j3_erase_16_rev_block _LABEL_ // // See if we have erased all the required blocks. // cmp r5, r4 bge intel_j3_erase_16_rev_done // // Erase this block. // strh r6, [r0, r5] strh r7, [r0, r5] // // Wait until the erase has completed. // bl intel_wait_16_rev // // Increment the block address. Each block is 128K. // mov r1, _CONST_ 0x02 lsl r1, r1, _CONST_ 16 add r5, r5, r1 // // Loop back. // b intel_j3_erase_16_rev_block // // We're done erasing the FLASH, so return to the caller. //_THUMB_LABEL_intel_j3_erase_16_rev_done _LABEL_ pop {r4-r7, pc}//****************************************************************************//// The routine for erasing a pair of 16-bit wide Intel J3 FLASHes in a 32-bit// configuration.////****************************************************************************_THUMB_LABEL_intel_j3_erase_32 _LABEL_ // // Save the link register to the stack. // push {r4-r7, lr} // // Save the length of the FLASH to be erased. // mov r4, r0 // // Load a pointer to the FLASH. // mov r0, _CONST_ 0x70 lsl r0, r0, _CONST_ 24 // // Get the commands to erase a block of the FLASH. // mov r5, _CONST_ 0x20 mov r6, r5 lsl r6, r6, _CONST_ 16 orr r6, r6, r5 mov r5, _CONST_ 0xd0 mov r7, r5 lsl r7, r7, _CONST_ 16 orr r7, r7, r5 // // Start erasing the FLASH from block zero. // mov r5, _CONST_ 0x00_THUMB_LABEL_intel_j3_erase_32_block _LABEL_ // // See if we have erased all the required blocks. // cmp r5, r4 bge intel_j3_erase_32_done // // Erase this block. // str r6, [r0, r5] str r7, [r0, r5] // // Wait until the erase has completed. // bl intel_wait_32 // // Increment the block address. Each block is 256K. // mov r1, _CONST_ 0x04 lsl r1, r1, _CONST_ 16 add r5, r5, r1 // // Loop back. // b intel_j3_erase_32_block // // We're done erasing the FLASH, so return to the caller. //_THUMB_LABEL_intel_j3_erase_32_done _LABEL_ pop {r4-r7, pc}//****************************************************************************//// The routine for erasing a 16-bit wide Intel J3 FLASH.////****************************************************************************_THUMB_LABEL_intel_j3_erase_16 _LABEL_ // // Save the link register to the stack. // push {r4-r7, lr} // // Save the length of the FLASH to be erased. // mov r4, r0 // // Load a pointer to the FLASH. // mov r0, _CONST_ 0x70 lsl r0, r0, _CONST_ 24 // // Get the commands to erase a block of the FLASH. // mov r6, _CONST_ 0x20 mov r7, _CONST_ 0xd0 // // Start erasing the FLASH from block zero. // mov r5, _CONST_ 0x00_THUMB_LABEL_intel_j3_erase_16_block _LABEL_ // // See if we have erased all the required blocks. // cmp r5, r4 bge intel_j3_erase_16_done // // Erase this block. // strh r6, [r0, r5] strh r7, [r0, r5] // // Wait until the erase has completed. // bl intel_wait_16 // // Increment the block address. Each block is 128K. // mov r1, _CONST_ 0x02 lsl r1, r1, _CONST_ 16 add r5, r5, r1 // // Loop back. // b intel_j3_erase_16_block // // We're done erasing the FLASH, so return to the caller. //_THUMB_LABEL_intel_j3_erase_16_done _LABEL_ pop {r4-r7, pc}//****************************************************************************//// The routine to program a Intel J3 FLASH. This must be a branch to the// routine for a single 16-bit wide FLASH, immediately followed by a branch to// the routine for a 32-bit wide FLASH (i.e. two 16-bit wide FLASHes),// immediately followed by the routine for a single 16-bit wide FLASH with a// reversed data bus.////****************************************************************************_THUMB_LABEL_intel_j3_program _LABEL_ b intel_j3_program_16 b intel_j3_program_32//****************************************************************************//// The routine for programming a 16-bit wide Intel J3 FLASH with a reversed// data bus.////****************************************************************************_THUMB_LABEL_intel_j3_program_16_rev _LABEL_ // // Save the link register to the stack. // push {r4-r7, lr} // // Save the offset, length, and pointer to the data to be programmed into // the FLASH. // mov r4, r0 mov r5, r1 mov r6, r2 // // Load a pointer to the FLASH. // mov r0, _CONST_ 0x70 lsl r0, r0, _CONST_ 24 // // Program the FLASH a sixteen words at a time. //_THUMB_LABEL_intel_j3_program_16_rev_16words _LABEL_ // // See if we have programmed all the required words. // cmp r6, _CONST_ 0 beq intel_j3_program_16_rev_done // // Send the write to buffer command. // mov r1, _CONST_ 0x17 lsl r1, r1, _CONST_ 8 strh r1, [r0, r5] mov r1, _CONST_ 0xf0 lsl r1, r1, _CONST_ 8 strh r1, [r0, r5] // // Write the next 16 words to the FLASH. // mov r2, _CONST_ 0x10 mov r3, r5_THUMB_LABEL_intel_j3_program_16_rev_word _LABEL_ // // Load the next word to be programmed. // ldrh r1, [r4] add r4, r4, _CONST_ 2 // // Write it to the FLASH. // strh r1, [r0, r3] add r3, r3, _CONST_ 2 // // Decrement the count of words to write. // sub r2, r2, _CONST_ 1 bne intel_j3_program_16_rev_word // // Write the program confirm command. // mov r1, _CONST_ 0x0b lsl r1, r1, _CONST_ 8 strh r1, [r0, r5] // // Wait until the words have been programmed. // bl intel_wait_16_rev // // Increment the address to be programmed. // add r5, r5, _CONST_ 32 // // Decrement the count of words to be programmed. // sub r6, r6, _CONST_ 32 // // Loop back. // b intel_j3_program_16_rev_16words // // We're done programming the FLASH, so put the FLASH into read array mode. //_THUMB_LABEL_intel_j3_program_16_rev_done _LABEL_ mov r1, _CONST_ 0xff lsl r1, r1, _CONST_ 8 strh r1, [r0] // // Return to the caller. // pop {r4-r7, pc}//****************************************************************************//// The routine for programming a pair of 16-bit wide Intel J3 FLASHes.////****************************************************************************_THUMB_LABEL_intel_j3_program_32 _LABEL_ // // Save the link register to the stack. // push {r4-r7, lr} // // Save the offset, length, and pointer to the data to be programmed into // the FLASH. // mov r4, r0 mov r5, r1 mov r6, r2 // // Load a pointer to the FLASH. // mov r0, _CONST_ 0x70 lsl r0, r0, _CONST_ 24 // // Program the FLASH sixteen words at a time. //_THUMB_LABEL_intel_j3_program_32_16words _LABEL_ // // See if we have programmed all the required words. // cmp r6, _CONST_ 0 beq intel_j3_program_32_done // // Send the write to buffer command. // mov r2, _CONST_ 0xe8 mov r1, r2 lsl r1, r1, _CONST_ 16 orr r1, r1, r2 str r1, [r0, r5] mov r2, _CONST_ 0x0f mov r1, r2 lsl r1, r1, _CONST_ 16 orr r1, r1, r2 str r1, [r0, r5] // // Write the next 16 words to the FLASH. // mov r2, _CONST_ 0x10 mov r3, r5_THUMB_LABEL_intel_j3_program_32_word _LABEL_ // // Load the next word to be programmed.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -