Skip to content

Commit a2c6402

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 3b7437d commit a2c6402

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
@@ -299,6 +299,7 @@ int main(void)
299299
enum hl78xx_cell_rat_mode tech;
300300
enum cellular_registration_status status;
301301
int16_t signal_strength = 0;
302+
uint32_t current_baudrate = 0;
302303
const char *newapn = "";
303304
const char *sample_cmd = "AT";
304305

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

347351
LOG_RAW("\n**********************************************************\n");
348352
LOG_RAW("********* Hello HL78XX Modem Sample Application **********\n");
@@ -360,6 +364,7 @@ int main(void)
360364
LOG_INF("RSRP : %d", signal_strength);
361365
#endif
362366
LOG_INF("Operator: %s", (strlen(operator) > 0) ? operator : "\"\"");
367+
LOG_INF("Current Baudrate: %dbps", current_baudrate);
363368
LOG_RAW("**********************************************************\n\n");
364369

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

0 commit comments

Comments
 (0)