205 uint32_t uDest = (uint32_t)pDestination;
206 uint32_t uSource = (uint32_t)pSource;
207 uint32_t length = uLength;
209 uint32_t address_offset;
210 uint32_t start_page_index;
211 uint32_t page_address;
212 uint32_t number_pages;
213 uint32_t current_dest;
214 uint32_t current_source;
215 uint32_t current_length;
216 volatile uint64_t data = 0;
218 if ((pDestination == NULL) || (pSource == NULL) || !IS_ADDR_ALIGNED_64BITS(uLength)
219 || !IS_ADDR_ALIGNED_64BITS((uint32_t)pDestination))
230 if (HAL_FLASH_Unlock() == HAL_OK)
233 number_pages =
PAGE_INDEX(uDest + uLength - 1U) - start_page_index + 1U;
235 if (number_pages > 1)
237 length = FLASH_PAGE_SIZE - (uDest % FLASH_PAGE_SIZE);
240 for (page_index = start_page_index; page_index < (start_page_index + number_pages); page_index++)
242 page_address = page_index * FLASH_PAGE_SIZE + FLASH_BASE;
252 UTIL_MEM_cpy_8(&
pAllocatedBuffer[uDest % FLASH_PAGE_SIZE], (
const void *)uSource, length);
262 current_dest = page_address;
264 current_length = FLASH_PAGE_SIZE;
267 if (HAL_OK != HAL_FLASH_Unlock())
272 for (address_offset = 0U; address_offset < current_length; address_offset += 8U)
274 data = (uint64_t)(*(uint32_t*)(current_source + address_offset));
275 data |= ((uint64_t)(*(uint32_t*)(current_source +
sizeof(current_source) + address_offset)) << 32U);
277 if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, current_dest, data) == HAL_OK)
280 if ( ((uint64_t)(*(uint32_t*)(current_dest)) | ((uint64_t)(*(uint32_t*)(current_dest +
sizeof(current_dest))) << 32U)) != data)
287 current_dest = current_dest + 8U;
306 length = ((uLength - length) > FLASH_PAGE_SIZE) ? FLASH_PAGE_SIZE : uLength - length;
348 HAL_StatusTypeDef hal_status = HAL_ERROR;
349 uint32_t page_error = 0U;
350 uint32_t uStart = (uint32_t)pStart;
351 FLASH_EraseInitTypeDef erase_init;
364 if (HAL_FLASH_Unlock() == HAL_OK)
366 erase_init.TypeErase = FLASH_TYPEERASE_PAGES;
369 erase_init.NbPages =
PAGE_INDEX(uStart + uLength - 1U) - erase_init.Page + 1U;
372 hal_status = HAL_FLASHEx_Erase(&erase_init, &page_error);
374 if (hal_status != HAL_OK)
FLASH_IF_StatusTypedef FLASH_IF_Write(void *pDestination, const void *pSource, uint32_t uLength)
This function writes a data buffer in internal or external flash.
static FLASH_IF_StatusTypedef FLASH_IF_INT_Read(void *pDestination, const void *pSource, uint32_t uLength)
This function reads flash.
static FLASH_IF_StatusTypedef FLASH_IF_INT_Write(void *pDestination, const void *pSource, uint32_t uLength)
This function writes a data buffer in flash (data are 64-bit aligned).
FLASH_IF_StatusTypedef FLASH_IF_Read(void *pDestination, const void *pSource, uint32_t uLength)
This function reads a amount of data from flash and copy into the output data buffer.