📄 flasher.s
字号:
// ldr r1, [r4] add r4, r4, _CONST_ 4 // // Write it to the FLASH. // str r1, [r0, r3] add r3, r3, _CONST_ 4 // // Decrement the count of words to write. // sub r2, r2, _CONST_ 1 bne intel_j3_program_32_word // // Write the program confirm command. // mov r2, _CONST_ 0xd0 mov r1, r2 lsl r1, r1, _CONST_ 16 orr r1, r1, r2 str r1, [r0, r5] // // Wait until the words have been programmed. // bl intel_wait_32 // // Increment the address to be programmed. // add r5, r5, _CONST_ 64 // // Decrement the count of words to be programmed. // sub r6, r6, _CONST_ 64 // // Loop back. // b intel_j3_program_32_16words // // We're done programming the FLASH, so put the FLASH into read array mode. //_THUMB_LABEL_intel_j3_program_32_done _LABEL_ mov r2, _CONST_ 0xff mov r1, r2 lsl r1, r1, _CONST_ 16 orr r1, r1, r2 str r1, [r0] // // Return to the caller. // pop {r4-r7, pc}//****************************************************************************//// The routine for programming a 16-bit wide Intel J3 FLASH.////****************************************************************************_THUMB_LABEL_intel_j3_program_16 _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_16words _LABEL_ // // See if we have programmed all the required words. // cmp r6, _CONST_ 0 beq intel_j3_program_16_done // // Send the write to buffer command. // mov r1, _CONST_ 0xe8 strh r1, [r0, r5] mov r1, _CONST_ 0x0f 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_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_word // // Write the program confirm command. // mov r1, _CONST_ 0xd0 strh r1, [r0, r5] // // Wait until the words have been programmed. // bl intel_wait_16 // // 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_16words // // We're done programming the FLASH, so put the FLASH into read array mode. //_THUMB_LABEL_intel_j3_program_16_done _LABEL_ mov r1, _CONST_ 0xff strh r1, [r0] // // Return to the caller. // pop {r4-r7, pc}//****************************************************************************//// SendChar sends a character to UART1.////****************************************************************************_THUMB_LABEL_SendChar _LABEL_ // // Load a pointer to the system status register. // mov r1, _CONST_ 0x80 lsl r1, r1, _CONST_ 20 mov r2, _CONST_ 0x14 orr r1, r1, r2 lsl r1, r1, _CONST_ 4 // // Wait until there is space in the transmit FIFO for UART1. // mov r3, _CONST_ 0x80 lsl r3, r3, _CONST_ 16_THUMB_LABEL_sendchar0 _LABEL_ ldr r2, [r1] tst r2, r3 bne sendchar0 // // Write the character to UART1. // mov r2, _CONST_ 0x34 lsl r2, r2, _CONST_ 4 add r1, r1, r2 str r0, [r1] // // Return to the caller. // mov pc, lr//****************************************************************************//// ReceiveChar receives a character from UART1.////****************************************************************************_THUMB_LABEL_ReceiveChar _LABEL_ // // Load a pointer to the system status register. // mov r1, _CONST_ 0x80 lsl r1, r1, _CONST_ 20 mov r2, _CONST_ 0x14 orr r1, r1, r2 lsl r1, r1, _CONST_ 4 // // Wait until there is a character in the receive FIFO for UART1. // mov r2, _CONST_ 0x40 lsl r2, r2, _CONST_ 16_THUMB_LABEL_receivechar0 _LABEL_ ldr r0, [r1] tst r0, r2 bne receivechar0 // // Read the character from UART1. // mov r2, _CONST_ 0x34 lsl r2, r2, _CONST_ 4 add r1, r1, r2 ldr r0, [r1] mov r1, _CONST_ 0xff and r0, r0, r1 // // Return to the caller. // mov pc, lr//****************************************************************************//// SetBaud sets the baud rate to the specified rate.////****************************************************************************_THUMB_LABEL_SetBaud _LABEL_ // // Save the link register to the stack. // push {lr} // // Read the baud rate indicator from the host. // bl ReceiveChar // // Get the baud rate divisor based on the requested baud rate. // mov r1, _CONST_ 0x17 cmp r0, _CONST_ 0x30 beq setbaud0 mov r1, _CONST_ 0x0b cmp r0, _CONST_ 0x31 beq setbaud0 mov r1, _CONST_ 0x05 cmp r0, _CONST_ 0x32 beq setbaud0 mov r1, _CONST_ 0x03 cmp r0, _CONST_ 0x33 beq setbaud0 mov r1, _CONST_ 0x01 // // Set the data length to 8 bits per character and enable the FIFO. //_THUMB_LABEL_setbaud0 _LABEL_ mov r0, _CONST_ 0x07 lsl r0, r0, _CONST_ 16 orr r1, r1, r0 // // Change the configuration of UART1. // mov r0, _CONST_ 0x80 lsl r0, r0, _CONST_ 20 mov r2, _CONST_ 0x4c orr r0, r0, r2 lsl r0, r0, _CONST_ 4 str r1, [r0] // // Wait until we receive a '-' character from the host. //_THUMB_LABEL_setbaud1 _LABEL_ bl ReceiveChar cmp r0, _CONST_ 0x2d bne setbaud1 // // Return to the caller. // pop {pc}//****************************************************************************//// ReadLong reads a 32-bit value from the serial port.////****************************************************************************_THUMB_LABEL_ReadLong _LABEL_ // // Save the link register to the stack. // push {r4, lr} // // Read the first byte. // bl ReceiveChar // // The first byte is the least significant 8 bits of the long value. // mov r4, r0 // // Read the second byte. // bl ReceiveChar // // The second byte is the next 8 significant bits of the long value. // lsl r0, r0, _CONST_ 8 orr r4, r4, r0 // // Read the third byte. // bl ReceiveChar // // The third byte is the next 8 significant bits of the long value. // lsl r0, r0, _CONST_ 16 orr r4, r4, r0 // // Read the fourth byte. // bl ReceiveChar // // The fourth byte is the most significant 8 bits of the long value. // lsl r0, r0, _CONST_ 24 orr r0, r0, r4 // // Return to the caller. // pop {r4, pc}//****************************************************************************//// ReadBlock reads a 1K block of data from the host.////****************************************************************************_THUMB_LABEL_ReadBlock _LABEL_ // // Save the link register to the stack. // push {r4-r5, lr} // // Load a pointer to the data buffer. // ldr r4, =DataBuffer // // Read 1K bytes of data. // mov r5, _CONST_ 0x04 lsl r5, r5, _CONST_ 8_THUMB_LABEL_read_byte _LABEL_ // // Read the next byte of data. // bl ReceiveChar // // Store this character in the data buffer. // strb r0, [r4] add r4, r4, _CONST_ 1 // // Decrement the count of bytes. // sub r5, r5, _CONST_ 1 bne read_byte // // Return to the caller. // pop {r4-r5, pc}//****************************************************************************//// ProgramFlash programs the data receive via the serial port into the on-board// FLASH.////****************************************************************************_THUMB_LABEL_ProgramFlash _LABEL_ // // Save the link register to the stack. // push {lr} // // Read the length of the data to be programmed. // bl ReadLong mov r4, r0 // // See if the data is small enough to fit into the FLASH. // mov r1, r8 cmp r0, r1 blt size_ok // // Tell the host that the data is too large. // mov r0, _CONST_ 0x26 // '&' bl SendChar // // We're done. // pop {pc} // // Erase the FLASH. //_THUMB_LABEL_size_ok _LABEL_ mov lr, pc mov pc, r9 // // Tell the host that we're ready to start receiving file data. // mov r0, _CONST_ 0x21 // '!' bl SendChar // // Now, read data in 1K blocks until we've read all the file data. // mov r5, _CONST_ 0x00 mov r11, r5_THUMB_LABEL_read_block _LABEL_ // // Read 1K bytes from the serial port. // bl ReadBlock // // Read the checksum from the host. // bl ReadLong // // Checksum the data we read. // mov r1, _CONST_ 0x04 lsl r1, r1, _CONST_ 8 ldr r2, =DataBuffer_THUMB_LABEL_checksum _LABEL_ // // Read this byte of the data buffer. // ldrb r3, [r2] add r2, r2, _CONST_ 1 // // Subtract this byte from the checksum from the host. // sub r0, r0, r3 // // Decrement the count of bytes. // sub r1, r1, _CONST_ 1 bne checksum // // See if the checksum matched (i.e. the counter is now zero). // cmp r0, _CONST_ 0x00 beq checksum_ok // // The checksum was bad, so ask the host to send this block again. // mov r0, _CONST_ 0x40 // '@' bl SendChar b read_block // // The checksum matched, so program this block of data into the FLASH. // First, get some values which we'll need. //_THUMB_LABEL_checksum_ok _LABEL_ ldr r0, =DataBuffer mov r1, r5 mov r2, _CONST_ 0x04 lsl r2, r2, _CONST_ 8 mov lr, pc mov pc, r10 // // Verify that the data was programmed correctly. // ldr r0, =DataBuffer mov r1, _CONST_ 0x70 lsl r1, r1, _CONST_ 24 add r1, r1, r5 mov r2, _CONST_ 0x04 lsl r2, r2, _CONST_ 8_THUMB_LABEL_verify_word _LABEL_ // // Load this word from FLASH and from the internal buffer. // ldr r6, [r0] add r0, r0, _CONST_ 4 ldr r7, [r1] add r1, r1, _CONST_ 4 // // See if the two words are identical. // cmp r6, r7 beq word_ok // // Indicate that there was an error. // mov r11, r0 // // Decrement the word count. //_THUMB_LABEL_word_ok _LABEL_ sub r2, r2, _CONST_ 4 bne verify_word // // Tell the host that we're done with this block and are ready for the // next one. // mov r0, _CONST_ 0x23 // '_CONST_ ' bl SendChar // // Increment the block address. // mov r0, _CONST_ 0x04 lsl r0, r0, _CONST_ 8 add r5, r5, r0 // // Decrement the count of bytes to be programmed. // sub r4, r4, r0 // // Loop back to the next block. // bne read_block // // See if there was an error programming the FLASH. // mov r0, r11 cmp r0, _CONST_ 0x00 beq program_done // // Tell the host that there was an error programming the FLASH. // mov r0, _CONST_ 0x5e // '^' bl SendChar // // Tell the host that we're done programming the FLASH. //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -