<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://www.baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2024:11:24</title>
        <description></description>
        <link>https://www.baszerr.eu/</link>
        <lastBuildDate>Wed, 06 May 2026 07:55:05 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://www.baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://www.baszerr.eu/</link>
        </image>
        <item>
            <title>2024-11-24_-_remote_flashing_embedded_device</title>
            <link>https://www.baszerr.eu/doku.php?id=blog:2024:11:24:2024-11-24_-_remote_flashing_embedded_device</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;remote_flashing_embedded_device&quot;&gt;2024-11-24 - remote flashing embedded device&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
recently, when working on &lt;a href=&quot;https://github.com/el-bart/yals&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/el-bart/yals&quot; rel=&quot;ugc nofollow&quot;&gt;YALS&lt;/a&gt; pet-project, i had a need to flash the board via attached programmer… but in such a way that would not back-feed 12V to my PC, in case i mess sth up in wiring / design. the answer was simple – just use &lt;a href=&quot;https://en.wikipedia.org/wiki/single board computer&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/single board computer&quot;&gt;SBC&lt;/a&gt; with WiFi, that can be considered disposable, in case of a hard-failure.
&lt;/p&gt;

&lt;p&gt;
my weapon of choice was &lt;a href=&quot;https://en.wikipedia.org/wiki/Raspberry Pi&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Raspberry Pi&quot;&gt;raspberry pi zero W&lt;/a&gt;, as it&amp;#039;s:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; small&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; cheap&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; WiFi-enabled&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; can natively support SWD for &lt;a href=&quot;https://en.wikipedia.org/wiki/RP2040&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/RP2040&quot;&gt;RP2040&lt;/a&gt; flashing&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
i must say – it worked like a charm! :) at the end of the day i managed to not release any magic smoke from either of the boards. yet stil knowing that i have a proper, physical isolation between my PC and test circuitry kept my mind calm and allowed me to focus on the real deal.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://www.baszerr.eu/lib/exe/detail.php?id=blog%3A2024%3A11%3A24%3A2024-11-24_-_remote_flashing_embedded_device&amp;amp;media=blog:2024:11:24:yals_rp-prog.jpg&quot; class=&quot;media&quot; title=&quot;blog:2024:11:24:yals_rp-prog.jpg&quot;&gt;&lt;img src=&quot;https://www.baszerr.eu/lib/exe/fetch.php?media=blog:2024:11:24:yals_rp-prog.jpg&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;RasPi Zero W as WiFi-enabled SWD flashing tool&quot; alt=&quot;RasPi Zero W as WiFi-enabled SWD flashing tool&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 24 Nov 2024 20:19:35 +0000</pubDate>
        </item>
        <item>
            <title>2024-11-24_-_unbricking_rp2040_from_watchdog_reset_loop</title>
            <link>https://www.baszerr.eu/doku.php?id=blog:2024:11:24:2024-11-24_-_unbricking_rp2040_from_watchdog_reset_loop</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;unbricking_rp2040_from_watchdog_reset_loop&quot;&gt;2024-11-24 - unbricking rp2040 from watchdog reset loop&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
recently, when working on &lt;a href=&quot;https://github.com/el-bart/yals&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/el-bart/yals&quot; rel=&quot;ugc nofollow&quot;&gt;YALS&lt;/a&gt; (&lt;a href=&quot;https://www.baszerr.eu/doku.php?id=blog:2024:11:24:2024-11-24_-_yet_another_linear_servo&quot; class=&quot;wikilink1&quot; title=&quot;blog:2024:11:24:2024-11-24_-_yet_another_linear_servo&quot; data-wiki-id=&quot;blog:2024:11:24:2024-11-24_-_yet_another_linear_servo&quot;&gt;more info on the project here&lt;/a&gt;), i found myself in an odd situation. on the last day of coding SW for it, as the very last feature, i&amp;#039;ve added watchdog support. device has a real-time processing cycle of 4ms, so i decided that watchdog should fire if we miss it 10x, as this should be fast enough prevent any observable effects, yet long enough to make sure a micro glitch would throw thing of the course.
&lt;/p&gt;

&lt;p&gt;
after writing a small &lt;a href=&quot;https://en.wikipedia.org/wiki/Hardware abstraction layer&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Hardware abstraction layer&quot;&gt;HAL&lt;/a&gt;, i wrote a manual test application, just to see if it worked. so the app just printed how long it will sleep before resetting watchdog… and finally, when it reached 40ms, watchdog kicked in, and application started all over again. brain-dead simple… and a bit of a trap! now it reset all the time. w/o a way to stop it… and i was not able to flash it again, since OpenOCD flashing required more time to start the process, than i had available between watchdog resets.
&lt;/p&gt;

&lt;p&gt;
but wait – you may know that &lt;a href=&quot;https://en.wikipedia.org/wiki/RP2040&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/RP2040&quot;&gt;RP2040&lt;/a&gt; is unbricable by design, right? you can always press the &lt;code&gt;boot&lt;/code&gt; button and upload a different &lt;code&gt;*.uf2&lt;/code&gt; file to unbrick it. easy as that… except that YALS, due to space constraints, does not have USB. whoopsee… so the fun begun!
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;2024-11-24 - unbricking rp2040 from watchdog reset loop&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;unbricking_rp2040_from_watchdog_reset_loop&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-1420&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;take_1bruteforce&quot;&gt;take 1: bruteforce&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
the first attempt was simple – just run:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;!&lt;/span&gt; rp2040_openocd &lt;span class=&quot;re5&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;program hello_world.elf verify reset exit&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;kw2&quot;&gt;date&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;done&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
…and pray. while it was running i started to read and think about a different take on my problem.
&lt;/p&gt;

&lt;p&gt;
turned out that i was fortunate enough to setup watchdog just long enough, that i finally managed to grab a window of opportunity and flash a small program. it took a while, but proved it&amp;#039;s possible. that kept my mind at peace. through the journey to find a better way out.
&lt;/p&gt;

&lt;p&gt;
btw: i&amp;#039;m using &lt;a href=&quot;https://github.com/el-bart/rp2040_sdk&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/el-bart/rp2040_sdk&quot; rel=&quot;ugc nofollow&quot;&gt;rp2040 SDK&lt;/a&gt; project for all the steps here.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;take 1: bruteforce&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;take_1bruteforce&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;1421-2077&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;take_2gdb&quot;&gt;take 2: gdb&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
while it turned out to be exceptionally difficult to do bruteforce-flashing hack, it turned out that it&amp;#039;s ok to connect &lt;code&gt;openocd&lt;/code&gt; to a running system, and not lost it when watchdog resets CPU. that was a big foot in the doors. next good news is that stopping CPU by attaching to a process also stopped watchdog timer. the bad news was that this mode also prevented flashing…
&lt;/p&gt;

&lt;p&gt;
so the next life hack was to start &lt;code&gt;gdb&lt;/code&gt;, then &lt;code&gt;load&lt;/code&gt; new program into the RAM (note that flash is still unchanged). the bad news is that it still kept watchdog running…
&lt;/p&gt;

&lt;p&gt;
that&amp;#039;s where rp2040 HAL sources came in handy! watchdog lives in a register that&amp;#039;s mapped to RAM address &lt;code&gt;0x40058000&lt;/code&gt;, at bit 30. so the way to top watchdog (during this run) is to one a terminal and run &lt;code&gt;openocd&lt;/code&gt;:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;rp2040_openocd&lt;/pre&gt;

