mirror of https://github.com/ARMmbed/mbed-os.git
Add alignment check in the flash_program_page
* Add source address word alignment check * malloc and memcpy are called only if data is unaligned * malloc size is now copySize (program page size), rather than whole buffer to be writtenpull/6413/head
parent
d76d511969
commit
3acdc81e6d
|
@ -115,20 +115,28 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
|
||||||
const uint32_t copySize = 1024; // should be 256|512|1024|4096
|
const uint32_t copySize = 1024; // should be 256|512|1024|4096
|
||||||
uint8_t *alignedData, *source;
|
uint8_t *alignedData, *source;
|
||||||
|
|
||||||
// always malloc outside critical section
|
alignedData = 0;
|
||||||
alignedData = malloc(size);
|
source = (uint8_t *)data;
|
||||||
if (alignedData == 0) {
|
|
||||||
return (1);
|
// check word boundary
|
||||||
|
if (((uint32_t)data % 4) != 0) {
|
||||||
|
// always malloc outside critical section
|
||||||
|
alignedData = malloc(copySize);
|
||||||
|
if (alignedData == 0) {
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
n = GetSecNum(address); // Get Sector Number
|
n = GetSecNum(address); // Get Sector Number
|
||||||
|
|
||||||
memcpy(alignedData, data, size);
|
|
||||||
source = alignedData;
|
|
||||||
|
|
||||||
core_util_critical_section_enter();
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
while (size) {
|
while (size) {
|
||||||
|
if (((uint32_t)data % 4) != 0) {
|
||||||
|
memcpy(alignedData, source, copySize);
|
||||||
|
source = alignedData;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Prepare_Sector_for_Write command must be exected before
|
Prepare_Sector_for_Write command must be exected before
|
||||||
Copy_RAM_to_Flash command.
|
Copy_RAM_to_Flash command.
|
||||||
|
|
Loading…
Reference in New Issue