-
Notifications
You must be signed in to change notification settings - Fork 3k
LPC176X: Fix flash program size #6413
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
Conversation
This patch fix flash write issue when program size is more than page size (= 1024 bytes). See detail - ARMmbed#6165 Source data always use aligned data in heap memory.
This looks fine to me. Just wonder whether you allocated the size for the full buffer (instead of copy_size) in order not to copy the data inside the critical section. If this was your intention, then got no problem here. |
I also wonder. Is there a reason these targets copies buffer to heap? Good to have this fixed 👍 |
/morph build |
Build : SUCCESSBuild number : 1516 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 1154 |
Test : FAILUREBuild number : 1294 |
/morph test |
Test : FAILUREBuild number : 1304 |
@davidsaada, could I get your help here? I'm not sure if the above test failure was caused by the PR, or by some spurious condition with the CI. The "NVStore: Multiple thread test" failure only occurred with an ARCH_PRO board compiled with IAR. |
@cmonr Reason for that failure is the combination of @toyowata 's solution for this problem and the nvstore test. This PR allocates heap memory for the entire source buffer. This leads to an exhaustion of heap memory in IAR, which seems to be the least efficient of all toolchains in regards to memory allocations. Really don't know what to suggest - already minimized this test's parameters to reduce memory consumption, but seems that this PR pushes the test over the border again. |
Thanks for the insight @davidsaada! Looks like @ccli8 has created a PR to fix the test. If you could take a quick look at it, it would be much appreciated. |
@cmonr @toyowata A solution such as the one @ccli8 created in his PR (reducing page size) would be the perfect solution here, if possible for ARCH_PRO as well. ARCH_PRO large page size causes a lot of issues in NVStore, both in memory consumption (as NVStore also allocates a page buffer) and in flash granularity (only allows storing 32 records in a sector, as page size is 1KB and sector size is 32KB). |
// always malloc outside critical section | ||
uint8_t *alignedData = malloc(size); | ||
alignedData = malloc(size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could be as @davidsaada proposed - smaller program page size if it is defined, or what I was initially thinking, was allocating only copySize
buffer on heap (because that one is used for flashing). It increases the runtime but making it possible to work for any app (1k of heap should be available). ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it would help in this case. I suspect that the extra allocation of 1024 bytes already pushes this test over the limit. However, it's worth the try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xc0170 @davidsaada In the current code, the reason of the malloc usage is to handle unaligned the data buffer here:
However, there is an alignment check logic here before calling the HAL driver:
https://github.com/ARMmbed/mbed-os/blob/master/drivers/FlashIAP.cpp#L101
I think therefore, the malloc in the flash_program_page() is not required and it should just check the size of flash data.
I am going to modify this and create new commit for review next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@toyowata You can still check the alignment for the (unlikely) case this code is not called from the driver (or if the driver logic is changed for some reason), and only then perform the malloc + memcpy. In the likely aligned case, you can point to the user buffer.
PR fix has been brought in. Feel free to rebase and address @0xc0170's comment when possible. |
@cmonr Unless I'm missing big time here, I think the PR you brought in should only be used as a reference for the right fix on the ARCH_PRO board (if possible, not sure about it), as it solves the same problem - but on another board. |
OH! Ha, you're right @davidsaada. That completely excaped me. The timing was so right that I thought it was the fix. |
* Add source address word alignment check * malloc and memcpy are called only if data is unaligned * malloc size is now copySize (program page size), rather than whole buffer to be written
@0xc0170 @davidsaada |
Looks very good now. |
/morph build |
Build : FAILUREBuild number : 1589 |
/morph build |
Build : FAILUREBuild number : 1595 |
License server failure, it should be resolved now, restarting /morph build |
Build : SUCCESSBuild number : 1617 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 1246 |
Test : SUCCESSBuild number : 1399 |
Description
This patch fix flash write issue when program size is more than page size (= 1024 bytes). See detail - Fixes #6165
Source data always use aligned data in heap memory.
Test result
[LPC1768]
[ARCH_PRO]
I also confirmed to pass the test case here.
Pull request type