Error building Zephyr project with Zephyr module

Hi to everyone, new here:

So I have a set of Zephyr RTOS projects that I can compile fine with the Zephyr west tool.

Right now I’m porting/moving some of them to platformio, so that I can have an integrated development environment.

The issue that I’m having has to do with Zephyr modules, not extra modules, but Zephyr provided modules that are on the framework packages such as framework-zephyr-canopennode or framework-zephyr-lorawan.

For example, if I add to the prj.conf config file under the zephyr directory for the Platformio project a line such as:

CONFIG_TINYCBOR=y

Since TinyCBOR is a zephyr module provided by framework-zehyr-tinycbor, it compiles with no issue. Other modules such CAN, also compile.

But If I add for example the framework-zephyr-loramac-node with:

CONFIG_LORAWAN=y

The compilation fails:

Processing TestNode (platform: ststm32; board: disco_l072cz_lrwan1; framework: zephyr)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/disco_l072cz_lrwan1.html
PLATFORM: ST STM32 (11.0.0) > ST DISCO-L072CZ-LRWAN1
HARDWARE: STM32L072CZ 32MHz, 20KB RAM, 192KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)
PACKAGES: 
 - framework-zephyr 2.20400.201210 (2.4.0) 
 - framework-zephyr-canopennode 0.0.0-alpha+sha.468d350028 
 - framework-zephyr-civetweb 0.0.0-alpha+sha.99129c5efc 
 - framework-zephyr-cmsis 0.0.0-alpha+sha.542b2296e6 
 - framework-zephyr-fatfs 0.0.0-alpha+sha.13697783bf 
 - framework-zephyr-hal-st 0.0.0-alpha+sha.5b3ec3e182 
 - framework-zephyr-hal-stm32 0.0.0-alpha+sha.cea57f86d3 
 - framework-zephyr-libmetal 0.0.0-alpha+sha.0b23894a04 
 - framework-zephyr-littlefs 0.0.0-alpha+sha.9e4498d1c7 
 - framework-zephyr-loramac-node 0.0.0-alpha+sha.3f545d76a2 
 - framework-zephyr-lvgl 0.0.0-alpha+sha.928b61c7c8 
 - framework-zephyr-mbedtls 0.0.0-alpha+sha.aef137b1af 
 - framework-zephyr-mcuboot 0.0.0-alpha+sha.a5d79cf8cc 
 - framework-zephyr-mcumgr 0.0.0-alpha+sha.5051f9d900 
 - framework-zephyr-mipi-sys-t 0.0.0-alpha+sha.957d46bc3c 
 - framework-zephyr-open-amp 0.0.0-alpha+sha.724f7e2a45 
 - framework-zephyr-openthread 0.0.0-alpha+sha.07f430dac6 
 - framework-zephyr-segger 0.0.0-alpha+sha.874d9e9696 
 - framework-zephyr-tinycbor 0.0.0-alpha+sha.40daca97b4 
 - framework-zephyr-tinycrypt 0.0.0-alpha+sha.3e9a49d267 
 - framework-zephyr-trusted-firmware-m 0.0.0-alpha+sha.143df67555 
 - tool-cmake 3.16.4 
 - tool-dtc 1.4.7 
 - tool-gperf 3.0.4 
 - tool-ninja 1.7.1 
 - toolchain-gccarmnoneeabi 1.80201.181220 (8.2.1)
 Reading CMake configuration...

 -- Application: /opt/pZephyrTest/zephyr

 -- Zephyr version: 2.4.0 (/home/dev/.platformio/packages/framework-zephyr)

 -- Found Python3: /usr/bin/python3.9 (found suitable exact version "3.9.1") found components: Interpreter 
 -- Found west (found suitable version "0.9.0", minimum required is "0.7.1")

 -- Board: b_l072z_lrwan1

 -- Cache files will be written to: /home/dev/.cache/zephyr

 -- Found dtc: /home/dev/.platformio/packages/tool-dtc/dtc (found suitable version "1.4.7", minimum 
 required is "1.4.6")

 -- Found toolchain: gnuarmemb (/home/dev/.platformio/packages/toolchain-gccarmnoneeabi)

 -- Found BOARD.dts: /home/dev/.platformio/packages/framework-zephyr/boards/arm/b_l072z_lrwan1/b_l072z_lrwan1.dts

 -- Generated zephyr.dts: /opt/pZephyrTest/.pio/build/TestNode/zephyr/zephyr.dts

 -- Generated devicetree_unfixed.h: /opt/pZephyrTest/.pio/build/TestNode/zephyr/include/generated/devicetree_unfixed.h

 Parsing /home/dev/.platformio/packages/framework-zephyr/Kconfig

 Loaded configuration '/home/dev/.platformio/packages/framework-zephyr/boards/arm/b_l072z_lrwan1/b_l072z_lrwan1_defconfig'

 Merged configuration '/opt/pZephyrTest/zephyr/prj.conf'

 Configuration saved to '/opt/pZephyrTest/.pio/build/TestNode/zephyr/.config'

 Kconfig header saved to '/opt/pZephyrTest/.pio/build/TestNode/zephyr/include/generated/autoconf.h'

 -- The C compiler identification is GNU 8.2.1

 -- The CXX compiler identification is GNU 8.2.1

 -- The ASM compiler identification is GNU

 -- Found assembler: /home/dev/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc

 -- Configuring done


 FATAL ERROR: no west workspace found from "/home/dev/.platformio/packages/framework-zephyr"; "west topdir" requires one.

 Things to try:

   - Change directory to somewhere inside a west workspace and retry.

   - Set ZEPHYR_BASE to a zephyr repository path in a west workspace.

   - Run "west init" to set up a workspace here.

   - Run "west init -h" for additional information.


 warning: The choice symbol LOG_MODE_OVERFLOW (defined at subsys/logging/Kconfig:154) was selected

 (set =y), but no symbol ended up as the choice selection. See

 http://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_LOG_MODE_OVERFLOW.html and/or look up

 LOG_MODE_OVERFLOW in the menuconfig/guiconfig interface. The Application Development Primer, Setting

 Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful

 too.


 CMake Warning at /home/dev/.platformio/packages/framework-zephyr/CMakeLists.txt:1327 (message):

 
 __ASSERT() statements are globally ENABLED



 CMake Error at /home/dev/.platformio/packages/framework-zephyr/cmake/extensions.cmake:398 (add_library):

 No SOURCES given to target: loramac-node

 Call Stack (most recent call first):

 /home/dev/.platformio/packages/framework-zephyr/drivers/lora/CMakeLists.txt:3 (zephyr_library_named)



 CMake Generate step failed.  Build files cannot be regenerated correctly.

