Lora-net / SWL2001

LoRa Basics Modem LoRaWAN stack
BSD 3-Clause Clear License
104 stars 60 forks source link

In Nordic NRF25840 Board port for SX1262, compilation fails since hal_spi_in_out() has too few parameters #34

Closed acutetech closed 6 months ago

acutetech commented 8 months ago

I am trying to build the nRF52840 example with the SX1262. Compilation fails with this error:

radio_hal/sx126x_hal.c:109:9: error: too few arguments to function 'hal_spi_in_out'

This is correct - since hal_spi_in_out() takes 5 arguments and the sx126x_hal.c code gives it only 2.

From what I can see, \lbm_applications\2_porting_nrf_52840\radio_hal\lr11xx_hal.c uses since hal_spi_in_out() correctly, but sx126x_hal.c and sx128x_hal.c do not.

This is a bit worrying, since it suggests the nRF52840 with SX126x or SX128x combination have never been tested.

Please provided a fix, and please provide reassurance that SWL2001 will work with the SX1262.

lbm-team commented 8 months ago

Hi acutetech

Thank you for using the sx1262 with the Nordic environment. Rest assured, LBM has been tested with the sx126x and sx128x without any problems. There are many evaluation board kits, our efforts have been made mainly on STM32. LBM is agnostic to the target but the HAL must aligned.

Below the diff to fix the problem on SX126x and SX128x radios connected to a Nordic

diff --git a/lbm_applications/2_porting_nrf_52840/radio_hal/sx126x_hal.c b/lbm_applications/2_porting_nrf_52840/radio_hal/sx126x_hal.c
index b103ad27b794a7eac6e446108d95071d0dadcd7a..a5bae82240af138465ca77dd0c130aefa85ab6b7 100644
--- a/lbm_applications/2_porting_nrf_52840/radio_hal/sx126x_hal.c
+++ b/lbm_applications/2_porting_nrf_52840/radio_hal/sx126x_hal.c
@@ -104,14 +104,10 @@ sx126x_hal_status_t sx126x_hal_write( const void* context, const uint8_t* comman

     // Put NSS low to start spi transaction
     hal_gpio_set_value( RADIO_NSS, 0 );
-    for( uint16_t i = 0; i < command_length; i++ )
-    {
-        hal_spi_in_out( RADIO_SPI_ID, command[i] );
-    }
-    for( uint16_t i = 0; i < data_length; i++ )
-    {
-        hal_spi_in_out( RADIO_SPI_ID, data[i] );
-    }
+
+    hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 );
+    hal_spi_in_out( RADIO_SPI_ID, data, data_length, NULL, 0 );
+
     // Put NSS high as the spi transaction is finished
     hal_gpio_set_value( RADIO_NSS, 1 );

@@ -135,13 +131,11 @@ sx126x_hal_status_t sx126x_hal_read( const void* context, const uint8_t* command

     // Put NSS low to start spi transaction
     hal_gpio_set_value( RADIO_NSS, 0 );
-    for( uint16_t i = 0; i < command_length; i++ )
-    {
-        hal_spi_in_out( RADIO_SPI_ID, command[i] );
-    }
-    for( uint16_t i = 0; i < data_length; i++ )
+    hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 );
+
+    if( data_length > 0 )
     {
-        data[i] = hal_spi_in_out( RADIO_SPI_ID, 0 );
+        hal_spi_in_out( RADIO_SPI_ID, 0, 0, data, data_length );
     }
     // Put NSS high as the spi transaction is finished
     hal_gpio_set_value( RADIO_NSS, 1 );
diff --git a/lbm_applications/2_porting_nrf_52840/radio_hal/sx128x_hal.c b/lbm_applications/2_porting_nrf_52840/radio_hal/sx128x_hal.c
index 11d4b434acfafe0b5ddbe76e9a09332e0c0be237..64846b6df84018ab646cf0e2b07296037ab1903d 100644
--- a/lbm_applications/2_porting_nrf_52840/radio_hal/sx128x_hal.c
+++ b/lbm_applications/2_porting_nrf_52840/radio_hal/sx128x_hal.c
@@ -103,14 +103,10 @@ sx128x_hal_status_t sx128x_hal_write( const void* context, const uint8_t* comman

     // Put NSS low to start spi transaction
     hal_gpio_set_value( RADIO_NSS, 0 );
-    for( uint16_t i = 0; i < command_length; i++ )
-    {
-        hal_spi_in_out( RADIO_SPI_ID, command[i] );
-    }
-    for( uint16_t i = 0; i < data_length; i++ )
-    {
-        hal_spi_in_out( RADIO_SPI_ID, data[i] );
-    }
+
+    hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 );
+    hal_spi_in_out( RADIO_SPI_ID, data, data_length, NULL, 0 );
+
     // Put NSS high as the spi transaction is finished
     hal_gpio_set_value( RADIO_NSS, 1 );

@@ -134,14 +130,13 @@ sx128x_hal_status_t sx128x_hal_read( const void* context, const uint8_t* command

     // Put NSS low to start spi transaction
     hal_gpio_set_value( RADIO_NSS, 0 );
-    for( uint16_t i = 0; i < command_length; i++ )
-    {
-        hal_spi_in_out( RADIO_SPI_ID, command[i] );
-    }
-    for( uint16_t i = 0; i < data_length; i++ )
+    hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 );
+
+    if( data_length > 0 )
     {
-        data[i] = hal_spi_in_out( RADIO_SPI_ID, 0 );
+        hal_spi_in_out( RADIO_SPI_ID, 0, 0, data, data_length );
     }
+
     // Put NSS high as the spi transaction is finished
     hal_gpio_set_value( RADIO_NSS, 1 );
lbm-team commented 6 months ago

Fixed in v4.3.1