<spanclass="line"><span>avrdude done. Thank you.</span></span></code></pre></div><h3id="setting-the-fuses"tabindex="-1">Setting the Fuses <aclass="header-anchor"href="#setting-the-fuses"aria-label="Permalink to "Setting the Fuses""></a></h3><p>This is a slightly more advanced topic, but may be necessary if you are switching from one bootloader to another (for example, Caterina to Atmel/QMK DFU on a Pro Micro). Fuses control some of the low-level functionality of the AVR microcontroller, such as clock speed, whether JTAG is enabled, and the size of the section of flash memory reserved for the bootloader, among other things. You can find a fuse calculator for many AVR parts <ahref="https://www.engbedded.com/conffuse/"target="_blank"rel="noreferrer">here</a>.</p><divclass="warning custom-block"><pclass="custom-block-title">WARNING</p><p>Setting incorrect fuse values, in particular the clock-related bits, may render the MCU practically unrecoverable without high voltage programming (not covered here)! Make sure to double check the commands you enter before you execute them.</p></div><p>To set the fuses, add the following to the <code>avrdude</code> command:</p><divclass="language- vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang"></span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><span>-U lfuse:w:0xXX:m -U hfuse:w:0xXX:m -U efuse:w:0xXX:m</span></span></code></pre></div><p>where the <code>lfuse</code>, <code>hfuse</code> and <code>efuse</code> arguments represent the low, high and extended fuse bytes as listed in the <ahref="#hardware">Hardware</a> section.</p><divclass="tip custom-block"><pclass="custom-block-title">TIP</p><p>You may get a warning from <code>avrdude</code> that the extended fuse byte does not match what you provided when reading it back. If the second hex digit matches, this can usually be safely ignored, because the top four bits of this fuse do not actually exist on many AVR parts, and may read back as anything.</p></div><h2id="creating-a-production-firmware"tabindex="-1">Creating a "Production" Firmware <aclass="header-anchor"href="#creating-a-production-firmware"aria-label="Permalink to "Creating a "Production" Firmware""></a></h2><p>For mass production purposes, it is possible to join the bootloader and QMK firmware together into a single file, due to the way the <ahref="https://en.wikipedia.org/wiki/Intel_HEX"target="_blank"rel="noreferrer">Intel Hex format</a> works:</p><ol><li>Open the QMK firmware and bootloader <code>.hex</code> files in a text editor.</li><li>Remove the last line of the QMK firmware (which should be <code>:00000001FF</code> - this is just an "end of file" marker).</li><li>Paste the contents of the bootloader <code>.hex</code> file onto a new line at the end of the QMK firmware file, with no empty lines between.</li><li>Save it as a new file, for example <code><keyboard>_<keymap>_production.hex</code>.</li></ol><p>You can then ISP flash this combined firmware instead, which allows you to skip the extra step of flashing the QMK firmware over USB.</p><h2id="flashing-stm32duino-bootloader"tabindex="-1">Flashing STM32Duino Bootloader <aclass="header-anchor"href="#flashing-stm32duino-bootloader"aria-label="Permalink to "Flashing STM32Duino Bootloader""></a></h2><p>As mentioned above, <em>most</em> supported STM32 devices already possess a USB DFU bootloader which cannot be overwritten, however the ROM bootloader in the STM32F103 used on the Bluepill is not USB capable. In this case an ST-Link V2 dongle is required to upload the STM32Duino bootloader to the device. These can be readily purchased for relatively cheap on eBay and other places.</p><p>This bootloader is a descendant of the Maple bootloader by Leaflabs, and is compatible with dfu-util.</p><h3id="software-1"tabindex="-1">Software <aclass="header-anchor"href="#software-1"aria-label="Permalink to "Software""></a></h3><p>
<spanclass="line"><span> descr: F1xx Medium-density</span></span></code></pre></div><p>If the reported <code>chipid</code> is <code>0x0410</code>, everything is working. If it is <code>0x0000</code>, check your wiring, and try swapping the <code>SWDIO</code> and <code>SWCLK</code> pins, as some ST-Link dongles may have incorrect pinouts.</p><p>Next, run the following command:</p><divclass="language- vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang"></span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><span>st-flash --reset --format binary write <path-to-bootloader> 0x08000000</span></span></code></pre></div><p>where <code><path-to-bootloader></code> is the path to the bootloader <code>.bin</code> file above. You can run this command from the directory you downloaded it to, so that you can simply pass in the filename.</p><p>If all goes well, you should get output similar to the following:</p><divclass="language- vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang"></span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><span>st-flash 1.7.0</span></span>
<spanclass="line"><span>2022-03-08T12:16:30 INFO common.c: F1xx Medium-density: 20 KiB SRAM, 64 KiB flash in at least 1 KiB pages.</span></span>
<spanclass="line"><span>2022-03-08T12:16:30 INFO common.c: Attempting to write 7172 (0x1c04) bytes to stm32 address: 134217728 (0x8000000)</span></span>
<spanclass="line"><span>2022-03-08T12:16:30 INFO common.c: Flash page at addr: 0x08000000 erased</span></span>
<spanclass="line"><span>2022-03-08T12:16:30 INFO common.c: Flash page at addr: 0x08000400 erased</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO common.c: Flash page at addr: 0x08000800 erased</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO common.c: Flash page at addr: 0x08000c00 erased</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO common.c: Flash page at addr: 0x08001000 erased</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO common.c: Flash page at addr: 0x08001400 erased</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO common.c: Flash page at addr: 0x08001800 erased</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO common.c: Flash page at addr: 0x08001c00 erased</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO common.c: Finished erasing 8 pages of 1024 (0x400) bytes</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO flash_loader.c: Successfully loaded flash loader in sram</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO flash_loader.c: Clear DFSR</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO common.c: Starting verification of write complete</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 INFO common.c: Flash written and verified! jolly good!</span></span>
<spanclass="line"><span>2022-03-08T12:16:31 WARN common.c: NRST is not connected</span></span></code></pre></div><p>Otherwise, if you receive an <code>Unknown memory region</code> error, run the following command to unlock the STM32F103:</p><divclass="language- vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang"></span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><span>openocd -f interface/stlink.cfg -f target/stm32f1x.cfg -c "init; reset halt; stm32f1x unlock 0; reset halt; exit"</span></span></code></pre></div><p>Then re-plug the ST-Link and try again.</p><p>After all of this, unplug the Bluepill from the ST-Link and connect it to USB. It should now be ready to flash using dfu-util, the QMK CLI or Toolbox.</p></div></div></main><footerclass="VPDocFooter"data-v-39a288b8data-v-09de1c0f><!--[--><!--]--><!----><navclass="prev-next"data-v-09de1c0f><divclass="pager"data-v-09de1c0f><aclass="VPLink link pager-link prev"href="/hand_wire"data-v-09de1c0f><!--[--><spanclass="desc"data-v-09de1c0f>Previous page</span><spanclass="title"data-v-09de1c0f>Hand Wiring Guide</span><!--]--></a></div><divclass="pager"data-v-09de1c0f><aclass="VPLink link pager-link next"href="/pr_checklist"data-v-09de1c0f><!--[--><spanclass="desc"data-v-09de1c0f>Next page</span><spanclass="title"data-v-09de1c0f>PR Checklist</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>