Skip to content
hamsadevPublic

About

RIL (Radio Interface Layer) - A comprehensive C library for interfacing with Quectel cellular modems on STM32 microcontrollers. Provides high-level AT command abstraction for SMS, HTTP/HTTPS, MQTT, and Socket operations.

Topics

Resources

Stars

17 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RIL β€” Radio Interface Layer for Embedded C

A zero-heap, hardware-agnostic AT command & cellular protocol stack for Quectel (EC200U, EG915U, EC600U) and MeiG Smart (SLM320) modems on STM32 β€” portable to any MCU or PC.

Language Target Modems Memory RTOS Tests License

Quick Start Β· Usage Recipes Β· Integration Β· Configuration Β· Module API Β· Examples Β· Host Tests


Why RIL?

Interfacing a cellular modem over UART quickly turns into fragile boilerplate: manual AT+... formatting, timeouts, binary prompt (>) framing, +CME ERROR parsing, and unsolicited messages (URCs) colliding with active AT commands.

RIL replaces raw AT plumbing with a clean, deterministic C API:

Without RIL With RIL
Hand-craft AT strings and state machines per command Call RIL_HTTP_Get(), RIL_MQTT_Publish(), RIL_SMS_SendSMS_Text(), RIL_SOC_Send()
URCs (+CMTI, +QMTRECV, +CREG) lost or mixed into AT responses Captured in a lock-safe circular byte-ring (urcRing) and dispatched in RIL_ServiceRoutine()
Heap fragmentation from malloc/free in long-running firmware Zero dynamic memory in RIL core & SMS; bounded, configurable static buffers
Locked to STM32 HAL, impossible to unit test on PC Hardware I/O isolated behind RIL_Transport with a built-in Unity mock test suite

Architecture

flowchart TB
    APP["Your Application (Bare-Metal or CMSIS-RTOS v2)"]
    MOD["Protocol Modules<br/>System Β· Network Β· SIM Β· SMS Β· HTTP/S Β· MQTT Β· File/UFS Β· Socket Β· Telephony Β· DateTime"]
    CORE["RIL Core Engine<br/>Sync AT Runner Β· Binary Framing Β· 40+ URC Parser Β· Circular Byte-Ring (urcRing)"]
    PORT["RIL_Transport Interface (I/O + Tick/Delay)"]
    STM["STM32 UARTStream Backend<br/>DMA / IT Ring Buffers (Libs/UARTStream)"]
    CUST["Custom MCU / POSIX / Host Mock<br/>(Tests/mock/ril_transport_mock.c)"]

    APP --> MOD
    APP --> CORE
    MOD --> CORE
    CORE --> PORT
    PORT --> STM
    PORT --> CUST
Loading

Supported Modems

Modem Manufacturer Technology Status
EC200U Quectel LTE Cat-1 / 2G / 3G βœ… Primary target β€” all 9 examples hardware-verified
SLM320 MeiG Smart LTE Cat-1 βœ… Compatible (shared AT command set)
EG915U / EC200A / EC600U Quectel LTE Cat-1 βœ… Compatible AT command set
Any AT-command modem Generic β€” ⚠️ Core AT/URC & binary transfer via RIL_SendATCmd() / RIL_SendBinaryData()

πŸš€ 5-Minute Quick Start

Important

Hardware & CubeMX Checklist (Read Before Flashing)

  1. Modem UART: 115200 8N1, Hardware Flow Control = None, with DMA (recommended) or Interrupts enabled for both RX and TX plus UART global NVIC interrupt. (Polling mode is not supported.)
  2. Power Supply: Cellular RF bursts draw > 2 A peaks β€” use a dedicated regulator and bulk capacitance near the modem.
  3. Power / Reset Pins Are Optional:
    • Always-on modem: You do not need to connect PWRKEY or RESET to the MCU β€” simply pass NULL as powerCommandCb to RIL_initialize(). RIL automatically skips power-restart cycling and RIL_POWER_RESTART_DELAY_MS.
    • MCU-controlled power: Implement on_modem_power and set RIL_POWER_RESTART_DELAY_MS in ril_config.h (the EC200U examples use 13000u to allow full modem boot).

Step 1 β€” Add RIL to Your Project

Choose the integration workflow that matches your toolchain:

  • CMake: add_subdirectory(ril) and link ril::ril
  • STM32CubeMX / Keil / IAR / STM32CubeIDE: copy SourceCode/ + Libs/ and add SourceCode/inc, Libs/Stream, Libs/UARTStream to your include paths

(Full step-by-step instructions for all 3 methods are in Integration (3 Ways) below.)

Step 2 β€” Wire UART Callbacks (and Optional Power Callback)

Add the UART hooks in main.c (or your UART IRQ file) for your modem UART (e.g., USART1). Implement on_modem_power only if your MCU controls PWRKEY / RESET:

#include "ril.h"

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
  if (huart->Instance == USART1) { RIL_rxCpltHandle(); }
}

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
  if (huart->Instance == USART1) { RIL_txCpltHandle(); }
}

void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
  if (huart->Instance == USART1) { RIL_errorHandle(); }
}

/* Optional: omit if modem is always powered on (pass NULL to RIL_initialize) */
static void on_modem_power(RIL_PowerCommand cmd)
{
  switch (cmd)
  {
  case RIL_POWER_COMMAND_ON:
  case RIL_POWER_COMMAND_OFF:
    HAL_GPIO_WritePin(EC_PWR_KEY_GPIO_Port, EC_PWR_KEY_Pin, GPIO_PIN_RESET);
    HAL_Delay(3000);
    HAL_GPIO_WritePin(EC_PWR_KEY_GPIO_Port, EC_PWR_KEY_Pin, GPIO_PIN_SET);
    break;
  case RIL_POWER_COMMAND_RESTART:
    HAL_GPIO_WritePin(EC_RST_GPIO_Port, EC_RST_Pin, GPIO_PIN_RESET);
    HAL_Delay(150);
    HAL_GPIO_WritePin(EC_RST_GPIO_Port, EC_RST_Pin, GPIO_PIN_SET);
    break;
  }
}

Step 3 β€” Initialize & Run the Service Loop

#include "ril.h"
#include "ril_system.h"

static void on_urc(RIL_URCInfo *info)
{
  switch (info->urcType)
  {
  case URC_CMTI:
    /* New SMS stored: info->params[0].str (storage), info->params[1].str (index) */
    break;
  case URC_CREG:
  case URC_CEREG:
    /* Network registration changed */
    break;
  case URC_QMTRECV:
    /* Incoming MQTT payload */
    break;
  default:
    break;
  }
}

Choose Bare-Metal or CMSIS-RTOS v2 / FreeRTOS:

  • Option A: Bare-Metal (RIL_USE_OS=0, default)

    int main(void)
    {
      HAL_Init();
      SystemClock_Config();
      MX_GPIO_Init();
      MX_DMA_Init();
      MX_USART1_UART_Init();
    
      /* Pass on_modem_power instead of NULL if MCU controls PWRKEY/RESET */
      if (RIL_initialize(&huart1, on_urc, NULL, NULL) != RIL_AT_SUCCESS)
      {
        Error_Handler();
      }
    
      char imei[32] = {0};
      RIL_SYS_GetIMEI(imei);
    
      while (1)
      {
        RIL_ServiceRoutine(); /* Drains queued URCs and polls incoming lines */
        HAL_Delay(20);
      }
    }
  • Option B: CMSIS-RTOS v2 / FreeRTOS (RIL_USE_OS=1)

    When RIL_USE_OS=1, RIL protects AT transactions and URC draining with a recursive CMSIS-RTOS v2 mutex, so application threads can safely call RIL_* APIs concurrently while a dedicated task services URCs.

    void RilServiceTask(void *argument)
    {
      if (RIL_initialize(&huart1, on_urc, NULL, NULL) != RIL_AT_SUCCESS)
      {
        Error_Handler();
      }
    
      for (;;)
      {
        RIL_ServiceRoutine();
        osDelay(20);
      }
    }

πŸ’‘ Usage Recipes

Expand any recipe to see complete, production-style module usage:

