Skip to content

drivers/mtd: fix mtd_write_sector#20234

Merged
benpicco merged 1 commit intoRIOT-OS:masterfrom
gschorcht:drivers/mtd/fix_mtd_write_sector
Jan 7, 2024
Merged

drivers/mtd: fix mtd_write_sector#20234
benpicco merged 1 commit intoRIOT-OS:masterfrom
gschorcht:drivers/mtd/fix_mtd_write_sector

Conversation

@gschorcht
Copy link
Copy Markdown
Contributor

Contribution description

This PR fixes mtd_write_sector function introduced with PR #20180.

mtd_write_page_raw requires the number of bytes to be written as parameter, which is the number of sectors to be written (parameter count) multiplied by the pages per sector mtd->pages_per_sector and the page size mtd->page_size.

Testing procedure

Use any board with SPI SD Card interface and set ENABLE_DEBUG in drivers/mtd_sdcard.c. Without the PR, writing to the SD card fails because of the wrong size. Formatting the SD card doesn't hangs.

> vfs w /sd0/test1.txt ascii o hello
mtd_sdcard_read_page: page:1991 offset:0 size:512
mtd_sdcard_write_page: page:1991 offset:0 size:1019392
mtd_sdcard_write_page: error 4
Write error: -EIO
mtd_sdcard_write_page: page:1991 offset:0 size:1019392
mtd_sdcard_write_page: error 3

With the PR writing to the SD card and formatting it works as expected.

> vfs w /sd0/test1.txt ascii o hello
mtd_sdcard_read_page: page:1991 offset:0 size:512
mtd_sdcard_read_page: page:95 offset:0 size:512
mtd_sdcard_write_page: page:95 offset:0 size:512
mtd_sdcard_write_page: page:2055 offset:0 size:512
mtd_sdcard_read_page: page:1991 offset:0 size:512
mtd_sdcard_write_page: page:1991 offset:0 size:512
mtd_sdcard_write_page: page:64 offset:0 size:512

Issues/PRs references

Fixes PR #20180

Parameter `num` of `mtd_write_page_raw` is the number of bytes to be written, which is the number of sectors to be written`count` multiplied by the pages per sector `mtd->pages_per_sector` and the page size `mtd->page_size`.
@gschorcht gschorcht requested a review from benpicco January 7, 2024 16:14
@github-actions github-actions bot added the Area: drivers Area: Device drivers label Jan 7, 2024
@gschorcht gschorcht added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 7, 2024
@riot-ci
Copy link
Copy Markdown

riot-ci commented Jan 7, 2024

Murdock results

✔️ PASSED

caa31ec drivers/mtd: fix mtd_write_sector

Success Failures Total Runtime
8085 0 8085 11m:37s

Artifacts

Copy link
Copy Markdown
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Oops, good catch - thank you!

@benpicco benpicco enabled auto-merge January 7, 2024 16:50
@benpicco benpicco added this pull request to the merge queue Jan 7, 2024
Merged via the queue into RIOT-OS:master with commit dca974d Jan 7, 2024
@benpicco benpicco added the Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer label Jan 8, 2024
@MrKevinWeiss MrKevinWeiss added this to the Release 2024.01 milestone Feb 7, 2024
@gschorcht gschorcht deleted the drivers/mtd/fix_mtd_write_sector branch July 31, 2025 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants