hello.
i am working on a project which is combine with a secondary bootloader and APP. bootloader used address 0x0000-0xFFFF(flash sector 0-1), APP used address 0x10000-0x7FFFF(flash sector 2-15).
i have made a function to update bootloader code on ROM when APP is running by using IAP function, which is same like bootloader update APP code.
but i got a 2521 return code when using below function:
void WriteNewBootloader ( void )
{
uint32_t status;
uint16_t i = 0;
uint8_t BINbuffer[FLASHWRITEMAXSIZE] __attribute__ ((aligned (4)));
__disable_irq();
for ( i = 0; i < (( 0x10000 ) / FLASHWRITEMAXSIZE); i++ )
{
memcpy ( BINbuffer, ( uint32_t * ) ( 0x70000 + i * FLASHWRITEMAXSIZE ), FLASHWRITEMAXSIZE );
FLASHIAP_PrepareSectorForWrite ( 0, 1 );
status = FLASHIAP_CopyRamToFlash ( 0x00000000ul + i * FLASHWRITEMAXSIZE, ( uint32_t * )BINbuffer, FLASHWRITEMAXSIZE, SystemCoreClock );
PRINTF ( "[Board]FLASHIAP_CopyRamToFlash status %d.\r\n", status);
status = FLASHIAP_Compare ( 0x00000000ul + i * FLASHWRITEMAXSIZE, ( uint32_t * ) BINbuffer, FLASHWRITEMAXSIZE );
if ( status != kStatus_FLASHIAP_Success )
{
PRINTF ( "[Board]FLASHIAP_Compare failed.\r\n" );
}
}
__enable_irq();
}
printed out msg were:
[Board]This version's bootloader will be updated now.
[Board]FLASHIAP_CopyRamToFlash status 2521.
[Board]FLASHIAP_Compare failed.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
[Board]FLASHIAP_CopyRamToFlash status 0.
there were no IAP return code 2521 specification from SDK header file:
/*!
* @brief Flashiap status codes.
*/
enum _flashiap_status
{
kStatus_FLASHIAP_Success = kStatus_Success, /*!< Api is executed successfully */
kStatus_FLASHIAP_InvalidCommand = MAKE_STATUS(kStatusGroup_FLASHIAP, 1U), /*!< Invalid command */
kStatus_FLASHIAP_SrcAddrError =
MAKE_STATUS(kStatusGroup_FLASHIAP, 2U), /*!< Source address is not on word boundary */
kStatus_FLASHIAP_DstAddrError =
MAKE_STATUS(kStatusGroup_FLASHIAP, 3U), /*!< Destination address is not on a correct boundary */
kStatus_FLASHIAP_SrcAddrNotMapped =
MAKE_STATUS(kStatusGroup_FLASHIAP, 4U), /*!< Source address is not mapped in the memory map */
kStatus_FLASHIAP_DstAddrNotMapped =
MAKE_STATUS(kStatusGroup_FLASHIAP, 5U), /*!< Destination address is not mapped in the memory map */
kStatus_FLASHIAP_CountError =
MAKE_STATUS(kStatusGroup_FLASHIAP, 6U), /*!< Byte count is not multiple of 4 or is not a permitted value */
kStatus_FLASHIAP_InvalidSector =
MAKE_STATUS(kStatusGroup_FLASHIAP,
7), /*!< Sector number is invalid or end sector number is greater than start sector number */
kStatus_FLASHIAP_SectorNotblank = MAKE_STATUS(kStatusGroup_FLASHIAP, 8U), /*!< One or more sectors are not blank */
kStatus_FLASHIAP_NotPrepared =
MAKE_STATUS(kStatusGroup_FLASHIAP, 9U), /*!< Command to prepare sector for write operation was not executed */
kStatus_FLASHIAP_CompareError =
MAKE_STATUS(kStatusGroup_FLASHIAP, 10U), /*!< Destination and source memory contents do not match */
kStatus_FLASHIAP_Busy =
MAKE_STATUS(kStatusGroup_FLASHIAP, 11U), /*!< Flash programming hardware interface is busy */
kStatus_FLASHIAP_ParamError =
MAKE_STATUS(kStatusGroup_FLASHIAP, 12U), /*!< Insufficient number of parameters or invalid parameter */
kStatus_FLASHIAP_AddrError = MAKE_STATUS(kStatusGroup_FLASHIAP, 13U), /*!< Address is not on word boundary */
kStatus_FLASHIAP_AddrNotMapped =
MAKE_STATUS(kStatusGroup_FLASHIAP, 14U), /*!< Address is not mapped in the memory map */
kStatus_FLASHIAP_NoPower = MAKE_STATUS(kStatusGroup_FLASHIAP, 24U), /*!< Flash memory block is powered down */
kStatus_FLASHIAP_NoClock =
MAKE_STATUS(kStatusGroup_FLASHIAP, 27U), /*!< Flash memory block or controller is not clocked */
};
so i had read out the datas from 0x0000-0xFFFF. there were all "0xFF" in 0x0000-0xFF0, and others address data were right.
but if i changed the target flash sector to 12-13, address 0x60000-0x6FFFF. the function worked well, and i could read out right datas on this address.
I want to know whether address 0x0000 can be used in IAP function to write in data, or somewhere I used these function in a wrong method?
解決済! 解決策の投稿を見る。
Thanks for your reply. And I just solved this problem.
I called this funtion after hardware initialization finished.
NewBootloader bin was set in 0x70000-0x7FFFF. the target address is 0x0000-0xFFFF.
I had read the UM10912 carefully, and I found below specification.
So I changed one word data 0xDFFD6728 at offset address 0x001C in my NewBootloader bin, which was 0x0000000. Wirte the first 7 words checksum in ROM address 0x0000001C to satisified to the rule.
After that, the function worked well. Thank your again.
Hello jiachun_tu,
"I have made a function to update bootloader code on ROM when APP is running by using IAP function,"
->> Please tell me how do you put the function (WriteNewBootlaoder)in to ROM?
And what address is about the ROM you said?
Regards,
Alice
Thanks for your reply. And I just solved this problem.
I called this funtion after hardware initialization finished.
NewBootloader bin was set in 0x70000-0x7FFFF. the target address is 0x0000-0xFFFF.
I had read the UM10912 carefully, and I found below specification.
So I changed one word data 0xDFFD6728 at offset address 0x001C in my NewBootloader bin, which was 0x0000000. Wirte the first 7 words checksum in ROM address 0x0000001C to satisified to the rule.
After that, the function worked well. Thank your again.