1. Bring Up Cellular Data (SIM + Registration + APN + PDP Context)
#include "ril_sim.h"
#include "ril_network.h"

bool cellular_connect(const char *apn)
{
  Enum_SIMState sim = SIM_STAT_UNSPECIFIED;
  RIL_NW_State gprs = RIL_NW_State_Unknown;

  if (RIL_SIM_GetSimState(&sim) != RIL_AT_SUCCESS || sim != SIM_STAT_READY)
    return false;

  if (RIL_NW_GetGPRSState(&gprs) != RIL_AT_SUCCESS ||
      (gprs != RIL_NW_State_Registered && gprs != RIL_NW_State_RegisteredRoaming))
    return false;

  if (RIL_NW_SetAPNEx(1, RIL_NW_AAuthType_None, RIL_NW_ContextType_IPV4,
                      (char *)apn, NULL, NULL) != RIL_AT_SUCCESS)
    return false;

  return (RIL_NW_OpenPDPContext(1) == RIL_AT_SUCCESS);
}

Full example: Example/RIL_Network_SIM

2. HTTP / HTTPS GET Request
#include "ril_http.h"

void http_fetch_example(void)
{
  static uint8_t rxBuf[1024];
  RIL_HTTPClient http;

  RIL_HTTP_Init(&http, 1, 0);          /* PDP cid=1, sslctx=0 (HTTP) */
  RIL_HTTP_CfgContextId(&http, 1);
  RIL_HTTP_CfgSSL(&http, 0);
  RIL_HTTP_CfgRspHeader(&http, false);

  if (RIL_HTTP_SetURL(&http, "http://httpbin.org/get", 30) == RIL_HTTP_OK &&
      RIL_HTTP_Get(&http, 30) == RIL_HTTP_OK)
  {
    uint32_t actualLen = 0;
    if (RIL_HTTP_ReadToBuf(&http, rxBuf, sizeof(rxBuf) - 1u, &actualLen, 30) == RIL_HTTP_OK)
    {
      rxBuf[actualLen] = '\0';
      /* Use rxBuf (status in http.lastStatus) */
    }
  }
  RIL_HTTP_Stop(&http);
}

Full example (including POST, line streaming, and HTTPS SSL config): Example/RIL_HTTP

3. MQTT Connect, Subscribe & Publish
#include "ril_mqtt_client.h"

void mqtt_publish_example(void)
{
  RIL_MQTTClient mqtt;
  const char *payload = "{\"temp\":24.5}";

  RIL_MQTT_InitClient(&mqtt, "stm32-node-1", NULL, NULL, 60, true);
  RIL_MQTT_ConfigVersion(&mqtt, MQTT_VERSION_3_1_1);
  RIL_MQTT_ConfigReceiveMode(&mqtt, MQTT_RECV_MODE_URC, 1);

  if (RIL_MQTT_Open(&mqtt, "broker.hivemq.com", 1883) == RIL_MQTT_ERR_OK &&
      RIL_MQTT_Connect(&mqtt) == RIL_MQTT_ERR_OK)
  {
    RIL_MQTT_Subscribe(&mqtt, 1, "devices/node1/cmd", QOS_1);
    RIL_MQTT_Publish(&mqtt, 2, "devices/node1/telemetry",
                     (const uint8_t *)payload, (uint32_t)strlen(payload), QOS_1, false);
  }
}

Full example (including LWT & auto-reconnect via URC_QMTSTAT): Example/RIL_MQTT

4. Send & Read Text SMS
#include "ril_sms.h"

void sms_example(void)
{
  uint32_t msgRef = 0;
  char number[] = "+15551234567";
  uint8_t text[] = "Hello from STM32 + RIL!";

  RIL_SMS_SetStorage(RIL_SMS_STORAGE_TYPE_SM, NULL, NULL);
  RIL_SMS_SendSMS_Text(number, (uint8_t)strlen(number),
                       LIB_SMS_CHARSET_GSM, text, sizeof(text) - 1u, &msgRef);
}

Full example (including +CMTI URC handling, reading & deleting): Example/RIL_SMS