And that’s it.

Platformio and packages are fully updated.

Any ideas?

Full project files for refernce? (best to upload to github e.g.)

Any project will do.
Just put CONFIG_LORAWAN=Y on the prj.conf file and compilation fails even without reaching the compilation phase, just by processing the prj.conf file.

CONFIG_GPIO=y

CONFIG_PRINTK=y
CONFIG_HEAP_MEM_POOL_SIZE=256 
CONFIG_ASSERT=y

CONFIG_USB=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr Console"
CONFIG_USB_UART_CONSOLE=y
CONFIG_USB_DEVICE_VID=0x2340

CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=y
CONFIG_UART_CONSOLE_ON_DEV_NAME="CDC_ACM_0"

#CONFIG_LORA=y
CONFIG_LORAWAN=y
#CONFIG_TINYCRYPT=y

It will then tell me

C:/Users/Max/Documents/PlatformIO/Projects/zephyr-blink/zephyr/prj.conf:3: warning: attempt to assign the value ‘y’ to the undefined symbol LORAWAN

Working from e.g. the official sample for the used Zephyr 2.4 version zephyr/samples/drivers/lora at v2.4-branch · zephyrproject-rtos/zephyr · GitHub, it uses configs like

Which makes sense if the board is connected to a Semtech SX12xx (e.g. SX1276) radio via the SPI bus.

