Silicon Labs EFM32 - linker fail on Thunderboard Sense 2

I get a linker error when trying to build a simple test application for the Sil Labs Thunderboard Sense 2 (env:tb_sense_12) This is the EFR32 MG12 (Mighty Gecko) variant.
When trying to build the same application for other types in the EFM32 Platform, it works okay.
My problem seems to be that the linker cannot find the rail_efr32xg12_release.ar. I have checked the platform installation and the files are where they should be. The error I get is

arm-none-eabi-g++ -o .pio\build\tb_sense_12\firmware.elf -T C:\Users\Trevor\Documents\PlatformIO\Projects\Thund_02\.pio\build\tb_sense_12\efr32mg12p.ld.link_script.ld -DMBED_BOOT_STACK_SIZE=1024 -DMBED_RAM_SIZE=0x40000 -DMBED_RAM_START=0x20000000 -DMBED_ROM_SIZE=0x100000 -DMBED_ROM_START=0x0 -DXIP_ENABLE=0 -Wl,--gc-sections -Wl,--wrap,_calloc_r -Wl,--wrap,_free_r -Wl,--wrap,_malloc_r -Wl,--wrap,_memalign_r -Wl,--wrap,_realloc_r -Wl,--wrap,atexit -Wl,--wrap,exit -Wl,--wrap,fprintf -Wl,--wrap,main -Wl,--wrap,printf -Wl,--wrap,snprintf -Wl,--wrap,sprintf -Wl,--wrap,vfprintf -Wl,--wrap,vprintf -Wl,--wrap,vsnprintf -Wl,--wrap,vsprintf -Wl,-n -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mthumb @"C:\Users\Trevor\Documents\PlatformIO\Projects\Thund_02\.pio\build\tb_sense_12\longcmd-8c9bf32d6ff45c837f164ee574d2018c" -L.pio\build\tb_sense_12 -LC:\Users\Trevor\.platformio\packages\framework-mbed\targets\TARGET_Silicon_Labs\TARGET_SL_RAIL\efr32-rf-driver\rail -LC:\Users\Trevor\.platformio\packages\framework-mbed\targets\TARGET_Silicon_Labs\TARGET_SL_RAIL\efr32-rf-driver\rail\TARGET_EFR32_12 -Wl,--start-group -lrail_efr32xg12_release -lrail_efr32xg12_release.ar -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys -lc -lgcc -Wl,--end-group
c:/users/trevor/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -lrail_efr32xg12_release.ar
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\tb_sense_12\firmware.elf] Error 1

If anyone who has experience with this board type can help it would be much appreciated.

Trev K

Can you state the exact platformio.ini and code that you’re working with?

This looks weird, as if it’s trying to interprete that -l.. flag as an object or archive to be linked.

The platformio.ini is

[env:tb_sense_12]
platform = siliconlabsefm32
board = tb_sense_12
framework = mbed

the code is a very basic example

#include <mbed.h>
#define WAIT_TIME_MS 500 
DigitalOut led1(LED1);
int main()
{
    printf("This is the bare metal blinky example running on Mbed OS %d.%d.%d.\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
    while (true)
    {
        led1 = !led1;
        thread_sleep_for(WAIT_TIME_MS);
    }
}

its one of the examples and I was just wanting to get things checked out prior to receiving hardware in the next few days.

I agree with your comment about the .ar being an archive but its the EMF32 Platform as installed from Platformio

Reproducable for me.

Linking .pio\build\tb_sense_12\firmware.elf
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -lrail_efr32xg12_release.ar
collect2.exe: error: ld returned 1 exit status

-Wl,–start-group -lrail_efr32xg12_release -lrail_efr32xg12_release.ar

These linker commands are the cause of the problem, the -l command shouldn’t contain the file extension and also not the lib prefix of the file.

The file C:\User\<user>\.platformio\packages\framework-mbed\targets\TARGET_Silicon_Labs\TARGET_SL_RAIL\CMakeLists.txt says

# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

if("EFR32_12" IN_LIST MBED_TARGET_LABELS)
    if(${MBED_TOOLCHAIN} STREQUAL "ARM")
        set(LIB_RAIL efr32-rf-driver/rail/TARGET_EFR32_12/librail_efr32xg12_release.ar)
    elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
        set(LIB_RAIL efr32-rf-driver/rail/TARGET_EFR32_12/librail_efr32xg12_release.a)
    endif()
endif()

target_link_libraries(mbed-core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_RAIL})


target_include_directories(mbed-core
    INTERFACE
        efr32-rf-driver/rail
        efr32-rf-driver/rail/ble
        efr32-rf-driver/rail/ieee802154
)

and first of all PlatformIO or mbed-os seems to make an error here because our toolchain is GCC_ARM but still lrail_efr32xg12_release.ar for the native ARM toolchain shows up in the linker command.

I’ve tried to replace the contents of that file with

# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

if("EFR32_12" IN_LIST MBED_TARGET_LABELS)
    set(LIB_RAIL efr32-rf-driver/rail/TARGET_EFR32_12/librail_efr32xg12_release.a)
endif()

target_link_libraries(mbed-core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_RAIL})


target_include_directories(mbed-core
    INTERFACE
        efr32-rf-driver/rail
        efr32-rf-driver/rail/ble
        efr32-rf-driver/rail/ieee802154
)

but that didn’t work. By renaming the librail_efr32xg12_release.ar file to do_not_link_me.ar I found out that the build system just tries to link every single *.ar and *.a file in that folder and that it doesn’t seem to be dependent of the CMakeLists.txt logic at all.

So, after renaming the file in C:\Users\<user>\.platformio\packages\framework-mbed\targets\TARGET_Silicon_Labs\TARGET_SL_RAIL\efr32-rf-driver\rail\TARGET_EFR32_12\ from librail_efr32xg12_release.ar to librail_efr32xg12_release.ar.backup, and doing a “Clean”, “General → Miscellanenous → Rebuild IntelliSense” and “Build”, it works.

Checking size .pio\build\tb_sense_12\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   3.7% (used 9784 bytes from 262144 bytes)
Flash: [          ]   3.7% (used 38336 bytes from 1048576 bytes)
======================= [SUCCESS] Took 4.22 seconds =======================

I’ll report this bug to Issues · platformio/platform-siliconlabsefm32 · GitHub.

Edit: Reported to Blinky mbed-os firmware does not link for tb_sense_12 board because of ARM library · Issue #4 · platformio/platform-siliconlabsefm32 · GitHub

Hi maxgerhardt,

Many thanks for your time in looking into this. This is my first venture into the Sil Labs radio devices.
I’m tied up on something else just now but will try out your suggestions later.

thank you once again
Trev

Hi maxgerhardt,
I finally got the time to try it. It now links correctly. I will carry on development now. Thanks once again

Trev