Skip to content

Conversation

@zafersn
Copy link
Contributor

@zafersn zafersn commented Dec 6, 2025

Summary

This PR adds automatic baud rate detection and switching capability to the Sierra Wireless HL78xx modem driver (HL7812/HL7800). The feature enables the driver to automatically detect the modem's current UART baud rate and switch to a configured target rate, improving reliability and flexibility in production environments.

In production deployments, modems may be configured with different baud rates from previous sessions, factory defaults, or manual AT commands. Currently, if the modem's baud rate doesn't match the device tree configuration, communication fails and the driver cannot initialize. This feature eliminates manual baud rate synchronization and enables automatic recovery from baud rate mismatches.

Key Features

  • Smart Detection: Automatically detects modem's current baud rate by testing a configurable list of rates
  • Dynamic Switching: Changes modem baud rate using AT+IPR command and reconfigures UART accordingly
  • Persistent Storage: Optionally saves configuration to modem NVRAM using AT&W for persistence across power cycles
    • Optimization Flags: Five smart configuration options for minimal boot time impact:
    • AUTOBAUD_ONLY_IF_COMMS_FAIL: Skip detection if modem already responds (default: enabled)
    • AUTOBAUD_START_WITH_TARGET_BAUDRATE: Try target rate first (default: enabled)
    • AUTOBAUD_CHANGE_PERSISTENT: Save with AT&W to NVRAM (default: enabled)
    • AUTOBAUD_DIAGNOSING_FIRST: Automatic recovery from diagnostic state (default: disabled)
    • AUTOBAUD_AT_BOOT: Ultra-fast boot mode, skip KSUP wait (default: disabled, advanced)
  • Configurable: Supports baud rates from 9600 to 3000000 bps
  • Robust: Configurable timeout (1-120 seconds) and retry count (1-10 attempts)
  • State Machine Integration: Seamlessly integrated into modem initialization flow

Extend socket-related chat match tables to handle generic "ERROR" responses
for both CONNECT and +KUDP_IND URCs, improving detection of failed socket
creation and connection attempts.

While updating match handling, unify all modem commands to use the standard
OK match set by adding hl78xx_get_ok_match_size(). All remaining users of
the former sockets-specific OK match are switched to the unified helpers.

Additionally, all dynamic command send paths now provide an explicit match
count and use MDM_CMD_TIMEOUT instead of the previous hard-coded `1` for
script timeout, improving consistency and reliability across:
* RAT configuration
* band configuration
* APN setup
* GSM PDP activation
* AirVantage DM session control
* socket send and TLS configuration paths

This brings all command execution onto the same match/timeout model and
ensures ERROR responses are handled correctly during socket operations.

Signed-off-by: Zafer SEN <zafersn93@gmail.com>
Extend modem_dynamic_cmd_send() with a response_timeout parameter to allow
callers to specify the overall script timeout per command. The previously
hardcoded 1000 ms timeout is removed (set to 0 in params) and the script
timeout is now driven by the passed-in value.

Update all internal call sites to provide MDM_CMD_TIMEOUT (in seconds) and
increase the default command timeout from 10 s to 40 s. Several chat
scripts and configuration paths are updated accordingly.

This improves reliability for long-running HL78xx operations and ensures
consistent timeout handling across sockets, RAT/band configuration, APN
setup, PDP activation, AirVantage DM session control, and TLS/TCP/UDP
socket management.

Signed-off-by: Zafer SEN <zafersn93@gmail.com>
Add MODEM_HL78XX_EVENT_AT_CMD_TIMEOUT event to distinguish chat scripts
timeouts from other script failures. The chat callback now maps
MODEM_CHAT_SCRIPT_RESULT_TIMEOUT to this new event.

Update state handlers so AT command timeouts trigger the init fail
diagnostic script during startup, and fall back to the power-on pulse in
the init-fail state, similar to existing timeout handling.

This improves error classification and enables more accurate recovery
logic for long-running or stalled AT command exchanges.

