Tedd OKANO
/
test_iap_20150205
small test code for IAP
main.cpp@1:90c9fa3e7462, 2015-02-05 (annotated)
- Committer:
- okano
- Date:
- Thu Feb 05 08:07:05 2015 +0000
- Revision:
- 1:90c9fa3e7462
- Parent:
- 0:57ed1971604d
- Child:
- 2:806eb710bbb0
correction for printf message and adding a comment on RAM address adjustment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:57ed1971604d | 1 | #define TEST_ON_MBED |
okano | 0:57ed1971604d | 2 | |
okano | 0:57ed1971604d | 3 | #ifdef TEST_ON_MBED |
okano | 0:57ed1971604d | 4 | #include "mbed.h" |
okano | 0:57ed1971604d | 5 | #else |
okano | 0:57ed1971604d | 6 | #include <lpc17xx.h> |
okano | 0:57ed1971604d | 7 | #include <absacc.h> |
okano | 0:57ed1971604d | 8 | #endif |
okano | 0:57ed1971604d | 9 | |
okano | 0:57ed1971604d | 10 | void IAP_Write(void); |
okano | 0:57ed1971604d | 11 | |
okano | 0:57ed1971604d | 12 | #ifdef TEST_ON_MBED |
okano | 0:57ed1971604d | 13 | unsigned char *a; |
okano | 0:57ed1971604d | 14 | unsigned char ram_buffer[ 5 + 3 ]; |
okano | 0:57ed1971604d | 15 | #else |
okano | 0:57ed1971604d | 16 | unsigned char a[5] at(0x10000400); |
okano | 0:57ed1971604d | 17 | #endif |
okano | 0:57ed1971604d | 18 | |
okano | 0:57ed1971604d | 19 | unsigned int command[ 5 ]; |
okano | 0:57ed1971604d | 20 | unsigned int result[ 5 ]; |
okano | 0:57ed1971604d | 21 | typedef void (*IAP)( unsigned int [], unsigned int[] ); |
okano | 0:57ed1971604d | 22 | |
okano | 0:57ed1971604d | 23 | IAP iap_entry = (IAP)0x1FFF1FF1; |
okano | 0:57ed1971604d | 24 | |
okano | 0:57ed1971604d | 25 | #define FLASH_TARGET_ADDR ((char *)0x00008100) |
okano | 0:57ed1971604d | 26 | |
okano | 0:57ed1971604d | 27 | int main(void) |
okano | 0:57ed1971604d | 28 | { |
okano | 0:57ed1971604d | 29 | unsigned char i = 0; |
okano | 0:57ed1971604d | 30 | |
okano | 1:90c9fa3e7462 | 31 | a = (unsigned char *)((unsigned long)ram_buffer & ~0x3); // to align to word boundary |
okano | 0:57ed1971604d | 32 | |
okano | 0:57ed1971604d | 33 | for( i = 0; i < 5; i++ ) |
okano | 0:57ed1971604d | 34 | a[ i ] = i; |
okano | 0:57ed1971604d | 35 | |
okano | 0:57ed1971604d | 36 | for( i = 0; i < 5; i++ ) |
okano | 1:90c9fa3e7462 | 37 | printf( "RAM : *((char *)0x%08X) == 0x%02X\r\n", (unsigned long)a + i, *(a + i) ); |
okano | 0:57ed1971604d | 38 | |
okano | 0:57ed1971604d | 39 | IAP_Write(); |
okano | 0:57ed1971604d | 40 | |
okano | 0:57ed1971604d | 41 | char *cp = FLASH_TARGET_ADDR; |
okano | 0:57ed1971604d | 42 | |
okano | 0:57ed1971604d | 43 | for( i = 0; i < 5; i++, cp++ ) |
okano | 1:90c9fa3e7462 | 44 | printf( "flash : *((char *)0x%08X) == 0x%02X\r\n", (unsigned long)cp, *cp ); |
okano | 0:57ed1971604d | 45 | } |
okano | 0:57ed1971604d | 46 | |
okano | 0:57ed1971604d | 47 | void IAP_Write(void) |
okano | 0:57ed1971604d | 48 | { |
okano | 0:57ed1971604d | 49 | command[0] = 50; // "prepare" cmmand |
okano | 0:57ed1971604d | 50 | command[1] = 8; // Start sector number is 8 |
okano | 0:57ed1971604d | 51 | command[2] = 8; // Finish sector number is 8 |
okano | 0:57ed1971604d | 52 | iap_entry( command, result ); |
okano | 0:57ed1971604d | 53 | |
okano | 0:57ed1971604d | 54 | printf( "error code for \"prepare\" = %d\r\n", result[ 0 ] ); |
okano | 0:57ed1971604d | 55 | |
okano | 0:57ed1971604d | 56 | |
okano | 0:57ed1971604d | 57 | command[0] = 51; // "copy from ram to flash" command |
okano | 0:57ed1971604d | 58 | command[1] = (unsigned int)FLASH_TARGET_ADDR; // Addrees of Flash |
okano | 0:57ed1971604d | 59 | command[2] = (unsigned int)a; // Addrees of Sram |
okano | 0:57ed1971604d | 60 | command[3] = 256; // How many bytes want to transfer |
okano | 0:57ed1971604d | 61 | command[4] = 96000; // Frequency in khz |
okano | 0:57ed1971604d | 62 | iap_entry( command, result ); |
okano | 0:57ed1971604d | 63 | |
okano | 0:57ed1971604d | 64 | printf( "error code for \"copy from ram to flash\" = %d\r\n", result[ 0 ] ); |
okano | 0:57ed1971604d | 65 | } |