RT1021 Nor_Flash_Page_Program needs a length field?

Showing results for 
Search instead for 
Did you mean: 

RT1021 Nor_Flash_Page_Program needs a length field?

Contributor V


File: fsl_flexspi_nor_flash.c

In the function Nor_Flash_Page_Program, are the following lines:

uint32_t pageSize = handle->bytesInPageSize;
flashXfer.dataSize = pageSize;

This means that calling this function does not allow you to program less than a page size. The flash parts I am using allow you to program down to a single byte using the page program command. The fix I put in was to add a length argument to the function:

status_t Nor_Flash_Page_Program(nor_handle_t *handle, uint32_t address, uint8_t *buffer, uint32_t length)

And then, use it in the flexspi call:

flashXfer.dataSize = length;

And not use pageSize at all.

I also added an assert near the top of the function to prevent length going over a page boundary, otherwise the data will be page wrapped by the device (may not be the most efficient way to do it):

#ifdef DEBUG
uint32_t nextPageStartBoundary = handle->bytesInPageSize * ((address + handle->bytesInPageSize) / handle->bytesInPageSize);
assert((address + length) <= nextPageStartBoundary); // address + length <= next page boundary.

Also the function Nor_Flash_Program would need to be modified to allow lengths that are not page aligned.

Is there a reason Nor_Flash_Page_Program limits the data size to a page? Or does my fix look reasonable? The current API will need to be maintained, so a new function with a length argument may be required.


MCUXpresso IDE v11.4.0 [Build 6224] [2021-07-15]

SDK 2.10.0

The demo I originally looked at is evkmimxrt1020_flash_component_nor, which contains a folder called nor_flash. That is where the code I refer to is located.

Kind regards,


Labels (1)
0 Kudos
1 Reply

NXP TechSupport
NXP TechSupport

Hello Ronnie,

The SDK examples allows to kickstart or demo some capabilities, albeit are not always as robust or have all the features you may need for your application on the field.

I couldn’t locate information on why it’s limited to pages, but chances are this was a way to simplify the SDK example. Your fix looks reasonable to add the functionality of writing data sizes different from a page.


0 Kudos