Semtech LoraWAN

davidb
Sat Mar 10, 2018 2:37 pm
Hi All,

I am working on a project with the DISCO_L072CZ_LRWAN1 board. I would like to use the Lora funcionality from this board and although I came across the Sandeep Mistry’s LoRa library, this is not enough. I would like to use the full LoraWAN stack, so that I am compliant with networks like The Things Network. The stack can be found here: http://stackforce.github.io/LoRaMac-doc/index.html

It contains some examples, including one of an endnode and it works as long as I use it within Keil IDE. But I would like to use this stack as well inside the Arduino IDE, but don’t know how to include is. Any advice, or resources that would bring me closer to a solution would be greatly appreciated!

Thanks,

David


fpiSTM
Sat Mar 10, 2018 3:43 pm
Hi David,
the next release will provide pins for driving lora module of the B-l072.
I’ve made some LoRa radio with Sandeep Arduino-Lora library.
https://github.com/stm32duino/Arduino_C … 2/pull/221

For LoraWan, with this board I did no test with Arduino, only with http://www.st.com/en/embedded-software/ … lrwan.html

Anyway, we’ve just release the https://github.com/stm32duino/I-NUCLEO-LRWAN1
allowing to make LoRaWan using the http://www.st.com/en/evaluation-tools/i … rwan1.html

Maybe it could be possible to use it with b-l072 or at least as a base.


davidb
Sun Mar 11, 2018 1:03 pm
Thanks for your quick answer!

Had a closer look to your suggestions. When I add the pin definitions you suggest to be used with the Sandeep library and try to compile an example sketch with the Arduino IDE, I run into error messages: error: 'class SPIClass' has no member named 'setMISO'


fpiSTM
Sun Mar 11, 2018 2:35 pm
I assume you use the latest release of the STM Core:
https://github.com/stm32duino/Arduino_C … /2018.1.18
which provide setMISO

davidb
Sun Mar 11, 2018 3:25 pm
Hi,

My mistake: I was using an older version of the library, which was missing these methods. I am installing the new one right now, that will solve the problem.

I was trying to cherrypick the Endnode implementation today, but I keep running into all sorts of compile errors. It’s a bit overwhelming. It would help if I had more information about the structure and workings of the abstraction layers, all I have now is this: http://stackforce.github.io/LoRaMac-doc/index.html.

Maybe stripping it all to the bare bones will make it work. Let’s try. :)

Thanks for your input!

Cheers,

David


Dust
Mon Mar 12, 2018 9:05 pm
David, you may want to look at LMIC (Lora-MAC-in-C or Lora-WAN-in-C), it has been ported to the arduino: https://github.com/matthijskooijman/arduino-lmic

It was originally developed by IBM, but unfortunately they dropped it, so it is a bit outdated, but it was working very well for me with Adafruit Feather with RFM95W, whcich is basically SX127x radio. With the examples provided I just had to define some GPIO pins and network keys an it was working right away with LORIOT.


davidb
Mon Mar 12, 2018 9:33 pm
Hi Dust,

Thanks for the suggestion. I actually looked into that library today. But when I was compiling it, I ran into _FDEV_SETUP_WRITE' was not declared in this scope


davidb
Mon Mar 12, 2018 9:56 pm
I just had to try if I could make the LMIC lib working with the suggestions that I already found, but I kept running into errors. One error is just replacing the other…

So the questions remains which lib I should invest my time in to make it work.

David


mrburnette
Wed Mar 14, 2018 1:37 pm
David,

I tried (quick and dirty) to drop all the files into one directory, but I keep running into errors. I have the impression that the Arduino IDE is somehow shielding definitions and declarations made in the ST HAL. (But it’s all relatively new form me, so I may be mistaken).

I publish junk a lots and I attempt to combine libraries into the sketch simply to avoid having to have the user given instructions to download and install same. In doing this, I eliminate tons of Q&A from novices about compile errors from non-installed libs. The big issues that have to be faced is that automatic prototyping by the ArduinoIDE can (and will) break and global variables often need to be made local to functional TABS, that is made private.

Tabs with no designated file extension become .INO files and are concatenated at compile time with automatic function prototype declarations. Tabs that are .cpp and .h do not enjoy such automation… back to having to do things the correct C way. You must also include the “xxx.h” file in the xxx.cpp file source.

Arduino-MultiTab.png
Arduino-MultiTab.png (11.6 KiB) Viewed 962 times

davidb
Wed Mar 14, 2018 3:34 pm
Ray, Thanks for your feedback! I will certainly keep this in mind. But unfortunately it won’t solve the whole problem: I also run into redeclarations of functions and variables. And it’s now always clear whether they actually mean the same.

