aboutsummaryrefslogtreecommitdiff
path: root/docs/platformdev_chibios_earlyinit.md
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2020-04-13 09:39:38 +1000
committerGitHub <noreply@github.com>2020-04-13 09:39:38 +1000
commit05e9ff6554a1be119a585d691067ca2379c1d80d (patch)
treecd483e68d7e05950600fd4b96a2698d963b5b250 /docs/platformdev_chibios_earlyinit.md
parent17bda000f39dd40317160576d0a948d7abb2612f (diff)
downloadqmk_firmware-05e9ff6554a1be119a585d691067ca2379c1d80d.tar.gz
qmk_firmware-05e9ff6554a1be119a585d691067ca2379c1d80d.zip
Add support for hardware and board initialisation overrides. (#8330)
* Add support for hardware and board initialisation overrides. * qmk cformat. * Add some documentation. * Docs clarity. * Make early_hardware_init_pre a no-op for now, until migrations occur. * Doco update * Make distinction between keyboard and ChibiOS board in docs * Doc anchors. * Update tmk_core/protocol/chibios/main.c Co-Authored-By: Joel Challis <git@zvecr.com> * Rework bootloader entry to be off by default, allow opting-in. Co-authored-by: Joel Challis <git@zvecr.com>
Diffstat (limited to 'docs/platformdev_chibios_earlyinit.md')
-rw-r--r--docs/platformdev_chibios_earlyinit.md53
1 files changed, 53 insertions, 0 deletions
diff --git a/docs/platformdev_chibios_earlyinit.md b/docs/platformdev_chibios_earlyinit.md
new file mode 100644
index 000000000..699c22377
--- /dev/null
+++ b/docs/platformdev_chibios_earlyinit.md
@@ -0,0 +1,53 @@
1# Arm/ChibiOS Early Initialization :id=chibios-early-init
2
3This page describes a part of QMK that is a somewhat advanced concept, and is only relevant to keyboard designers.
4
5QMK uses ChibiOS as the underlying layer to support a multitude of Arm-based devices. Each ChibiOS-supported keyboard has a low-level board definition which is responsible for initializing hardware peripherals such as the clocks, and GPIOs.
6
7Older QMK revisions required duplication of these board definitions inside your keyboard's directory in order to override such early initialization points; this is now abstracted into the following APIs, and allows usage of the board definitions supplied with ChibiOS itself. Check `<qmk_firmware>/lib/chibios/os/hal/boards` for the list of official definitions. If your keyboard needs extra initialization at a very early stage, consider providing keyboard-level overrides of the following APIs:
8
9## `early_hardware_init_pre()` :id=early-hardware-init-pre
10
11The function `early_hardware_init_pre` is the earliest possible code that can be executed by a keyboard firmware. This is intended as a replacement for the ChibiOS board definition's `__early_init` function, and is the equivalent of executing at the start of the function.
12
13This is executed before RAM gets cleared, and before clocks or GPIOs are configured; any delays or preparation using GPIOs is not likely to work at this point. After executing this function, RAM on the MCU may be zero'ed. Assigning values to variables during execution of this function may be overwritten.
14
15As such, if you wish to override this API consider limiting use to writing to low-level registers. The default implementation of this function can be configured to jump to bootloader if a `RESET` key was pressed, by ensuring `#define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE` is in the keyboard's `config.h` file.
16
17To implement your own version of this function, in your keyboard's source files:
18
19```c
20void early_hardware_init_pre(void) {
21 // do things with registers
22}
23```
24
25## `early_hardware_init_post()` :id=early-hardware-init-post
26
27The function `early_hardware_init_post` is the next earliest possible code that can be executed by a keyboard firmware. This is executed after RAM has been cleared, and clocks and GPIOs are configured. This is intended as a replacement for the ChibiOS board definition's `__early_init` function, and is the equivalent of executing at the end of the function.
28
29Much like `early_hardware_init_pre`, ChibiOS has not yet been initialized either, so the same restrictions on delays and timing apply.
30
31If you wish to override this API, consider limiting functionality to register writes, variable initialization, and GPIO toggling. The default implementation of this function is to do nothing.
32
33To implement your own version of this function, in your keyboard's source files:
34
35```c
36void early_hardware_init_post(void) {
37 // toggle GPIO pins and write to variables
38}
39```
40
41## `board_init()` :id=board-init
42
43The function `board_init` is executed directly after the ChibiOS initialization routines have completed. At this stage, all normal low-level functionality should be available for use (including timers and delays), with the restriction that USB is not yet connected. This is intended as a replacement for the ChibiOS board definition's `boardInit` function.
44
45The default implementation of this function is to do nothing.
46
47To implement your own version of this function, in your keyboard's source files:
48
49```c
50void board_init(void) {
51 // initialize anything that requires ChibiOS
52}
53``` \ No newline at end of file