&lt;p&gt;
and then in another one launch &lt;code&gt;gdb&lt;/code&gt; and type in the following commands:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;target remote localhost:&lt;span class=&quot;nu0&quot;&gt;3333&lt;/span&gt;
p &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;unsigned&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;0x40058000&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;=&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;
load &lt;span class=&quot;st0&quot;&gt;&amp;quot;hello_world.elf&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw3&quot;&gt;continue&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
what it does is:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; connect to remote target (rp2040)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; clear watchdog-enabled bit (wrote to whole 32-bit word, but who cares?)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;load&lt;/code&gt; some non-watchdog-enabled program&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;continue&lt;/code&gt; it in a background (so that &lt;code&gt;gdb&lt;/code&gt; can be stopped)&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
now i was able to disconnect and use regular &lt;a href=&quot;https://github.com/el-bart/rp2040_sdk/blob/38a3aa69f2cfa809b597c7a96012b0db9f316acf/template/sdk/rp2040_disable_watchdog&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/el-bart/rp2040_sdk/blob/38a3aa69f2cfa809b597c7a96012b0db9f316acf/template/sdk/rp2040_disable_watchdog&quot; rel=&quot;ugc nofollow&quot;&gt;rp2040_flash&lt;/a&gt; to write new program (w/o watchdog reset loop) into flash.
&lt;/p&gt;

&lt;p&gt;
for a brief moment i though this is going to be my safe-house, and wrote a helper &lt;a href=&quot;https://github.com/el-bart/rp2040_sdk/blob/38a3aa69f2cfa809b597c7a96012b0db9f316acf/template/sdk/rp2040_disable_watchdog&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/el-bart/rp2040_sdk/blob/38a3aa69f2cfa809b597c7a96012b0db9f316acf/template/sdk/rp2040_disable_watchdog&quot; rel=&quot;ugc nofollow&quot;&gt;rp2040_load&lt;/a&gt; that automate all of this in a single, simple script, that&amp;#039;s just parametrized with a new &lt;code&gt;*.elf&lt;/code&gt; file to flash.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;take 2: gdb&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;take_2gdb&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;2078-3928&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;take_3make_it_right_with_openocd&quot;&gt;take 3: make it right with openocd&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
so i had a working solution, that was fast and reliable… yet it still smell like a big hack from a mile. can i make it less of a hack? what if &lt;code&gt;openocd&lt;/code&gt; would help sth that could help with that… turned out that it has! there&amp;#039;s a command that can write to arbitrary RAM location… so we can now do watchdog turn-off faster, with a simple:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;rp2040_openocd \
  &lt;span class=&quot;re5&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;init&amp;quot;&lt;/span&gt; \
  &lt;span class=&quot;re5&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;rp2040.core0 mww 0x40058000 0 ; exit&amp;quot;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
for convenience &lt;a href=&quot;https://github.com/el-bart/rp2040_sdk/blob/38a3aa69f2cfa809b597c7a96012b0db9f316acf/template/sdk/rp2040_disable_watchdog&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/el-bart/rp2040_sdk/blob/38a3aa69f2cfa809b597c7a96012b0db9f316acf/template/sdk/rp2040_disable_watchdog&quot; rel=&quot;ugc nofollow&quot;&gt;rp2040_disable_watchdog&lt;/a&gt; was added to SDK, too. now it&amp;#039;s also a default part of &lt;a href=&quot;https://github.com/el-bart/rp2040_sdk/blob/38a3aa69f2cfa809b597c7a96012b0db9f316acf/template/sdk/rp2040_flash&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/el-bart/rp2040_sdk/blob/38a3aa69f2cfa809b597c7a96012b0db9f316acf/template/sdk/rp2040_flash&quot; rel=&quot;ugc nofollow&quot;&gt;rp2040_flash&lt;/a&gt; to make sure watchdog never bothers developer again.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;take 3: make it right with openocd&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;take_3make_it_right_with_openocd&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;3929-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 24 Nov 2024 20:58:35 +0000</pubDate>
        </item>
        <item>
            <title>2024-11-24_-_yet_another_linear_servo</title>
            <link>https://www.baszerr.eu/doku.php?id=blog:2024:11:24:2024-11-24_-_yet_another_linear_servo</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;yet_another_linear_servo&quot;&gt;2024-11-24 - Yet Another Linear Servo&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;https://www.baszerr.eu/lib/exe/detail.php?id=blog%3A2024%3A11%3A24%3A2024-11-24_-_yet_another_linear_servo&amp;amp;media=blog:2024:11:24:yals.jpg&quot; class=&quot;media&quot; title=&quot;blog:2024:11:24:yals.jpg&quot;&gt;&lt;img src=&quot;https://www.baszerr.eu/lib/exe/fetch.php?w=800&amp;amp;tok=1d2f03&amp;amp;media=blog:2024:11:24:yals.jpg&quot; class=&quot;mediaright&quot; align=&quot;right&quot; loading=&quot;lazy&quot; title=&quot;YALS&amp;#039; prototype&quot; alt=&quot;YALS&amp;#039; prototype&quot; width=&quot;800&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
recently had some time off and decided to push forward one of my pet-projects: &lt;a href=&quot;https://github.com/el-bart/yals&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/el-bart/yals&quot; rel=&quot;ugc nofollow&quot;&gt;YALS&lt;/a&gt;. &lt;abbr title=&quot;Too long; didn&amp;#039;t read&quot;&gt;TL;DR&lt;/abbr&gt; recently i needed a good linear servo for another project. some key aspects were:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; non-backdriveable (so that it does not consume current when not moving)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; digital controlled with feedback (controllable from host, with telemetry, etc.)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; big throw (here: 100mm)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; ease of adding magnetic coupling (if needed)&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
this was an interesting experience as it was the 1st time i&amp;#039;ve designed &lt;a href=&quot;https://en.wikipedia.org/wiki/RP2040&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/RP2040&quot;&gt;RP2040&lt;/a&gt;-based HW platform and wrote a bigger piece of code for it (~5&lt;a href=&quot;https://en.wikipedia.org/wiki/Source_lines_of_code&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Source_lines_of_code&quot;&gt;KLOC&lt;/a&gt;). on top of that it also used a cheap &lt;a href=&quot;https://en.wikipedia.org/wiki/single board computer&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/single board computer&quot;&gt;SBC&lt;/a&gt; for &lt;a href=&quot;https://www.baszerr.eu/doku.php?id=blog:2024:11:24:2024-11-24_-_remote_flashing_embedded_device&quot; class=&quot;wikilink1&quot; title=&quot;blog:2024:11:24:2024-11-24_-_remote_flashing_embedded_device&quot; data-wiki-id=&quot;blog:2024:11:24:2024-11-24_-_remote_flashing_embedded_device&quot;&gt;programming remotely&lt;/a&gt; (over WiFi), to make sure that high-current 12V power supply won&amp;#039;t by accident backfire over 5V TTL logic wires to a PC. it was also an &lt;a href=&quot;https://www.baszerr.eu/doku.php?id=blog:2024:11:24:2024-11-24_-_unbricking_rp2040_from_watchdog_reset_loop&quot; class=&quot;wikilink1&quot; title=&quot;blog:2024:11:24:2024-11-24_-_unbricking_rp2040_from_watchdog_reset_loop&quot; data-wiki-id=&quot;blog:2024:11:24:2024-11-24_-_unbricking_rp2040_from_watchdog_reset_loop&quot;&gt;interesting experience to unbrick CPU from watchdog reset loop&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
after ~week of full-throttle fun, the project has now reached &lt;code&gt;v0.3&lt;/code&gt; with all key elements working and tested! :D
&lt;/p&gt;

&lt;p&gt;
the only exception atm is EEPROM, that for some magic reason seems to get stuck when writing (failed batch?). that will require some more investigations, but fortunately it&amp;#039;s not crucial for functioning of the servo.
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 24 Nov 2024 20:59:07 +0000</pubDate>
        </item>
    </channel>
</rss>
