mongoose-os-libs / spi

Implements SPI API for Mongoose OS
Other
5 stars 0 forks source link

documentation for mgos_spi_txn does not match behavior of mgos_spi_run_txn for full-duplex (at least in ESP32) #2

Open scaprile opened 4 years ago

scaprile commented 4 years ago

In mgos_spi.h, for a full-duplex transaction I read:

 rx_data may also be NULL, in which case this effectively becomes a simple tx-only transaction

However, at least on an ESP32, setting rx_data to NULL causes a core dump:

[Oct 22 16:17:25.205] Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
[Oct 22 16:17:25.205] Core 1 register dump:
[Oct 22 16:17:25.205] PC      : 0x401284b2  PS      : 0x00060c30  A0      : 0x800f1f04  A1      : 0x3ffb4800  
[Oct 22 16:17:25.205] A2      : 0x60025000  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x00000002  
[Oct 22 16:17:25.227] A6      : 0x00000010  A7      : 0x0000003a  A8      : 0x00000000  A9      : 0x00000000  
[Oct 22 16:17:25.227] A10     : 0x00000000  A11     : 0xe7f94f00  A12     : 0x00000000  A13     : 0x3ffb4840  
[Oct 22 16:17:25.227] A14     : 0x00000000  A15     : 0x3ffb2b40  SAR     : 0x00000003  EXCCAUSE: 0x0000001d  
[Oct 22 16:17:25.249] EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000  
0x401284b2 in esp32_spi_get_rx_data (dev=0x60025000, data=0x0, skip=0, len=2)
at /data/fwbuild-volumes/2.18.0/apps/lora-demo/esp32/build_contexts/build_ctx_080674621/deps/spi/src/esp32/esp32_spi_master.c:267
267 /data/fwbuild-volumes/2.18.0/apps/lora-demo/esp32/build_contexts/build_ctx_080674621/deps/spi/src/esp32/esp32_spi_master.c: No such file or directory.
#0  0x401284b2 in esp32_spi_get_rx_data (dev=0x60025000, data=0x0, skip=0, 
len=2)
at /data/fwbuild-volumes/2.18.0/apps/lora-demo/esp32/build_contexts/build_ctx_080674621/deps/spi/src/esp32/esp32_spi_master.c:267
#1  0x400f1f04 in mgos_spi_run_txn_fd (len=0, rx_data=<optimized out>, 
tx_data=<optimized out>, c=<optimized out>)
at /data/fwbuild-volumes/2.18.0/apps/lora-demo/esp32/build_contexts/build_ctx_080674621/deps/spi/src/esp32/esp32_spi_master.c:315
#2  mgos_spi_run_txn (c=<optimized out>, full_duplex=<optimized out>, 
txn=<optimized out>)
at /data/fwbuild-volumes/2.18.0/apps/lora-demo/esp32/build_contexts/build_ctx_080674621/deps/spi/src/esp32/esp32_spi_master.c:409

Which goes away setting rx_data to a writable space. In fact, I see no check for NULL pointer in src/esp32/esp32_spi_master.c Which one is not correct, doc or implementation ?

rojer commented 4 years ago

implementation. you should be able to set rx_data to NULL if you don't want the data.

rojer commented 4 years ago

if you can send a PR that fixes it, please go ahead.

scaprile commented 4 years ago

I went ahead and checked the EFM32 implementation as well. It has the same issue. Here The ESP32 implementation, here, pulls 32-bit words out of some register. I don't know how safe it is to skip those readings, and directly avoid the function call here, I guess I should just check for NULL pointer and skip writing at the destination, but do the chip reads; in both cases ? I'll probably address this after I finish my current (related) endeavor. The ESP32 part I can check for operation; the EFM32 part I can do it but I can't check it.

rojer commented 4 years ago

yes, read the bytes but ignore them.

cikarnd commented 4 years ago

see PR #3 (BTW, "EFM32" --> "STM32" in previous comment...)