Skip to content

Commit 903f752

Browse files
committed
fix: add connect-under-reset to flash.sh, so now all stm32g0 flashes are successful
1 parent 9ffb38c commit 903f752

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ tests:
9999
${ROOT_DIR}/scripts/tests.sh
100100

101101
upload:
102-
LATEST_TARGET=$$(ls -td ${BUILD_DIR}/release/*.bin | head -1) && ./scripts/tools/stm32/flash.sh $$LATEST_TARGET
102+
LATEST_TARGET=$$(ls -td ${BUILD_DIR}/release/*.bin | head -1) && ./scripts/flash.sh $$LATEST_TARGET
103103

104104
SOCKETCAN_URL:=https://gist.githubusercontent.com/PonomarevDA/6ecc8fc340e4c50619c1e5dfcedc37b2/raw/2db6d1626a9ada543602ff0a52b48fecb94e6e07/socketcan.sh
105105
SOCKETCAN_EXECUTABLE:=build/tools/socketcan-v1.0.2.sh

docs/issues.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@
44
- affected versions: [v1.4.0, v1.5.0]
55
- introduced by: `b65b63c` (`pwm: introduce pwm router and refactor pwm frontends`, 2025-12-08)
66
- on test: `Tests/test_issue_0001_pwm_same_channel_apply.py`
7+
8+
## ISSUE-0002
9+
- affected versions: [v3 introduction, v1.6.0)
10+
- introduced by: STM32G0 (Mini v3) support
11+
- symptoms: stm32g0 flashing fails every second attempt with `st-flash ... Flash programming error: 0x00000080`
12+
- root cause: flashing without connect-under-reset; target may be running IWDG and reset during programming
13+
- fixed in: v1.6.0 by using `--connect-under-reset` in `scripts/flash.sh`

scripts/flash.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
# https://gist.github.com/PonomarevDA/829961851abeca5c51154a0882a625fa
3+
# This software is distributed under the terms of the MIT License.
4+
# Copyright (c) 2023-2026 Dmitry Ponomarev.
5+
# Author: Dmitry Ponomarev <ponomarevda96@gmail.com>
6+
7+
SCRIPT_NAME="flash.sh"
8+
VERSION="v1.1.0"
9+
10+
BINARY_FILE=$1
11+
12+
RED='\033[0;31m'
13+
NC='\033[0m'
14+
if [ -z "$BINARY_FILE" ]; then
15+
echo -e "${RED}${SCRIPT_NAME} ${VERSION} error on line $LINENO: expected an argument!${NC}"
16+
exit
17+
elif [ ! -f "$BINARY_FILE" ]; then
18+
echo -e "${RED}${SCRIPT_NAME} ${VERSION} error on line $LINENO: specified file $BINARY_FILE is not exist!${NC}"
19+
exit
20+
elif [[ ! $BINARY_FILE == *.bin ]]; then
21+
echo -e "${RED}${SCRIPT_NAME} ${VERSION} error on line $LINENO: speficied file must have .bin extension!${NC}"
22+
exit
23+
fi
24+
25+
for attempt in {1..25}; do
26+
echo ""
27+
echo "${SCRIPT_NAME} ${VERSION}: attempt $attempt. Trying to load the firmware..."
28+
echo -en "\007"
29+
30+
output=$(st-info --probe)
31+
32+
is_programmer_not_found=$(echo "$output" | grep "Found 0 stlink programmers")
33+
if [ ! -z "$is_programmer_not_found" ]; then
34+
echo "${SCRIPT_NAME} ${VERSION}: stlink programmer not found. Please connect it to your USB port!"
35+
sleep 2
36+
continue
37+
fi
38+
39+
is_device_not_found=$(echo "$output" | grep "unknown device")
40+
if [ ! -z "$is_device_not_found" ]; then
41+
echo "${SCRIPT_NAME} ${VERSION}: STM32 not found. Please connect it to the stlink programmer!"
42+
sleep 2
43+
continue
44+
fi
45+
46+
# stm32f103 has a wrong flash size. It says 64 KBytes, but it is actually 128 KBytes!
47+
# Medium-density for old versions of st-link, MD for the newer versions of st-link
48+
is_stm32f103=$(echo "$output" | grep "F1xx Medium-density\|STM32F1xx_MD")
49+
if [ ! -z "$is_stm32f103" ]; then
50+
EXPLICIT_FLASH_SIZE="--flash=0x00020000"
51+
fi
52+
53+
output=$(st-flash $EXPLICIT_FLASH_SIZE --connect-under-reset --reset write $BINARY_FILE 0x8000000 | tee /dev/tty)
54+
compare_res=$(echo "$output" | grep "pages written")
55+
if [ -z "$compare_res" ]; then
56+
sleep 2
57+
else
58+
echo "${SCRIPT_NAME} ${VERSION}: done"
59+
for attempt in {1..15}; do
60+
sleep 0.1
61+
echo -en "\007"
62+
done
63+
exit
64+
fi
65+
done
66+
67+
for attempt in {1..15}; do
68+
sleep 0.1
69+
echo -en "\007"
70+
done

0 commit comments

Comments
 (0)