Skip to content

Commit b4b36a6

Browse files
committed
fix(modem_sim): Add support to setup initial uart pins
1 parent 25513d0 commit b4b36a6

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

common_components/modem_sim/install.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
set -e
33

44
# Create directory "modem_sim_esp32", go inside it
5-
# Usage: ./install.sh [platform] [module]
5+
# Usage: ./install.sh [platform] [module] [uart_tx_pin] [uart_rx_pin]
66

77
SCRIPT_DIR=$(pwd)
8+
UPDATE_UART_PINS_SCRIPT="$(cd "$(dirname "$0")" && pwd)/update_uart_pins.py"
89
mkdir -p modem_sim_esp32
910
cd modem_sim_esp32
1011

@@ -39,6 +40,8 @@ mkdir -p build
3940
# Default values for platform and module
4041
platform="PLATFORM_ESP32"
4142
module="WROOM-32"
43+
uart_tx_pin=""
44+
uart_rx_pin=""
4245

4346
# Override defaults if parameters are provided
4447
if [ ! -z "$1" ]; then
@@ -47,17 +50,42 @@ fi
4750
if [ ! -z "$2" ]; then
4851
module="$2"
4952
fi
53+
if [ ! -z "$3" ]; then
54+
uart_tx_pin="$3"
55+
fi
56+
if [ ! -z "$4" ]; then
57+
uart_rx_pin="$4"
58+
fi
59+
60+
# Use provided pins for description when present; otherwise keep defaults
61+
description="4MB, Wi-Fi + BLE, OTA, TX:17 RX:16"
62+
if [ -n "$uart_tx_pin" ] || [ -n "$uart_rx_pin" ]; then
63+
desc_tx=${uart_tx_pin:-17}
64+
desc_rx=${uart_rx_pin:-16}
65+
description="4MB, Wi-Fi + BLE, OTA, TX:${desc_tx} RX:${desc_rx}"
66+
fi
5067

5168
# Create file "build/module_info.json" with content
5269
cat > build/module_info.json << EOF
5370
{
5471
"platform": "$platform",
5572
"module": "$module",
56-
"description": "4MB, Wi-Fi + BLE, OTA, TX:17 RX:16",
73+
"description": "$description",
5774
"silence": 0
5875
}
5976
EOF
6077

78+
# Optionally update UART pins in factory_param_data.csv for the selected module
79+
if [ -n "$uart_tx_pin" ] || [ -n "$uart_rx_pin" ]; then
80+
csv_path="components/customized_partitions/raw_data/factory_param/factory_param_data.csv"
81+
if [ ! -f "$csv_path" ]; then
82+
echo "Warning: $csv_path not found; skipping UART pin update."
83+
else
84+
python3 "$UPDATE_UART_PINS_SCRIPT" "$platform" "$module" "$uart_tx_pin" "$uart_rx_pin" "$csv_path"
85+
echo "Updated UART pins in $csv_path"
86+
fi
87+
fi
88+
6189
cp "$SCRIPT_DIR/sdkconfig.defaults" "module_config/module_esp32_default/sdkconfig.defaults"
6290

6391
echo "Installation completed successfully!"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
import csv
3+
import pathlib
4+
import sys
5+
6+
7+
def update_uart_pins(platform: str, module: str, tx_pin: str, rx_pin: str, csv_path: str) -> None:
8+
path = pathlib.Path(csv_path)
9+
rows = []
10+
found = False
11+
12+
with path.open(newline="") as f:
13+
reader = csv.DictReader(f)
14+
fieldnames = reader.fieldnames
15+
for row in reader:
16+
if row.get("platform") == platform and row.get("module_name") == module:
17+
if tx_pin:
18+
row["uart_tx_pin"] = tx_pin
19+
if rx_pin:
20+
row["uart_rx_pin"] = rx_pin
21+
found = True
22+
rows.append(row)
23+
24+
if not found:
25+
print(f"Warning: no row updated for platform={platform} module={module}")
26+
27+
with path.open("w", newline="") as f:
28+
writer = csv.DictWriter(f, fieldnames=fieldnames)
29+
writer.writeheader()
30+
writer.writerows(rows)
31+
32+
33+
def main() -> int:
34+
if len(sys.argv) != 6:
35+
print("Usage: update_uart_pins.py <platform> <module> <uart_tx_pin> <uart_rx_pin> <csv_path>")
36+
return 1
37+
38+
platform, module, tx_pin, rx_pin, csv_path = sys.argv[1:6]
39+
update_uart_pins(platform, module, tx_pin, rx_pin, csv_path)
40+
return 0
41+
42+
43+
if __name__ == "__main__":
44+
raise SystemExit(main())
45+

0 commit comments

Comments
 (0)