ofauchon / go-lorawan-stack

Lightweight Lorawan stack for Golang
MIT License
7 stars 1 forks source link

stm32wl55 #1

Open tcpipchip opened 1 year ago

tcpipchip commented 1 year ago

i have plans to test you stack in our LoRaWAN module, the LSI110A

it's is a STM32WL55+SX1262 :)

tcpipchip commented 1 year ago

Hi, starting now! Can you help me ?

Starting blogs https://ninab3-python.blogspot.com/2022/12/u-blox-nina-b302-rodando-tinygo.html https://ninab3-python.blogspot.com/2022/12/wisol-lsm110a-rodando-tinygo-blynk-led.html

Where to include your package and start the compile ?

├───bin ├───lib │ ├───clang │ │ └───include │ ├───CMSIS │ │ └───CMSIS │ │ └───Include │ ├───compiler-rt-builtins │ │ ├───aarch64 │ │ ├───arm │ │ ├───Darwin-excludes │ │ ├───hexagon │ │ ├───i386 │ │ ├───macho_embedded │ │ ├───ppc │ │ ├───riscv │ │ ├───ve │ │ └───x86_64 │ ├───macos-minimal-sdk │ │ ├───download │ │ ├───src │ │ │ ├───arm64 │ │ │ ├───usr │ │ │ │ └───include │ │ │ │ ├───arm │ │ │ │ ├───arpa │ │ │ │ ├───i386 │ │ │ │ ├───libkern │ │ │ │ │ ├───arm │ │ │ │ │ └───i386 │ │ │ │ ├───mach │ │ │ │ │ ├───arm │ │ │ │ │ ├───i386 │ │ │ │ │ └───machine │ │ │ │ ├───machine │ │ │ │ ├───malloc │ │ │ │ ├───protocols │ │ │ │ ├───secure │ │ │ │ ├───sys │ │ │ │ │ ├───_pthread │ │ │ │ │ └───_types │ │ │ │ ├───xlocale │ │ │ │ └───_types │ │ │ └───x86_64 │ │ └───test │ ├───mingw-w64 │ │ ├───mingw-w64-crt │ │ │ ├───def-include │ │ │ └───lib-common │ │ └───mingw-w64-headers │ │ ├───crt │ │ │ ├───sdks │ │ │ ├───sec_api │ │ │ │ └───sys │ │ │ └───sys │ │ └───defaults │ │ └───include │ │ └───sdks │ ├───musl │ │ ├───arch │ │ │ ├───aarch64 │ │ │ │ └───bits │ │ │ ├───arm │ │ │ │ └───bits │ │ │ ├───generic │ │ │ │ └───bits │ │ │ ├───i386 │ │ │ │ └───bits │ │ │ └───x86_64 │ │ │ └───bits │ │ ├───crt │ │ ├───include │ │ │ ├───arpa │ │ │ ├───net │ │ │ ├───netinet │ │ │ ├───netpacket │ │ │ ├───scsi │ │ │ └───sys │ │ └───src │ │ ├───env │ │ ├───errno │ │ ├───exit │ │ │ └───arm │ │ ├───include │ │ │ ├───arpa │ │ │ └───sys │ │ ├───internal │ │ │ ├───i386 │ │ │ └───sh │ │ ├───malloc │ │ ├───math │ │ │ ├───aarch64 │ │ │ ├───arm │ │ │ ├───i386 │ │ │ ├───mips │ │ │ ├───powerpc │ │ │ ├───powerpc64 │ │ │ ├───riscv64 │ │ │ ├───s390x │ │ │ ├───x32 │ │ │ └───x86_64 │ │ ├───mman │ │ ├───signal │ │ │ ├───aarch64 │ │ │ ├───arm │ │ │ ├───i386 │ │ │ ├───m68k │ │ │ ├───microblaze │ │ │ ├───mips │ │ │ ├───mips64 │ │ │ ├───mipsn32 │ │ │ ├───or1k │ │ │ ├───powerpc │ │ │ ├───powerpc64 │ │ │ ├───riscv64 │ │ │ ├───s390x │ │ │ ├───sh │ │ │ ├───x32 │ │ │ └───x86_64 │ │ ├───stdio │ │ ├───string │ │ │ ├───arm │ │ │ ├───i386 │ │ │ └───x86_64 │ │ ├───thread │ │ │ ├───aarch64 │ │ │ ├───arm │ │ │ ├───i386 │ │ │ ├───m68k │ │ │ ├───microblaze │ │ │ ├───mips │ │ │ ├───mips64 │ │ │ ├───mipsn32 │ │ │ ├───or1k │ │ │ ├───powerpc │ │ │ ├───powerpc64 │ │ │ ├───riscv64 │ │ │ ├───s390x │ │ │ ├───sh │ │ │ ├───x32 │ │ │ └───x86_64 │ │ ├───time │ │ └───unistd │ │ ├───mips │ │ ├───mips64 │ │ ├───mipsn32 │ │ ├───sh │ │ └───x32 │ ├───nrfx │ │ ├───doc │ │ │ ├───buildfiles │ │ │ └───config_dox │ │ ├───drivers │ │ │ ├───include │ │ │ └───src │ │ │ └───prs │ │ ├───hal │ │ ├───helpers │ │ ├───mdk │ │ ├───soc │ │ └───templates │ ├───picolibc │ │ └───newlib │ │ ├───libc │ │ │ ├───ctype │ │ │ ├───include │ │ │ │ ├───machine │ │ │ │ ├───rpc │ │ │ │ ├───ssp │ │ │ │ └───sys │ │ │ ├───locale │ │ │ ├───string │ │ │ └───tinystdio │ │ │ └───ryu │ │ └───libm │ │ ├───common │ │ └───math │ └───wasi-libc │ └───sysroot │ ├───include │ │ ├───arpa │ │ ├───bits │ │ ├───net │ │ ├───netinet │ │ ├───netpacket │ │ ├───scsi │ │ ├───sys │ │ └───wasi │ └───lib │ └───wasm32-wasi ├───pkg │ ├───thumbv6m-unknown-unknown-eabi-cortex-m0 │ │ ├───compiler-rt │ │ └───picolibc │ │ └───include │ ├───thumbv6m-unknown-unknown-eabi-cortex-m0plus │ │ ├───compiler-rt │ │ └───picolibc │ │ └───include │ └───thumbv7em-unknown-unknown-eabi-cortex-m4 │ ├───compiler-rt │ └───picolibc │ └───include ├───src │ ├───crypto │ │ ├───internal │ │ │ └───boring │ │ │ └───sig │ │ └───rand │ ├───device │ │ ├───arm │ │ ├───arm64 │ │ ├───avr │ │ ├───esp │ │ ├───kendryte │ │ ├───nrf │ │ ├───nxp │ │ ├───riscv │ │ ├───rp │ │ ├───sam │ │ ├───sifive │ │ └───stm32 │ ├───examples │ │ ├───adc │ │ ├───blinkm │ │ ├───blinky1 │ │ ├───blinky2 │ │ ├───button │ │ ├───button2 │ │ ├───can │ │ ├───caninterrupt │ │ ├───dac │ │ ├───echo │ │ ├───echo2 │ │ ├───gba-display │ │ ├───hid-keyboard │ │ ├───hid-mouse │ │ ├───i2s │ │ ├───mcp3008 │ │ ├───memstats │ │ ├───microbit-blink │ │ ├───pininterrupt │ │ ├───pwm │ │ ├───rand │ │ ├───serial │ │ ├───systick │ │ ├───temp │ │ ├───test │ │ ├───uart │ │ ├───usb-midi │ │ └───wasm │ │ ├───callback │ │ ├───export │ │ ├───invoke │ │ ├───main │ │ └───slices │ ├───internal │ │ ├───bytealg │ │ ├───fuzz │ │ ├───reflectlite │ │ └───task │ ├───machine │ │ └───usb │ │ ├───cdc │ │ ├───hid │ │ │ ├───keyboard │ │ │ └───mouse │ │ └───midi │ ├───net │ ├───os │ │ └───exec │ ├───reflect │ ├───runtime │ │ ├───cgo │ │ ├───debug │ │ ├───internal │ │ │ └───sys │ │ ├───interrupt │ │ ├───pprof │ │ ├───trace │ │ └───volatile │ ├───sync │ ├───syscall │ └───testing └───targets

