<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style="--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>
GitLab
</title>

<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>

<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: hsla(0,0%,100%,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style="font-size: inherit; -webkit-text-shadow: hsla(0,0%,100%,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";">
<div class="content">

<p style="color: #777777;">
<a href="https://gitlab.rtems.org/TheSamPrice">Sam Price</a>
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1555#note_161772">commented</a>:
</p>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">For reviewers, here is where the same sequence appears elsewhere. Links are pinned to the current upstream commits.</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial"><strong style="font-weight: 600; margin-top: 0px;">ESP32-C3 Technical Reference Manual v1.4</strong> (<a href="https://documentation.espressif.com/esp32-c3_technical_reference_manual_en.pdf" rel="nofollow noreferrer noopener" target="_blank">PDF</a>), Chapter 12, Watchdog Timers:</p>
<ul dir="auto" style="text-align: initial; list-style-type: disc; margin: 0px 0px 1rem; padding: 0;">
<li style="margin-top: 0px; line-height: 1.6em; margin-left: 25px; padding-left: 3px;">§12.1, p. 305: RWDT and timer group 0's MWDT are enabled automatically during flash boot.</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">§12.2.2.3, Write Protection, pp. 308–309: each watchdog has its own key field (<code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">TIMG_WDT_WKEY</code>, <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">RTC_CNTL_WDT_WKEY</code>). Writes are ignored until 0x50D83AA1 is written there, and the procedure ends by writing any other value to lock it again.</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">§12.2.2.4, Flash Boot Protection, p. 309: "After booting, TIMG_WDT_FLASHBOOT_MOD_EN and RTC_CNTL_WDT_FLASHBOOT_MOD_EN should be cleared to stop the flash boot protection procedure."</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">§12.3, Super Watchdog, pp. 309–310: the 0x8F1D312A key and <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">RTC_CNTL_SWD_AUTO_FEED_EN</code>.</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">Register 11.10, <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">TIMG_WDTCONFIG0_REG</code>, p. 298: <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">TIMG_WDT_CONF_UPDATE_EN</code>, "Updates the WDT configuration registers."</li>
</ul>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial"><strong style="font-weight: 600; margin-top: 0px;">ESP-IDF</strong>, what its second-stage bootloader does before an application runs. This is why ESP-IDF applications never hit the bug and a direct-boot image like this BSP does:</p>
<ul dir="auto" style="text-align: initial; list-style-type: disc; margin: 0px 0px 1rem; padding: 0;">
<li style="margin-top: 0px; line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<a href="https://github.com/espressif/esp-idf/blob/0e6b480f858c69862ffb6001d96e9eef74599a6e/components/bootloader_support/src/bootloader_init.c#L76-L112" rel="nofollow noreferrer noopener" target="_blank" style="margin-top: 0px;"><code style="font-size: 90%; color: inherit; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">bootloader_config_wdt()</code></a>: unlock, clear flash-boot mode, lock, for the RWDT and then MWDT0.</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<a href="https://github.com/espressif/esp-idf/blob/0e6b480f858c69862ffb6001d96e9eef74599a6e/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c#L74-L79" rel="nofollow noreferrer noopener" target="_blank" style="margin-top: 0px;"><code style="font-size: 90%; color: inherit; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">bootloader_super_wdt_auto_feed()</code></a>: unlock, set auto-feed, lock. Both functions are called from the <a href="https://github.com/espressif/esp-idf/blob/0e6b480f858c69862ffb6001d96e9eef74599a6e/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c#L130" rel="nofollow noreferrer noopener" target="_blank">C3 hardware init</a> and <a href="https://github.com/espressif/esp-idf/blob/0e6b480f858c69862ffb6001d96e9eef74599a6e/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c#L186" rel="nofollow noreferrer noopener" target="_blank">later in the same file</a>.</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<a href="https://github.com/espressif/esp-idf/blob/0e6b480f858c69862ffb6001d96e9eef74599a6e/components/esp_hal_wdt/esp32c3/include/hal/mwdt_ll.h#L183-L195" rel="nofollow noreferrer noopener" target="_blank" style="margin-top: 0px;"><code style="font-size: 90%; color: inherit; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">mwdt_ll_set_flashboot_en()</code></a>: clears <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">wdt_flashboot_mod_en</code> and then sets <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">wdt_conf_update_en</code>, because "Config registers are updated asynchronously".</li>
</ul>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial"><strong style="font-weight: 600; margin-top: 0px;">NuttX</strong>, <a href="https://github.com/apache/nuttx/blob/5eca74f254c8d32847179f6ebbd5a6e4b588bec0/arch/risc-v/src/common/espressif/esp_start.c" rel="nofollow noreferrer noopener" target="_blank"><code style="font-size: 90%; color: inherit; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">esp_start.c</code></a>: in simple-boot mode (no second-stage bootloader, as here) it <a href="https://github.com/apache/nuttx/blob/5eca74f254c8d32847179f6ebbd5a6e4b588bec0/arch/risc-v/src/common/espressif/esp_start.c#L517-L523" rel="nofollow noreferrer noopener" target="_blank">calls ESP-IDF's <code style="font-size: 90%; color: inherit; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">bootloader_init()</code></a>, which runs the functions above. Before <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">nx_start()</code> it also <a href="https://github.com/apache/nuttx/blob/5eca74f254c8d32847179f6ebbd5a6e4b588bec0/arch/risc-v/src/common/espressif/esp_start.c#L666-L676" rel="nofollow noreferrer noopener" target="_blank">clears the RWDT's flash-boot mode and disables it, under the key</a>.</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial"><strong style="font-weight: 600; margin-top: 0px;">Zephyr</strong>, <a href="https://github.com/zephyrproject-rtos/zephyr/blob/d1b8eec76bfd14058854245d09aa1e413e355c4a/soc/espressif/esp32c3/hw_init.c" rel="nofollow noreferrer noopener" target="_blank"><code style="font-size: 90%; color: inherit; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">soc/espressif/esp32c3/hw_init.c</code></a>: its no-bootloader path calls <a href="https://github.com/zephyrproject-rtos/zephyr/blob/d1b8eec76bfd14058854245d09aa1e413e355c4a/soc/espressif/esp32c3/hw_init.c#L36" rel="nofollow noreferrer noopener" target="_blank"><code style="font-size: 90%; color: inherit; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">super_wdt_auto_feed()</code></a> and <a href="https://github.com/zephyrproject-rtos/zephyr/blob/d1b8eec76bfd14058854245d09aa1e413e355c4a/soc/espressif/esp32c3/hw_init.c#L91" rel="nofollow noreferrer noopener" target="_blank"><code style="font-size: 90%; color: inherit; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">config_wdt()</code></a>. The implementations live in Espressif's HAL module for Zephyr.</p>
<p dir="auto" style="color: #3a383f; margin: 0px;" align="initial">The second commit, <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/commit/ffb50e00c9775fcdeeaf5e2f835025235fdbf11d" title="bsps/riscv/esp32: Relock the watchdogs and latch the MWDT change" class="gfm gfm-commit has-tooltip" data-original="ffb50e00c9" data-link="false" data-link-reference="false" data-commit="ffb50e00c9775fcdeeaf5e2f835025235fdbf11d" data-project="26" data-project-path="rtems/rtos/rtems" data-container="body" data-placement="top" data-reference-type="commit" style="font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; font-size: 95%; margin-top: 0px;">ffb50e00</a>, brings this MR in line with those implementations. It locks each watchdog again after changing it, and it sets <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">TIMG_WDT_CONF_UPDATE_EN</code> after writing <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">TIMG_WDTCONFIG0</code>. It builds with no warnings but hasn't been run on hardware yet; I'll report back when it has. The first commit is the one that was tested on hardware.</p>
</div>


</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">
—
<br>
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1555#note_161772">View it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.rtems.org">gitlab.rtems.org</a>. <a href="https://gitlab.rtems.org/-/namespace/49/sent_notifications/6-dfms6yjqcpvecsdsu7e2tuazn-1d/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.rtems.org/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.rtems.org/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1555#note_161772 at 1793680825
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Merge request","url":"https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1555#note_161772"}}</script>


</p>
</div>
</body>
</html>