Skip to content

periph_flashpage: Make pagewise API optional#15412

Merged
benpicco merged 11 commits intoRIOT-OS:masterfrom
bergzand:pr/flashpage/merge_raw
Nov 12, 2020
Merged

periph_flashpage: Make pagewise API optional#15412
benpicco merged 11 commits intoRIOT-OS:masterfrom
bergzand:pr/flashpage/merge_raw

Conversation

@bergzand
Copy link
Copy Markdown
Member

@bergzand bergzand commented Nov 9, 2020

Contribution description

flashpage currently requires pagewise implementation with an optional
extension for per block writes (flashpage_raw). Most implementations
with flashpage_raw implement the pagewise access via the flashpage_raw
functions. This commit makes the flashpage raw the main access method
and adds an extension feature for the pagewise access.

The functions and defines are renamed to reflect this. The API is also
extended with a dedicated function for erasing a sector.

Testing procedure

Preferably every CPU family should be tested with tests/periph_flashpage

  • cc2538
  • efm32
  • kinetis
  • nrf5x
  • msp430
  • sam0
  • stm32

Issues/PRs references

Depends on #15410

@bergzand bergzand added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Area: drivers Area: Device drivers labels Nov 9, 2020
@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Nov 9, 2020

When I see the HAS_PERIPH_FLASHPAGE_PAGEWISE new name, I even wonder why the base feature is called periph_flashpage, why not simply rather call it periph_flash ?
Then the new pagewise variant would be called periph_flash_pagewise.

@fjmolinas
Copy link
Copy Markdown
Contributor

samr21-xpro (sam0) OK
>

> test_last_raw

>  test_last_raw
wrote raw short buffer to last flash page
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
>

openmote-b (cc2538) OK
> test_last_raw

>  test_last_raw
wrote raw short buffer to last flash page
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
>
dwm1001 (nrf5x) OK
> test_last_raw

>  test_last_raw
wrote raw short buffer to last flash page
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
>
nucleo-l152re (stm32) OK
test_last_raw

>  test_last_raw
wrote raw short buffer to last flash page
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
>

frdm-kw41z (kinetis) OK
> test_last_raw

>  test_last_raw
wrote raw short buffer to last flash page
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
>
z1 (msp430) OK (with patch)
> test_last_raw

>  test_last_raw
The last page holds the ISR vector, so test page 101
wrote raw short buffer to last flash page
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
> help
 help
Command              Description
---------------------------------------
info                 Show information about pages
dump                 Dump the selected page to STDOUT
dump_local           Dump the local page buffer to STDOUT
read                 Copy the given page to the local page buffer and dump to STDOUT
write_raw            Write (ASCII, max 64B) data to the given address
erase                Erase the given page buffer
edit                 Write bytes to the local page buffer
test_last_raw        Write and verify raw short write on last page available
>

@fjmolinas
Copy link
Copy Markdown
Contributor

@basilfx @benpicco have efm32 I think.

@bergzand
Copy link
Copy Markdown
Member Author

bergzand commented Nov 9, 2020

why not simply rather call it periph_flash ?
Then the new pagewise variant would be called periph_flash_pagewise.

I fully agree! Anything against this? I can do the rename tomorrow during the sprint day.

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Nov 9, 2020

Anything against this?

Only thing I see is that it would be a massive api change: I think that all functions in the API and files, and includes would have to be renamed as well (flashpage_write => flash_write, periph/flashpage.h => periph/flash.h etc).
But I'm not against it.

@bergzand
Copy link
Copy Markdown
Member Author

bergzand commented Nov 9, 2020

Only thing I see is that it would be a massive api change: I think that all functions in the API and files, and includes would have to be renamed as well (flashpage_write => flash_write, periph/flashpage.h => periph/flash.h etc).

I already had to rename all functions because of the flashpage_writeflashpage_write_page, I think I can manage a few more renames :)

@bergzand bergzand force-pushed the pr/flashpage/merge_raw branch from 5d25f04 to 63c39fd Compare November 10, 2020 09:13
@bergzand
Copy link
Copy Markdown
Member Author

rebased to exclude the commit from #15410

@bergzand
Copy link
Copy Markdown
Member Author

Only thing I see is that it would be a massive api change: I think that all functions in the API and files, and includes would have to be renamed as well (flashpage_write => flash_write, periph/flashpage.h => periph/flash.h etc).

Decided offline to postpone this to a future PR.

@bergzand
Copy link
Copy Markdown
Member Author

needs a rebase wink

Rebased!

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.

looks good, mostly mechanical translations

* block is always FLASHPAGE_SIZE.
*/
#define FLASHPAGE_RAW_BLOCKSIZE (4U)
#define FLASHPAGE_BLOCK_SIZE (4U)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since you are doing a rename anyway, how about calling this FLASHPAGE_WRITE_BLOCK_SIZE

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

flashpage_write_raw(page_addr, data, FLASHPAGE_SIZE);
flashpage_write(page_addr, data, FLASHPAGE_SIZE);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can now have a generic flashpage_write_page() implementation in drivers/periph_common/flashpage.c

void flashpage_write_page(unsigned page, const void *data)
{
    assert((unsigned) page < FLASHPAGE_NUMOF);

    flashpage_erase(page);

    /* write page */
    if (data != NULL) {
        flashpage_write(flashpage_addr(page), data, FLASHPAGE_SIZE);
    }
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good idea. I can add this here (or in a follow up) and guard it to only include it when FLASHPAGE_SIZE is available (it is not available on the stm32f{2,4,7}) and allow CPU implementations to override it if they have an optimized version available.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done and deduplicated

@benpicco
Copy link
Copy Markdown
Contributor

Please squash!

@bergzand bergzand force-pushed the pr/flashpage/merge_raw branch from 257a4f2 to f4dda1a Compare November 11, 2020 16:48
@bergzand
Copy link
Copy Markdown
Member Author

Please squash!

Squashed!

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 11, 2020
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.

looks good to me.
I check all the patches and there are only mechanical changes / renames.

flashpage currently requires pagewise implementation with an optional
extension for per block writes (flashpage_raw). Most implementations
with flashpage_raw implement the pagewise access via the flashpage_raw
functions. This commit makes the flashpage raw the main access method
and adds an extension feature for the pagewise access.

The functions and defines are renamed to reflect this. The API is also
extended with a dedicated function for erasing a sector.
@bergzand bergzand force-pushed the pr/flashpage/merge_raw branch 3 times, most recently from 395198d to 411c690 Compare November 11, 2020 21:42
@bergzand bergzand force-pushed the pr/flashpage/merge_raw branch from 411c690 to 7222239 Compare November 11, 2020 22:16
@benpicco benpicco merged commit d9598a0 into RIOT-OS:master Nov 12, 2020
@bergzand
Copy link
Copy Markdown
Member Author

Thanks for reviewing!

@benpicco
Copy link
Copy Markdown
Contributor

So can we drop all the !CONFIG_RIOTBOOT_FLASHWRITE_RAW code now that it's unused?

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 Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants