tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.16k stars 890 forks source link

Add support for Generic Node Sensor Edition from The Things Industries #2066

Closed jamestait closed 2 years ago

jamestait commented 3 years ago

Generic Node Sensor Edition (GNSE) is a LoRaWAN device based on the STM32WL55CCU6 dual-core Arm Cortex®-M4/M0+ LoRaWAN SOC. The Github repo has various examples in C, with a CMake build system. It also has schematics and KiCAD design files.

I'm no Golang expert, but I'm learning. I've not done real embedded development before, but I'm learning. I'd like to see this board supported, and I'm happy to contribute time and effort to help out.

soypat commented 3 years ago

I believe @ofauchon had gotten tinygo to work on the STM32WL. Last I heard he was in the process of implementing a lightweight Go LoRaWAN stack over on the tinygo slack channel.

ofauchon commented 3 years ago

Hi all.

I confirm, I could run TInyGo on STM32WL (a couple of month ago) (Clocks, GPIO, timers, and radio sx126x peripherals where working fine)

I could even join a TTN network and send/receive datas with a Lora E5 (stm32wle5) device !

But some major changes occured in Tinygo STM32 Timers handling and I could not finish porting the device. I already opened an issue for that :

Github issue for STM32WL timers support

I plan to resume my project when this issue is solved.

However, If you are interested, you can get all the relevants parts of the port code here:

Of course, All of this code will be merged in tinygo and tinygo-driver when the "timer issue" is solved.

Hope that helps !

@jamestait: Are you related to Generic Node Sensor manufacturer or The Things Industries ? I would be interested in working on this device if I can get one free sample (or low priced).

Olivier

jamestait commented 3 years ago

Hi Olivier!

On 29 August 2021 07:53:28 UTC, Fauchon @.***> wrote:

Hi all.

I confirm, I could run TInyGo on STM32WL (a couple of month ago) (Clocks, GPIO, timers, and radio sx126x peripherals where working fine)

I could even join a TTN network dans send/receive datas with a Lora E5 (stm32wle5) device !

This all sounds very promising!

But some major changes occured in Tinygo STM32 Timers handling and I could not finish porting the device. I already opened an issue for that :

Github issue for STM32WL timers support

That's a shame, but I'll take a look at that issue and follow along. I doubt I'll be much help in resolving it at this stage.

I plan to resume my project when this issue is solved.

However, If you are interested, you can get all the relevants parts of the port code here:

Of course, All of this code will be merged in tinygo and tinygo-driver when the "timer issue" is solved.

Great, I'll take a look. As I said, I'm still learning about all this but most of what I've read so far makes sense (in a similar sense to “I can understand enough when other people are talking a different language to know what they're saying, but can only contribute little bits to the conversation”).

@jamestait: Are you related to Generic Node Sensor manufacturer or The Things Industries ? I would be interested in working on this device if I can get one free sample (or low priced).

Not related to the project, no. Just signed up to get my hands on (AIUI) an early access device via a tweet like this one:

https://twitter.com/generic_node/status/1431257705013026822

I've been interested in IoT for a few years, and this device happens to have a bunch of features that align nicely with an idea I have for a project (based on work I did in a previous job).

I'm looking forward to learning more!

ofauchon commented 3 years ago

Following @kenbell advice, I could fix timer's problem. Now I can run simple code on stm32wle5 (led blink, uart)

Next step is to fix the SPI bus and Lora radio driver. I hope I can fix that in the next days.

Meanwhile, I'm trying to order a Generic Node to experiment with tinygo.

jamestait commented 3 years ago

On 03/09/2021 10:39, Olivier Fauchon wrote:

Following @kenbell https://github.com/kenbell advice, I could fix timer's problem. Now I can run simple code on stm32wle5 (led blink, uart)

Brilliant news! Do you have a branch available to share? I'm obviously interested in seeing if this will work with the GNSE, but also in seeing what changes were necessary, to help me develop my understanding.

Next step is to fix the SPI bus and Lora radio driver. I hope I can fix that in the next days.

I've been reading about the SPI bus and need to take another look at your code in that context. Happy to be a test subject if you happen to get anything working!

Meanwhile, I'm trying to order a Generic Node to experiment with tinygo.

I'm still tinkering at this stage, learning a bit about the device and poking around with the provided examples. Hopefully this will enable me to start contributing something useful soon.

-- ---------------------------------------+-------------------------------- James Tait, BSc | @.*** Programmer and Free Software advocate | Tel: +44 (0)870 490 2407 ---------------------------------------+--------------------------------

ofauchon commented 2 years ago

STM32WL initial support has been merged in dev branch. This may be the first step toward more comprehensive support of Generic Node Sensor device

jamestait commented 2 years ago

STM32WL initial support has been merged in dev branch. This may be the first step toward more comprehensive support of Generic Node Sensor device

Nice work, this is great news! I've been tracking your work and the upstream and managed to cobble together enough to get blinky working, and a stripped-back version of the basic example app that comes with the GNSE SDK -- only cycling the RGB LEDs and printing output over the serial interface for now.

IIUC, the stm32wlex5 is a single-core (Cortex-M4 based) MCU, whereas the stm32wl55 is dual-core (Cortex-M4 and Cortex-M0+). So far I've been targetting just the Cortex-M4 -- you can see from the target file. There is much copy-pasta! But I am gradually understanding more and more.

ofauchon commented 2 years ago

This is great news you could run TinyGo code on Generic Node! Thanks for testing with this chipset!

I had a quick look to your code, and the new "target" addition looks good. We just need to reuse the machine_stm32wlxxxx and ressource_stm32wlxxx code between the two chipsets.

If you want, I can take your contribution, review/improve it, and make the pull request for you. (Or maybe, you'd prefer to do it by yourself ... no problem)

FYI, I'm working on the following improvements, at the moment:

When it's done, we'll be able to use the early Lora SX126x driver, and focus on the lightweight Lorawan stack developpement. (This will require a lot of work, and help is welcome).

Thx

Olivier

jamestait commented 2 years ago

I definitely want to collaborate in whatever way makes most sense. I think my preference, if you'd be willing, would be to make the necessary changes under your guidance -- I'm still learning a lot (about Go, about Tinygo, about embedded devices and the stm32 ecosystem, and about reading reference manuals and translating that into code) and I think I'd improve my understanding more that way.

I've rebased on the upstream dev branch with your stm32wle5 additions -- just enough to get it running again for now, but I'll try to take a look at refactoring for reuse. And I'll keep an eye on your progress and help out where I can.

Did you manage to get your hands on a GNSE device?

ofauchon commented 2 years ago

Hi @jamestait,

Don't worry, there is a lot more to do with TinyGo / LoraWan / Generic Node! And your help will be very welcome.

But at the moment, we need to have a clean and robust STM32WL support.

As soon as PR https://github.com/tinygo-org/tinygo/pull/2309 is merged in dev branch, we could work together on STM32WL55 support and GNSE board addition.

I'll get one GNSE next week, so can help you with that.

ofauchon commented 2 years ago

Hi.

If you read the discussions in PR #2309, you may have noticed some code has to move in tinygo-driver (SubGhzInit) You should follow this PR https://github.com/tinygo-org/drivers/pull/344 to stay up-to-date with this change.

Olivier

ofauchon commented 2 years ago

I'm still waiting for GNSE board (It's on the way, and should not take long now)

Meanwhile, I'm working on Lorawan for STM32WL/SX126x : https://github.com/ofauchon/tinygo-drivers/blob/lora-sx126x/examples/lora/sx126x/lora_lorawan/lora_lorawan.go (Basic support for joigning a network and send uplinks messages)

As Lorawan requires random numbers for the encryption, and I'm also working on adding RNG support in stm32WL (WIP) https://github.com/tinygo-org/tinygo/pull/2351

I guess we'll have something working very soon.

ofauchon commented 2 years ago

Hi @jamestait,

I got my GNSE yesterday. I could run tinygo and even join a Lorawan.

Now it's time to add board/machine/runtime declarations in TinyGo to properly support it.

Would you be ok if I take your code, and make a PR for you ? Or maybe you prefer doing it yourself.

Tell me what you prefer.

Thanks

Olivier.

jamestait commented 2 years ago

Hi @ofauchon!

Would you be ok if I take your code, and make a PR for you ? Or maybe you prefer doing it yourself.

Yes, please do: I've just pushed my latest small changes, but I haven't managed to carve out the time to deep dive on this yet. :( I'll follow along and try to learn from your work.

ofauchon commented 2 years ago

Hi @jamestait.

I opened PR #2379 ... Thanks for your help.

jamestait commented 2 years ago

Hi @ofauchon!

I opened PR #2379 ...

And I see it's already merged to dev; this is great news! Thank you for carrying it over the line!

Thanks for your help.

I'm not sure how much help I've been so far! But I'm still following along with great interest and enthusiasm, and dipping my toe in when I can. Hopefully with the basics covered, I'll be able to look at adding support for its various features.