zephyr: stm32: spi: Infinite loop of RXNE bit check

Describe the bug I have often experienced board hangs when using LoRa on STM32L151CBT. If gdb checks while the board is stopped, RXNE continues to be checked.
https://github.com/zephyrproject-rtos/zephyr/blob/master/drivers/spi/spi_ll_stm32.c#L114-L116

while (!ll_func_rx_is_not_empty(spi)) {
        /* NOP */
}

To Reproduce

west init zephyrproject_spi_rxne -m https://github.com/KwonTae-young/zephyr/ --mr stm32_spi_rxne
cd zephyrproject_spi_rxne
west update
cd zephyr
source zephyr.sh
west build -b 96b_wistrio samples/drivers/lora/send
west flash -r stm32flash --device /dev/ttyUSB0

Expected behavior The board should not stop.

Impact When using LoRa, the board hangs at random times.

Screenshots or console output

  1. console
*** Booting Zephyr OS build zephyr-v1.13.0-13521-ga22c423b115e  ***
[00:00:00.222,000] <inf> sx1276: SX1276 Version:12 found
[00:00:00.232,000] <inf> lora_send: Data sent!
[00:00:00.243,000] <inf> lora_send: Data sent!
[00:00:00.254,000] <inf> lora_send: Data sent!
...
...
[00:00:03.328,000] <inf> lora_send: Data sent!                                  
[00:00:03.339,000] <inf> lora_send: Data sent!                                  
[00:00:03.350,000] <inf> lora_send: Data sent!                                  
[00:00:03.361,000] 
  1. gdb
Reading symbols from /work/zephyrproject_spi_rxne/zephyr/samples/drivers/lora/send/build/zephyr/zephyr.elf...done.
(gdb) bt
#0  LL_SPI_IsActiveFlag_RXNE (SPIx=0x40013000)
    at /work/zephyrproject_spi_rxne/modules/hal/stm32/stm32cube/stm32l1xx/drivers/include/stm32l1xx_ll_spi.h:739
#1  ll_func_rx_is_not_empty (spi=0x40013000)
    at /work/zephyrproject_spi_rxne/zephyr/drivers/spi/spi_ll_stm32.h:40
#2  spi_stm32_shift_m (data=<optimized out>, spi=<optimized out>)
    at /work/zephyrproject_spi_rxne/zephyr/drivers/spi/spi_ll_stm32.c:114
#3  spi_stm32_shift_frames (data=0x20001e20 <spi_stm32_dev_data_1>, 
    spi=<optimized out>)
    at /work/zephyrproject_spi_rxne/zephyr/drivers/spi/spi_ll_stm32.c:179
#4  transceive (asynchronous=false, signal=0x0, rx_bufs=<optimized out>, 
    tx_bufs=0x20000cc8 <z_main_stack+864>, config=0x20000268 <dev_data+12>, 
    dev=<optimized out>)
    at /work/zephyrproject_spi_rxne/zephyr/drivers/spi/spi_ll_stm32.c:434
#5  spi_stm32_transceive (dev=<optimized out>, 
    config=0x20000268 <dev_data+12>, tx_bufs=0x20000cc8 <z_main_stack+864>, 
    rx_bufs=<optimized out>)
    at /work/zephyrproject_spi_rxne/zephyr/drivers/spi/spi_ll_stm32.c:457
#6  0x08006b12 in z_impl_spi_transceive (config=0x20000268 <dev_data+12>, 
    rx_bufs=0x0, tx_bufs=0x20000cc8 <z_main_stack+864>, dev=<optimized out>)
    at /work/zephyrproject_spi_rxne/zephyr/include/drivers/spi.h:263
#7  spi_transceive (config=0x20000268 <dev_data+12>, rx_bufs=0x0, 
    tx_bufs=0x20000cc8 <z_main_stack+864>, dev=<optimized out>)
--Type <RET> for more, q to quit, c to continue without paging--
    at /work/zephyrproject_spi_rxne/zephyr/samples/drivers/lora/send/build/zephyr/include/generated/syscalls/spi.h:33
#8  spi_write (config=0x20000268 <dev_data+12>, 
    tx_bufs=0x20000cc8 <z_main_stack+864>, dev=<optimized out>)
    at /work/zephyrproject_spi_rxne/zephyr/include/drivers/spi.h:303
#9  sx1276_transceive (length=<optimized out>, data=<optimized out>, 
    write=true, reg=<optimized out>)
    at /work/zephyrproject_spi_rxne/zephyr/drivers/lora/sx1276.c:216
#10 sx1276_write (reg_addr=<optimized out>, data=<optimized out>, 
    len=<optimized out>)
    at /work/zephyrproject_spi_rxne/zephyr/drivers/lora/sx1276.c:226
#11 0x08006b26 in SX1276WriteBuffer (addr=<optimized out>, 
    buffer=<optimized out>, size=<optimized out>)
    at /work/zephyrproject_spi_rxne/zephyr/drivers/lora/sx1276.c:233
#12 0x08009920 in SX1276Write (addr=addr@entry=17, data=<optimized out>, 
    data@entry=247 '\367')
    at /work/zephyrproject_spi_rxne/modules/lib/loramac-node/src/radio/sx1276/sx1276.c:1258
#13 0x08006fdc in SX1276SetTx (timeout=<optimized out>)
    at /work/zephyrproject_spi_rxne/modules/lib/loramac-node/src/radio/sx1276/sx1276.c:1085
#14 0x08007152 in SX1276Send (
    buffer=buffer@entry=0x20001ea8 <data> "helloworldGPIOA", 
--Type <RET> for more, q to quit, c to continue without paging--
    size=<optimized out>, size@entry=10 '\n')
    at /work/zephyrproject_spi_rxne/modules/lib/loramac-node/src/radio/sx1276/sx1276.c:850
#15 0x08009854 in sx1276_lora_send (dev=<optimized out>, 
    data=0x20001ea8 <data> "helloworldGPIOA", data_len=<optimized out>)
    at /work/zephyrproject_spi_rxne/zephyr/drivers/lora/sx1276.c:325
#16 0x080041dc in lora_send (data=0x20001ea8 <data> "helloworldGPIOA", 
    data_len=10, dev=0x20001fa8 <__device_sx1276_lora>)
    at /work/zephyrproject_spi_rxne/zephyr/include/drivers/lora.h:115
#17 main ()
    at /work/zephyrproject_spi_rxne/zephyr/samples/drivers/lora/send/src/main.c:48
(gdb) 
(gdb) x /9x 0x40013000
0x40013000:	0x00000324	0x00000000	0x00000000	0x0000008b
0x40013010:	0x00000007	0x00000000	0x00000000	0x00000000
0x40013020:	0x00000000
(gdb) 

Environment

  • OS: Ubuntu 18.04
  • Toolchain: Zephyr SDK(0.10.3)
  • Commit SHA or Version used: 9fe1e2a66378ffbfbbd0c08cf27859db80cf0c0d

Additional context The test program modified the delay to 10ms for quick symptom reproduction. The time the board stops is random. If symptoms do not appear within 1 minute, the symptoms do not seem to be reproduced. So I test for 1 minute and reset the power.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (10 by maintainers)

Most upvoted comments

@KwonTae-young @erwango So looks like the issue arises when two consecutive DIO0 interrupts arrive one after the other. Then the board hangs. I can confirm that the DioIrq callback gets executed successfully for the second time though.

Will dig more into this.