b54e1c22e7
Both compile the same portable core (src/meshcore_companion.c) and differ only in the UART transport: - examples-esp-idf/tty_bridge: full ESP-IDF project (UART driver), core compiled directly via the component CMakeLists (no copy) - examples-stm32/uart_bridge: HAL drop-in (meshcore_setup/meshcore_poll) for a CubeMX/CubeIDE project, with integration README README updated: new examples in layout + an 'Other platform examples' section. Verified host build/test still pass and both new examples pass -Wall -Wextra syntax checks against stubbed platform headers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1.9 KiB
1.9 KiB
STM32 example: uart_bridge
Integration example showing how to drive a MeshCore Companion Radio from an STM32
using the CubeMX-generated HAL. The protocol logic is the repo's portable C core
(src/meshcore_companion.c); this file supplies only the UART transport and two
entry points you call from your generated main().
Because an STM32 firmware build is tied to your specific MCU, clocks, pins and linker script (all produced by STM32CubeIDE / CubeMX), this is not a standalone buildable project — it is a drop-in.
Steps (STM32CubeIDE / CubeMX)
- Generate a project with one USART enabled at 115200 8N1 (e.g.
USART1). Wire it to the companion radio: host TX → radio RX, host RX ← radio TX, GND↔GND. The radio must run the serial companion firmware (companion_radio_usb). - Add
src/meshcore_companion.candsrc/meshcore_companion.hfrom this repo to your project (or add this repo'ssrc/to the include paths). - Add
meshcore_stm32.cto your project. If your USART handle isn'thuart1, change theextern UART_HandleTypeDef huart1;line near the top. - In the generated
main.c:/* USER CODE BEGIN 2 */ meshcore_setup(); /* USER CODE END 2 */ while (1) { /* USER CODE BEGIN 3 */ meshcore_poll(); }
Notes
meshcore_poll()polls the UART one byte at a time, which is fine for the companion's low data rate. For high throughput, switch the RX side to interrupt/DMA into a ring buffer and feed that tomc_rx_feed()— the core code is unchanged.- Logging uses
printf(). Retarget it to a separate debug UART or SWO/ITM (commonly USART2 = the ST-Link VCP) by implementing_write(); do not point it at the companion UART. - The same two-function transport pattern (
send bytes/read available bytes) ports directly to bare-metal STM32, nRF52 (nRF5 SDK or Zephyr), or any other MCU — only the HAL calls change.