Skip to content
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

Handle unaligned address in EspClass::flashWrite u8 overload #8605

Merged
merged 12 commits into from
Jul 3, 2022

Conversation

mcspr
Copy link
Collaborator

@mcspr mcspr commented Jun 16, 2022

another approach at fixing #8372
resolves #8588 @fabianoriccardi

instead of changing the branch, just break the flow on a lower level when actually writing things
both unaligned src and dest are placed into buffer. this copies behaviour of RTOS functions that I mentioned in the issue

example sketch seems to work. I just hope I did not break something else while fixing spiffs
(...and geez, how much unaligned writes it does. no wonder it's slow...)

@fabianoriccardi
Copy link

I guessed that this issue could be solved with a good refactor of the whole spi_flash_write_ methods. Sure I will vote for your pull request, my intention was proposing a punctual fix, modifying as little as possible, that the overall refactor is the way to go!

cores/esp8266/Esp.cpp Outdated Show resolved Hide resolved
cores/esp8266/Esp.cpp Outdated Show resolved Hide resolved
if (!flashReplaceBlock(address + offset, data + offset, sizeLeft)) {
return false;
while (size > 0) {
auto len = std::min(size, sizeof(buf));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe have a double check on what is returned by sizeof(buf) here?
I always find it tricky to see for myself whether the sizeof is returning the size of the array or the size of a pointer.
In this instance, it should be FLASH_PAGE_SIZE

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No point guessing when IDE / language server in any editor will display this b/c it's a compile time value :)
But I suppose this could be std::size(buf); instead

Copy link
Contributor

Choose a reason for hiding this comment

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

Well my "code review IDE" (also called "brain") is lacking this feature. ;) It is only highlighting code which looks like code I have spent numerous hours on to fix in the past where I missed such a mistake.
Apart from that you still need to hover your mouse on those parts of the code in an IDE that does show you what it will do and that was my suggestion, to actually do that ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which is why I mentioned the IDE as a tool to help with guesses, since we don't have this issue here. Review with a real test case might've helped too, would you mind re-checking with some ESPeasy builds if it's possible?

Copy link
Contributor

Choose a reason for hiding this comment

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

I did just now test ESPEasy with the code changes of this PR.
It does seem to work fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

puya supports looks fine as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

puya supports looks fine as well?

I don't have any Puya device here at hand, so have not tested it.
If you like, I can have another look at the code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please do.

@mcspr
Copy link
Collaborator Author

mcspr commented Jun 27, 2022

re. does it work with u8 data, we do have these test cases for various offsets
https://github.com/esp8266/Arduino/blob/master/tests/device/test_spi_flash/test_spi_flash.ino

PR adds an additional case, which fails with the current master

Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

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

device test started & passed

@fabianoriccardi
Copy link

I've tested the new commits and they solve #8372. Hoping they will be integrated soon in the main line.

@mcspr mcspr linked an issue Jul 3, 2022 that may be closed by this pull request
6 tasks
@mcspr mcspr merged commit 65d3043 into esp8266:master Jul 3, 2022
@mcspr mcspr deleted the unaligned-everything branch July 3, 2022 19:47
@mcspr mcspr added this to the 3.1 milestone Jul 3, 2022
hasenradball pushed a commit to hasenradball/Arduino that referenced this pull request Nov 18, 2024
esp8266#8605)

Separate page handling logic and the actual writing. Make sure we place both unaligned src and dest into a buffer.
Fixes edge-case introduced for SPIFFS that exclusively works through unaligned flash write function.

This copies the behaviour of official RTOS port, but does not change the original spi_flash_write.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SPIFFS println weird behavior with long strings
4 participants