Skip to content

Commit 8c5b929

Browse files
committed
samples: modem: hello_hl78xx: add auto-baud support and log current baud
Enable HL78XX modem auto-baudrate detection and switching in the sample application. Set 921600 bps as the target baudrate with fallback options (9600, 115200, 57600, 38400, 19200). Also read and log the current baudrate from the modem during startup. This helps verify and debug communication speed mismatches between the modem and the device UART. Signed-off-by: Zafer SEN <zafersn93@gmail.com>
1 parent 4e85c3c commit 8c5b929

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

samples/drivers/modem/hello_hl78xx/prj.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ CONFIG_MODEM_HL78XX=y
5959
# Statistics
6060
CONFIG_MODEM_STATS=y
6161

62+
# ============================================================================
63+
# Auto Baud Rate Detection and Switching
64+
# ============================================================================
65+
CONFIG_MODEM_HL78XX_AUTO_BAUDRATE=y
66+
# CONFIG_MODEM_HL78XX_AUTOBAUD_AT_BOOT=y
67+
# CONFIG_MODEM_HL78XX_AUTOBAUD_ONLY_IF_COMMS_FAIL=n
68+
# CONFIG_MODEM_HL78XX_TARGET_BAUDRATE_9600=y
69+
# CONFIG_MODEM_HL78XX_TARGET_BAUDRATE_115200=y
70+
CONFIG_MODEM_HL78XX_TARGET_BAUDRATE_921600=y
71+
CONFIG_MODEM_HL78XX_AUTOBAUD_DETECTION_BAUDRATES="9600,115200,921600,57600,38400,19200"
72+
CONFIG_MODEM_HL78XX_AUTOBAUD_TIMEOUT=4
73+
CONFIG_MODEM_HL78XX_AUTOBAUD_RETRY_COUNT=3
74+
# After enabling auto-baud once WITH CONFIG_MODEM_HL78XX_AUTOBAUD_CHANGE_PERSISTENT,
75+
# the modem's baud rate is saved to NV-MEM with AT&W, so it persists across power cycles.
76+
# If you later disable CONFIG_MODEM_HL78XX_AUTO_BAUDRATE, the driver won't detect/switch,
77+
# but the modem is still at the target baud rate (e.g., 921600)
78+
# If your device tree UART is at 115200 but the modem is at 921600, communication will fail
79+
# CONFIG_MODEM_HL78XX_AUTOBAUD_CHANGE_PERSISTENT=n
80+
# CONFIG_MODEM_HL78XX_AUTOBAUD_START_WITH_TARGET_BAUDRATE=n
81+
6282
# ============================================================================
6383
# APN Configuration (Disabled - using defaults)
6484
# ============================================================================

samples/drivers/modem/hello_hl78xx/src/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ int main(void)
300300
enum hl78xx_cell_rat_mode tech;
301301
enum cellular_registration_status status;
302302
int16_t signal_strength = 0;
303+
uint32_t current_baudrate = 0;
303304
const char *newapn = "";
304305
const char *sample_cmd = "AT";
305306

@@ -344,6 +345,9 @@ int main(void)
344345
/* Get the current network operator name */
345346
hl78xx_get_modem_info(modem, HL78XX_MODEM_INFO_NETWORK_OPERATOR, (char *)operator,
346347
sizeof(operator));
348+
/* Get the current baudrate */
349+
hl78xx_get_modem_info(modem, HL78XX_MODEM_INFO_CURRENT_BAUD_RATE, &current_baudrate,
350+
sizeof(current_baudrate));
347351

348352
LOG_RAW("\n**********************************************************\n");
349353
LOG_RAW("********* Hello HL78XX Modem Sample Application **********\n");
@@ -361,6 +365,7 @@ int main(void)
361365
LOG_INF("RSRP : %d", signal_strength);
362366
#endif
363367
LOG_INF("Operator: %s", (strlen(operator) > 0) ? operator : "\"\"");
368+
LOG_INF("Current Baudrate: %dbps", current_baudrate);
364369
LOG_RAW("**********************************************************\n\n");
365370

366371
LOG_INF("Setting new APN: %s", newapn);

0 commit comments

Comments
 (0)