const__pageData=JSON.parse('{"title":"Arm/ChibiOS Early Initialization","description":"","frontmatter":{},"headers":[],"relativePath":"platformdev_chibios_earlyinit.md","filePath":"platformdev_chibios_earlyinit.md"}');
const_hoisted_1=/* @__PURE__ */createStaticVNode('<h1id="chibios-early-init"tabindex="-1">Arm/ChibiOSEarlyInitialization<aclass="header-anchor"href="#chibios-early-init"aria-label="Permalink to "Arm/ChibiOS Early Initialization {#chibios-early-init}""></a></h1><p>ThispagedescribesapartofQMKthatisasomewhatadvancedconcept,andisonlyrelevanttokeyboarddesigners.</p><p>QMKusesChibiOSastheunderlyinglayertosupportamultitudeofArm-baseddevices.EachChibiOS-supportedkeyboardhasalow-levelboarddefinitionwhichisresponsibleforinitializinghardwareperipheralssuchastheclocks,andGPIOs.</p><p>OlderQMKrevisionsrequiredduplicationoftheseboarddefinitionsinsideyourkeyboard'sdirectoryinordertooverridesuchearlyinitializationpoints;thisisnowabstractedintothefollowingAPIs,andallowsusageoftheboarddefinitionssuppliedwithChibiOSitself.Check<code><qmk_firmware>/lib/chibios/os/hal/boards</code>forthelistofofficialdefinitions.Ifyourkeyboardneedsextrainitializationataveryearlystage,considerprovidingkeyboard-leveloverridesofthefollowingAPIsinsteadofduplicatingtheboarddefinitions:</p><h2id="early-hardware-init-pre"tabindex="-1"><code>early_hardware_init_pre()</code><aclass="header-anchor"href="#early-hardware-init-pre"aria-label="Permalinkto"`early_hardware_init_pre()`{#early-hardware-init-pre}""></a></h2><p>Thefunction<code>early_hardware_init_pre</code>istheearliestpossiblecodethatcanbeexecutedbyakeyboardfirmware.ThisisintendedasareplacementfortheChibiOSboarddefinition's<code>__early_init</code>function,andistheequivalentofexecutingatthestartofthefunction.</p><p>ThisisexecutedbeforeRAMgetscleared,andbeforeclocksorGPIOsareconfigured;forexample,ChibiOSdelaysarenotlikelytoworkatthispoint.Afterexecutingthisfunction,RAMontheMCUmaybezero'ed.Assigningvaluestovariablesduringexecutionofthisfunctionmaybeoverwritten.</p><p>Assuch,ifyouwishtooverridethisAPIconsiderlimitingusetowritingtolow-levelregisters.Thedefaultimplementationofthisfunctioncanbeconfiguredtojumptobootloaderifa<code>QK_BOOT</code>keywaspressed:</p><table><thead><tr><th><code>config.h</code>override</th><th>Description</th><th>Default</th></tr></thead><tbody><tr><td><code>#defineEARLY_INIT_PERFORM_BOOTLOADER_JUMP</code></td><td>WhetherornotbootloaderistobeexecutedduringtheearlyinitialisationcodeofQMK.</td><td><code>FALSE</code></td></tr><tr><td><code>#defineSTM32_BOOTLOADER_DUAL_BANK</code></td><td>Relevantfordual-bankSTM32MCUs,signifiesthataGPIOistobetoggledinordertoenterbootloadermode.</td><td><code>FALSE</code></td></tr><tr><td><code>#defineSTM32_BOOTLOADER_DUAL_BANK_GPIO</code></td><td>Relevantfordual-bankSTM32MCUs,thepintotogglewhenattemptingtoenterbootloadermode,e.g.<code>B8</code></td><td><code><none></code></td></tr><tr><td><code>#defineSTM32_BOOTLOADER_DUAL_BANK_POLARITY</code></td><td>Relevantfordual-bankSTM32MCUs,thevaluetosetthepintoinordertotriggerchargingoftheRCcircuit.e.g.<code>0</code>or<code>1</code>.</td><td><code>0</code></td></tr><tr><td><code>#defineSTM32_BOOTLOADER_DUAL_BANK_DELAY</code></td><td>Relevantfordual-bankSTM32MCUs,anarbitrarymeasurementoftimetodelaybeforeresettingtheMCU.Increasingnumberincreasesthedelay.</td><td><code>100</code></td></tr></tbody></table><p>KinetisMCUshavenoconfigurableoptions.</p><p>Alternatively,toimplementyourownversionofthisfunction,inyourkeyboard'ssourcefiles:</p><divclass="language-cvp-adaptive-theme"><buttontitle="CopyCode"class="copy"></button><spanclass="lang">c</span><preclass="shikishiki-themesgithub-lightgithub-darkvp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">early_hardware_init_pre</s