IAP compatible.
Fork of IAP by
Import programSTM32_IAP_internal_flash_write
STM32_IAP demo.
Import programSTM32_IAP_test
STM32_IAP test
Diff: IAP_STM32L1.cpp
- Revision:
- 10:a0c5bb26d159
- Parent:
- 9:7e19f12b81b4
- Child:
- 12:fd6a08b46228
diff -r 7e19f12b81b4 -r a0c5bb26d159 IAP_STM32L1.cpp --- a/IAP_STM32L1.cpp Mon Apr 11 03:09:59 2016 +0000 +++ b/IAP_STM32L1.cpp Mon Apr 11 20:01:05 2016 +0900 @@ -160,35 +160,36 @@ return 0; } -#if defined(TARGET_LPC11UXX) +struct EEPROM_Unlock { + EEPROM_Unlock() { HAL_FLASHEx_DATAEEPROM_Unlock(); } + ~EEPROM_Unlock() { HAL_FLASHEx_DATAEEPROM_Lock(); } +}; int IAP::write_eeprom( char *source_addr, char *target_addr, int size ) { - IAP_command[ 0 ] = IAPCommand_EEPROM_Write; - IAP_command[ 1 ] = (unsigned int)target_addr; // Destination EEPROM address where data bytes are to be written. This address should be a 256 byte boundary. - IAP_command[ 2 ] = (unsigned int)source_addr; // Source RAM address from which data bytes are to be read. This address should be a word boundary. - IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096. - IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz. - - iap_entry( IAP_command, IAP_result ); - - return ( (int)IAP_result[ 0 ] ); + if (!IS_FLASH_DATA_ADDRESS((uint32_t)target_addr) || !IS_FLASH_DATA_ADDRESS((uint32_t)target_addr + size -1)) { + return DST_ADDR_NOT_MAPPED; + } + EEPROM_Unlock unlock; + for(int i = 0; i < size; i++, source_addr++, target_addr++) { + if (HAL_OK != HAL_FLASHEx_DATAEEPROM_Program(TYPEPROGRAMDATA_BYTE, (uint32_t)target_addr, *source_addr)) { + return INVALID_COMMAND; + } + } + return CMD_SUCCESS; } int IAP::read_eeprom( char *source_addr, char *target_addr, int size ) { - IAP_command[ 0 ] = IAPCommand_EEPROM_Read; - IAP_command[ 1 ] = (unsigned int)source_addr; // Source EEPROM address from which data bytes are to be read. This address should be a word boundary. - IAP_command[ 2 ] = (unsigned int)target_addr; // Destination RAM address where data bytes are to be written. This address should be a 256 byte boundary. - IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096. - IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz. - - iap_entry( IAP_command, IAP_result ); - - return ( (int)IAP_result[ 0 ] ); + if (!IS_FLASH_DATA_ADDRESS((uint32_t)source_addr) || !IS_FLASH_DATA_ADDRESS((uint32_t)source_addr + size - 1)) { + return SRC_ADDR_NOT_MAPPED; + } + EEPROM_Unlock unlock; + memcpy(target_addr, source_addr, size); + return CMD_SUCCESS; } -#elif defined(TARGET_LPC81X) || defined(TARGET_LPC82X) +#if defined(TARGET_LPC81X) || defined(TARGET_LPC82X) int IAP::erase_page( int start, int end ) {