Merge pull request #442 from QuangNguyenMinh123/Update_STM32_Build

Update build STM32 build instruction
This commit is contained in:
Ernie Pasveer
2026-04-19 08:51:07 -05:00
committed by GitHub
5 changed files with 108 additions and 12 deletions
+46
View File
@@ -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"]
+37
View File
@@ -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}"
+14
View File
@@ -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)
+11 -7
View File
@@ -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` <br>
Final image is located at: stm32f1_blink/build/main.elf<br>
+ Flash image to STM32 board: (run in host terminal)
+ make flash JLINK_CFG=interface/jlink.cfg <br>
You'll see the STM32 led blinks
# Troubleshoot:
+ Install Jlink driver
+ Proper connection
-5
View File
@@ -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