Having said this, I haven’t tried your suggestion with the LMIC. It may be possible to solve my problems with your suggestions. I will try later. :)

Cheers,

David


GrumpyOldPizza
Wed Mar 14, 2018 6:25 pm
[davidb – Wed Mar 14, 2018 3:34 pm] –
Ray, Thanks for your feedback! I will certainly keep this in mind. But unfortunately it won’t solve the whole problem: I also run into redeclarations of functions and variables. And it’s now always clear whether they actually mean the same.

Having said this, I haven’t tried your suggestion with the LMIC. It may be possible to solve my problems with your suggestions. I will try later. :)

Cheers,

David

It may not help right now. It’s alpha, and I have not yet had time to add a B-L072Z-LRWAN1 variant:

https://github.com/GrumpyOldPizza/ArduinoCore-stm32l0

The LoRaWAN class is here:

https://github.com/GrumpyOldPizza/Ardui … /LoRaWAN.h


davidb
Wed Mar 14, 2018 9:44 pm
Mr. Pizza, that looks very promising! :)

I will have a closer look at it tomorrow. Thanks for your help!

Cheers,

David


GrumpyOldPizza
Thu Apr 05, 2018 4:03 am
[davidb – Wed Mar 14, 2018 9:44 pm] –
Mr. Pizza, that looks very promising! :)

I will have a closer look at it tomorrow. Thanks for your help!

Cheers,

David

Added officially support for B-L072Z-LRWAN1 to the repository. The LoRaWAN examples see to work fine on my end for US915 and EU868. So maybe worth a look.


asmallri
Fri Apr 27, 2018 8:32 am
The LMIC code is very well supported by TheThingsNetwork community and there are several posts on their very active forum including posts using the STM32 BluePill with the library.

goran.mahovlic
Wed May 02, 2018 1:27 pm
Do you know a arduino code that could work with STM32L051 MCU?

I have all ready for testing.
With I-CUBE-LRWAN consumtion is around 4uA in sleep.

This is old setup with wires, now it is all on board, and have one more module on test…

LoRaSTM32L051.jpeg
LoRaSTM32L051.jpeg (29.6 KiB) Viewed 671 times

RogerClark
Wed May 02, 2018 9:19 pm
STM32GENERIC Core can probably be ported to that processor.

I am not sure about the F1 core being converted. I susoect it’s too differnt


GrumpyOldPizza
Thu May 03, 2018 12:08 pm
[goran.mahovlic – Wed May 02, 2018 1:27 pm] –
Do you know a arduino code that could work with STM32L051 MCU?

I have all ready for testing.
With I-CUBE-LRWAN consumtion is around 4uA in sleep.

This is old setup with wires, now it is all on board, and have one more module on test…
LoRaSTM32L051.jpeg
4uA.jpeg

Not sure, but I wanted to add STM32L052 support to this here (if it ever goes non-alpha): https://github.com/GrumpyOldPizza/ArduinoCore-stm32l0


fpiSTM
Thu May 03, 2018 12:23 pm
[RogerClark – Wed May 02, 2018 9:19 pm] –
STM32GENERIC Core can probably be ported to that processor.

I am not sure about the F1 core being converted. I susoect it’s too differnt

STM core too…


goran.mahovlic
Fri May 04, 2018 6:11 am
[GrumpyOldPizza – Thu May 03, 2018 12:08 pm] –

[goran.mahovlic – Wed May 02, 2018 1:27 pm] –
Do you know a arduino code that could work with STM32L051 MCU?

I have all ready for testing.
With I-CUBE-LRWAN consumtion is around 4uA in sleep.

This is old setup with wires, now it is all on board, and have one more module on test…
LoRaSTM32L051.jpeg
4uA.jpeg

Not sure, but I wanted to add STM32L052 support to this here (if it ever goes non-alpha): https://github.com/GrumpyOldPizza/ArduinoCore-stm32l0

Great, it could work. I will test it with L082 when I get time. Then I can switch to L051 ….


goran.mahovlic
Wed May 09, 2018 4:24 pm
I did add L051 as variant and “fixed pinout I want to use”

Now two more problems are left If you can help?

After fixing missing lib got lot of errors probably related with .a file :)

/home/mistery/Arduino/hardware/TleraCorp/stm32l0/system/STM32L0xx/Lib/libstm32l051xx.a(timer.o): In function `TimerGetCurrentTime’:
/home/mistery/Arduino/hardware/TleraCorp/stm32l0/system/STM32L0xx/Source/LoRa/System/timer.c:71: undefined reference to
`stm32l0_rtc_timer_reference’
collect2: error: ld returned 1 exit status

