Repository navigation
kmicro 0.2.0
kmicro 0.2.0: Kotlin® on bare-metal microcontrollers, built by the official compiler, now for every Cortex-M core from the Cortex-M0 to the Cortex-M33.
To try it, follow BUILDING.md and the quick start in the README.
kmicro builds for every Cortex-M core from the Cortex-M0 to the Cortex-M33, and the problems listed with 0.1.0 are
fixed.
What a build script or a board has to change
- qbuild gives a program the memory of the STM32L431: 256 KB of flash and 64 KB of RAM on
l475(and on the new
targetsan385,an500andan505), where it gave 1 MB and 96 KB. A program that does not fit fails to link, and
with the default heap the stack is 40,960 bytes instead of 73,728.qbuild --largegives the old memory. - stdio: the runtime has a weak
_writethat sendsprintfoutput whereprintlngoes. A board's own_write
still replaces it. Akmicro_putsorkmicro_writethat itself prints through stdio would now call itself: write
to the device directly. - The uncaught-exception report names a local class by its simple name and the class of an anonymous object
Throwable, asThrowable.toString()does; it printed the compiler's internal names. - Nothing changes in
runtime/kmicro.h, and a build for the Cortex-M4F needs no new option.
Cores
--cpu COREon kbuild, qbuild, run_all and difftest (orKMICRO_CPU) chooses the core:cortex-m0,
cortex-m0plus,cortex-m1,cortex-m3,cortex-m4,cortex-m4f(the default),cortex-m7,cortex-m7-sp,
cortex-m23,cortex-m33,cortex-m33f. A core without an FPU uses the soft-float calling convention.
docs/roadmap.md lists them with what was checked on each and the size of the selftest;
docs/porting.md says what a board with another core changes.- The runtime and the start code build for ARMv6-M (atomics without LDREX/STREX, Thumb-1 assembly) and for ARMv8-M
(the MPU guards of the start code, IPSR on ARMv8-M Baseline). - QEMU targets for the tests:
an385(Cortex-M3),an500(Cortex-M7),an505(Cortex-M33, which also runs the
code built for the Cortex-M23). Code for the Cortex-M0, M0+, M1 and M4 runs on the Cortex-M4F of the STM32L475. - Not supported: Cortex-M55 and M85, Cortex-R, 32-bit Cortex-A, 64-bit ARM.
Fixed
- Runtime:
printfprinted nothing onqemu-l475and on a board (#102);String.toDouble()failed on text with
400 or more significant digits (#93); the uncaught-exception report showed internal class names (#94); an uncaught
exception hung when the reset entry called the start function withbl(#143); the start code relied on the reset
value of lr, which a Cortex-M0 does not define. - Build: a header included from a subfolder did not trigger a rebuild of its cinterop library (#98); two
.def
files with the same name collided (#92);--init-allskipped root-package objects whose name does not start with
A-Z (#113);-Xbinary=latin1Strings=truefailed on a string that containsthread_local(#105);
suspend fun main()is refused with a message (#107); the LLVM is found underKONAN_DATA_DIR(#109). - Tools:
--target an386has a SysTick vector (#104);gen_regs.pyreads more of C and names what it leaves out
(#103);symbolize.pyandframes.pywork in a folder outside the ANSI code page on Windows (#90);
isr_check.pycounts indirect tail calls (#106);retarget.pyandmissing_natives.pystop with a message on a
file that is not LLVM IR (#108).
New in the tools
qbuild --icountruns QEMU on its instruction count instead of the host's clock, so a timer interrupt lands on the
same instruction in every run (#114). run_all uses it.- kbuild warns about a program that uses Regex, which does not fit 256 KB of flash without
--size; the Regex rows
of docs/kotlin-support.md say "partly" (#99). retarget.pywarns when one of its rewrites of the standard library matches nothing in a module that contains its
target, the first sign that a compiler version writes that code in another way (#115).
Tests and CI
- CI runs run_all for eight cores and on Windows on every pull request, and a weekly job builds and tests with the
newest Kotlin release without failing the others (#95, #115, #119). - The size budget counts the stack (#97); run_all builds the STM32L431 example (#110); difftest checks the stack
frames of its programs (#142). - Every source file carries its copyright and license header (#91).
Tested with
- Kotlin/Native 2.4.21 with the LLVM 21 it downloads, xPack GNU Arm Embedded GCC 15.2.1-1.1, xPack QEMU Arm 9.2.4-1,
Python 3.10 to 3.12 (toolchain/versions.txt). - Hosts: Windows and Linux x64, both in CI. macOS is untested.
- Cores: run_all passes for cortex-m0plus, cortex-m3, cortex-m4, cortex-m4f, cortex-m7, cortex-m23, cortex-m33 and
cortex-m33f on QEMU; an STM32L431 board in a run recorded before 0.1.0. - Suites: 79 run_all tests, on the default core also with a collection at every allocation; 45 difftest programs,
the same way; 143 tool tests.