ArmDeveloperEcosystem / lorawan-library-for-pico

Enable LoRaWAN communications on your Raspberry Pi Pico or any RP2040 based board. 📡
BSD 3-Clause "New" or "Revised" License
125 stars 47 forks source link

Needed to edit two files to include spi.h when using the code #30

Closed shabaz123 closed 1 year ago

shabaz123 commented 1 year ago

(Please ignore this issue, it was a fault in my CMakeLists.txt file. I have corrected it, and this issue can be closed. For the benefit of anyone interested, it was a conflict with the header files for pico-lorawan, and a SD card FAT library, which both use files called spi.h. The solution was to place the text pico-lorawan/lib/LoRaMac-node/src/system as the first entry for target_include_directories in CMakeLists.txt).

Hello,

I don't know if it is an issue with my CMakeLists.txt or not, but when I tried integrating the pico-lorawan project into the rest of my application, I received an error, relating to spi.h during the code building.

The error is:

C:/development/pico/myproj/pico-lorawan/src/boards/rp2040/sx1276-board.c
In file included from C:/development/pico/myproj/pico-lorawan/lib/LoRaMac-node/src/boards/sx1276-board.h:33,
                 from C:/development/pico/myproj/pico-lorawan/src/boards/rp2040/sx1276-board.c:33:
C:/development/pico/myproj/pico-lorawan/lib/LoRaMac-node/src/radio/sx1276/sx1276.h:148:5: error: unknown type name 'Spi_t'
  148 |     Spi_t         Spi;
      |     ^~~~~
C:/development/pico/myproj/pico-lorawan/src/boards/rp2040/sx1276-board.c: In function 'SX1276IoInit':
C:/development/pico/myproj/pico-lorawan/src/boards/rp2040/sx1276-board.c:114:26: error: request for member 'Nss' in something not a structure or union
  114 |     GpioInit( &SX1276.Spi.Nss, SX1276.Spi.Nss.pin, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); // CS
      |                          ^

To fix it, I had to do these things:

  1. in src/boards/rp2040/spi-board.c I had to add this line: #include "../../../LoRaMac-node/src/system/spi.h"

  2. in lorawan.c I had to add this line: #include "spi.h"

Now the code builds fine, and runs.

My code structure consists of several files (main.c and so on) at a top level, and the pico-lorawan library is in a folder.

I'm a beginner with CMake, so I don't know if it's a real issue, or some fault at my end. This is what my CMakeLists.txt file contains:

cmake_minimum_required(VERSION 3.12)
include(pico_sdk_import.cmake)
project(myproj)

pico_sdk_init()

add_subdirectory(pico-lorawan pico-lorawan/lib/LoRaMac-node)
add_subdirectory(no-OS-FatFS-SD-SPI-RPi-Pico/FatFs_SPI)

# rest of your project
add_executable(myproj
    main.c
    hw_config.c
)

target_include_directories(myproj PUBLIC
        no-OS-FatFS-SD-SPI-RPi-Pico/FatFs_SPI/include
        no-OS-FatFS-SD-SPI-RPi-Pico/FatFs_SPI/sd_driver
        no-OS-FatFS-SD-SPI-RPi-Pico/FatFs_SPI/ff14a/source
        pico-lorawan/lib/LoRaMac-node/src/system
        )

target_link_libraries(myproj pico_lorawan hardware_adc pico_stdlib hardware_clocks
        FatFs_SPI hardware_i2c hardware_dma hardware_spi
        )

# enable usb output, disable uart output
pico_enable_stdio_usb(myproj 1)
pico_enable_stdio_uart(myproj 0)

# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(myproj)

If you think my CMakeLists.txt looks OK, then I'm happy to create a pull request with the modifications.

Many thanks!

shabaz123 commented 1 year ago

(Please ignore this issue, it was a fault in my CMakeLists.txt file. I have corrected it, and this issue can be closed. For the benefit of anyone interested, it was a conflict with the header files for pico-lorawan, and a SD card FAT library, which both use files called spi.h. The solution was to place the text pico-lorawan/lib/LoRaMac-node/src/system as the first entry for target_include_directories in CMakeLists.txt).