second problem is stm32l0_gpio.h
Where do I find those no. for L051 I have just copy pasted L072 but need to check what will be wrong now…

https://github.com/goran-mahovlic/ArduinoCore-stm32l0


GrumpyOldPizza
Thu May 10, 2018 11:55 am
[goran.mahovlic – Wed May 09, 2018 4:24 pm] –
I did add L051 as variant and “fixed pinout I want to use”

Now two more problems are left If you can help?

After fixing missing lib got lot of errors probably related with .a file :)

/home/mistery/Arduino/hardware/TleraCorp/stm32l0/system/STM32L0xx/Lib/libstm32l051xx.a(timer.o): In function `TimerGetCurrentTime’:
/home/mistery/Arduino/hardware/TleraCorp/stm32l0/system/STM32L0xx/Source/LoRa/System/timer.c:71: undefined reference to
`stm32l0_rtc_timer_reference’
collect2: error: ld returned 1 exit status

second problem is stm32l0_gpio.h
Where do I find those no. for L051 I have just copy pasted L072 but need to check what will be wrong now…

https://github.com/goran-mahovlic/ArduinoCore-stm32l0

In general, I would just declare the board to be a STM32L072 and be done. Just looked at your github, and saw quite a few issues:

startup_stm32l051.s is not really gonna work, as it uses the ST HAL’s semantics (actually the Atollic Toolchain). This will not work with the linker scripts and the rest of the infrastructure. Same goes for the linker script.

stm32l0_rtc_timer_reference is defined in stm32l0_rtc.c. So that’s really odd that this one would be missing.

stm32l0_gpio.h: Those are in the datasheet for STM32L051. So it’s kind of some tedious work.

Think about this another way around. STM32L0x1 is a STM32L0x2 without USB. STM32L0x2 is a STM32L0x3 without LCD peripheral. STM32L08x is a STM32L07x with AES peripheral. And STM32L05x is a cut down STM32L07x. All of this from the users perspective, probably not from real silicon.

BTW, does your board have HSE connected to PH0/PH1 ?


goran.mahovlic
Thu May 10, 2018 3:56 pm
Tnx,

I have startup_stm32l051.s from generated code for Makefile.
What do I need to chose to get right one if I generate files from cubeMX?
Ok I will check datasheet It should not be to much difference …
I have just soldered Low Speed crystal on board, and L051 does not have HSE nor Port H … Just two pins on Port C for LSE
So I will probably need to change HSE to HSI but that can be last part before uploading :)

I have just copy paste L072 .S .ld and library file to L051

And now it compiles – So now blink LED on PA0 could work – I just need to check if you are using HSE


goran.mahovlic
Thu May 10, 2018 4:30 pm
Niceeeee

Blink LED on PA8 – I did define it as A0 is working …

LoRa code is doing steps – I have add blink LED after packet send and led is blinking if I put one module.

But LoRa does not sends anything.

With DORJI module it code stops at beginning and it does not blink.

I first need to check if every pin blinks on scope, and then check if SPI is working…

This is my pinout for now, but if I get it work I will try to use your pinout on new board…

STM32L051_Arduino_LoRa.png
STM32L051_Arduino_LoRa.png (146.01 KiB) Viewed 523 times

GrumpyOldPizza
Fri May 11, 2018 12:32 pm
[goran.mahovlic – Thu May 10, 2018 4:30 pm] –
Niceeeee

Blink LED on PA8 – I did define it as A0 is working …

LoRa code is doing steps – I have add blink LED after packet send and led is blinking if I put one module.

But LoRa does not sends anything.

With DORJI module it code stops at beginning and it does not blink.

I first need to check if every pin blinks on scope, and then check if SPI is working…

This is my pinout for now, but if I get it work I will try to use your pinout on new board…

STM32L051_Arduino_LoRa.png

I have tested TimerMillis and works.
And STOP mode with timer is working
DownTo2uAFromArduino.jpg

So for now only SPI problem remains, or maybe some pin miss defined by me :)

I see. Next step. The code as of right now for LoRaWAN is hardcoded for CMWX1ZZABZ (want to do this more generically, but time is a problem here).

https://github.com/GrumpyOldPizza/Ardui … 76-board.h

You need to change the GPIOs for your module (is it this here: https://www.tindie.com/products/DORJI_C … -drf1276g/).

You don’t have a TCXO, so you might want to comment the code that is using that pin.

Then you need to mess with https://github.com/GrumpyOldPizza/Ardui … 76-board.c:

Throw out the TCXO code, have SX1276GetWakeupTime() return 1 (no TCXO wakeup time). The RX/TX switch is hooked up rather differently for your module. CMWX1ZZABZ uses 3 GPIOs to route RFI/RFO/PABOOST. The datasheet says (assuming again it’s the DORJI module):

“The switch of TX/RX is realized by controlling the levels of RXTX/RFMOD and DIO4 pins in
Lora mode. When RXTX/RFMOD=VHIGH and DIO4=0, TX is enabled and RX is disabled. When RXTX/RFMOD=0 and DIO4=VHIGH, the RX is enabled and TX is disabled. The level change of DIO4 is controlled by the related register”

So DIO4 has to be configured as DIO4_01 (PllLock) for RX, and DIO4_11 (undefined) for TX. Just odd, but not a biggy. For FSK (EU868, DR_5 I think), this has to be DIO4_01 and DIO4_11 as well (the 11 mapping is undefined for anything by RX) …

Lastly you need to patch SX1276GetPaSelect() to always return RF_PACONFIG_PASELECT_PABOOST.

Guess to make that more portable I needed to add a stm32l0_sx1276.c and stm32l0_sx1272.c piece that messes with the SPI/RESET/DIO0/DIO1/DIO2/DIO3/DIO4/DIO5 pins, TXCO enable/disable, the antenna switch and the RFO/PABOOST selection.

N.b that the SPI code in there bypasses the Arduino SPI stuff. So please make sure that the instance that controls this module is not mapped as SPI or GPIOs in variant.cpp. All the pins are exclusive, so there is no point to have them in the Arduino sandbox exposed as well. The code plays quite a few tricks with low power settings there …

For your board, you do not need HSE. I was just curious.

Since you are using SWD to debug. There is STM32L0.enableSWD() and STM32L0.disableSWD(). During debugging I would recommed to set STM32L0.enableSWD(). This blocks some clocks to be shut off during SLEEP/STOP, at the expense of power. When ready to really use this design, I’d put it STM32L0.disableSWD(). Saves a few uA in STOP mode.


goran.mahovlic
Fri May 11, 2018 1:33 pm
Tnx,

Will check it out when I get home.

I have those two modules already tested with cube 115 stack, and there CMWX1ZZABZ works to.
So I should probably copy paste some stuff from there into your code…


GrumpyOldPizza
Fri May 11, 2018 3:21 pm
[goran.mahovlic – Fri May 11, 2018 1:33 pm] –
Tnx,

Will check it out when I get home.

I have those two modules already tested with cube 115 stack, and there CMWX1ZZABZ works to.
So I should probably copy paste some stuff from there into your code…

Pretty much. Don’t know about the DIO4 yet. IMHO that should perhaps be integrated into sx1276.c (mainly because this is where the Radio driver controls the DIO mappings). On the other hand perhaps sx1276.c should Set DIO4 to PllLock and DIO5 to ModeReady at init time, and then not touch them anymore (unlike Semtech’s code which is all over the place with this).

How did you do this with cube 115 ? N.b. ST’s code is missing a good number of fixes. It also assumes DIO3 is used for CadDetect. The code in ArduinoCore-stm32l0 does not use DIO3. So simple copy and paste will not work.


goran.mahovlic
Fri May 11, 2018 5:36 pm
I did try all you have described, but still did not manage to get sending work.
I will fix receive in 115 and try after that.
How do you use debug from arduino?
Or I just load code and use gdb

As for 115 i am uploading it:
https://github.com/goran-mahovlic/stm32l051_test

I have only fixed for ABP join for DORJI
So I have fixed transmit, but for receive I still need to check datasheet and set registers…
And after transmit lora module goes into SLEEP

I use 112 on filed for a 6 months and did not noticed any real problems.
And I have 114 is working 3 months and seams OK
I did fix some issues at begin but did not notice to many critical problems


GrumpyOldPizza
Fri May 11, 2018 6:40 pm
[goran.mahovlic – Fri May 11, 2018 5:36 pm] –
I did try all you have described, but still did not manage to get sending work.
I will fix receive in 115 and try after that.
How do you use debug from arduino?
Or I just load code and use gdb

As for 115 i am uploading it:
https://github.com/goran-mahovlic/stm32l051_test

I have only fixed for ABP join for DORJI
So I have fixed transmit, but for receive I still need to check datasheet and set registers…
And after transmit lora module goes into SLEEP

I use 112 on filed for a 6 months and did not noticed any real problems.
And I have 114 is working 3 months and seams OK
I did fix some issues at begin but did not notice to many critical problems

I just load code and use gdb ;-)


Leave a Reply

Your email address will not be published. Required fields are marked *