@@ -812,14 +812,17 @@ static uint32_t erase_storage_sector(uint32_t adr)
812
812
return status ;
813
813
}
814
814
815
- static uint32_t program_storage_page (uint32_t adr , uint32_t sz , uint32_t * buf )
815
+ static uint32_t program_storage_page (uint32_t adr , uint32_t sz , uint8_t * buf )
816
816
{
817
- int status = FLASH_Program (& g_flash , adr , buf , sz );
817
+ /* Verify data is word aligned */
818
+ util_assert (!((uint32_t )buf & 0x3 ));
819
+
820
+ int status = FLASH_Program (& g_flash , adr , (uint32_t * ) buf , sz );
818
821
if (status == kStatus_Success )
819
822
{
820
823
// Must use kFlashMargin_User, or kFlashMargin_Factory for verify program
821
824
status = FLASH_VerifyProgram (& g_flash , adr , sz ,
822
- buf , kFLASH_marginValueUser ,
825
+ ( uint32_t * ) buf , kFLASH_marginValueUser ,
823
826
NULL , NULL );
824
827
}
825
828
return status ;
@@ -844,7 +847,7 @@ static void i2c_write_flash_callback(uint8_t* pData, uint8_t size) {
844
847
/* Validate length field matches with I2C Write data */
845
848
if (size == length + 8 ) {
846
849
/* Address range and alignment validation done inside program_storage_page() */
847
- status = program_storage_page (address , length , (uint32_t * ) data );
850
+ status = program_storage_page (address , length , (uint8_t * ) data );
848
851
849
852
if (0 != status ) {
850
853
pI2cCommand -> cmdId = gFlashError_c ;
@@ -989,7 +992,7 @@ static void i2c_write_flash_callback(uint8_t* pData, uint8_t size) {
989
992
pI2cCommand -> cmdId = gFlashError_c ;
990
993
}
991
994
else {
992
- status = program_storage_page (FLASH_CONFIG_ADDRESS , sizeof (flashConfig_t ), (uint32_t * ) & gflashConfig );
995
+ status = program_storage_page (FLASH_CONFIG_ADDRESS , sizeof (flashConfig_t ), (uint8_t * ) & gflashConfig );
993
996
}
994
997
}
995
998
i2c_fillBuffer ((uint8_t * ) pI2cCommand , 0 , 1 );
0 commit comments