Skip to content

MCUXpresso: Update LPC Flash driver program page function #8528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2018

Conversation

mmahadevan108
Copy link
Contributor

Description

Handle the case where the number of bytes to write is not aligned to page size.
The mbed-os flash tests do not check this use-case, maybe some additional tests are required for the scenarios where the write size is less than page size and greater than page size.

Pull request type

[X] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Handle the case where the number of bytes to write is not aligned
to page size

Signed-off-by: Mahesh Mahadevan <[email protected]>
@mmahadevan108
Copy link
Contributor Author

cc @0xc0170 @cmonr @maclobdell

@maclobdell
Copy link
Contributor

Hi Mahesh - thanks for this PR! Just to confirm, this does not seem to support writes where the address is not aligned to 256 bytes, right? So this will be an important consideration to the calling functions - they will need to ensure they are writing to addresses on 256 byte boundaries. I will speak with the cloud client team about this.

@mmahadevan108
Copy link
Contributor Author

Non-page aligned addresses is not supported by the flash controller.

@cmonr
Copy link
Contributor

cmonr commented Oct 25, 2018

@maclobdell Will you let is know when you've heard back from the cloud client team (or better yet, invite them into this PR conversation)?

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 25, 2018

The mbed-os flash tests do not check this use-case, maybe some additional tests are required for the scenarios where the write size is less than page size and greater than page size.

FlashIAP::program checks alignment to the page size here https://github.com/ARMmbed/mbed-os/blob/master/drivers/FlashIAP.cpp#L100

@mmahadevan108
Copy link
Contributor Author

@0xc0170 Based on the checks implemented inside FlashIAP driver do we need to add this code inside the HAL layer?

@maclobdell Is Pelion not using the FlashIAP driver?

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 25, 2018

@0xc0170 Based on the checks implemented inside FlashIAP driver do we need to add this code inside the HAL layer?

Is it possible that someone was not using the program method correctly (assumed that HAL should support it) ?
Also error can come from wrong sized get_program_size() return value (much bigger than the flash controller can do?)

@mmahadevan108
Copy link
Contributor Author

@0xc0170 . Based on the checks available inside the FlashIAP driver do you think I can get rid of support for non-page aligned sizes for the program function.

@cmonr
Copy link
Contributor

cmonr commented Oct 31, 2018

@ARMmbed/mbed-os-storage

Handle the case where the number of bytes to write is not aligned to page size.
The mbed-os flash tests do not check this use-case, maybe some additional tests are required for the scenarios where the write size is less than page size and greater than page size.

@maclobdell
Copy link
Contributor

@mmahadevan108 - I don't know if this PR is necessary. There is a separate issue with the cloud client trying to write to non-page aligned addresses. This is discussed in PelionIoT/mbed-cloud-client#18, with @adamelhakham having a fix and potentially making a PR soon. That should address the problem in the cloud client code without a need to modify the flash driver.

@adamelhakham
Copy link

@maclobdell @mmahadevan108 My fix is a fix only in the SOTP feature of mbed-cloud-client which is equivalent to the mbed-os nvstore feature (that stores items in the internal flash). my fix makes sure that the writes (using the sotp feature) are aligned to the flash write unit. Using the mbed-os nvstore feature will do the same, so you may use it if you wish.
If you wish to use the driver API directly than you must make sure that the address is aligned.. I am not changing any mbed-os code


if (num_of_bytes) {
/* First write page size aligned bytes of data */
status = FLASHIAP_CopyRamToFlash(address, (uint32_t *)data, num_of_bytes, SystemCoreClock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment for FLASHIAP_CopyRamToFlash() says it can handle num_of_bytes:
"The addresses should be a 256 byte boundary and the number of bytes should be 256 | 512 | 1024 | 4096."
Here num_of_bytes can be any number aligned to 256. Its worth double checking whether 256|512|1024|4096 also includes other multiplies of 256... e.g. 768

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the test to set the test_size to be page_size * 3, the tests passed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate it - thanks!

@offirko
Copy link
Contributor

offirko commented Nov 5, 2018

@maclobdell - I believe this fix is required for the driver... others than cloud client may use the driver

@mmahadevan108
Copy link
Contributor Author

Anything more needed for this PR?

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 6, 2018

@offirko Can you finilize the review? Needs approval/request changes if there's anything left.

Copy link
Contributor

@offirko offirko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cmonr cmonr added the rollup PR label Nov 9, 2018
@cmonr cmonr mentioned this pull request Nov 9, 2018
@cmonr
Copy link
Contributor

cmonr commented Nov 9, 2018

Note: This PR is now a part of a rollup PR (#8686).

No further work is needed here, as once that PR is merged, this PR will also be closed and marked as merged.

If any more commits are made in this PR, this PR will remain open and have to go through CI on its own.

@cmonr cmonr merged commit 48d4a45 into ARMmbed:master Nov 9, 2018
@cmonr cmonr removed the needs: CI label Nov 9, 2018
@cmonr cmonr removed the rollup PR label Nov 9, 2018
@mmahadevan108 mmahadevan108 deleted the Fix_LPC_Flash_Driver branch November 16, 2018 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants