From d49b425fb1f09cc99786d0a47a1530deff5eddca Mon Sep 17 00:00:00 2001
From: QuangNguyenMinh123
<100016403+QuangNguyenMinh123@users.noreply.github.com>
Date: Fri, 20 Mar 2026 23:58:33 +0700
Subject: [PATCH] Update build STM32 build instruction
---
tests/stm32f1_blink/Docker/Dockerfile | 46 ++++++++++++++++++++++++
tests/stm32f1_blink/Docker/entrypoint.sh | 37 +++++++++++++++++++
tests/stm32f1_blink/Makefile | 14 ++++++++
tests/stm32f1_blink/README.md | 18 ++++++----
tests/stm32f1_blink/build.sh | 5 ---
5 files changed, 108 insertions(+), 12 deletions(-)
create mode 100755 tests/stm32f1_blink/Docker/Dockerfile
create mode 100755 tests/stm32f1_blink/Docker/entrypoint.sh
diff --git a/tests/stm32f1_blink/Docker/Dockerfile b/tests/stm32f1_blink/Docker/Dockerfile
new file mode 100755
index 0000000..5ff1a33
--- /dev/null
+++ b/tests/stm32f1_blink/Docker/Dockerfile
@@ -0,0 +1,46 @@
+# =============================================================================
+# STM32 Firmware Build Environment
+# =============================================================================
+
+FROM ubuntu:22.04
+
+ENV DEBIAN_FRONTEND=noninteractive \
+ TZ=UTC \
+ PATH="/opt/arm-gnu-toolchain/bin:${PATH}"
+
+# ----------------------------------------------------------------------
+# 1. Install system packages
+# ----------------------------------------------------------------------
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ ca-certificates curl xz-utils \
+ make cmake ninja-build git \
+ python3 python3-venv libncurses5 \
+ dfu-util stlink-tools sudo \
+ && rm -rf /var/lib/apt/lists/*
+
+# ----------------------------------------------------------------------
+# 2. Install Arm GNU Toolchain
+# ----------------------------------------------------------------------
+RUN curl -L -o /tmp/tc.tar.xz \
+ https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi.tar.xz && \
+ mkdir -p /opt/arm-gnu-toolchain && \
+ tar -xJf /tmp/tc.tar.xz -C /opt/arm-gnu-toolchain --strip-components=1 && \
+ rm -f /tmp/tc.tar.xz
+
+# ----------------------------------------------------------------------
+# 3. Create user + permissions
+# ----------------------------------------------------------------------
+RUN useradd -m -s /bin/bash -u 1000 developer && \
+ echo "developer ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/developer && \
+ chmod 0440 /etc/sudoers.d/developer && \
+ mkdir -p /workdir && chown developer:developer /workdir && \
+ echo 'export PATH="/opt/arm-gnu-toolchain/bin:$PATH"' >> /home/developer/.bashrc
+
+USER developer
+WORKDIR /workdir
+
+COPY --chown=developer:developer ./entrypoint.sh /opt/entrypoint.sh
+RUN chmod +x /opt/entrypoint.sh
+
+ENTRYPOINT ["/opt/entrypoint.sh"]
+CMD ["bash"]
\ No newline at end of file
diff --git a/tests/stm32f1_blink/Docker/entrypoint.sh b/tests/stm32f1_blink/Docker/entrypoint.sh
new file mode 100755
index 0000000..7907f0b
--- /dev/null
+++ b/tests/stm32f1_blink/Docker/entrypoint.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+USER_NAME=developer
+GROUP_NAME=scom-group
+
+# Verification that the user is not already created. (For bug in gitlab CI where the entrypoint is run multiple times)
+if id "${USER_NAME}" >/dev/null 2>&1; then
+ echo "user ${USER_NAME} found"
+else
+ # User creation
+ if [ -d "/workdir" ]; then
+ USER_ID=$(stat -c %u /workdir/)
+ GROUP_ID=$(stat -c %g /workdir/)
+
+ echo "Init ${USER_NAME} with uid: ${USER_ID} & gid; ${GROUP_ID}"
+ sudo groupadd -g "${GROUP_ID}" "${GROUP_NAME}"
+ sudo useradd ${USER_NAME} -u "${USER_ID}" -g "${GROUP_ID}" -ml -s /bin/bash
+ else
+ echo "Error: Directory /workdir does not exists. Unable to set the container UID & GID."
+ sudo useradd ${USER_NAME} -ml -s /bin/bash
+ fi
+fi
+
+# sudo usermod -G sudo ${USER_NAME}
+
+if [ -d "/host" ]; then
+ # shellcheck disable=SC2045
+ for ITEM in $(ls -A /host/); do
+ if [ -e "/home/${USER_NAME}/${ITEM}" ]; then
+ echo "File $ITEM already present. Overwriting it with the one found in /host."
+ fi
+ sudo ln -svf "/host/${ITEM}" "/home/${USER_NAME}/${ITEM}"
+ sudo chown "${USER_NAME}:${GROUP_NAME}" "/home/${USER_NAME}/${ITEM}"
+ done
+fi
+
+sudo su "${USER_NAME}"
\ No newline at end of file
diff --git a/tests/stm32f1_blink/Makefile b/tests/stm32f1_blink/Makefile
index e669822..6839eff 100644
--- a/tests/stm32f1_blink/Makefile
+++ b/tests/stm32f1_blink/Makefile
@@ -119,6 +119,20 @@ flash: $(BUILD_DIR)/$(TARGET).elf
openocd -f $(JLINK_CFG) -f $(OPENOCD_TARGET) \
-c "program $< verify reset exit"
+build_docker:
+ docker build -t docker_stm32 Docker
+
+docker:
+ docker run --rm -it --user $(id -u):$(id -g) \
+ --name "docker_build_stm32" \
+ --mount type=bind,source="${HOME}/.bash_history",target=/home/user/.bash_history \
+ --mount type=bind,source="${HOME}/.bashrc",target=/home/user/.bashrc \
+ --mount type=bind,source="${HOME}/.gitconfig",target=/home/user/.gitconfig \
+ --mount type=bind,source="${HOME}/.ssh",target=/home/user/.ssh \
+ --mount type=bind,source="${PWD}",target=/workdir \
+ --workdir=/workdir \
+ docker_stm32
+
clean:
@echo "[RM] $(BUILD_DIR)"; $(RM) -r $(BUILD_DIR)
diff --git a/tests/stm32f1_blink/README.md b/tests/stm32f1_blink/README.md
index 9581d9f..ec27c9b 100644
--- a/tests/stm32f1_blink/README.md
+++ b/tests/stm32f1_blink/README.md
@@ -5,13 +5,17 @@ This test for quick build and testing seer using stm32 smart v2.0j board, or ess
+ stm32 smart v2.0j board
+ J-Link, or you can use other hardware debugger if you're capable of doing
# Prerequisite
-Install gdb-multiarch:
-```sudo apt install gcc-arm-none-eabi```
-and install openocd and openocd driver for J-link:
-```./install_openocd.sh```
-# Build
-Connect hardware debugger to stm32f1 board
-run `./build.sh`, it will pull remote library, build and flash image to stm32f1 automatically for your
++ Install docker, makefile
++ Install openocd: `./install_openocd.sh`
+# Instruction
++ Build STM32 firmware: (run in docker container)
+ + Build docker image: `make build_docker`
+ + Run docker image: `make docker`
+ + Build image in docker: `./build.sh`
+Final image is located at: stm32f1_blink/build/main.elf
++ Flash image to STM32 board: (run in host terminal)
+ + make flash JLINK_CFG=interface/jlink.cfg
+You'll see the STM32 led blinks
# Troubleshoot:
+ Install Jlink driver
+ Proper connection
diff --git a/tests/stm32f1_blink/build.sh b/tests/stm32f1_blink/build.sh
index 195acfb..88158e9 100755
--- a/tests/stm32f1_blink/build.sh
+++ b/tests/stm32f1_blink/build.sh
@@ -4,10 +4,5 @@ git clone https://github.com/STMicroelectronics/STM32CubeF1.git vendor
cd vendor
git submodule update --init --recursive
cd ..
-# install package
-sudo apt install gcc-arm-none-eabi
# make
make
-# make flash, assume that openocd is installed by running install_openocd.sh
-make flash JLINK_CFG=${PWD}/../openocd/tcl/interface/jlink.cfg
-