element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Internet of Things
  • Technologies
  • More
Internet of Things
Blog Port Semtech LoRaWan Modem library to Pico: Pt. 1: Gather info and prepare development infra
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Internet of Things to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 29 Jun 2024 9:57 AM Date Created
  • Views 2259 views
  • Likes 5 likes
  • Comments 18 comments
  • raspberry
  • lorawan
  • pico
  • semtech
  • rp2040
Related
Recommended

Port Semtech LoRaWan Modem library to Pico: Pt. 1: Gather info and prepare development infra

Jan Cumps
Jan Cumps
29 Jun 2024

The Semtch LoRa-node lib, that I used with some success in  Test LoRaWan Thing code ported for Raspberry Pico . is deprecated. It's replaced by LoRa Basic Modem.  I'm going to try and port that for the RP2040 controller. I've set ambitious goals:

  • don't change Semtech's code
  • port as specified by LoRa Basics Modem Porting Guide (30 pages of instructions)
  • use CMake, for compatibility with the Pico C/C++ SDK. Unless I find a way to integrate the make files in the build.
  • reusable for other projects

image
image source: Semtech Porting guide

Create a directory structure and get the LoRa Modem lib

I created a directory in the IDE workspace. I use VSCode, but the project works for any environment that can build one of Raspberry's Pico examples.

C:\Users\jancu\Documents\Pico\PicoSDKv1.5.1\workspace_1.5.1\pico_lorawan_modem

Then checked out Semtech's LoRa Modem lib:

git clone --recurse-submodules https://github.com/Lora-net/SWL2001.git

I created a main file, empty at the moment, and 2 CMake config files.

main.cpp

#include <stdio.h>
#include "pico/stdlib.h"

int main() {
    stdio_init_all();
    while (true) {
    }
    return 0;
}

CMakeList.txt

cmake_minimum_required(VERSION 3.13)

set(PICO_DEOPTIMIZED_DEBUG 1)

# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)
set(PICO_BOARD seeed_xiao_rp2040)

project(pico_lorawan_modem C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)

pico_sdk_init()

set(RADIO sx1276)
include (CMakeSWL2001.txt)

add_executable(${CMAKE_PROJECT_NAME} main.cpp )

pico_set_program_name(${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_NAME})
pico_set_program_version(${CMAKE_PROJECT_NAME} "0.1")

pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 0)
pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 1)



# Add any user requested libraries
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
        pico_stdlib
        )

pico_add_extra_outputs(${CMAKE_PROJECT_NAME})

This is a very common RP2040 file. You'll see that I only added two lines for the LoRa Modem:

set(RADIO sx1276)
include (CMakeSWL2001.txt)

That's because I plan to have anything related to the Semtech lib in a separate file.

CMakeSWL2001.txt

set(LORAWAN_LIB_NAME SWL2001)
add_library(${LORAWAN_LIB_NAME} INTERFACE)

target_include_directories(${LORAWAN_LIB_NAME} INTERFACE)
set(LORAMAC_LIB_PATH ${CMAKE_CURRENT_LIST_DIR}/SWL2001/lbm_lib)

if(NOT DEFINED RADIO)
  message("You must set a radio")
  message("set(RADIO <semtech radio model>")
  message("Valid options: (lr1110 lr1120 lr1121 sx1261 sx1262 sx1268 sx128x sx1272s) sx1276")
  message(FATAL_ERROR "Fix this before continuing.")
endif()
message("Radio selected: ${RADIO}")


target_sources(${LORAWAN_LIB_NAME} INTERFACE
#    ${LORAMAC_NODE_PATH}/src/peripherals/soft-se/soft-se.c
)

target_include_directories(${LORAWAN_LIB_NAME} INTERFACE
#    ${LORAMAC_NODE_PATH}/src
)

You can see it's still in its infant stage. It can manage a few things that I'll need later:

  • configure it so that the Pico example will see it as "one of the usual" libraries
  • check if a LoRaWan radio chip is selected. Error the build if not.
  • infra to collect all include and source files that 'll be required later.

image

  • Sign in to reply
Parents
  • eriklundh
    eriklundh over 1 year ago

    Do you have any github repo for this code?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to eriklundh

    no, but I'll attach the - currently not compiling - zip of my project here.

    I'm battling with the situation that the radio I'm using, sx1276, does not have a mature MODEM implementation in the LoRa MODEM lib.

    pico_lorawan_modem_02240707.zip

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • eriklundh
    eriklundh over 1 year ago in reply to Jan Cumps

    Two years ago, I battled with the previous official Semtech Lora Stack, and the wrapper that some guy at ARM wrote.
    I had mysterious crashes when doing some iterative testing, blamed myself in the beginning, but soon learned that most companies using Lora with that stack had to store vital infoi in flash and reboot the whole controller to avoid teh Lora stack to crash unpredictibly if you tried to send several messages. 
    One medium sized vendor had even tried to sell a kind of "sandbox for crappy code" solution to Semtech, something they needed for thir own products to work, but Semtech was not interested. All the original engineers from the startup where Lora originated,  left some time after Semtechs acqusition. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to eriklundh

    using Lora with that stack had to store vital infoi in flash and reboot the whole controller to avoid teh Lora stack to crash unpredictibly if you tried to send several messages

    The Pico port that shabaz and I tried out, still has that behaviour: see  Test LoRaWan Thing code ported for Raspberry Pico 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • eriklundh
    eriklundh over 1 year ago in reply to Jan Cumps

    What kind of gateway do you use?
    I did my testing in 2022 with two Raspberry PI-based gateways.
    The advantage was that I could set up a full open source chirpstack, without any ties to TTN.
     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • eriklundh
    eriklundh over 1 year ago in reply to Jan Cumps

    What kind of gateway do you use?
    I did my testing in 2022 with two Raspberry PI-based gateways.
    The advantage was that I could set up a full open source chirpstack, without any ties to TTN.
     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to eriklundh

    > What kind of gateway do you use?

    Also a Pi based one:  Set up Elecrow TTN LoRaWAN gateway on Raspberry Pi - Pt. 1: build and test 

    I used the TTN cloud approach.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • eriklundh
    eriklundh over 1 year ago in reply to Jan Cumps

    I forgot to mention that I used opensource Chirpstack on Raspberry Pi4 for testing, which allowed me full control of the whole chain from Gateway hardware to MQTT feed

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • eriklundh
    eriklundh over 1 year ago in reply to eriklundh

    I used  two different LoRA gateway boards for PI: RAK831 and RAK2245, both from RAK Wireless  

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube