Skip to content

drivers: STM32 async flash erase and write #93173

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jpowen898
Copy link

  • Implemented async flash erase and writes using the STM32 hal HAL_FLASHEx_Erase_IT() and HAL_FLASH_Program_IT() functions with their associated interrupt handler.
  • I only implemented this for the h7, l4, and f4 stm32 families because that is the hardware I had available to test on.
  • Async flash transactions can be enabled using the FLASH_STM32_ASYNC config option.
  • Async transactions are implemented using a semaphore which blocks while waiting for the flash IRQ to indicate the end of a flash transaction. This allows other threads to take action while flash erase and write actions are taking place.

Copy link

Hello @jpowen898, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@jpowen898 jpowen898 force-pushed the main branch 2 times, most recently from c34e153 to ae67109 Compare July 16, 2025 14:49
@jpowen898
Copy link
Author

@nordicjm Thanks for the feedback. I made all the requested changes, let me know if there is anything else.

@zephyrbot zephyrbot requested a review from etienne-lms July 17, 2025 16:05
@jpowen898 jpowen898 force-pushed the main branch 2 times, most recently from 9129568 to b5d3812 Compare July 17, 2025 16:13
@jpowen898 jpowen898 requested a review from nordicjm July 17, 2025 16:16
@de-nordic de-nordic assigned erwango and unassigned de-nordic Jul 17, 2025
@erwango erwango added this to the v4.3.0 milestone Jul 18, 2025
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.

As a general comment, please follow existing code style in this driver (and zephyr code base generally): break a line between code blocks.

Then it would be interesting to introduce this new feature into doc/releases/release-notes-4.3.rst

Comment on lines +74 to +88
FLASH_STM32_PRIV(dev)->async_complete = false;
FLASH_STM32_PRIV(dev)->async_error = false;
HAL_FLASH_Program_IT(FLASH_TYPEPROGRAM_DOUBLEWORD, offset + FLASH_STM32_BASE_ADDRESS, val);
k_sem_take(&FLASH_STM32_PRIV(dev)->async_sem, K_FOREVER);
if (FLASH_STM32_PRIV(dev)->async_complete) {
LOG_DBG("Flash write successful. Wrote 0x%llx at 0x%lx",
val, offset + FLASH_STM32_BASE_ADDRESS);
rc = 0;
} else {
if (FLASH_STM32_PRIV(dev)->async_error) {
LOG_ERR("Flash write failed %d", FLASH_STM32_PRIV(dev)->async_ret);
}
rc = -EIO;
}
Copy link
Member

Choose a reason for hiding this comment

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

Break a line between code blocks.
Apply everywhere.

Copy link
Author

Choose a reason for hiding this comment

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

I wasn't 100% sure what you were looking for but I added line breaks before #if, and after #else and #endif. Let me know if that is not what you were looking for or if you wanted line breaks before and after #else or something else.

Added optional use of the stm32 hal async flash write and erase
capabilities on the l4, f4, and h7 soc families. It is implemented
using semaphores to allow for other threads to take action during
the erase/write actions. This feature is disabled by default and
can be optionally enabled using the FLASH_STM32_ASYNC config option.

Signed-off-by: Parker Owen <jpowen898@gmail.com>
Copy link

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.

5 participants