5. TCP Client Socket
#include "ril_socket.h"

void tcp_echo_example(void)
{
  uint8_t sockId = 0;
  const uint8_t tx[] = "PING\r\n";
  uint8_t rx[128];
  uint32_t rxLen = 0;

  if (RIL_SOC_Open(1, RIL_SOC_TYPE_TCP, "tcpbin.com", 4242, 0,
                   RIL_SOC_ACCESS_BUFFER, &sockId) == RIL_SOC_SUCCESS)
  {
    RIL_SOC_Send(sockId, tx, sizeof(tx) - 1u, NULL, 0);
    RIL_SOC_Recv(sockId, rx, sizeof(rx), &rxLen);
    RIL_SOC_Close(sockId);
  }
}

Full example: Example/RIL_Socket


Integration (3 Ways)

RIL has no CMake-generated headers inside SourceCode/, so it drops cleanly into any embedded workflow:

Method 1: CMake (add_subdirectory / FetchContent)

Root CMakeLists.txt exports target ril (alias ril::ril):

set(RIL_USE_OS OFF CACHE BOOL "" FORCE)
set(RIL_LOG_ENABLE ON CACHE BOOL "" FORCE)
set(RIL_TRANSPORT_UARTSTREAM ON CACHE BOOL "" FORCE)
set(RIL_HAL_TARGET stm32cubemx CACHE STRING "" FORCE)
set(RIL_USER_CONFIG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc CACHE PATH "" FORCE)

add_subdirectory(path/to/ril ril_build)
target_link_libraries(my_firmware PRIVATE ril::ril)
CMake Option Default Description
RIL_USE_OS OFF Enable CMSIS-RTOS v2 mutex + osKernelGetTickCount/osDelay
RIL_LOG_ENABLE OFF Enable RIL logging (log.h or custom RIL_LOG_* macros)
RIL_TRANSPORT_UARTSTREAM ON Compile STM32 UARTStream backend (Libs/Stream + Libs/UARTStream)
RIL_BUILD_TESTS OFF Build host Unity + CTest suite
RIL_USER_CONFIG_DIR "" Directory containing your ril_config.h
RIL_HAL_TARGET "" CMake target providing STM32 HAL headers (main.h); auto-detects stm32cubemx
Method 2: STM32CubeMX
  1. Configure your modem UART (115200 8N1, Flow Control None), enable DMA or Interrupts for RX & TX, and enable the UART global interrupt in NVIC.
  2. Optionally configure modem control GPIOs (EC_PWR_KEY, EC_RST) if you want MCU-controlled power/reset.
  3. Copy SourceCode/ and Libs/ into your project, optionally add Core/Inc/ril_config.h, and wire the HAL callbacks from Step 2.
Method 3: Direct File Copy (Keil MDK-ARM / IAR / STM32CubeIDE)
  1. Copy SourceCode/ and Libs/ into your project tree.
  2. Add Include Paths:
    • SourceCode/inc
    • Libs/Stream
    • Libs/UARTStream
  3. Add Source Files to your target:
    • SourceCode/src/*.c
    • Libs/Stream/*.c
    • Libs/UARTStream/*.c
  4. Optionally place ril_config.h on your include path (e.g., Core/Inc/ril_config.h) or pass -DRIL_... preprocessor defines.

Configuration (ril_config.h)

Configuration is resolved in SourceCode/inc/ril_config_defaults.h in this priority order:

  1. Compiler -D preprocessor flags (CMake options, Keil/IAR defines)
  2. User ril_config.h on the include path β€” auto-detected via __has_include("ril_config.h") (or forced with -DRIL_USE_CONFIG_HEADER=1)
  3. Built-in #ifndef defaults

Configuration Reference

Macro Default Description
RIL_USE_OS 0 1 = CMSIS-RTOS v2 recursive mutex + osDelay/osKernelGetTickCount; 0 = bare-metal HAL_Delay/HAL_GetTick
RIL_LOG_ENABLE 0 1 = enable RIL logs; 0 = compile out all logs as ((void)0)
RIL_TRANSPORT_UARTSTREAM 1 1 = compile STM32 UARTStream backend; 0 = custom/host transport only
RIL_RX_STREAM_SIZE 512 UART RX ring buffer size (bytes)
RIL_TX_STREAM_SIZE 512 UART TX ring buffer size (bytes)
RIL_LINE_LEN 512 Max single AT/URC line buffer (bytes)
RIL_URC_RING_SIZE 1024u Circular byte-ring size (bytes) for URCs arriving during active AT commands
RIL_URC_QUEUE_SIZE 8u (Deprecated) Retained only for ril_config.h backward compatibility; superseded by RIL_URC_RING_SIZE
RIL_INIT_RETRY 10 AT sync retries inside RIL_deInitialize()
RIL_POWER_RESTART_DELAY_MS 1000u Settling delay (ms) after RIL_POWER_COMMAND_RESTART (ignored when powerCommandCb == NULL; examples use 13000u)
RIL_INIT_ENABLE_CTZU 0 1 = automatically send AT+CTZU=1 during RIL_deInitialize()
RIL_URC_QIND_CSQ_DEFAULT 0 Default enable flag for URC_QIND_CSQ in ril_urc.h
Sample Core/Inc/ril_config.h (with Custom Logger)

When RIL_LOG_ENABLE == 1, RIL includes "log.h" by default. To route logs to your own logger (printf, RTT, UART, etc.) without needing log.h, define all five RIL_LOG_* macros in ril_config.h:

#ifndef _RIL_CONFIG_H_
#define _RIL_CONFIG_H_

#include "my_platform_log.h"

#define RIL_USE_OS                 1
#define RIL_LOG_ENABLE             1
#define RIL_URC_RING_SIZE          1024u
#define RIL_POWER_RESTART_DELAY_MS 13000u
#define RIL_INIT_ENABLE_CTZU       1

#define RIL_LOG_TRACE(fmt, ...)    MY_LOG_TRACE(fmt, ##__VA_ARGS__)
#define RIL_LOG_DEBUG(fmt, ...)    MY_LOG_DEBUG(fmt, ##__VA_ARGS__)
#define RIL_LOG_INFO(fmt, ...)     MY_LOG_INFO(fmt, ##__VA_ARGS__)
#define RIL_LOG_WARN(fmt, ...)     MY_LOG_WARN(fmt, ##__VA_ARGS__)
#define RIL_LOG_ERROR(fmt, ...)    MY_LOG_ERROR(fmt, ##__VA_ARGS__)

#endif /* _RIL_CONFIG_H_ */

πŸ“š Module & API Cheat Sheet

Module Header Key Functions
Core & Transport ril.h, ril_transport.h RIL_initialize, RIL_initializeWithTransport, RIL_deInitialize, RIL_ServiceRoutine, RIL_SendATCmd, RIL_SendBinaryData, RIL_AT_GetErrCode
System ril_system.h RIL_SYS_GetIMEI, RIL_SYS_GetFirmwareVersion, RIL_SYS_GetModel, RIL_SYS_GetSerialNumber, RIL_SYS_GetPowerSupply, RIL_SYS_GetFullSystemReport, RIL_SYS_PowerOff
SIM ril_sim.h RIL_SIM_GetSimState, RIL_SIM_GetIMSI, RIL_SIM_GetCCID
Network ril_network.h RIL_NW_GetGSMState, RIL_NW_GetGPRSState, RIL_NW_SetAPNEx, RIL_NW_OpenPDPContext, RIL_NW_GetIP, RIL_NW_SetDNS, RIL_NW_GetSignalQuality, RIL_NW_GetExtendedSignalQuality, RIL_NW_SetNTP
SMS ril_sms.h, lib_ril_sms.h RIL_SMS_SetStorage, RIL_SMS_GetStorage, RIL_SMS_SendSMS_Text, RIL_SMS_SendSMS_PDU, RIL_SMS_ReadSMS_Text, RIL_SMS_ReadSMS_PDU, RIL_SMS_DeleteSMS
HTTP / HTTPS ril_http.h RIL_HTTP_Init, RIL_HTTP_CfgContextId, RIL_HTTP_CfgSSL, RIL_HTTP_SetURL, RIL_HTTP_Get, RIL_HTTP_Post, RIL_HTTP_Put, RIL_HTTP_ReadToBuf, RIL_HTTP_ReadLineStream, RIL_HTTP_Stop
MQTT ril_mqtt_client.h RIL_MQTT_InitClient, RIL_MQTT_ConfigSSL, RIL_MQTT_ConfigWill, RIL_MQTT_Open, RIL_MQTT_Connect, RIL_MQTT_Subscribe, RIL_MQTT_Publish, RIL_MQTT_ReadMessage, RIL_MQTT_Close
File / UFS ril_file.h RIL_FILE_GetSpace, RIL_FILE_List, RIL_FILE_Upload, RIL_FILE_Download, RIL_FILE_Open, RIL_FILE_Read, RIL_FILE_Write, RIL_FILE_Seek, RIL_FILE_Close, RIL_FILE_Delete
Socket ril_socket.h RIL_SOC_Open, RIL_SOC_Send, RIL_SOC_Recv, RIL_SOC_GetStates, RIL_SOC_Close
Telephony ril_telephony.h RIL_Telephony_Dial, RIL_Telephony_Answer, RIL_Telephony_Hangup
Date / Time ril_dateTime.h RIL_DateTime_Get, RIL_DateTime_Set, RIL_TimeZoneUpdate_Set, RIL_TimeZone_Get

