One program for every board, F9: compiled, loaded and debugged in its source.
Asmonite compiles C with its own compiler cBelle, a subset of C without floating point. It writes the machine code itself, without an assembler and without a linker, for Windows and for the boards of three architectures: Xtensa (ESP32, ESP32-S3), RISC-V (ESP32-C3, ESP32-S31) and Arm Cortex-M (Raspberry Pi Pico, Pico 2). A program without a line #pragma target runs on each of these boards. F9 starts it there, and it can be debugged over the USB cable: breakpoints, one step per line, the variables under the mouse.
cBelle is in the ZIP: cbelle.exe next to Asmonite.exe, its library in cBelle\lib, the examples in examples. The license of Asmonite applies: free, and programs written with it belong to their authors. Before it came aBelle, a small language of its own with the look of Python.
On the left a program for every board: it takes the functions of the Asmonite console from console.c and blinks the LED. On the right one only for the ESP32: the registers of the chip are an array at their address, and a function of the ROM gets its address with #pragma at.
#include "console.c" enum { LED_PIN = 2 }; // the LED of the board void wait_ms(int n) { int t = millis(); while (millis() - t < n) { } } void main() { println("blink"); gpio_output(LED_PIN); while (1) { gpio_write(LED_PIN, 1); wait_ms(500); gpio_write(LED_PIN, 0); wait_ms(500); } }
#pragma target esp32 unsigned *gpio = (unsigned *)0x3FF44000; unsigned *iomux = (unsigned *)0x3FF49000; #pragma at 0x40008534 void ets_delay_us(int us); // in the ROM void main() { iomux[0x40 / 4] = 0x2800; // GPIO 2 is a GPIO gpio[0x538 / 4] = 0x100; gpio[0x24 / 4] = 1 << 2; // an output while (1) { gpio[0x08 / 4] = 1 << 2; // on ets_delay_us(500000); gpio[0x0C / 4] = 1 << 2; // off ets_delay_us(500000); } }
The files are called .c, and an ordinary C compiler understands them too: it skips the lines #pragma. Without a line #pragma target Asmonite compiles a program for the board of Project > Target, that is the board in the tab Serial; #include "console.c" then takes the file of that board from cBelle\lib.
cBelle is small on purpose: as much C as a compiler needs to translate itself, and the registers of a board. What is there is ordinary C; some of it is stricter. All of it in detail is in cBelle\README.md (in German).
| What | How |
|---|---|
| Types | int, unsigned, char *, int *, unsigned *; void for functions without a value. int and unsigned mix only with a cast |
| Global | int x = 5;, char text[80];, unsigned u[4];, enum { A = 1, B };, a pointer to registers: unsigned *sio = (unsigned *)0xD0000000; |
| Statements | blocks, if / else, while, for, break, continue, return, local variables, =, += and the others, ++, -- |
| Expressions | the operators of C for whole numbers (|| && | ^ & == < << + * / % …), casts, calls, index, numbers decimal and hex, 'c', "text" |
| Boards | #pragma target esp32 (or esp32s3, esp32c3, esp32s31, pico, pico2); #pragma at 0x40008534 above a function without a body puts it at that address |
| Windows | a function without a body comes from kernel32.dll, with #pragma import msvcrt.dll cdecl from another DLL, also printf with ... |
| Several files | #include "net.c" puts in the text of a file, each file once |
cbelle.exe is one program with four back ends: x86, Xtensa, Thumb and RISC-V. F9 calls it and loads what it writes.
| Windows | ESP32, ESP32-S3 | Pico, Pico 2 | ESP32-C3, ESP32-S31 | |
|---|---|---|---|---|
| Code | x86, a console program (PE) | Xtensa LX6 / LX7: code for the IRAM, data for the DRAM | Thumb for the RAM from 0x20000000 | RISC-V (RV32IM) for the RAM of the programs |
| F9 | compiles and starts in the debugger | loads into the RAM over the console on the board, without a reset; breakpoints over the USB cable | loads into the RAM over the console; breakpoints over the USB cable | loads over the USB JTAG of the chip, the console starts it; afterwards it is at its prompt again |
A program can also stay on the board as a file: Project > Compile and Upload puts it into the flash, the Asmonite console starts it by its name as a command (blink, ping example.com), Autostart in the Board Manager after every reset. When main ends, the console is back.
What a program includes is in cBelle\lib, written in C itself: it can be read, changed and followed in the debugger. The files of the same name are there for every board; the same functions do the same on every board.
| File | What it brings |
|---|---|
console.c | the functions of the console: text (print, println, print_int …), keys, millis, the files in the flash (file_read, file_write), args, exit, the pins (gpio_output, gpio_write); on Windows the same over the console of Windows |
wifi.c | the WiFi of the board: the network the console knows (wlan set), sending and receiving frames |
net.c | ARP, IPv4, ICMP (ping), UDP, DHCP, DNS and mDNS |
tcp.c | TCP, one connection at a time, as a client or a server |
tls.c | TLS 1.3 (ChaCha20-Poly1305, X25519, SHA-256) for httpsget |
cpuclock.c | the clock of the core: cpu_clock, cpu_clock_khz |
When the debugger holds a program at a breakpoint, the WiFi connection stays up, and what comes in waits in a buffer. So a DHCP exchange or a TCP connection can be followed line by line. The network is set once per board with wlan set in the console; F9 writes the WiFi package by itself when a program needs it.
Next to the program the compiler writes a map file: which code belongs to which line and where the variables are. With it Asmonite debugs right in the .c file, on Windows as on the board.
cBelle is written in exactly the C it translates: one file, cbelle.c. It translates itself into the same cbelle.exe, byte for byte.
It works in one pass per function: read, split into tokens and write code at once, without a syntax tree and without an optimizer. An expression leaves its value in a register, so every line stays easy to follow in the debugger. At every test run of Asmonite it translates itself and its test programs; the same programs print the same lines on Windows and on the boards. It grew out of the compiler of aBelle.
| Every board | With WiFi |
|---|---|
hello.c – Hello, world! | scan, dhcp, dns, ping, ntp, arpscan, wol, udpecho |
blink.c – the LED blinks | httpget, httpsget – fetch a web page, also over TLS 1.3 |
runs.c – a number that stays in a file | webserver – the board as a web server |
args.c – the arguments of a program | pingled – the LED flashes at each ping |
clockspeed.c, setclock.c – the clock of the core (per board) |
The examples are in the folder examples of the ZIP: examples\common for every board, examples\esp32, examples\pico and so on for one. All examples with a description →
struct, typedef, switch, do, ?:, sizeof, floating point, numbers of 64 bits.&x and *p (a pointer is read through its index: p[0]), local arrays, arrays with initial values.#include and #pragma: no #define; constants are an enum.cBelle\lib begin their names with c_ for that.