Skip to content

bug fixes: jazzy: serial transport#163

Open
kristkis wants to merge 9 commits intomicro-ROS:kiltedfrom
kristkis:jazzy
Open

bug fixes: jazzy: serial transport#163
kristkis wants to merge 9 commits intomicro-ROS:kiltedfrom
kristkis:jazzy

Conversation

@kristkis
Copy link
Copy Markdown

Summary

Fix serial transport build failure on Zephyr 4.1+ and make the UART device configurable without patching module source files.

  • Build fix: <unistd.h> / <zephyr/posix/unistd.h> cause _SC_ADVISORY_INFO enum/macro collision on Zephyr 4.1 with SDK 0.17.0. Replaced with standard C headers + k_usleep().
  • Configurable UART: UART device is now selectable via DT alias microros-serial in the application's board overlay. Falls back to usart1 when the alias is absent (no breaking change).
  • Bug fixes: ring_buf_init() was using the wrong buffer, device_is_ready() replaces a null-pointer check that can't trigger in modern Zephyr, dead code removed.

Motivation

Anyone using the serial transport on Zephyr 4.1+ with the Zephyr SDK 0.17.0 ARM toolchain hits a hard build error:

zephyr/posix/sys/sysconf.h:17:9: error: expected identifier before numeric constant 17 | _SC_ADVISORY_INFO

This is caused by <unistd.h> pulling in the toolchain's POSIX sysconf macros, which collide with Zephyr's own POSIX enum of the same names. The only symbols actually needed from <unistd.h> were size_t, bool, and usleep() — the first two come from standard C headers, and usleep() is replaced by k_usleep().
Additionally, UART_NODE was hardcoded to DT_NODELABEL(usart1), forcing anyone with a different UART (e.g. lpuart1 on STM32G4) to patch this file locally. The DT alias approach lets applications select the UART in their overlay:

/ { aliases { microros-serial = &lpuart1; }; };

Discussion point: DT alias vs Kconfig for UART selection

This PR uses a DT alias (microros-serial) for UART selection because it follows Zephyr idiom (similar to zephyr,console) and works cleanly with the devicetree preprocessor. A Kconfig string approach was considered but Kconfig strings expand as quoted C strings, which are incompatible with DT_NODELABEL() token pasting.
Open to feedback on whether a different mechanism (e.g. DT chosen node, or a Kconfig that selects between a fixed set of UART labels) would be preferred by the maintainers.

Changes

File Change
microros_transports.h <unistd.h><stddef.h> / <stdint.h> / <stdbool.h>
microros_transports.c Remove <zephyr/posix/unistd.h>, usleep()k_usleep()
microros_transports.c Configurable UART via DT_ALIAS(microros_serial), fallback to usart1
microros_transports.c Fix ring_buf_init() using wrong buffer (uart_out_bufferuart_in_buffer)
microros_transports.c Remove unused uart_out_buffer and out_ringbuf
microros_transports.c device_is_ready() instead of null check in transport_open()

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

pablogs9 and others added 9 commits June 3, 2024 10:28
* updates project to work with zephyr v4.0.x

* updating workflows for zephyr v4.0.x

* adds cmake prefix path, changes to ci image

* adds manual trigger to ci workflows

* updates CI workflows for all active ROS2 distros

* Get uart device with Zephyr 4's Devicetree-centric approach

Signed-off-by: Antón Casas <antoncasas@eprosima.com>

* Tested in v4.1.0 using manual installation on Ubuntu:24.04 base Docker image

Signed-off-by: Antón Casas <antoncasas@eprosima.com>

* Add v4.1.0 to CI and nightly

Signed-off-by: Antón Casas <antoncasas@eprosima.com>

* State SDK used in CI. Restore Z0rdon's info about docker image used.

Signed-off-by: Antón Casas <antoncasas@eprosima.com>

---------

Signed-off-by: Antón Casas <antoncasas@eprosima.com>
Co-authored-by: Antón Casas <antoncasas@eprosima.com>
Signed-off-by: Antón Casas <antoncasas@eprosima.com>
(cherry picked from commit b81263f)

Co-authored-by: Antón Casas <antoncasas@eprosima.com>
* Free space in docker



* Build script as step



* Nightly



---------

Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com>
Co-authored-by: EugenioCollado <121509066+EugenioCollado@users.noreply.github.com>
- Replace <unistd.h> with <stddef.h>/<stdint.h>/<stdbool.h> in the
  header and remove <zephyr/posix/unistd.h> from the source. On
  Zephyr 4.1+ with SDK 0.17.0 the toolchain's unistd.h collides
  with Zephyr's posix/sys/sysconf.h, causing a build error
  ("expected identifier before numeric constant" on _SC_ADVISORY_INFO).
- Replace usleep() with k_usleep() — the POSIX sleep was the only
  reason for including unistd.h. k_usleep is Zephyr-native and
  does not require CONFIG_POSIX_API.
- Make the UART device configurable via a DT alias (microros-serial).
  Applications that need a different UART define the alias in their
  board overlay. Falls back to DT_NODELABEL(usart1) when the alias
  is absent, preserving backward compatibility.
- Fix ring_buf_init() passing uart_out_buffer as storage for the
  input ring buffer instead of uart_in_buffer. Worked by accident
  (out_ringbuf was never used) but was incorrect.
- Remove unused uart_out_buffer and out_ringbuf (dead code).
- Use device_is_ready() instead of a null pointer check in
  transport_open(). DEVICE_DT_GET never returns NULL in modern
  Zephyr; device_is_ready() is the correct readiness check.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Signed-off-by: Kristina Kisiuk kisyuk.kristina@gmail.com
Signed-off-by: kristkis <kisyuk.kristina@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants