Skip to content

Getting started

Install

You need Python 3.10 or newer, and one of the supported boards. For the STM32H7 you also need an ST-Link.

pip install microgoose
microgoose setup

setup fetches the Goose compiler and checks that your shell finds the microgoose command. Three things can stop you here. They come from how Python is installed on your computer, or from what it lets run:

Your shell can't find microgoose. Windows says 'microgoose' is not recognized as an internal or external command, and other shells say command not found. pip installed the command in a folder that is not on your PATH. That happens with Python from the Microsoft Store and with pip install --user, and pip says so in a warning as it installs. Run it through Python:

python -m microgoose setup

It prints that folder and the line that adds it to PATH. Until you have done that, type python -m microgoose wherever these pages say microgoose.

Windows blocks microgoose.exe. The message is An Application Control policy has blocked this file, or blocked by your organization's Device Guard policy. Smart App Control doesn't know the small launcher pip makes for the command at install time. Python itself is signed, so run the same tool through it: type python -m microgoose wherever these pages say microgoose. python -m microgoose setup tells you when this is the case.

pip stops with error: externally-managed-environment. Recent Debian and Ubuntu, and Homebrew's Python on macOS, don't let pip install into the system's Python. Install with pipx, which gives MicroGoose an environment of its own:

pipx install microgoose
pipx ensurepath          # if pipx says its folder is not on PATH; then open a new terminal

Or use a virtual environment, which you activate in each new terminal:

python3 -m venv ~/.venvs/microgoose
source ~/.venvs/microgoose/bin/activate
pip install microgoose

MicroGoose downloads the Goose compiler v2026.5 from its official release and refuses it unless the SHA-256 matches. To use your own build of Goose instead, set GOOSE to its path. The compiler and the build workspace live in ~/.microgoose; set MICROGOOSE_HOME to move them.

The first build for each board is the slow one. PlatformIO downloads that board's toolchain (ESP-IDF for the ESP32s, arm-none-eabi-gcc and STM32Cube for the STM32), then compiles the parts of it MicroGoose uses. With the downloads already there, that first build took 5 minutes for the ESP32-S3, 5 for the ESP32 and under a minute for the STM32H7 on our PC. Later builds compile your program only and take seconds. The first build after you upgrade MicroGoose compiles everything again.

Your first program

microgoose new hello                 # writes hello/main.goose
microgoose run hello/main.goose                  # ESP32-S3 (default target)
microgoose run hello/main.goose --target esp32   # WROOM-32 / WROVER-E
microgoose run hello/main.goose --target h7      # STM32H743 over ST-Link
microgoose run hello/main.goose --target pico2w  # Raspberry Pi Pico 2 W over USB

run compiles, builds the firmware, flashes it, then shows the board's output until the program exits. After the chip's own boot log, the ESP32-S3 prints:

[microgoose] starting Goose program (free heap 8768739, internal 382827, psram 8385912)
hello from Goose at 240 MHz
tick 0 at 64 ms
tick 1 at 565 ms
tick 2 at 1065 ms
tick 3 at 1566 ms
tick 4 at 2066 ms

[microgoose] program exited with code 0 (free heap 8731731)

On a WROOM-32, the boot log has three error lines about PSRAM before that. They are expected: see Boards.

microgoose new NAME --example blink starts from one of the bundled examples instead: hello, blink, sieve, threads, boots, analog, pwm, serial, can, interrupts or overflow, or for the ESP32s, web and mqtt (see Networking). blink is written for the ESP32-S3 board: it drives that board's RGB LED and reads its temperature sensor. On the other boards it still runs and prints, but there is no LED to light, and the classic ESP32, which has no temperature sensor, reports -273 °C. velxio/traffic, velxio/dimmer and velxio/rainbow come with a circuit, to watch in the Velxio browser simulator with no board at all.

To edit it in VS Code, with errors as you type and Ctrl+Shift+B to run it, install the Goose extension once and open the folder: see Editors.

The tutorials take it from here step by step: a traffic light, the Goose language for Arduino and MicroPython programmers, LEDs and a button, then a knob, a dimmer and a servo.

Commands

Command What it does
microgoose build FILE Goose → C → firmware, without flashing
microgoose run FILE build, flash, and show the output until the program ends
microgoose flash flash the last build
microgoose monitor reset the board and show its console
microgoose wifi SSID save the WiFi network for import net; (see Networking)
microgoose velxio FILE build for the Velxio browser simulator: its firmware and circuit files
microgoose vscode [FILE] VS Code tasks and settings for the program's folder (microgoose new writes them too; see Editors)
Option Meaning
--target s3\|esp32\|h7\|pico2w which board (MG_TARGET sets the default)
--port COM7 the ESP32 board's serial port, when MicroGoose finds none or several (see Choosing the serial port)
--reserve 16K bytes per data stack (see How it works)
--worker-reserve 4K bytes per data stack of a thread_spawn worker; without it, a worker's take --reserve too (see Sizing data stacks)
--worker-stack 4K bytes of native stack for a thread_spawn worker; without it, 16 KB (see A worker's native stack)
--stack-report measure how much of each stack the program uses, and print it when the program ends and at stack_report() (see Measuring stacks)
--debug Goose's own range and overflow checks on
--data PATH a file or folder the program can read (repeatable; see Files)
--stdin FILE what read_line and read_stdin read
--include HEADER a C header beside the program, for its extern fns
--net make the program networked: it joins the saved WiFi network before main() and takes updates over it (ESP32 targets)
--name HOST the board's network name, HOST.local
--ota build, flash or monitor over WiFi instead of USB (see Updates over WiFi)
--host ADDR with --ota: the board's name or address, instead of NAME.local
--seconds N how long run and monitor wait for output
--emulate run in an emulator of the chip instead of on a board: QEMU for s3 and esp32, Renode for h7, picoem for pico2w

Files and stdin

Goose's file functions (read_file, write_file, list_dir, make_dir, rename_file and the rest) work on the board against a small filesystem in RAM. It starts out holding the files you pass with --data, under the same paths they have next to your program:

microgoose run words/main.goose --data words/data      # read_file("data/alice.txt")
microgoose run calc/main.goose --stdin calc/input.txt  # read_line() reads it

The --data files are built into the firmware and stay in flash until something writes to them. Whatever the program writes lives in RAM and is gone after a reset, except in the flash/ folder. A program can also spell paths /mg/data/alice.txt.

Files that survive a reset

On the ESP32s, the flash/ folder of the tree is kept in the board's flash chip, in LittleFS. What a program writes there is still there after a reset, a power cut or new firmware:

write_file("flash/settings.json", text);   // kept
write_file("cache.txt", text);             // in RAM, gone at the next reset

examples/boots.goose counts the board's boots this way. A file's new contents are on flash once the program closes it, as write_file does; a power cut while one is being written leaves the old version, whole. Moving a file between flash/ and the rest of the tree copies it.

Board flash/ holds
ESP32-S3 (16 MB flash) 12 MB
ESP32 WROOM-32 (4 MB flash) 448 KB
STM32H7 no flash/ yet: every file is in RAM

An image can't bring files into flash/ (--data refuses it); copy them in over the network with microgoose sftp, or have the program write them. A USB flash leaves flash/ as it is. A board flashed with MicroGoose 0.1 gets the storage area at its next USB flash; an update over WiFi can't change the partition table.

What a program prints on stderr (its warnings, and the timings Goose's samples print) shows in red, so it stands apart from its output.

Choosing the serial port

For the ESP32 targets, MicroGoose uses the one Espressif, CH343, CP210x or FTDI port it finds. It deliberately skips CH340 adapters, because Arduino clones use them too. If it finds none or several, it stops before it builds and lists the ports it sees. Name the board's port with --port:

microgoose run hello/main.goose --target esp32 --port COM7

A port is COM7 on Windows, and looks like /dev/ttyUSB0 on Linux and /dev/cu.usbserial-0001 on macOS. To make one the default, set the MG_PORT environment variable to it.

The STM32H7 has no serial port to choose: its console is SEGGER RTT over the ST-Link.

Sizing data stacks

microgoose prints how much memory a program's data stacks take before it builds:

[mg] sieve.goose: 2 data stacks, 2 main regions, 0 per worker; 200 KB each -> 400 KB for main

If a program stops with goose runtime error: data stack overflow ... raise --reserve, give it more with --reserve 64K (or more, up to what the board has). If it stops with cannot reserve data stack address space, the total doesn't fit: use a smaller --reserve, or a board with PSRAM.

Each thread_spawn worker reserves data stacks of its own (1 per worker in a line like the one above), beside a 16 KB native stack. They are --reserve bytes each unless --worker-reserve gives them another size:

[mg] bench.goose: 6 data stacks, 6 main regions, 1 per worker; 16 KB each, a worker's 4 KB -> 96 KB for main

A worker that computes on numbers and passes messages writes little or nothing to a data stack. One that builds strings or arrays writes more. The size is a multiple of 4K on the ESP32s and of 32 bytes on the H7. On a board with no PSRAM this is what decides how many workers fit: on the WROOM-32, four workers with 16 KB data stacks take 130 KB, and with 4 KB ones 82 KB.

A worker's native stack

Beside its data stacks, each worker has a native stack: where the compiled code keeps its calls. It is 16 KB unless --worker-stack gives another size, at least 2K:

microgoose run main.goose --worker-reserve 4K --worker-stack 4K

On the WROOM-32 a waiting worker with 4 KB data stacks holds 21 KB as built and 9 KB with --worker-stack 4K, so 19 fit where 8 did.

How much a worker needs depends on what it calls, not on its data. On the ESP32s a worker that does nothing used 0.7 to 0.9 KB of it, one that builds a text and prints it 1.1 to 1.3 KB, and one that writes a file and reads it back 2.6 to 2.8 KB. Measure it with the stack at its 16 KB, then choose a size with room to spare: a worker that runs past its native stack overwrites whatever lies below it. On the STM32H7 that faults at once, with native call stack overflow. On the ESP32s nothing stops it. In one test a worker that needed 2.8 KB of a 2 KB stack wrote over the main program's data and the program carried on. More often the board crashes on what was overwritten, and MicroGoose then says what it found:

goose runtime error: native call stack overflow, most likely (a worker had 128 bytes of its native stack untouched when the board crashed; raise --worker-stack)

Measuring stacks

--stack-report builds a program that measures its own stacks. It prints the report when the program ends, and wherever the program calls stack_report(), which is how a program that never ends gets one:

[microgoose] stack report: bytes used, of bytes reserved
[microgoose]   main: native stack 1464 of 24576; data stacks 66 83 149 0 0 of 16384 each
[microgoose]   workers: 5 started; in those that ended, native stack at most 2836 of 16384, a data stack at most 670 of 16384
  • main is the main program: its native stack, and each of its data stacks in the order the compiler numbered them.
  • workers has the fullest native stack and the fullest data stack among the workers that have ended. A worker still running isn't counted yet.

Read --reserve off the largest of main's data stacks, --worker-reserve off the workers' data stack and --worker-stack off their native stack, each with room to spare: the report is what one run used, and another run can take a path that uses more.

A native stack's figure is where its untouched bytes begin, and a call doesn't touch every byte it takes. So a figure near the stack's size can't be trusted, and the report says so: (too close to tell: it may have run past the end). Measure with a stack that is large enough, the 16 KB a worker has as built, and size from that.

The measuring costs time: every data stack is filled with a pattern when it is reserved and read back when it is released, and a worker's native stack is read when the worker ends. Build without the option once the sizes are chosen. Without it, stack_report() prints the main program's native stack alone. The Pico 2 W doesn't measure its stacks yet: --stack-report stops the build there.