micro-ROS / micro_ros_zephyr_module

micro-ROS Zephyr module and sample code
Apache License 2.0
46 stars 22 forks source link

Fix of unknown Ringbuffer and not found USB-Serial Device #125

Closed scrapforge closed 8 months ago

scrapforge commented 8 months ago

I added in prj.conf a CONFIG_RING_BUFFER=y line, due to an error while building, which stated an undefined reference occured, similar to this on https://github.com/zephyrproject-rtos/zephyr/issues/30183. Also i could not reliably reproduce the error. This line fixed any appearance of it.

Also if usb-serial configured as transport layer for microros, the code hang up. After a lot of debugging i found that in the file mymicromodule/modules/libmicroros/microros_transports/serial-usb/microros_transports.c the device is searched by its label CDC_ACM_0. Therefore an app.overlay file is needed, which i added.

I have used zephyr 3.5.0-rc3 and zephyr-sdk 0.16.3

pablogs9 commented 8 months ago

I added in prj.conf a CONFIG_RING_BUFFER=y line, due to an error while building, which stated an undefined reference occured, similar to this on https://github.com/zephyrproject-rtos/zephyr/issues/30183.

Could you provide details on how to trigger this build error?

Also, the CI seems to have errors

scrapforge commented 8 months ago

The CI for Zephyr 2.7.2 complains about: Error: disco_l475_iot1.dts.pre.tmp:1921.1-13 Label or path zephyr_udc0 not found FATAL ERROR: Syntax error parsing input tree.

I considered the error could be based on an api/syntax change between the versions 2.7.2 and 3.1 but as i searched the documentation for Zephyr 2.7.2 i found, that the added overlay code is the same as proposed in https://docs.zephyrproject.org/2.7.2/reference/usb/uds_cdc_acm.html?highlight=zephyr_udc0.

So i compared the device-tree overlays disco_l475_iot1.dts for the board and got (just the important detail):

-  &usbotg_fs {
+  zephyr_udc0: &usbotg_fs {
      pinctrl-0 = <&usb_otg_fs_dm_pa11 &usb_otg_fs_dp_pa12
                 &usb_otg_fs_id_pa10>;
+     pinctrl-names = "default";
      status = "okay";
   };

So error is caused by a change in the devicetree-overlay. Do you have a idea how to solve this?

pablogs9 commented 8 months ago

Can you update the PR?

scrapforge commented 8 months ago

I'm sorry, but i dont understand you. Could you explain it?

pablogs9 commented 8 months ago

Sure, I wonder if you can update the PR with the required changes in order to make the CI pass.

scrapforge commented 8 months ago

I added in prj.conf a CONFIG_RING_BUFFER=y line, due to an error while building, which stated an undefined reference occured, similar to this on zephyrproject-rtos/zephyr#30183.

Could you provide details on how to trigger this build error?

Steps to trigger this error:

results in the error message:

.../zephyrproject/applications/micro_ros_zephyr_module/modules/libmicroros/microros_transports/serial/microros_transports.c:44: undefined reference to `ring_buf_put'
.../zephyrproject/applications/micro_ros_zephyr_module/modules/libmicroros/microros_transports/serial/microros_transports.c:102: undefined reference to `ring_buf_get'
pablogs9 commented 8 months ago

https://github.com/micro-ROS/micro_ros_zephyr_module/pull/126 merged, could you rebase?

scrapforge commented 8 months ago

126 merged, could you rebase?

I hope i did it right.

scrapforge commented 8 months ago

The problem that I ran (originally) into has been, that my code did compile, but when i flashed it, it didn't work. It took me while to understand, that the problem was caused by this line

device_get_binding("CDC_ACM_0");

This function call itself it not dependent on any correct hardware configuration. A string is a string.

But at runtime it tried to get the device, by a label/name not known to the zephyr OS, due to lacking configuration. So the surrounding RCCHECK of the function, which calls this code line indirect, did throw an error:

RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));

So i dont think that any CI, which only compiles the code (as far as i unterstand the log), would actually detect my problem, because it only shows up at runtime.

So i can currently confirm my solution for my setup only (Zephyr 3.5, Zephyr-Sdk 0.16, Board nucleo_h743zi)

scrapforge commented 8 months ago

I> Is it possible to embedded this dependency of the USB CDC transport at KConfig level. Something like the following in modules/libmicroros/KConfig

It is possible, also all warnings to the use of "select" in Kconfig apply. The only other option i found, would to use set( 1 ) in CMake and use this to conditional add .conf files. But this couldn't be managed by Kconfig anymore, because this has to be done before Zephyr is included.

pablogs9 commented 8 months ago

@mergify backport humble rolling

mergify[bot] commented 8 months ago

backport humble rolling

✅ Backports have been created

* [#129 Fix of unknown Ringbuffer and not found USB-Serial Device (backport #125)](https://github.com/micro-ROS/micro_ros_zephyr_module/pull/129) has been created for branch `humble` but encountered conflicts * [#130 Fix of unknown Ringbuffer and not found USB-Serial Device (backport #125)](https://github.com/micro-ROS/micro_ros_zephyr_module/pull/130) has been created for branch `rolling`