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

drivers: flash: stm32: expose stm32 option byte apis #82079

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

fabiobaltieri
Copy link
Member

@fabiobaltieri fabiobaltieri commented Nov 26, 2024

The STM32 flash driver includes some APIs to lock/unlock/set the option bytes. Make these public so that an application can use them to tweak option bytes as needed, add a read api as well.

Allows doing stuff like

        uint32_t val = flash_stm32_option_bytes_read(flash);
        printk("optb=%08x\n", val);

        if (val & FLASH_OPTR_nSWBOOT0_Msk) {
                printk("flip");

                ret = flash_stm32_option_bytes_lock(flash, false);
                if (ret < 0) {
                        printk("unlock failed %d\n", ret);
                        return -1;
                }

                ret = flash_stm32_option_bytes_write(flash, FLASH_OPTR_nSWBOOT0_Msk, 0);
                if (ret < 0) {
                        printk("write failed %d\n", ret);
                        return -1;
                }

                ret = flash_stm32_option_bytes_lock(flash, true);
                if (ret < 0) {
                        printk("lock failed %d\n", ret);
                        return -1;
                }

                printk("done\n");
        }

@fabiobaltieri fabiobaltieri force-pushed the st-flash-optb branch 4 times, most recently from 59b629f to 385bb3a Compare November 26, 2024 18:25
@fabiobaltieri fabiobaltieri changed the title drivers: flash: stm32: expose flash_stm32_write_optb drivers: flash: stm32: expose stm32 option byte apis Nov 26, 2024
@fabiobaltieri fabiobaltieri force-pushed the st-flash-optb branch 4 times, most recently from c958ffb to 5b8d8a2 Compare November 27, 2024 15:39
@fabiobaltieri fabiobaltieri marked this pull request as ready for review November 27, 2024 21:33
@fabiobaltieri fabiobaltieri assigned erwango and unassigned de-nordic Nov 27, 2024
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

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

Thanks @fabiobaltieri.

Looks fine, but however, I wonder if, for consistency sake, these APIs shouldn't be made available through already existing flash_ex_op() api, which is there to expose flash controller specific features ?

Agreed this would be slightly more complex to implement and likely consume more footprint, but I think consistency is key for users.

Alternatively, if there are good reasons not to use flash_ex_op(), let's make it explicit.

@fabiobaltieri
Copy link
Member Author

Looks fine, but however, I wonder if, for consistency sake, these APIs shouldn't be made available through already existing flash_ex_op() api, which is there to expose flash controller specific features ?

Oh that makes load of sense, yeah thanks for the pointer I'll move this back to draft and rework it.

@fabiobaltieri fabiobaltieri marked this pull request as draft November 28, 2024 10:50
Add missing include guards to flash_stm32.h.

Signed-off-by: Fabio Baltieri <[email protected]>
Add two new flash extended operations for reading and writing STM32
option bytes from the application code.

Signed-off-by: Fabio Baltieri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants