drivers/flashpage: use const pointers for write and verify#8773
drivers/flashpage: use const pointers for write and verify#8773kYc0o merged 6 commits intoRIOT-OS:masterfrom
Conversation
f7c80f2 to
6c27e75
Compare
|
Rebased |
|
@cladmi can you take a look? I remember we talked something about this but decided to not go this way for a reason... I can't recall it right now... |
|
Going for However you removed the From what I remember, the goal of these lines was to somehow counter a lack in the api types saying that "data" should be 4 bytes aligned. Its a hack instead of a proper fix, but there is not need to remove it now. |
cladmi
left a comment
There was a problem hiding this comment.
Please keep the (const uint32_t *) cast as explained in the comment.
| assert(page < (int)FLASHPAGE_NUMOF); | ||
|
|
||
| uint32_t *page_addr = (uint32_t *)flashpage_addr(page); | ||
| uint32_t *data_addr = (uint32_t *)data; |
There was a problem hiding this comment.
I think this should be kept as (const uint32_t *)data as it somehow says alignment constraints, even if its note in the API.
There was a problem hiding this comment.
I did not repeat but its also present in other files.
There was a problem hiding this comment.
I don't understand why you want that.
In most cases, the implicit cast is still there anyway. And casting does not enforce any alignment. In this example, without casting, you could have a crash if the alignment is not met. If you use this temporary variable and you cast, you will have the right alignment, but you could write data that you do not expect to write. So I'm not sure which is worst, but I think a crash would be better to catch issues here.
There was a problem hiding this comment.
I would say it should not be changed in this PR that says to only change to const. Fixing this it is a different problem.
I agree that the current state is far from perfect. But random crash are not good either.
Having this line helped me debug a crash in someone else code with a buffer coming from the shell and there was no other mention that for this platform it should be aligned and having this in the code helped me find it.
I would prefer an API fix with a per platform type or alignment definition but I would say it should be another PR.
There was a problem hiding this comment.
OK to re-add the temp variable but I would prefer keeping implicit cast, which is IMO more aligned with the rest of the code base.
There was a problem hiding this comment.
I re-checked all the changes and my bad, I generalized this line as if you did the same to the other files.
For the other ones you just removed the cast part, which is true does not help at all. Keeping only the assignement to an uint32_t * variable is enough I agree. So you can keep them as you changed now as murdock does not issue warnings.
Here however you also removed the uint32_t *data_addr instead of only defining it const.
And from the MSC_WriteWordI implementation, it also cast the pointer to uint32_t somewhere, so I would prefer keeping this data_addr intermediate variable.
There was a problem hiding this comment.
:D I was answering at the same time.
And yes, re-adding the temp variable here is enough for me.
48f1edc to
549bf0e
Compare
|
I agree on the API change, not tested on mentioned hardware. |
|
Before merging, I was testing a bit more thoroughly this PR and discovered that the stm32 driver is not working properly, at least on my desk. Can someone test on the F variants that |
kYc0o
left a comment
There was a problem hiding this comment.
Sorry for this, I know it's not this PR the culprit but I'd like to have more testing on the flash driver for stm32f.
|
Works as expected for me om nucleo-f091 (stm32f091). What do you see @kYc0o ? |
|
I'm on a nucleo-f072 (stm32f072rb) and when I do Very strange... Do you have access to IoT-Lab? |
|
Ok so I just discovered that I have the right to write one command on each turn off/turn on round (another issue...). The pattern written by |
|
However, I have no issues at all on nucleo-l152. It might be my board which has something strange. If we could have a valid test on iotlab-m3 it would be awesome. Yesterday I succeeded to test but today I have failed assertions with |
|
I gave another try on nucleo32-f042 and it works like a charm. I don't have access to IoT-Lab |
|
This is my output on IoT-Lab test 100
1521046351.786173;m3-100;> test 100
help
1521046356.899114;m3-100;error verifying the content of page 100: > help
1521046356.901197;m3-100;Command Description
1521046356.903274;m3-100;---------------------------------------
1521046356.903466;m3-100;info Show information about pages
1521046356.903601;m3-100;dump Dump the selected page to STDOUT
1521046356.907255;m3-100;dump_local Dump the local page buffer to STDOUT
1521046356.907447;m3-100;read Read and output the given page
1521046356.907583;m3-100;write Write (ASCII) data to the given page
1521046356.909116;m3-100;write_raw Write (ASCII, max 64B) data to the given address
1521046356.909308;m3-100;erase Erase the given page
1521046356.912688;m3-100;edit Write bytes to the local page
1521046356.912881;m3-100;test Write and verify test patternSomehow the serial is retained... I don't know exactly what can be related but I'm investigating. |
This is a bug in the test application a |
|
It works on IoT-LAB with commits before #8768 |
|
On So this PR can be merged as the problem comes from somewhere else. |
|
Ok, let's merge this then. |
Contribution description
This update the periph_flashpage interface to use const pointer for writes and verify operations.
Issues/PRs references
Based on #8768