zephyr: STM32WL LoRa SoC stuck at initialization due to SPI transmit buffer not emptying

Describe the bug The MCU gets stuck at initialization when the LoRa radio in the STM32WL SoC is enabled. It seems to be stuck trying to send data through the SPI to the intergrate LoRa module of the STM32WL SoC. The MCU is in an endless loop waiting for the SPI transmit buffer to empty (waiting for LL_SPI_IsActiveFlag_TXE to be set).

I am using Seeed Studio LoRa-E5 mini board with STM32WLE5JC SoC. I have attached a backtrace when it is in a stuck state from a openocd gdb server below.

To Reproduce Steps to reproduce the behavior:

  1. Use the sample at samples/drivers/lora/send
  2. Build and flash for board lora_e5_dev_board: west build -b lora_e5_dev_board && west flash --runner openocd

Expected behavior The MCU should not be stuck at initialization and data should be sent through the SPI.

Impact Showstopper as the MCU does not even boot when the LoRa module is enabled.

Logs and console output The backtrace from a gdb server is shown as below

(gdb) bt
#0  0x08002c02 in LL_SPI_IsActiveFlag_TXE (SPIx=0x58010000)
    at /home/hwtb/zephyrproject/modules/hal/stm32/stm32cube/stm32wlxx/drivers/include/stm32wlxx_ll_spi.h:919
#1  ll_func_tx_is_empty (spi=0x58010000)
    at /home/hwtb/zephyrproject/zephyr/drivers/spi/spi_ll_stm32.h:104
#2  spi_stm32_shift_m (data=<optimized out>, spi=<optimized out>)
    at /home/hwtb/zephyrproject/zephyr/drivers/spi/spi_ll_stm32.c:258
#3  spi_stm32_shift_frames (data=0x2000008c <spi_stm32_dev_data_1>, spi=<optimized out>)
    at /home/hwtb/zephyrproject/zephyr/drivers/spi/spi_ll_stm32.c:359
#4  transceive (asynchronous=false, signal=0x0, rx_bufs=<optimized out>, tx_bufs=<optimized out>,
    config=<optimized out>, dev=<optimized out>)
    at /home/hwtb/zephyrproject/zephyr/drivers/spi/spi_ll_stm32.c:660
#5  spi_stm32_transceive (dev=<optimized out>, config=<optimized out>, tx_bufs=<optimized out>,
    rx_bufs=<optimized out>) at /home/hwtb/zephyrproject/zephyr/drivers/spi/spi_ll_stm32.c:831
#6  0x080037b4 in z_impl_spi_transceive (config=0x8008530 <dev_config+4>, rx_bufs=0x0,
    tx_bufs=0x200013c0 <z_main_stack+960>, dev=<optimized out>)
    at /home/hwtb/zephyrproject/zephyr/include/zephyr/drivers/spi.h:542
#7  spi_transceive (config=0x8008530 <dev_config+4>, rx_bufs=0x0, tx_bufs=0x200013c0 <z_main_stack+960>,
    dev=<optimized out>)
    at /home/hwtb/projects/lora_bridge2/build/zephyr/include/generated/syscalls/spi.h:36
#8  spi_write (config=0x8008530 <dev_config+4>, tx_bufs=0x200013c0 <z_main_stack+960>,
    dev=<optimized out>) at /home/hwtb/zephyrproject/zephyr/include/zephyr/drivers/spi.h:628
#9  spi_write_dt (spec=0x800852c <dev_config>, tx_bufs=0x200013c0 <z_main_stack+960>)
    at /home/hwtb/zephyrproject/zephyr/include/zephyr/drivers/spi.h:646
#10 SX126xWakeup () at /home/hwtb/zephyrproject/zephyr/drivers/lora/sx126x.c:391
#11 0x08003a82 in SX126xInit (dioIrq=dioIrq@entry=0x8003e09 <RadioOnDioIrq>)
    at /home/hwtb/zephyrproject/modules/lib/loramac-node/src/radio/sx126x/sx126x.c:119
#12 0x08004624 in RadioInit (events=<optimized out>)
    at /home/hwtb/zephyrproject/modules/lib/loramac-node/src/radio/sx126x/radio.c:524
#13 0x080034e2 in sx12xx_init (dev=dev@entry=0x8008054 <__device_dts_ord_174>)
    at /home/hwtb/zephyrproject/zephyr/drivers/lora/sx12xx_common.c:352
#14 0x0800360c in sx126x_lora_init (dev=0x8008054 <__device_dts_ord_174>)
    at /home/hwtb/zephyrproject/zephyr/drivers/lora/sx126x.c:457
#15 0x08004fa4 in z_sys_init_run_level (level=level@entry=2)
    at /home/hwtb/zephyrproject/zephyr/kernel/device.c:70
#16 0x08005102 in bg_thread_main (unused1=<optimized out>, unused2=<optimized out>,
    unused3=<optimized out>) at /home/hwtb/zephyrproject/zephyr/kernel/init.c:213
#17 0x0800644c in z_thread_entry (entry=0x80050f5 <bg_thread_main>, p1=<optimized out>,
    p2=<optimized out>, p3=<optimized out>) at /home/hwtb/zephyrproject/zephyr/lib/os/thread_entry.c:36
#18 0x08001c48 in arch_switch_to_main_thread (main_thread=<optimized out>,
    stack_ptr=0x20001440 <z_idle_stacks> "`", _main=0x80050f5 <bg_thread_main>)
    at /home/hwtb/zephyrproject/zephyr/arch/arm/core/aarch32/thread.c:576
#19 0x00000000 in ?? ()
(gdb)

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: Zephyr SDK v0.14.0
  • Zephyr v3.1.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

Hey, we’ve encountered a similar problem when using Lora-E5 Dev Kit - device was stuck on SPI initialization not only when we was using LoRa, but even when we add CONFIG_SPI=y in prj.conf file in blank project. Solution we’ve come up with was kinda described on ST Community, here. Seting SUBGHSPISD register to 1, e.g. by using STM32CubeProgrammer helps, now LoRa sent example from Zephyr is working fine 😃

Hi @ballardr. I guess you mean @HelloWorldTeraByte instead. My code has been working fine for a long time, although it is limited to LoRa and not LoRaWAN.