Error Handling

Core AT functions return RIL_ATSndError (RIL_AT_SUCCESS = 0, RIL_AT_FAILED = -1, RIL_AT_TIMEOUT = -2, RIL_AT_BUSY = -3, RIL_AT_INVALID_PARAM = -4, RIL_AT_UNINITIALIZED = -5). When a modem responds with +CME ERROR: <code> or +CMS ERROR: <code>, call RIL_AT_GetErrCode() for the exact numeric code. Protocol modules (ril_http.h, ril_mqtt_client.h, ril_file.h, ril_socket.h) expose typed error enums mapped from modem responses.


Porting to Any Platform (RIL_Transport)

All core AT framing and protocol modules talk to I/O and time exclusively through RIL_Transport. To run RIL on another MCU (ESP32, nRF, STM32 LL), POSIX UART, or a test harness, set RIL_TRANSPORT_UARTSTREAM=0 and pass your own transport table:

static const RIL_Transport myTransport = {
    .write            = my_uart_write,
    .flush            = my_uart_flush,
    .available        = my_uart_available,
    .readBytes        = my_uart_read_bytes,
    .readUntilChar    = my_uart_read_until_char,
    .readUntilPattern = my_uart_read_until_pattern,
    .txSpace          = my_uart_tx_space,
    .txPending        = my_uart_tx_pending,
    .getTickMs        = my_get_tick_ms,
    .delayMs          = my_delay_ms,
    .ctx              = &myUartCtx
};

RIL_initializeWithTransport(&myTransport, on_urc, NULL, NULL);

Reference implementations: ril_transport_uartstream.c (STM32) and ril_transport_mock.c (PC mock).


Examples (Hardware-Verified)

Nine standalone STM32F407 + Quectel EC200U examples live under Example/. Each includes a CubeMX .ioc, Keil MDK-ARM .uvprojx, Core/Inc/ril_config.h, SerialLog on UART5, and a CMakeLists.txt cross-compile file:

Example Modules Covered What It Demonstrates
Example/RIL_Basic ril, ril_system Init/power callbacks, URC dispatch, RIL_SYS_GetFullSystemReport(), battery & alive check
Example/RIL_Network_SIM ril_sim, ril_network SIM state, IMSI/CCID, GSM/GPRS wait, operator/RAT, CSQ + LTE RSRP/SINR/RSRQ, APN/DNS/PDP IP
Example/RIL_SMS ril_sms, lib_ril_sms Storage select/info, Text SMS send, +CMTI URC receive, read & delete
Example/RIL_HTTP ril_http, ril_network PDP activation, HTTP GET (ReadToBuf), HTTP POST (ReadLineStream), HTTPS SSL config
Example/RIL_MQTT ril_mqtt_client, ril_network Client init, LWT, broker open/connect, subscribe, periodic JSON publish, +QMTRECV/+QMTSTAT reconnect
Example/RIL_File ril_file UFS space/free, Mkdir/Upload/List/Download, binary random-access Open/Write/Seek/Read/Close
Example/RIL_Socket ril_socket, ril_network TCP client RIL_SOC_Open, RIL_SOC_GetStates, RIL_SOC_Send, RIL_SOC_Recv, RIL_SOC_Close
Example/RIL_Telephony ril_telephony +CLIP/+CRING incoming call auto-answer & hangup, optional RIL_Telephony_Dial
Example/RIL_DateTime ril_dateTime, ril_network RTC Get/Set, automatic NITZ (CTZU/CTZR + +CTZV/+CTZE URCs), NTP synchronization
Building an Example (Keil MDK-ARM or CMake + arm-none-eabi-gcc)
  • Keil MDK-ARM: Open Example/<Name>/MDK-ARM/<Name>.uvprojx and press F7.
  • CMake cross-compile:
    cmake -S Example/RIL_Basic -B build/ex_basic -G Ninja \
          -DCMAKE_SYSTEM_NAME=Generic \
          -DCMAKE_C_COMPILER=arm-none-eabi-gcc \
          -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
    cmake --build build/ex_basic

Host Unit & Integration Tests

Run the vendored Unity + CTest suite on your PC (no STM32 hardware required) using ril_transport_mock.c:

cmake -B build -G Ninja -DRIL_BUILD_TESTS=ON
cmake --build build
ctest --test-dir build --output-on-failure
Test Suite Coverage
test_ril_urc.c In-place RIL_ParseURC tokenization, quote stripping, truncation bounds, leftmost prefix matching
test_ril_core.c RIL_initializeWithTransport, always-on (powerCommandCb == NULL) init, boot gating (urcReady), byte-ring urcRing wrap-around/overflow & RIL_ServiceRoutine drain, AT echo/OK/ERROR/+CME ERROR/timeout/prompt >, RIL_SendBinaryData
test_ril_file.c RIL_FILE_Read binary framing (payload containing "OK"), EOF, timeout mapping
test_ril_protocols.c RIL_HTTP_CfgSSL (sslctxid), RIL_SYS_GetSerialNumber, RIL_SYS_GetFullSystemReport bounds, heap-free SMS PDU encoding

Troubleshooting

Symptom Likely Cause Fix
RIL_initialize() returns RIL_AT_TIMEOUT UART callbacks not wired, wrong baud rate, or insufficient boot wait Verify 115200 8N1 + RX/TX DMA or IT callbacks (RIL_rxCpltHandle, RIL_txCpltHandle, RIL_errorHandle). If using a power callback, verify PWRKEY/RESET polarity and RIL_POWER_RESTART_DELAY_MS; if modem is always on, pass NULL
Modem resets mid-boot or during attach Power rail voltage sag Ensure supply can deliver > 2 A bursts with low-ESR bulk capacitors
URCs dropped or delayed RIL_ServiceRoutine() not called frequently enough or ring full Call RIL_ServiceRoutine() every 20–50 ms and increase RIL_URC_RING_SIZE in ril_config.h
HTTP / MQTT / Socket fails to connect PDP context not active or SIM/network not ready Confirm SIM_STAT_READY, network registration (GSM/GPRS), RIL_NW_SetAPNEx(), and RIL_NW_OpenPDPContext() succeed first

Contributing

  1. Fork the repository and create a feature branch.
  2. Run the host test suite (ctest --test-dir build --output-on-failure) and verify ARM compilation (arm-none-eabi-gcc or Keil MDK-ARM).
  3. Submit a pull request.

License

Licensed under the MIT License β€” see LICENSE for details.

About

RIL (Radio Interface Layer) - A comprehensive C library for interfacing with Quectel cellular modems on STM32 microcontrollers. Provides high-level AT command abstraction for SMS, HTTP/HTTPS, MQTT, and Socket operations.

Topics

Resources

Stars

17 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages