Skip to content

First Sail51 build

Select the MCU

In the terminal prepared during installation, list the profiles in your installed SDK. Inspect the exact profile you intend to build for. This guide uses the STC8H8K64U.

Terminal window
sail51 --list-targets
sail51 --target stc8h8k64u --print-target

An exact profile gives the compiler the device’s memory limits and core settings. A family profile provides common settings. Check the specific part’s limits and debug support before using a family profile on hardware.

Compile a program

Save this program as counter.c in a writable project folder. It increments a volatile byte in memory and does not need board-specific peripherals.

static volatile unsigned char counter;
int main(void) {
for (;;) {
++counter;
}
}

From that project folder, run the build in the same terminal.

Terminal window
sail51 --target stc8h8k64u -std=c99 -Os --memory-model small --emit all counter.c -o counter

Open counter.map and check the CODE and data allocations. counter.hex is the Intel HEX firmware image. Select the actual MCU and check the memory layout before programming a board.

Options to carry into a project

Option What to select
--target The exact MCU profile whenever one is available.
--memory-model Use small, compact, or large as required by the project and its libraries. Default data placement uses DATA, PDATA, or XDATA respectively. Check the resulting memory map.
-std The language mode your sources need. The driver lists c90, c99, c11, c17, and c23.
-Os Optimize for code size. Keep the project’s optimization and compatibility flags consistent when comparing firmware builds.
--emit all Request the firmware outputs and the linker map. Use sail51 --help for the available output modes.

For an existing C51 project, use its current device, memory model, and libraries when you convert and debug it.