Signed-off-by: Zafer SEN <zafersn93@gmail.com>
@zafersn zafersn force-pushed the feature/hl78xx-auto-baudrate branch 2 times, most recently from 0311f12 to 340ee1c Compare December 6, 2025 14:00
…ching

This adds an optional auto-baudrate mechanism that improves robustness
when the modem boots with an unknown or changed UART speed.

Key additions:
* New Kconfig option MODEM_HL78XX_AUTO_BAUDRATE and related settings:
  - selectable target baud rate
  - detection baudrate list
  - detection timeout and retry count
  - option to persist AT+IPR updates
  - option to start diagnostics or boot directly with auto-baud logic
* UART status tracking added to hl78xx_data, including current and target
  baud rates
* New HL78XX_MODEM_INFO_CURRENT_BAUD_RATE info field
* New MODEM_HL78XX_STATE_SET_BAUDRATE state with detection and switching
  logic
* Chat, init, and diagnostic handlers updated to route failures into the
  auto-baudrate logic when enabled
* New helpers: hl78xx_get_uart_config(), hl78xx_try_baudrate(),
  hl78xx_detect_current_baudrate(), hl78xx_switch_baudrate()
* Startup delay increased when auto-baudrate-at-boot is enabled

These changes allow the driver to recover from unexpected modem UART rate
changes and keep the UART configuration synchronized with the modem.

Signed-off-by: Zafer SEN <zafersn93@gmail.com>
Reorganize the sample configuration files for clarity and easier
maintenance. This introduces grouped sections with descriptive comments
and improves consistency between prj.conf and the verbose-logging
overlay.

Main updates:
* Add structured headers for system, UART, networking, modem, RAT,
  AirVantage, shell, and logging settings
* Expand verbose overlay with clearer purpose, build notes, and grouped
  modem logging options
* Improve readability by aligning comments and collecting related
  options
* No functional behavior is changed; this is a documentation and
  structure improvement

These changes make the sample configuration easier to understand and
simplify future maintenance.

Signed-off-by: Zafer SEN <zafersn93@gmail.com>
The sample no longer requires the POSIX API layer, so the
CONFIG_POSIX_API option is removed from prj.conf. The code is updated to
use the native zsock_* APIs instead of the POSIX getaddrinfo(),
inet_ntop(), and freeaddrinfo() variants.

This aligns the sample with Zephyr’s preferred socket API and avoids
pulling in unnecessary POSIX compatibility layers.

No functional behavior is changed.

Signed-off-by: Zafer SEN <zafersn93@gmail.com>
Add support for handling AirVantage WDSI indications in the sample
application. FOTA update progress, download requests, and completion
events are processed and coordinated using a new semaphore. The sample
can restart its connection workflow after a successful firmware update.

Additional updates include:
- add serial number retrieval and logging
- add fota_complete_rerun semaphore and status tracking
- simplify debug logging in event listener and OK handler
- reorganize main loop to support FOTA-triggered reruns

This aligns the sample with the modem driver's expanded AirVantage and
WDSI support.

Signed-off-by: Zafer SEN <zafersn93@gmail.com>
The sample previously always queried RSRP, which is not valid when the
HL78xx operates in GSM mode. Use RSSI when GSM RAT is active and RSRP
for other RATs. Update the log output and rename the variable for
clarity.

Signed-off-by: Zafer SEN <zafersn93@gmail.com>
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>
Add detailed documentation for the HL78xx auto-baudrate feature,
including:

- AUTO_BAUDRATE_README.md: full description, use cases,
  configuration options, and troubleshooting
- QUICK_REFERENCE.md: concise reference for presets, Kconfig
  options, and supported baud rates

Covers:
- Feature overview and implementation details
- Supported baud rates and Kconfig options
- State machine integration
- Troubleshooting guidance
- Performance and optimization tips
- Integration examples

This improves usability and provides a quick reference for developers
working with the HL78xx modem in Zephyr projects.

Signed-off-by: Zafer SEN <zafersn93@gmail.com>
@zafersn zafersn force-pushed the feature/hl78xx-auto-baudrate branch from 340ee1c to 8559e9a Compare December 6, 2025 14:10
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 6, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants