<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
 xmlns:blogChannel="http://backend.userland.com/blogChannelModule"
>

<channel>
<title><![CDATA[Dobrica Pavlinušić's random unstructured stuff: STM32]]></title>
<link>https://saturn.ffzg.hr/rot13/index.cgi?action=weblog_display;category=STM32</link>
<description></description>
<pubDate>Sun, 08 Aug 2021 07:52:55 -0000</pubDate>
<webMaster>root@saturn.ffzg.hr</webMaster>
<generator>Socialtext Workspace v2.19.0.2</generator>

<item>
<title><![CDATA[Blue Pill]]></title>
<link>https://saturn.ffzg.hr/rot13/index.cgi?blue_pill</link>
<description><![CDATA[<div>Creator: Dobrica Pavlinušić</div><hr/><div>Tags: stm32</div><hr/><div class="wiki">
<span class="nlw_phrase"><a href="https://saturn.ffzg.hr/rot13/index.cgi/The-Generic-STM32F103-Pinout-Diagram.pdf?action=attachments_download;page_name=blue_pill;id=20201206115233-0-25777">The-Generic-STM32F103-Pinout-Diagram.pdf</a><!-- wiki: {file: The-=Generic-=STM32F103-=Pinout-=Diagram.pdf} --></span><br /><br /><div class="nlw_phrase"><table class="wafl_container">
  <tr>
    <td>
      <div class="wafl_box">
        
          <div class="wafl_titlebox">
            <div class="wafl_title">
              
                Contents: [Dobrica Pavlinušić's random unstructured stuff]
              
            </div>
          </div>
          <div class="wafl_items">
            
              <div class="wiki">
<ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#arduino_boot_loader">Dobrica Pavlinušić's random unstructured stuff (arduino boot loader)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] arduino boot loader} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#triple_usb_serial">Dobrica Pavlinušić's random unstructured stuff (triple usb serial)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] triple usb serial} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#pill_serial">Dobrica Pavlinušić's random unstructured stuff (pill_serial)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] pill_serial} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#bluepill_serial_monster">Dobrica Pavlinušić's random unstructured stuff (bluepill-serial-monster)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] bluepill-=serial-=monster} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#openocd_with_raspberry_pi">Dobrica Pavlinušić's random unstructured stuff (openocd with raspberry pi)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] openocd with raspberry pi} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#clones">Dobrica Pavlinušić's random unstructured stuff (clones)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] clones} --></span></li>
</ul>
</div>

            
            
          </div>
        
      </div>
    </td>
  </tr>
</table>
<!-- wiki: {toc: }
--></div><br /><br /><p>
stm32f103 board</p>
<h1 id="arduino_boot_loader">arduino boot loader</h1>
<ul>
<li><a target="_blank" title="(external link)" href="https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Flashing-Bootloader-for-BluePill-Boards">https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Flashing-Bootloader-for-BluePill-Boards</a></li>
</ul>
<h1 id="triple_usb_serial">triple usb serial</h1>
<h2 id="pill_serial">pill_serial</h2>
<ul>
<li><a target="_blank" title="(external link)" href="https://satoshinm.github.io/blog/171223_stm32serial_triple_usb-to-serial_adapter_using_stm32_blue_pill.html">https://satoshinm.github.io/blog/171223_stm32serial_triple_usb-to-serial_adapter_using_stm32_blue_pill.html</a></li>
<li><a target="_blank" title="(external link)" href="https://github.com/satoshinm/pill_serial">https://github.com/satoshinm/pill_serial</a></li>
</ul>
<table style="border-collapse: collapse;" class="formatter_table">
<tr>
<td style="border: 1px solid black;padding: .2em;">Function</td>
<td style="border: 1px solid black;padding: .2em;">Pin and Port</td>
</tr>
<tr>
<td style="border: 1px solid black;padding: .2em;">USART3 TX</td>
<td style="border: 1px solid black;padding: .2em;">PB10</td>
</tr>
<tr>
<td style="border: 1px solid black;padding: .2em;">USART3 RX</td>
<td style="border: 1px solid black;padding: .2em;">PB11</td>
</tr>
<tr>
<td style="border: 1px solid black;padding: .2em;">USART2 TX</td>
<td style="border: 1px solid black;padding: .2em;">PA2</td>
</tr>
<tr>
<td style="border: 1px solid black;padding: .2em;">USART2 RX</td>
<td style="border: 1px solid black;padding: .2em;">PA3</td>
</tr>
<tr>
<td style="border: 1px solid black;padding: .2em;">USART1 TX</td>
<td style="border: 1px solid black;padding: .2em;">PA9</td>
</tr>
<tr>
<td style="border: 1px solid black;padding: .2em;">USART1 RX</td>
<td style="border: 1px solid black;padding: .2em;">PA10</td>
</tr>
</table>
<br /><table style="border-collapse: collapse;" class="formatter_table">
<tr>
<td style="border: 1px solid black;padding: .2em;">USART</td>
<td style="border: 1px solid black;padding: .2em;">TX pin</td>
<td style="border: 1px solid black;padding: .2em;">RX pin</td>
<td style="border: 1px solid black;padding: .2em;">special</td>
<td style="border: 1px solid black;padding: .2em;">speed</td>
<td style="border: 1px solid black;padding: .2em;">sensor</td>
<td style="border: 1px solid black;padding: .2em;">linux</td>
</tr>
<tr>
<td style="border: 1px solid black;padding: .2em;">3</td>
<td style="border: 1px solid black;padding: .2em;">PB10</td>
<td style="border: 1px solid black;padding: .2em;">PB11</td>
<td style="border: 1px solid black;padding: .2em;"><span style="padding:.5em">&nbsp;</span></td>
<td style="border: 1px solid black;padding: .2em;">9600</td>
<td style="border: 1px solid black;padding: .2em;"><a href="https://saturn.ffzg.hr/rot13/index.cgi?mh_z19b" title="(77 months)  Product model number MH-Z19B Gas Detection Carbon Dioxide Supply voltage 4.5 5.5V DC Average curren...">MH-Z19B</a></td>
<td style="border: 1px solid black;padding: .2em;">/dev/ttyACM1</td>
</tr>
<tr>
<td style="border: 1px solid black;padding: .2em;">2</td>
<td style="border: 1px solid black;padding: .2em;">PA2</td>
<td style="border: 1px solid black;padding: .2em;">PA3</td>
<td style="border: 1px solid black;padding: .2em;"><span style="padding:.5em">&nbsp;</span></td>
<td style="border: 1px solid black;padding: .2em;">9600</td>
<td style="border: 1px solid black;padding: .2em;"><span style="padding:.5em">&nbsp;</span></td>
<td style="border: 1px solid black;padding: .2em;"><span style="padding:.5em">&nbsp;</span></td>
</tr>
<tr>
<td style="border: 1px solid black;padding: .2em;">1</td>
<td style="border: 1px solid black;padding: .2em;">PA9</td>
<td style="border: 1px solid black;padding: .2em;">PA10</td>
<td style="border: 1px solid black;padding: .2em;">BOOT=0</td>
<td style="border: 1px solid black;padding: .2em;">9600</td>
<td style="border: 1px solid black;padding: .2em;"><span style="padding:.5em">&nbsp;</span></td>
<td style="border: 1px solid black;padding: .2em;"><span style="padding:.5em">&nbsp;</span></td>
</tr>
</table>
<br /><pre>
dpavlin@nuc:/nuc/stm32/pill_serial$ cat flash.sh
sudo ../stlink/build/Release/st-flash write src/pill_serial.bin 0x08000000
</pre>
<br /><p>
lower serial speed to 9600 so we can use slow sensors on it: <span class="nlw_phrase"><a href="https://saturn.ffzg.hr/rot13/index.cgi/serial-speed.diff?action=attachments_download;page_name=blue_pill;id=20200209104806-1-31164">serial-speed.diff</a><!-- wiki: {file: serial-=speed.diff} --></span></p>
<h2 id="bluepill_serial_monster">bluepill-serial-monster</h2>
<p>
<a target="_blank" title="(external link)" href="https://github.com/r2axz/bluepill-serial-monster">https://github.com/r2axz/bluepill-serial-monster</a></p>
<h1 id="openocd_with_raspberry_pi">openocd with raspberry pi</h1>
<p>
<a target="_blank" title="(external link)" href="http://git.rot13.org/?p=openocd-rpi2-stm32;a=blob;f=openocd-rpi.txt">http://git.rot13.org/?p=openocd-rpi2-stm32;a=blob;f=openocd-rpi.txt</a></p>
<h1 id="clones">clones</h1>
<p>
<a target="_blank" title="(external link)" href="https://github.com/thanks4opensource/buck50/issues/2">https://github.com/thanks4opensource/buck50/issues/2</a></p>
<p>
<a target="_blank" title="(external link)" href="https://github.com/keirf/Greaseweazle/wiki/STM32-Fakes">https://github.com/keirf/Greaseweazle/wiki/STM32-Fakes</a></p>
<pre>
dpavlin@nuc:/nuc/stm32/Greaseweazle$ wget https://github.com/keirf/Greaseweazle/releases/download/v0.22/Greaseweazle-v0.22.zip

dpavlin@nuc:/nuc/stm32/Greaseweazle$ unzip Greaseweazle-v0.22.zip Greaseweazle-v0.22/alt/Blinky_Test-v0.22.hex
Archive:  Greaseweazle-v0.22.zip
  inflating: Greaseweazle-v0.22/alt/Blinky_Test-v0.22.hex
</pre>
<br /><p>
write it to flash using openocd</p>
<pre>
&gt; flash write_image erase /nuc/stm32/Greaseweazle/Greaseweazle-v0.22/alt/Blinky_Test-v0.22.hex 0 ihex
auto erase enabled
wrote 5120 bytes from file /nuc/stm32/Greaseweazle/Greaseweazle-v0.22/alt/Blinky_Test-v0.22.hex in 0.299529s (16.693 KiB/s)
</pre>
<br /><p>
serial output is on the programming interface at pins A9/TX and A10/RX: Not via the USB port!</p>
<pre>
pi@pihdmi:/nuc/stm32/buck50 $ microcom -p /dev/ttyUSB1
connected to /dev/ttyUSB1
Escape character: Ctrl-\
Type the escape character to get to the prompt.

** Blinky
** Blinky Test **
** Keir Fraser &lt;keir.xen@gmail.com&gt;
** https://github.com/keirf/Greaseweazle
Serial = ff48:0670:8967:5655:4740:6706
Flash Size  = 128kB
Device ID = 0x0000
Revision  = 0x0000
Testing I2C1... OK
Testing I2C2... OK
Testing SPI1... OK
Testing SPI2... OK
Testing TIM1... OK
Testing TIM2... OK
Testing TIM3... OK
Testing TIM4... OK
DMA Test #1... OK
DMA Test #2... OK
DMA Test #3... OK
DMA Test #4... OK
Testing 64kB Flash... OK
Enable TIM4 IRQ... .OK
Testing 20kB SRAM (endless loop)................................................................
</pre>
<br /><p>
After flashing this test, you will not be able to address blue pill using openocd.</p>
<p>
To work-around this problem, I switched boot0 jumper, used stm32loader (after pressing reset button) to load alternative binary.</p>
</div>
<hr/><div>Attachments: serial-speed.diff, The-Generic-STM32F103-Pinout-Diagram.pdf</div>]]></description>
<author>Dobrica Pavlinu&#x161;i&#x107;</author>
<category>stm32</category>
<guid isPermaLink="true">https://saturn.ffzg.hr/rot13/index.cgi?blue_pill</guid>
<pubDate>Sun, 08 Aug 2021 07:52:55 -0000</pubDate>
</item>
<item>
<title><![CDATA[Maple r5]]></title>
<link>https://saturn.ffzg.hr/rot13/index.cgi?maple_r5</link>
<description><![CDATA[<div>Creator: Dobrica Pavlinušić</div><hr/><div>Tags: STM32</div><hr/><div class="wiki">
<p>
<a target="_blank" title="(external link)" href="https://github.com/leaflabs/maple/blob/master/maple-r5/maple-r5-schematic.pdf">https://github.com/leaflabs/maple/blob/master/maple-r5/maple-r5-schematic.pdf</a></p>
<div class="nlw_phrase"><table class="wafl_container">
  <tr>
    <td>
      <div class="wafl_box">
        
          <div class="wafl_titlebox">
            <div class="wafl_title">
              
                Contents: [Dobrica Pavlinušić's random unstructured stuff]
              
            </div>
          </div>
          <div class="wafl_items">
            
              <div class="wiki">
<ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#specification">Dobrica Pavlinušić's random unstructured stuff (specification)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] specification} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#serial_flash">Dobrica Pavlinušić's random unstructured stuff (serial flash)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] serial flash} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#maple_boot_loader">Dobrica Pavlinušić's random unstructured stuff (maple boot loader)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] maple boot loader} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#stm32_arduino_upgrade">Dobrica Pavlinušić's random unstructured stuff (STM32 Arduino upgrade)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] STM32 Arduino upgrade} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#bootloader">Dobrica Pavlinušić's random unstructured stuff (bootloader)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] bootloader} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#build">Dobrica Pavlinušić's random unstructured stuff (build)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] build} --></span></li>
</ul></ul>
</div>

            
            
          </div>
        
      </div>
    </td>
  </tr>
</table>
<!-- wiki: {toc: }
--></div><br /><br /><h1 id="specification">specification</h1>
<p>
STM32 F103RB: a 32-bit ARM Cortex M3 microprocessor<br />
Clock Speed: 72 MHz<br />
Operating Voltage: 3.3V<br />
Input Voltage (recommended): 3.0V-12V<br />
39 Digital I/O Pins (GPIO)<br />
16 Analog Input Pins<br />
12-bit ADC resolution (ADC)<br />
15 PWM pins at 16-bit resolution (PWM)<br />
Dedicated USB port for programming and communications (USB)<br />
External JTAG interface (USB)<br />
128 Flash and 20KB SRAM<br />
64 Channel nested vector interrupt handler (including external interrupt on GPIO’s)<br />
Integrated SPI (SPI)<br />
Integrated I2C (I2C)<br />
7 Channels of Direct Memory Access (DMA)<br />
3 USART devices<br />
Four 4-channel Timers (Timers)<br />
Supplies up to 500mA @ 3.3v<br />
Support for low power and sleep modes (&lt;500uA)</p>
<h1 id="serial_flash">serial flash</h1>
<p>
Press boot 0, press reset, release reset, release boot 0</p>
<pre>
dpavlin@nuc:/nuc/stm32$ git clone https://github.com/jsnyder/stm32loader

dpavlin@nuc:/nuc/stm32/stm32loader$ ./stm32loader.py -p /dev/ttyUSB0 
Bootloader version 22
Chip id: 0x410 (STM32 Medium-density)

dpavlin@nuc:/nuc/stm32/stm32loader$ ./stm32loader.py -p /dev/ttyUSB0 -e -w -v maple_rev5_boot20.bin
Bootloader version 22
Chip id: 0x410 (STM32 Medium-density)
Write 256 bytes at 0x8000000
Write 256 bytes at 0x8000100
...
</pre>
<br /><h1 id="maple_boot_loader">maple boot loader</h1>
<pre>
dpavlin@nuc:/nuc/stm32/stm32loader$ wget http://docs.leaflabs.com/static.leaflabs.com/pub/leaflabs/maple-bootloader/maple_boot.bin

dpavlin@nuc:/nuc/stm32/stm32loader$ ./stm32loader.py -p /dev/ttyUSB0 -e -w -v maple_boot.bin

</pre>
<br /><h1 id="stm32_arduino_upgrade">STM32 Arduino upgrade</h1>
<h2 id="bootloader">bootloader</h2>
<ul>
<li><a target="_blank" title="(external link)" href="https://github.com/rogerclarkmelbourne/STM32duino-bootloader">https://github.com/rogerclarkmelbourne/STM32duino-bootloader</a></li>
</ul>
<pre>

dpavlin@nuc:/nuc/stm32/stm32loader$ wget https://github.com/rogerclarkmelbourne/STM32duino-bootloader/raw/master/STM32F1/binaries/maple_rev5_boot20.bin

</pre>
<br /><p>
maple r5 is not reported with dfu-util</p>
<p>
<a target="_blank" title="(external link)" href="https://github.com/rogerclarkmelbourne/STM32duino-bootloader/pull/20">https://github.com/rogerclarkmelbourne/STM32duino-bootloader/pull/20</a></p>
<h2 id="build">build</h2>
<pre>
dpavlin@nuc:/nuc/stm32/STM32duino-bootloader$ make maple-rev5

...

Copying to binaries folder

cp build/maple_boot.bin bootloader_only_binaries/maple_rev5_boot20.bin

</pre>
</div>
<hr/><div>Attachments: maple-r5-schematic.pdf</div>]]></description>
<author>Dobrica Pavlinu&#x161;i&#x107;</author>
<category>STM32</category>
<guid isPermaLink="true">https://saturn.ffzg.hr/rot13/index.cgi?maple_r5</guid>
<pubDate>Mon, 21 Jan 2019 20:00:39 -0000</pubDate>
</item>
<item>
<title><![CDATA[FST-01]]></title>
<link>https://saturn.ffzg.hr/rot13/index.cgi?fst_01</link>
<description><![CDATA[<div>Creator: Dobrica Pavlinušić</div><hr/><div>Tags: hardware, STM32</div><hr/><div class="wiki">
<ul>
<li><a target="_blank" title="(external link)" href="http://www.seeedstudio.com/wiki/FST-01">http://www.seeedstudio.com/wiki/FST-01</a></li>
<li><a target="_blank" title="(external link)" href="https://gitorious.org/gnuk">https://gitorious.org/gnuk</a></li>
<li><a target="_blank" title="(external link)" href="http://www.fsij.org/doc-gnuk/index.html">http://www.fsij.org/doc-gnuk/index.html</a></li>
<li>build one from ST-Link clone <a target="_blank" title="(external link)" href="https://blog.danman.eu/2-usb-crypto-token-for-use-with-gpg-and-ssh/">https://blog.danman.eu/2-usb-crypto-token-for-use-with-gpg-and-ssh/</a></li>
</ul>
<h1 id="update_vid_and_pid_in_compiled_binary">update vid and pid in compiled binary</h1>
<p>
since version 1.2.8 you need to insert vid and pid into the binary by running</p>
<pre>
make build/gnuk-vidpid.elf
</pre>
<br /><p>
and than flash the resulting gnuk-vidpid.bin binary into your FST-01</p>
<h1 id="swd_flashing_using_st_link_v2">SWD flashing using ST Link v2</h1>
<pre>
usb 1-1.6.4: new full-speed USB device number 16 using ehci-pci
usb 1-1.6.4: New USB device found, idVendor=0483, idProduct=3748
usb 1-1.6.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1.6.4: Product: STM32 STLink
usb 1-1.6.4: Manufacturer: STMicroelectronics
usb 1-1.6.4: SerialNumber: Qÿl^FH&lt;85&gt;PH'Q^C&lt;87&gt;
</pre>
<br /><ul>
<li><a target="_blank" title="(external link)" href="http://www.gniibe.org/memo/development/fst-01/dongle/fst-01-swd-connection">http://www.gniibe.org/memo/development/fst-01/dongle/fst-01-swd-connection</a></li>
<li><a target="_blank" title="(external link)" href="http://no-passwd.net/askbot/question/48/how-can-i-re-flash-fst-01/">http://no-passwd.net/askbot/question/48/how-can-i-re-flash-fst-01/</a></li>
</ul>
<p>
Problem:</p>
<pre>
dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk/tool$ ./stlinkv2.py -s
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0002 -&gt; 0001
CORE: 0de01477, CHIP_ID: 00000000
Flash ROM read protection: off
Option bytes: 00000000
Core does not halt, try API V2 halt.
ValueError('Status of core is not halt.', 128)
</pre>
<br /><p>
after several re-runs:</p>
<pre>
dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk/tool$ ./stlinkv2.py -s
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0002 -&gt; 0001
CORE: 1ba01477, CHIP_ID: a0036410
Flash ROM read protection: off
Option bytes: a0036410
Core does not halt, try API V2 halt.
ValueError('Status of core is not halt.', 128)
</pre>
<br /><p>
after a bit of fiddling with cables (it's always cables, right?)</p>
<p>
Lovro contributed that if you are getting continous output like this</p>
<pre>
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0002 -&gt; 0001
Core does not halt, try API V2 halt.
ValueError('Status of core is not halt.', 128)
</pre>
<br /><p>
then run this while holding reset active (hold tweezers on both side of C3)<br />
that should hand the uC in a mode that will enable stlinkv2.py script to turn off the flash rom protection and erase the flash while doing that</p>
<pre>
dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk$ sudo ./tool/stlinkv2.py -s
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0002 -&gt; 0001
CORE: 1ba01477, CHIP_ID: 20036410
Flash ROM read protection: ON
Option bytes: 03fffffe
The MCU is now stopped.
SUCCESS

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk$ sudo ./tool/stlinkv2.py -u
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0002 -&gt; 0001
Status is 0081
CORE: 1ba01477, CHIP_ID: 20036410
Flash ROM read protection: ON
Option bytes: 03fffffe
Flash ROM read protection disabled.  Reset the board, now.
SUCCESS

# plugin, plugout st-link/v2

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk$ sudo ./tool/stlinkv2.py -s
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0100 -&gt; 0001
CORE: 1ba01477, CHIP_ID: 20036410
Flash ROM read protection: off
Option bytes: ffff5aa5
Flash ROM blank check: True
SUCCESS

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk$ sudo ./tool/stlinkv2.py -b ../binaries/gnuk/gnuk.bin 
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0001 -&gt; 0001
CORE: 1ba01477, CHIP_ID: 20036410
Flash ROM read protection: off
Option bytes: ffff5aa5
Flash ROM blank check: True
SPI Flash ROM ID: bf254a
WRITE
VERIFY
PROTECT
Flash ROM read protection enabled.  Reset the board to enable protection.
SUCCESS

# power cycle

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk$ sudo ./tool/stlinkv2.py -s
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0100 -&gt; 0001
CORE: 1ba01477, CHIP_ID: 20036410
Flash ROM read protection: ON
Option bytes: 03fffffe
The MCU is now stopped.
SUCCESS
</pre>
<br /><p>
plugin just FST-01:</p>
<pre>
[ 9890.019368] usb 1-1.6.4: New USB device found, idVendor=234b, idProduct=0000
[ 9890.019372] usb 1-1.6.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 9890.019374] usb 1-1.6.4: Product: Gnuk Token
[ 9890.019375] usb 1-1.6.4: Manufacturer: Free Software Initiative of Japan
[ 9890.019377] usb 1-1.6.4: SerialNumber: FSIJ-1.0.4-50FF7006
</pre>
</div>
]]></description>
<author>Dobrica Pavlinu&#x161;i&#x107;</author>
<category>hardware, STM32</category>
<guid isPermaLink="true">https://saturn.ffzg.hr/rot13/index.cgi?fst_01</guid>
<pubDate>Thu, 12 Apr 2018 17:47:31 -0000</pubDate>
</item>
<item>
<title><![CDATA[Black Magic Probe]]></title>
<link>https://saturn.ffzg.hr/rot13/index.cgi?black_magic_probe</link>
<description><![CDATA[<div>Creator: Dobrica Pavlinušić</div><hr/><div>Tags: stm32</div><hr/><div class="wiki">
<span class="nlw_phrase"><img alt="Bluepillpinout.gif" src="https://saturn.ffzg.hr/rot13/index.cgi/Bluepillpinout.gif?action=attachments_download;page_name=black_magic_probe;id=20170413104531-0-3985" /><!-- wiki: {image: Bluepillpinout.gif} --></span><br /><br /><div class="nlw_phrase"><table class="wafl_container">
  <tr>
    <td>
      <div class="wafl_box">
        
          <div class="wafl_titlebox">
            <div class="wafl_title">
              
                Contents: [Dobrica Pavlinušić's random unstructured stuff]
              
            </div>
          </div>
          <div class="wafl_items">
            
              <div class="wiki">
<ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#black_magic_probe">Dobrica Pavlinušić's random unstructured stuff (Black Magic Probe)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] Black Magic Probe} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#links">Dobrica Pavlinušić's random unstructured stuff (links)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] links} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#blue_pill">Dobrica Pavlinušić's random unstructured stuff (blue pill)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] blue pill} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#st_link">Dobrica Pavlinušić's random unstructured stuff (st-link)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] st-=link} --></span></li>
</ul>
</div>

            
            
          </div>
        
      </div>
    </td>
  </tr>
</table>
<!-- wiki: {toc: }
--></div><br /><br /><h1 id="black_magic_probe">Black Magic Probe</h1>
<p>
<a target="_blank" title="(external link)" href="https://github.com/blacksphere/blackmagic">https://github.com/blacksphere/blackmagic</a></p>
<h1 id="links">links</h1>
<ul>
<li><a target="_blank" title="(external link)" href="https://github.com/blacksphere/blackmagic/pull/198/files">https://github.com/blacksphere/blackmagic/pull/198/files</a></li>
</ul>
<ul>
<li><a target="_blank" title="(external link)" href="https://embdev.net/articles/STM_Discovery_as_Black_Magic_Probe">https://embdev.net/articles/STM_Discovery_as_Black_Magic_Probe</a></li>
</ul>
<ul>
<li>stlink clone <a target="_blank" title="(external link)" href="https://github.com/blacksphere/blackmagic/issues/62">https://github.com/blacksphere/blackmagic/issues/62</a></li>
</ul>
<ul>
<li><a target="_blank" title="(external link)" href="https://github.com/jsnyder/stm32loader">https://github.com/jsnyder/stm32loader</a></li>
</ul>
<h1 id="blue_pill">blue pill</h1>
<p>
<a target="_blank" title="(external link)" href="http://wiki.stm32duino.com/index.php?title=Blue_Pill">http://wiki.stm32duino.com/index.php?title=Blue_Pill</a></p>
<pre>
dpavlin@klin:/rest/cvs/blackmagic/src$ make PROBE_HOST=stli

  LD      blackmagic
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/bin/ld: address 0x8010dd0 of blackmagic section `.text' is not within region `rom'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/bin/ld: blackmagic section `.data' will not fit in region `rom'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/bin/ld: address 0x8010dd0 of blackmagic section `.text' is not within region `rom'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/bin/ld: region `rom' overflowed by 3768 bytes
collect2: error: ld returned 1 exit status
Makefile:66: recipe for target 'blackmagic' failed
make: *** [blackmagic] Error 1

git remote add mubes https://github.com/mubes/blackmagic
git fetch mubes
git checkout -b bluepill mubes/bluepill

make clean

# gcc 5 generates too big binaries!
export PATH=/opt/DesignLab-1.0.8/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/:$PATH

make PROBE_HOST=bluepill

/nuc/stm32/stlink/build/Release/st-flash erase

/nuc/stm32/stlink/build/Release/st-flash write blackmagic_dfu.bin 0x8000000

/nuc/stm32/stlink/build/Release/st-flash write blackmagic.bin 0x8002000

# power cycle blue pill

dpavlin@nuc:/nuc/stm32/blackmagic/src$ dmesg | tail -8 | cut -c18-
usb 2-4.4: new full-speed USB device number 12 using xhci_hcd
usb 2-4.4: New USB device found, idVendor=1d50, idProduct=6018
usb 2-4.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-4.4: Product: Black Magic Probe (Bluepill), (Firmware v1.6-rc0-274-g39197b7)
usb 2-4.4: Manufacturer: Black Sphere Technologies
usb 2-4.4: SerialNumber: BED69CDC
cdc_acm 2-4.4:1.0: ttyACM0: USB ACM device
cdc_acm 2-4.4:1.2: ttyACM1: USB ACM device


</pre>
<br /><h1 id="st_link">st-link</h1>
<p>
<a target="_blank" title="(external link)" href="https://github.com/texane/stlink">https://github.com/texane/stlink</a></p>
<pre>

dpavlin@nuc:/nuc/stm32$ git clone https://github.com/texane/stlink

dpavlin@nuc:/nuc/stm32/stlink$ ./build/Release/st-info --probe
Found 1 stlink programmers
 serial: 533f6a06483f55532144033f
openocd: &quot;\x53\x3f\x6a\x06\x48\x3f\x55\x53\x21\x44\x03\x3f&quot;
  flash: 65536 (pagesize: 1024)
   sram: 20480
 chipid: 0x0410
  descr: F1 Medium-density device
dpavlin@nuc:/nuc/stm32/stlink$ 


dpavlin@nuc:/nuc/stm32/stlink$ ./build/Release/st-flash erase
st-flash 1.3.1-14-geb03b7c
2017-04-07T17:37:27 INFO src/common.c: Loading device parameters....
2017-04-07T17:37:27 INFO src/common.c: Device connected is: F1 Medium-density device, id 0x20036410
2017-04-07T17:37:27 INFO src/common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
Mass erasing


dpavlin@nuc:/nuc/stm32/blackmagic/src$ make HOST_PROBE=stlink

dpavlin@nuc:/nuc/stm32/blackmagic/src$ ../../stlink/build/Release/st-flash write blackmagic_dfu.bin 0x8000000
st-flash 1.3.1-14-geb03b7c
2017-04-07T17:41:59 INFO src/common.c: Loading device parameters....
2017-04-07T17:41:59 INFO src/common.c: Device connected is: F1 Medium-density device, id 0x20036410
2017-04-07T17:41:59 INFO src/common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
2017-04-07T17:41:59 INFO src/common.c: Attempting to write 6780 (0x1a7c) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08001800 erased
2017-04-07T17:41:59 INFO src/common.c: Finished erasing 7 pages of 1024 (0x400) bytes
2017-04-07T17:41:59 INFO src/common.c: Starting Flash write for VL/F0/F3 core id
2017-04-07T17:41:59 INFO src/flash_loader.c: Successfully loaded flash loader in sram
  6/6 pages written
2017-04-07T17:41:59 INFO src/common.c: Starting verification of write complete
2017-04-07T17:41:59 INFO src/common.c: Flash written and verified! jolly good!



dpavlin@nuc:/nuc/stm32/blackmagic/src$ ../../stlink/build/Release/st-flash --reset --flash=128k write blackmagic.bin 0x8002000
st-flash 1.3.1-14-geb03b7c
2017-04-07T17:45:52 INFO src/common.c: Loading device parameters....
2017-04-07T17:45:52 INFO src/common.c: Device connected is: F1 Medium-density device, id 0x20036410
2017-04-07T17:45:52 INFO src/common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
Forcing flash size: --flash=0x00020000
2017-04-07T17:45:52 INFO src/common.c: Attempting to write 77076 (0x12d14) bytes to stm32 address: 134225920 (0x8002000)
Flash page at addr: 0x08014c00 erased
2017-04-07T17:45:54 INFO src/common.c: Finished erasing 76 pages of 1024 (0x400) bytes
2017-04-07T17:45:54 INFO src/common.c: Starting Flash write for VL/F0/F3 core id
2017-04-07T17:45:54 INFO src/flash_loader.c: Successfully loaded flash loader in sram
 75/75 pages written
2017-04-07T17:45:58 INFO src/common.c: Starting verification of write complete
2017-04-07T17:45:59 INFO src/common.c: Flash written and verified! jolly good!

</pre>
<br /><p>
this flash instructions doesn't work, recepie above for blue pill is more recent</p>
</div>
<hr/><div>Attachments: Bluepillpinout.gif</div>]]></description>
<author>Dobrica Pavlinu&#x161;i&#x107;</author>
<category>stm32</category>
<guid isPermaLink="true">https://saturn.ffzg.hr/rot13/index.cgi?black_magic_probe</guid>
<pubDate>Thu, 13 Apr 2017 10:45:31 -0000</pubDate>
</item>
<item>
<title><![CDATA[STM32discovery]]></title>
<link>https://saturn.ffzg.hr/rot13/index.cgi?stm32discovery</link>
<description><![CDATA[<div>Creator: Dobrica Pavlinušić</div><hr/><div>Tags: hardware, STM32</div><hr/><div class="wiki">
<div class="nlw_phrase"><table class="wafl_container">
  <tr>
    <td>
      <div class="wafl_box">
        
          <div class="wafl_titlebox">
            <div class="wafl_title">
              
                Contents: [Dobrica Pavlinušić's random unstructured stuff]
              
            </div>
          </div>
          <div class="wafl_items">
            
              <div class="wiki">
<ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#install_toolchain">Dobrica Pavlinušić's random unstructured stuff (Install toolchain)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] Install toolchain} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#install_openocd">Dobrica Pavlinušić's random unstructured stuff (Install openocd)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] Install openocd} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#start_openocd">Dobrica Pavlinušić's random unstructured stuff (start openocd)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] start openocd} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#summon_toolchain">Dobrica Pavlinušić's random unstructured stuff (summon toolchain)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] summon toolchain} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#openocd">Dobrica Pavlinušić's random unstructured stuff (openocd)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] openocd} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#using_arduino_ide">Dobrica Pavlinušić's random unstructured stuff (Using Arduino IDE)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] Using Arduino IDE} --></span></li>
</ul>
</div>

            
            
          </div>
        
      </div>
    </td>
  </tr>
</table>
<!-- wiki: {toc: }
--></div><br /><br /><p>
STM32F100RBT6B</p>
<ul>
<li>different from <a target="_blank" title="(external link)" href="http://pulkomandy.tk/_/_Electronique/_Discovering%20the%20STM32F3%20Discovery">http://pulkomandy.tk/_/_Electronique/_Discovering%20the%20STM32F3%20Discovery</a></li>
</ul>
<pre>
dpavlin@blue:~$ lsusb | grep ST
Bus 003 Device 006: ID 0483:3744 SGS Thomson Microelectronics STLINK Pseudo disk
</pre>
<br /><h1 id="install_toolchain">Install toolchain</h1>
<pre>
dpkg --add-architecture i386
apt-get install libc6-i386
#wget https://launchpad.net/gcc-arm-embedded/4.7/4.7-2012-q4-major/+download/gcc-arm-none-eabi-4_7-2012q4-20121208-linux.tar.bz2
wget https://sourcery.mentor.com/GNUToolchain/package4463/public/arm-none-eabi/arm-2009q1-161-arm-none-eabi-i686-pc-linux-gnu.tar.bz2

</pre>
<br /><h1 id="install_openocd">Install openocd</h1>
<pre>
dpavlin@blue:~$ sudo apt-get install openocd
dpavlin@blue:~$ dpkg -l openocd
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                    Version          Architecture     Description
+++-=======================-================-================-====================================================
ii  openocd                 0.6.1-1          amd64            Open on-chip JTAG debug solution for ARM and MIPS sy
</pre>
<br /><h2 id="start_openocd">start openocd</h2>
<p>
Disable STLINKv1 SCSI emulation, see <a target="_blank" title="(external link)" href="https://github.com/texane/stlink">https://github.com/texane/stlink</a></p>
<pre>
root@blue:~# modprobe -r usb-storage &amp;&amp; modprobe usb-storage quirks=483:3744:i

root@blue:~# sudo openocd -f /usr/share/openocd/scripts/board/stm32vldiscovery.cfg
Open On-Chip Debugger 0.6.1 (2012-12-05-01:32)
Licensed under GNU GPL v2
For bug reports, read
       http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
Info : clock speed 1000 kHz
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
</pre>
<br /><p>
Open another window and connect with telnet:</p>
<pre>
dpavlin@blue:~$ telnet localhost 4444
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
&gt; reset init
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000b4c msp: 0x20000400
</pre>
<br /><h1 id="summon_toolchain">summon toolchain</h1>
<ul>
<li><a target="_blank" title="(external link)" href="https://github.com/esden/summon-arm-toolchain">https://github.com/esden/summon-arm-toolchain</a></li>
</ul>
<h2 id="openocd">openocd</h2>
<pre>
dpavlin@blue:~/sat$ sudo openocd -f /usr/share/openocd/scripts/board/stm32vldiscovery.cfg
[sudo] password for dpavlin: 
Open On-Chip Debugger 0.6.1 (2012-12-05-01:32)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
Info : clock speed 1000 kHz
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'telnet' connection from 4444
Warn : target was in unknown state when halt was requested
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x080001ce msp: 0x20001ff0
</pre>
<br /><p>
From different terminal</p>
<pre>
dpavlin@blue:~/sat$ telnet localhost 4444
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
&gt; halt
target was in unknown state when halt was requested
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x080001ce msp: 0x20001ff0
&gt; 

&gt; flash write_image erase /virtual/stm32discovery/libopencm3/examples/stm32/f1/stm32vl-discovery/fancyblink/fancyblink.hex
auto erase enabled
device id = 0x10016420
flash size = 128kbytes
target state: halted
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20001ff0
wrote 2048 bytes from file /virtual/stm32discovery/libopencm3/examples/stm32/f1/stm32vl-discovery/fancyblink/fancyblink.hex in 0.192207s (10.405 KiB/s)

</pre>
<br /><h1 id="using_arduino_ide">Using Arduino IDE</h1>
<p>
<a target="_blank" title="(external link)" href="http://forums.leaflabs.com/topic.php?id=630">http://forums.leaflabs.com/topic.php?id=630</a></p>
</div>
]]></description>
<author>Dobrica Pavlinu&#x161;i&#x107;</author>
<category>hardware, STM32</category>
<guid isPermaLink="true">https://saturn.ffzg.hr/rot13/index.cgi?stm32discovery</guid>
<pubDate>Thu, 13 Feb 2014 00:24:59 -0000</pubDate>
</item>
</channel>
</rss>