your package ?

deadprogram commented 1 year ago

@tcpipchip this here package is for the Go programming language, not for the C SDK you are referencing.

If you want to use TinyGo with that board and this package, you can find out more from the @ofauchon video here https://www.youtube.com/watch?v=PhGiLQMHoQg

Hope that helps!

tcpipchip commented 1 year ago

hi Yes, I know Its only gave a example that e5 is compatible LSM110A

deadprogram commented 1 year ago

I think the place to start is then probably adding a new board definition to TinyGo. Please see https://github.com/tinygo-org/tinygo/wiki/Adding-a-new-board#adding-a-new-board

ofauchon commented 1 year ago

Hi @tcpipchip ,

@deadprogram is right. Here are the main steps to run Lorawan on STM32WLxx :

Note: you 'll need to declare the correct GPIOS for the rfswitch, which is board dependant (see : https://github.com/tinygo-org/drivers/tree/dev/examples/sx126x/rfswitch)

Il you can run the lora_rxtx driver example, you'll then be able to continue with testing the lorawan stack.

Olivier

tcpipchip commented 1 year ago

Hi, I had sent other question to a similar group, with some common users. I have already installed go and Tinygo and I can compile serial and blink examples on LSM110a. C:\tinygo\src\Tinygo flash xxxxx\examples\yyyyy How can I add the sx126x libraries and the lora example and instructions to compile ?

