IAP compatible.
Fork of IAP by
Import programSTM32_IAP_internal_flash_write
STM32_IAP demo.
Import programSTM32_IAP_test
STM32_IAP test
Diff: IAP_STM32F4.cpp
- Revision:
- 12:fd6a08b46228
- Parent:
- 11:937bd817d5bf
--- a/IAP_STM32F4.cpp Tue Apr 12 15:09:09 2016 +0000 +++ b/IAP_STM32F4.cpp Sat Apr 30 03:32:33 2016 +0000 @@ -82,16 +82,16 @@ } int *IAP::read_serial( void ) { - memcpy(&IAP_result[1], (void*)0x1fff7a10, sizeof(uint32_t) * 3); + memcpy(&IAP_result[1], (void*)0x1fff7a10, sizeof(uint32_t) * 3); // RM0383 24.1 IAP_result[4] = 0; return ( (int *)&IAP_result[ 1 ] ); // to return the number itself (this command always returns CMD_SUCCESS) } int IAP::blank_check( int start, int end ) { - if (start > end || start >= FLASH_SECTOR_TOTAL || end >= FLASH_SECTOR_TOTAL) { + if (start > end || !IS_FLASH_SECTOR(start) || !IS_FLASH_SECTOR(end)) { return INVALID_SECTOR; - } + } static const int offset[8+1] = {0x00000, 0x04000, 0x08000, 0xc000, 0x10000, 0x20000, 0x40000, 0x60000, 0x80000}; uint8_t* it = reinterpret_cast<uint8_t*>(FLASH_BASE + offset[start]); uint8_t* it_end = reinterpret_cast<uint8_t*>(FLASH_BASE + offset[end + 1]); @@ -110,7 +110,7 @@ int IAP::erase( int start, int end ) { - if (start >= FLASH_SECTOR_TOTAL || end >= FLASH_SECTOR_TOTAL) { + if (start > end || !IS_FLASH_SECTOR(start) || !IS_FLASH_SECTOR(end)) { return INVALID_SECTOR; } FLASH_EraseInitTypeDef Erase; @@ -126,7 +126,7 @@ int IAP::prepare( int start, int end ) { - if (start >= FLASH_SECTOR_TOTAL || end >= FLASH_SECTOR_TOTAL) { + if (start > end || !IS_FLASH_SECTOR(start) || !IS_FLASH_SECTOR(end)) { return INVALID_SECTOR; } return CMD_SUCCESS; @@ -134,6 +134,9 @@ int IAP::write( char *source_addr, char *target_addr, int size ) { + if (!IS_FLASH_ADDRESS((int)target_addr) || !IS_FLASH_ADDRESS((int)target_addr + size - 1)) { + return DST_ADDR_NOT_MAPPED; + } uint32_t data; FLASH_Unlock unlock; for(int n = 0; n < size; n += sizeof(data)) { @@ -212,4 +215,4 @@ #endif -#endif // TARGET_STM32L1 +#endif // TARGET_STM32F4