Merge pull request #9940 from davidsaada/david_psoc6_reduce_prog_size

Reduce flash page size from 512 to 32 bytes in PSOC6 based boards
pull/9998/head
Cruz Monrreal 2019-03-06 13:44:39 -06:00 committed by GitHub
commit f3ecc0b485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 6 deletions

View File

@ -47,10 +47,27 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
{
(void)(obj);
int32_t status = 0;
if (Cy_Flash_ProgramRow(address, (const uint32_t *)data) != CY_FLASH_DRV_SUCCESS) {
status = -1;
static uint8_t prog_buf[CY_FLASH_SIZEOF_ROW];
while (size) {
uint32_t offset = address % CY_FLASH_SIZEOF_ROW;
uint32_t chunk_size;
if (offset + size > CY_FLASH_SIZEOF_ROW) {
chunk_size = CY_FLASH_SIZEOF_ROW - offset;
} else {
chunk_size = size;
}
uint32_t row_address = address / CY_FLASH_SIZEOF_ROW * CY_FLASH_SIZEOF_ROW;
memcpy(prog_buf, (const void *)row_address, CY_FLASH_SIZEOF_ROW);
memcpy(prog_buf + offset, data, chunk_size);
if (Cy_Flash_ProgramRow(row_address, (const uint32_t *)prog_buf) != CY_FLASH_DRV_SUCCESS) {
status = -1;
}
address += chunk_size;
size -= chunk_size;
}
Cy_SysLib_ClearFlashCacheAndBuffer();
return status;
}
@ -67,7 +84,7 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
uint32_t flash_get_page_size(const flash_t *obj)
{
(void)(obj);
return CY_FLASH_SIZEOF_ROW;
return CY_FLASH_EFFECTIVE_PAGE_SIZE;
}
uint32_t flash_get_start_address(const flash_t *obj)

View File

@ -377,6 +377,8 @@ extern "C" {
/** Flash row size */
#define CY_FLASH_SIZEOF_ROW (CPUSS_FLASHC_PA_SIZE * 4u)
/** Flash effective page size */
#define CY_FLASH_EFFECTIVE_PAGE_SIZE 32
/** Long words flash row size */
#define CY_FLASH_SIZEOF_ROW_LONG_UNITS (CY_FLASH_SIZEOF_ROW / sizeof(uint32_t))

View File

@ -332,6 +332,8 @@ extern "C" {
/** Flash row size */
#define CY_FLASH_SIZEOF_ROW (CPUSS_FLASHC_PA_SIZE * 4u)
/** Flash effective page size */
#define CY_FLASH_EFFECTIVE_PAGE_SIZE 32
/** Number of flash rows */
#define CY_FLASH_NUMBER_ROWS (CY_FLASH_SIZE / CY_FLASH_SIZEOF_ROW)
/** Long words flash row size */

View File

@ -47,10 +47,27 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
{
(void)(obj);
int32_t status = 0;
if (Cy_Flash_ProgramRow(address, (const uint32_t *)data) != CY_FLASH_DRV_SUCCESS) {
status = -1;
static uint8_t prog_buf[CY_FLASH_SIZEOF_ROW];
while (size) {
uint32_t offset = address % CY_FLASH_SIZEOF_ROW;
uint32_t chunk_size;
if (offset + size > CY_FLASH_SIZEOF_ROW) {
chunk_size = CY_FLASH_SIZEOF_ROW - offset;
} else {
chunk_size = size;
}
uint32_t row_address = address / CY_FLASH_SIZEOF_ROW * CY_FLASH_SIZEOF_ROW;
memcpy(prog_buf, (const void *)row_address, CY_FLASH_SIZEOF_ROW);
memcpy(prog_buf + offset, data, chunk_size);
if (Cy_Flash_ProgramRow(row_address, (const uint32_t *)prog_buf) != CY_FLASH_DRV_SUCCESS) {
status = -1;
}
address += chunk_size;
size -= chunk_size;
}
Cy_SysLib_ClearFlashCacheAndBuffer();
return status;
}
@ -67,7 +84,7 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
uint32_t flash_get_page_size(const flash_t *obj)
{
(void)(obj);
return CY_FLASH_SIZEOF_ROW;
return CY_FLASH_EFFECTIVE_PAGE_SIZE;
}
uint32_t flash_get_start_address(const flash_t *obj)