then I can do fast feedback

and making a lot of new blogs

https://ninab3-python.blogspot.com/2022/12/wisol-lsm110a-rodando-tinygo-blynk-led.html?m=1

tcpipchip commented 1 year ago

image

this means that is it working ?

at least detected the sx1262 ?

deadprogram commented 1 year ago

Looks like it to me!

tcpipchip commented 1 year ago

Thanks! I am happy!!!

need now only compile the lorawan_test.go or must to install something else before ?

please, instruct me!!! :)

ofauchon commented 1 year ago

Hi.

Well done, It seem you passed radio module detection step in the driver.

This means Tinygo driver could read and write SX126x registers through SPI bus. (That was the hard part ... )

Now, if you have two boards, you could flash them both with the lora_rxtx example and see if they can cross send/receive Lora frames (That would be the best way to ensure everything is OK)

If the test fails, it can be because of an external RF SWITCH in front of the STM32WL which is not properly driven (and the antennas are not RX/TX properly)

This is the reason I added an extra rfswitch code for the supported STM32WL boards (have a look to https://github.com/ofauchon/tinygo-drivers/tree/dev/examples/sx126x/rfswitch) .

Your LSI board may use different GPIOs to drive the board's RF switch.

The manufacturer SDK seems to contain RFSWITCH code: https://github.com/SeongJiIoT/LSM100A_SDK/blob/e5ee7eed74e5e11e3d06900ff9c486fc3f1d7170/Projects/NUCLEO-WL55CC/Applications/LoRaWAN_Sigfox/LSM100A/Core/Inc/radio_board_if.h#L87-L112

and :

https://github.com/SeongJiIoT/LSM100A_SDK/blob/e5ee7eed74e5e11e3d06900ff9c486fc3f1d7170/Projects/NUCLEO-WL55CC/Applications/SubGHz_Phy/SubGHz_Phy_PingPong/SubGHz_Phy/Target/radio_board_if.c#L154-L185

This can help you understand how to switch between High/Low TX power mode , RX mode, and OFF (by toggling GPIOs connected to RF Switch)

You can also contact LSM board manufacturer and ask for the circuit schematics, so you can see how the RFSwitch is connected to STM32WL GPIOs

Hope that helps.

Olivier

tcpipchip commented 1 year ago

hi @ofauchon and @deadprogram

Running two LSM110A

image

Right ?

image

Wich the next step ?

How i install your github lib and compile it ?

In meantime, i writing the BLOG, with merits to this group :)

https://ninab3-python.blogspot.com/2022/12/wisol-lsm110a-rodando-tinygo-p2p.html

ofauchon commented 1 year ago

Hi @tcpipchip,

You're going very fast ! That's awesome.

Thanks for the blog page. It'll help newcomers on TinyGO & Lora(WAN)

What do you want to do with Lorawan as a next step, so I can help you best. (Connecting a LoraWAN network ? which one : Public TTN or private Lorawan operator ? Sending uplink frames with sensors metrics ?)

Tell us more about your project and goals...

Thx

tcpipchip commented 1 year ago

Hi I am not fast! 😀 Well, I have now here a dragino pointing to chirpstack, boths are working. Now I want only send “hello” using OTAA. I already have the EUI and APKKEY defined on chirpstack. My question is wich of tinygo examples I must to test and wich are the go dependencies and how to install them😀

need only test uplink for a while

send me instructions..

thank you!

ofauchon commented 1 year ago

Hi,

You can try to use the composter demo here:

https://github.com/ofauchon/ttn2022-tinygo/tree/main/apps/gnse-lorawan-composter

Basically, it connects a Lorawan provider, and send periodically some datas to the network

Olivier

tcpipchip commented 1 year ago

Hi @ofauchon Must I replace the code that i tested to LoRa https://github.com/tinygo-org/drivers/tree/dev/examples/sx126x/lora_rxtx in my LSM110a GoLand project by your code above, without need more go lib dependencies ?

Need only config the LoraWAN credencies, right ?

tcpipchip commented 1 year ago

And have you config to AU915 ?

tcpipchip commented 1 year ago

hey what means this error ? image

ofauchon commented 1 year ago

Hi...

Relative path imports should not be used anymore (and considered ad bad practice) This code really needs refactoring.

But it still compiles on my setup : image

Try replace "import ./extra" with "import github.com/ofauchon/ttn2022-tinygo/apps/gnse-lorawan-composter/extra". The idea is to use absolute locations to the modules.

.. There may be something different on your setup ( I can see extra "go.mod" and "go.sum", try remove them, or change import path like explained above)

You can also read https://go.dev/ref/mod to learn on how Go deal with dependencies.

