FreeRTOS port for lorawan

hello Lorawaners,
I would like to know if anyone has experience with porting lorawan lib (lmic, loramac, or similar) on FreeRTOS?
I have a stm nucleo board (STM32L476RG) with sx1276mb1mas shield and my motivation is to help my application running on FreeRTOS to send data over the lorawan network.

Appreciate any pointers to such discussions.

thanks,
Arun

Porting LoRaMac-Node to FreeRTOS on a STM32L4 shouldn’t be too hard. You already have all the drivers you need (courtesy of ST), it’s possible that all you have to do is to simply put calls to lora_fsm() in its own task.

EDIT: for completeness’ sake, I should add:

  • FreeRTOS doesn’t have any API for hardware peripheral. For instance there’s no SPI API. At the end of the day FreeRTOS is ‘just’ a task scheduler, so there’s no way to “port LoRaMac-Node to FreeRTOS” because it simply doesn’t make sense - you’re comparing apples and oranges.
  • ST provides full examples and drivers for LoRaMac-Node. Since you have an official Nucleo/LoRa shield combination, it’s going to work out of the box for you.
1 Like

The LMIC library is built around a liteweight RTOS. I guess moving from one RTOS wanbe to the full blown FreeRTOS shouldn’t be a complex task.
The LoraMAC is more a library where you call on regular interval the state machine, as indicated by @Gig.
You also potentially take the STM’s version of LoraMAC which is clearly separated from teh application code and run it in its own task.

1 Like

We did run the LMIC inside a freeRTOS task. It needed a little adaption but nothing serious. Feel free to contact us if you are interested in this code.

But the better solution in my opionen is to develop a own stack based on freeRTOS features. This took me 1.5 days from scratch until first packets found their way to TTN. With this solution you know whats going on - in contrasr to much magic inside lmic.

3 Likes

Hi Lobaro, I would welcome a chance to evaluate your code. Here is what I did with the original STM demo LoRaWAN code: https://www.thethingsnetwork.org/labs/story/using-node-red-with-st-nucleo-l073rz-sx1272
Thanks!

1 Like

As far as LMIC is concerned, some operators aren’t recommending/certifying its usage on their network. The reason behind this may be the fact that

  • missing active dev/maintenance in their repo
  • problems arise when the network configures the device parameters on downlink (when not all mac commands are implemented).
  • missing clear references to lorawan standard document.

Other available option is loramac stack adapted by ST. but here I agree with you that we need to tweak a lot of timers/interrupts (more or less from scratch :)) in order to make it completely running on OS based timers.

Used Hardware: P-NUCLEO-LRWAN1 (Nucleo-L073RZ and SX1272MB2DAS)
Used Software: CubeMX, OpenStm32 (SW4STM32 toolchain), I-CUBE-LRWAN)

Hallo together,
I have a similar problem to build a project that combines FreeRTOS with the Ping Pong example-project from the I-CUBE-LRWAN expansion pack. The goal of my current work is a thread-based ping-pong project running on two nodes and exchanging messages. Therefore, I have created a new SW4STM32-toolchain project in CubeMx for the Nucleo-L073RZ board that includes FreeRTOS. After that, I have opened the project in the OpenStm32-IDE and have added the LoRa-middleware and the SX1272MB2DAS drivers from the I-CUBE-LRWAN expansion pack to the project. At this state, the project could not be compiled and there were a lot of errors. After adding the required files from the ping pong project and adjusting the includes and compiler settings, the project could be compiled. At this state, threading works well (the scheduler could switch between two threads, a default and a blinking LED thread). Then I have created a LoRa-ping-pong thread with the ping pong code of the I-CUBE-LRWAN expansion pack. The project is still able to be compiled, but there is a problem with unexpected interrupts, because the control flow ends in the infinity loop of the default handler. After debugging, I have found out that the following code snippet, executing before initializing the threads, cause the problems. I hope that someone could help me to get the project running or shows me a better way combining a RTOS with the ping pong project.

static RadioEvents_t RadioEvents;
RadioEvents.TxDone = OnTxDone;
RadioEvents.RxDone = OnRxDone;
RadioEvents.TxTimeout = OnTxTimeout;
RadioEvents.RxTimeout = OnRxTimeout;
RadioEvents.RxError = OnRxError;
Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );

#if defined( USE_MODEM_LORA )
  Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
                                 LORA_SPREADING_FACTOR, LORA_CODINGRATE,
                                   LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
                                   true, 0, 0, LORA_IQ_INVERSION_ON, 3000000 );
  Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
                                   LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
                                   LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
                                   0, true, 0, 0, LORA_IQ_INVERSION_ON, true );

#elif defined( USE_MODEM_FSK )
  Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0,
                                  FSK_DATARATE, 0,
                                  FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON,
                                  true, 0, 0, 0, 3000000 );
  Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE,
                                  0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH,
                                  0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true,
                                  0, 0,false, true );

#else
    #error "Please define a frequency band in the compiler options."
#endif

 Radio.Rx( RX_TIMEOUT_VALUE );

Can you share your implementation?

You can find the code on my GitHub Repo: https://github.com/Niondir/lmic-freertos

1 Like

it missing some include files. linked to lobaro git. but these files are no more in there…

Please create issues in GitHub. Currently the code can be used as a showcase / example. But I’m happy to accept pull requests to make it more usable out of the box.

Hi,
Im trying to connect FreeRTOS(my board is STM32L0CZ) to the things network without using AWS and Im so confused with all the tasks that I have to make. could you please help me?
thanks!

Not using AWS presumably means you’ll be using the public TTN network, rather than a private instance.

Do you have a proper 8-channel LoRaWAN gateway in range which is connected to TTN? If not, you’ll need that before you can accomplish anything with the node.

On the node side, you should probably start with whatever example is workable off the shelf, eg, maybe ST’s version of LoRAMAC node? Don’t worry if it doesn’t have FreeRTOS support; first get it working exactly as the example author intended, as the only program running on your board, and gain some experience.

Only worry about trying to get it going under FreeRTOS or to interact with your actual sensors or other embedded software requirements after you’ve been able to achieve basic interaction with TTN servers - eg, don’t try to change example code until you’ve both seen that it works, and had a chance to develop some knowledge of how it works. Otherwise debugging without any reliable starting point is too complex.

2 Likes