But if I add that, I get the error…

*** Multiple ways to build the same target were specified for: C:\Users\Max\Documents\PlatformIO\Projects\zephyr-blink.pio\build\nucleo_l073rz\loramac-node\zephyr\drivers\lora\sx1276.c.o (from [‘C:\Users\Max\.platformio\packages\framework-zephyr\drivers\lora\sx1276.c’] and from [‘C:\Users\Max\.platformio\packages\framework-zephyr-loramac-node\src\radio\sx1276\sx1276.c’])
File “C:\Users\Max.platformio\packages\framework-zephyr\scripts\platformio\platformio-build.py”, line 658, in compile_source_files

The problem is that there’s two sx1276.c file with different contents (one is a Zephyr-interface and the other the Semtech driver code), but PlatformIO wants to put the object file in the same folder somehow, this creating a conflict. I’ll create an issue to have that fixed.

Meanwhile as a workaround, I rename C:\Users\<user>\.platformio\packages\framework-zephyr-loramac-node\src\radio\sx1276\sx1276.c to sx1276_driver.c and adapt the C:\Users\Max\.platformio\packages\framework-zephyr-loramac-node\zephyr\CMakeLists.txt accordingly regarding the new filename.

I then take the main.c code from the send example liked above and use a platformio.ini of

[env:disco_l072cz_lrwan1]
platform = ststm32
framework = zephyr
board = disco_l072cz_lrwan1

and build…

Reading CMake configuration...
Parsing system calls...
Generating syscall files
Generating KObject files...
Validating driver...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\disco_l072cz_lrwan1\offsets\zephyr\arch\arm\core\offsets\offsets.c.o
..
Linking .pio\build\disco_l072cz_lrwan1\firmware.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       28228 B       192 KB     14.36%
            SRAM:        6472 B        20 KB     31.60%
        IDT_LIST:          0 GB         2 KB      0.00%
Building .pio\build\disco_l072cz_lrwan1\firmware.bin
Checking size .pio\build\disco_l072cz_lrwan1\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [===       ]  31.0% (used 6348 bytes from 20480 bytes)
Flash: [=         ]  14.0% (used 27434 bytes from 196608 bytes)
==================== [SUCCESS] Took 12.51 seconds ====================

which is successfull.

Note that the LoRa driver in Zephyr is experimental and supports only raw LoRa packets, not LoRaWAN packets.

There exists the option CONFIG_HAS_SEMTECH_LORAMAC=y to include the Mac driver from semtech as well, and there are examples in C:\Users\<user>\.platformio\packages\framework-zephyr-loramac-node\src\apps but these are “baremetal” examples and not directly in the style as the Zephyr sample projects are.

1 Like

Hi thanks for your input:

Regarding the example that you use, I can confirm that I have the same issue, and your workaround does indeed work. So by just enabling LORA with CONFIG_LORA does create the issue with the conflicting files.
Renaming the radio driver file and updating the CMakeLists.txt file does the trick.

While it is nice to found this, it doesn’t solve the initial issue with CONFIG_LORAWAN.

While Zephyr LORAWAN is experimental (https://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_LORAWAN.html) it does work. It needs some polishing but it works.

When this CONFIG option is enabled, the project configuration fails as described on the initial post.

Can you try to replicate it? Just add the CONFIG_LORAWAN=y to the prj.conf file, and the issue should pop up.

Thanks!

Hi,

take care about the version of the Zephyr framework. You referenced to the latest development version, which is V2.5.0-rc1 and not released yet. The CONFIG_LORAWAN option is not available in the latest release V2.4.0 (which is used by PlatformIO).

1 Like

Hi:

Thanks, that was what I was suspecting: that the Platformio Zephyr version isn’t yet supporting the Lorawan config flag.

Note as of this date the current Zephyr version available with PlatformIO is now v2.5.0.

However the lorawan multiple targets issue is still present, and is being tracked here: Zephyr Menuconfig vs prj.conf: Multiple ways to build same target were specified · Issue #153 · platformio/platform-atmelsam · GitHub