Olivier

tcpipchip commented 1 year ago

Hi I had updated to the correct image, see now Ok, I will verify

ofauchon commented 1 year ago

And have you config to AU915 ?

Lorawan Uplink and Downlink frequency plans is not the same in AU (compared to EU):

https://www.thethingsnetwork.org/docs/lorawan/frequency-plans/

Try to change the frequency / spread factor / ... here :

https://github.com/ofauchon/ttn2022-tinygo/blob/703e689643f7a5f373104fd06c13c1c566abd603/apps/gnse-lorawan-composter/lorawan_demo.go#L136-L146

... According to AU frequency plan (uplinks)...

Then try to connect...

You should turn on radio module debug logs in your ChripStack Lorawan server to determine if the ChripStack server receive the join packet, and what downlink frequency/modulation it uses for the answers.

If uplink and downlink frequencies/modulations are different, some changes will be needed in the lorawan stack .

deadprogram commented 1 year ago

Worth mentioning this branch which in addition to trying to complete @ofauchon work on additional chip is also doing some config refactoring https://github.com/tinygo-org/drivers/pull/494

tcpipchip commented 1 year ago

Btw, I have to test on LOM204a too

tcpipchip commented 1 year ago

it´s compiles! Next Step, make comunication with CHIRPSTACK :)

tcpipchip commented 1 year ago

some tests image image

accept the join, but looks that the STM32WL55 is not receiving the confirmation of JOIN

loraConf := sx126x.LoraConfig{ Freq: 916800000, Bw: sx126x.SX126X_LORA_BW_125_0, Sf: sx126x.SX126X_LORA_SF9, Cr: sx126x.SX126X_LORA_CR_4_7, HeaderType: sx126x.SX126X_LORA_HEADER_EXPLICIT, Preamble: 12, Ldr: sx126x.SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_OFF, Iq: sx126x.SX126X_LORA_IQ_STANDARD, Crc: sx126x.SX126X_LORA_CRC_ON, SyncWord: sx126x.SX126X_LORA_MAC_PUBLIC_SYNCWORD, LoraTxPowerDBm: 20, }

wrong downlink frequency to AU915

923.3 - SF7BW500 to SF12BW500 (RX1) 923.9 - SF7BW500 to SF12BW500 (RX1) 924.5 - SF7BW500 to SF12BW500 (RX1) 925.1 - SF7BW500 to SF12BW500 (RX1) 925.7 - SF7BW500 to SF12BW500 (RX1) 926.3 - SF7BW500 to SF12BW500 (RX1) 926.9 - SF7BW500 to SF12BW500 (RX1) 927.5 - SF7BW500 to SF12BW500 (RX1) 923.3 - SF12BW500 (RX2)

where to modify in go code ?

Merry Christmas

image

image

ofauchon commented 1 year ago

Merry Christmas @tcpipchip.

The problem is here:

https://github.com/ofauchon/go-lorawan-stack/blob/e556eb6bab74f587a90e974eb76951f9b12b5cf4/lorawan.go#L290-L308

There is no frequency change between the Lora.Tx (the Join Packet) and the Lora.Rx (the Join Accept Receive) This was not the problem with EU regional setting, but seems required for AU operation.

You can get more informations here: https://lora-alliance.org/resource_hub/rp2-1-0-3-lorawan-regional-parameters/

Anyway, this is the reason you can't receive the Lora JoinAccept and join the network.

As a quick & dirty workaround, you can try to add some "r.radio.SetLoraFrequency(xxxxx)" in the LoraWanJoin() function to send and receive the frame at the correct frequency.

I'll have a look to the code to see how this feature can be implemented properly.

Olivier

tcpipchip commented 1 year ago

Nice @ofauchon Maybe is better you implement and i test. It will be faster to us reach fast results. Btw i am doing in meantime the blog about LoRaWAN with lsm110a

tcpipchip commented 1 year ago

I did try workaround… But not works @ofauchon

ofauchon commented 1 year ago

please share the diff so I can see what's wrong with your changes.

tcpipchip commented 1 year ago

i only set the JOIN frequency and JOIN accept frequency values for regional values

This was not enough

image

ofauchon commented 1 year ago

OK,

Changing frequency is not enough... Your previous screenshot tells us the bandwith must be changed from 125khz to 500khz between Join and JoinAccept:

image

So you'll have to play with the SetModulationParams function of the driver too.

That's a bit more tricky as this SetModulationParams changes multiple parameters (coding rates, bandwidth ...)

Anyway, I hope I can fix this properly next week.

tcpipchip commented 1 year ago

Ok! Then I will wait! Thanks for all help @ofauchon Thanks again!!!!

ofauchon commented 1 year ago

Hi @tcpipchip.

I opened #2 issue for the implementation of a fix for your problem. I'll tell you when I have some code ready for testing .