Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions targets/TARGET_Cypress/TARGET_PSOC6/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
23 changes: 20 additions & 3 deletions targets/TARGET_Cypress/TARGET_PSOC6_FUTURE/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down