Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Xiao nRF52840 (Sense) board support #151

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

maxgerhardt
Copy link
Contributor

@maxgerhardt maxgerhardt commented Jun 22, 2022

Fixes #142.

Based on https://medium.com/@alwint3r/working-with-seeed-xiao-ble-sense-and-platformio-ide-5c4da3ab42a3.

As requested in https://community.platformio.org/t/support-for-seeeduino-xiao-ble-board/28420.

Uses the latest core version as defined in the Arduino package manifest referenced in https://wiki.seeedstudio.com/XIAO_BLE/#software-setup.

Adds xiaoblesense and xiaoble as available boards. (Difference is, the "Sense" version has a IMU and microphone sensors per this).

Adds the Seeed version of framework-mbed as a new package, framework-mbed-seeed with version "2.8.1". Adaptions in the builder script are done according to maxgerhardt/builder-framework-arduino-core-mbed@abb229f.

Further adds framework-arduinoadafruitnrf52-seeed variant of framework-arduinoadafruitnrf52 and adds dedicated board files for the Adafruit varaint of the board used with the "1.0.0" core.

Suggested course of action:

This PR can be tested by using the platformio.ini

[env]
platform = https://github.com/maxgerhardt/platform-nordicnrf52
framework = arduino

[env:xiaoblesense_arduinocore_mbed]
board = xiaoblesense

[env:xiaoblesense_adafruit_nrf52]
board = xiaoblesense_adafruit

[env:xiaoble_arduinocore_mbed]
board = xiaoble

[env:xiaoble_adafruit_nrf52]
board = xiaoble_adafruit

@maxgerhardt maxgerhardt changed the title Add Xiao nRF52480 (Sense) board support Add Xiao nrf52840 (Sense) board support Jun 22, 2022
@maxgerhardt maxgerhardt changed the title Add Xiao nrf52840 (Sense) board support Add Xiao nRF52840 (Sense) board support Jun 22, 2022
@maxgerhardt
Copy link
Contributor Author

Works on hardware per this report.

@vlad-the-compiler
Copy link

vlad-the-compiler commented Jun 30, 2022

Thanks for the contribution!
I see you've adopted Seeed's Mbed-based implementation, which is forked from the original Nano 33 BLE (Sense) BSP.
Seeed themselves have 2 BSPs for the Xiao BLE (Sense) series, v1.0.0 being forked from Adafruit's FreeRTOS implementation bundled with their excellent Bluefruit libraries that support higher-level functionality such as HID, MIDI, etc, compared to the barebones original ArduinoBLE library.
According to Seeed themselves, v1.0.0 is recommended in case one wishes to leverage the Bluefruit functionalities.
Could there be a way to support both v1.0.0 (FreeRTOS + Bluefruit) and the official Arduino implementation (what has been forked for this PR, based on the latest version for the Seeed core)? I would definitely look into it myself, but I've got no experience with adding support for boards/frameworks in PIO.
To clarify, I do not mean supporting them at the same time, but as different BSPs for the Xiao nRF52 boards under PlatformIO.

@maxgerhardt
Copy link
Contributor Author

This PR is based on the ArduinoCore-mbed fork of Seeed, not the Adafruit nRF52 fork.

But indeed I now see that there are two packages

			{
				"name": "Seeed nRF52 Boards",
				"architecture": "nrf52",
				"version": "2.6.1",
				"category": "Contributed",
				"url": "https://files.seeedstudio.com/arduino/core/nRF52840/nrf52840_05202022_2.6.1.tar.bz2",
				"archiveFileName": "nrf52840_05202022_2.6.1.tar.bz2",
				"checksum": "SHA-256:32A4544728E9C9E234BA7A2F0719019F1FD5AD5A204BCE1227EC2E20F265C4BB",
				"size": "31600049",
				"boards": [{
					"name": "Seeed XIAO nRF52840 Sense"
				}],
...
			{
				"name": "Seeed nRF52 Boards",
				"architecture": "nrf52",
				"version": "1.0.0",
				"category": "Contributed",
				"url": "https://files.seeedstudio.com/arduino/core/nRF52840/Arduino_core_nRF52840.tar.bz2",
				"archiveFileName": "Arduino_core_nRF52840.tar.bz2",
				"checksum": "SHA-256:2754015D46A2EF7A8CF2727F5459BC8C5CAD9F73A7E69A130AC744D39BECEF77",
				"size": "49463833",
},
....

What an extremely bad way to name board packages. If there's a 1.0.0 version and a 2.6.1 version, I won't even look at the 1.0.0 version for integration. But indeed, the 1.0.0 core is indeed an entirely different core (https://github.com/adafruit/Adafruit_nRF52_Arduino).

I'll have a look at adding this. Not sure if I want to add another board = .. option to this or a special core switching logic via board_build.core, which would be more in-line with other PlatformIO integrations where a board supports multiple different arduino cores.

@vlad-the-compiler
Copy link

What an extremely bad way to name board packages

Pretty much. I'd imagine they thought about maintaining the 2 varaints under the 1.x and 2.x versioning, so an upstream bugfix/feature addition for 1.0.0 would yield an updated BSP package under e.g. 1.0.1, but since Arduino BSPs never do this, this is just asking for trouble.
Maybe they wanted to avoid naming Adafruit for whatever legal reason and resorted to the confusing 1.x / 2.x system as a consequence? I don't think Adafruit would go after them for forking their open-source Arduino BSP, though.

@leroyle
Copy link

leroyle commented Jul 29, 2022

I also would like to see the Adafruit runtime support.
My observations/understandings subject to correction by anyone more knowlegeable:
It seems to wiggle with v 1.3.0 though I've not tried any of the Nordic SoftDevice functionality.
Other than porting the variants pin definition code the other major thing I hit was a SoftDevice version mismatch between what the Seeed bootloader is built with by default (Seems to be 7.3.0) and what the Adafruit runtime is built with by default, 6.1.1.

The Adafruit runtime uses FreeRTOS under the covers, thus an RTOS task is run to execute the "Arduino" setup()/loop(), don't know about the mbed runtime.
If the Softdevice versions do no match the inital RTOS task will not start and you end up in the weeds with a Hard Fault. has to do with locating the correct SVC_Handler() within the Adafruit runtime. The addressing for this is Softdevice version specific.
(The actual SVC instruction that kicks off the start of the first RTOS task should also change a bit from "SVC 0" to SVC "3" or some other non interfering value. I believe 0 is reserved for SoftDevice use)

As mentioned it does wiggle with SoftDevice 6.1.1, I have yet to try rebuilding bootloader/runtime with Softdevice version 7.3.0.

I've not discussed this with Seeed at all to see if they might have a heart ache with support tickets re the Adafruit runtime.
Edit..
Does seem to wiggle with SoftDevice 7.3.0.

https://github.com/leroyle/Adafruit_nRF52_Arduino/tree/leroyle
A fork of the Adafruit_nRF52_Arduino repo with my above changes incorporated into branch "leroyle". PlatformIO board definition is "xiaoblesense" as in:
[env]
platform = nordicnrf52
board = xiaoblesense
framework = arduino
...
TODO: create a separate board definition for "Xiao BLE" vs "Xiao BLE Sense"
The current pin definition incarnation is for the non "Sense" version
Probably needs to be a separate issue of incorporating AdaFrutit runtime.

platform.py Show resolved Hide resolved
@aovestdipaperino
Copy link

What's blocking this PR?

@maxgerhardt
Copy link
Contributor Author

I've updated the Seed ArduinoCore-mbed version from 2.6.1 to 2.8.1 and added support for building for the "1.0.0" core, aka the Adafruit nRF52 core fork, by using the dedicated board definitions xiaoble_adafruit and xiaoblesense_adafruit .

I also had to make an update to the extra_script.py of the Adafruit nRF Crypto library to make it compile with the latest PIO version.

Blinky and BLE examples are at https://github.com/maxgerhardt/pio-xiao-ble-test.

Copy link

@FernandoPerezLara FernandoPerezLara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mike1808
Copy link

Tested the latest update. It works great!

@vlad-the-compiler
Copy link

Sounds like a merge is in order.

@projectitis
Copy link

Would love to be able to use this board with PIO!

@nachocpol
Copy link

Great work! Would be awesome to use this board with PIO (dito!) 😄

@maxgerhardt
Copy link
Contributor Author

Hm I see the full picture now, the new 1.1.1 core does define that macro by itself.

maxgerhardt/framework-arduinoadafruitnrf52-seeed@3ae21c3#diff-cb7f085ad29408821e4beac17a66977e6016fb818c03a905f2d80a7b59f76b48

I just updated the core. So if you do

pio pkg update -g -p "https://github.com/maxgerhardt/platform-nordicnrf52"

in a PlatformIO Core CLI, then it you should not even need the above build_flags addition.

@Xarbenence
Copy link

Oh I see. It has this macro

https://github.com/Seeed-Studio/Seeed_Arduino_LSM6DS3/blob/997df38fc15beeb2402232ba1ba5ff82b3296b7b/LSM6DS3.cpp#L35-L37

but maybe that's not set. Can you just add

build_flags = -DTARGET_SEEED_XIAO_NRF52840_SENSE

to the platformio.ini and retry?

That did it! Thanks, Max. Much appreciated.

@DoomHammer
Copy link

Is there a way to solve Could not find the package with 'https://github.com/maxgerhardt/platform-nordicnrf52' requirements for your system 'darwin_arm64'?

@maxgerhardt
Copy link
Contributor Author

maxgerhardt commented Jul 27, 2023 via email

@DoomHammer
Copy link

Sorry, I might've gotten lost in the conversation. Which ini are you referring to?

@maxgerhardt
Copy link
Contributor Author

If you have created a new blank PlatformIO project (doesn't matter with which board or framework), you should have in your VSCode file explorer a platformio.ini file in it. That stores the entire configuration of the PlatformIO project. Depending on which board or core you want to use, you copy in the platformio.ini I posted in bottom of the PR decsription, use it to replace your platformio.ini and delete the [env:xxx] sections you don't need.

@maxgerhardt
Copy link
Contributor Author

I updated my branch to the latest develop to resolve all the conflicts and the CI passes.

Can PlatformIO staff please look at this PR? This has been open since Jun 22, 2022 now and nothing should be blocking it :(

@mrWheel
Copy link

mrWheel commented Oct 4, 2023

@maxgerhardt

Thanks for your work on the Seeed XIAO BLE board stuff.

I’m using the Seeed XIAO BLE with this setup and it works great.

But now I want to get the chip to sleep or indeed set it in low power mode. All examples I can find are based on Adafruit libraries that are a real PIA because a simple program needs SPI, SoftwareSerial and so on. I don’t like Adafruit libraries.

Are you still developing for/with the nRF52840 chips and can you lead me to some libraries that will work in this setup without all the Adafruit overhead?

For now just BLE, low power modes and interrupt handling (from timers, BLE or gpio pins)..

@maxgerhardt
Copy link
Contributor Author

I don't even have a single Seeed XIAO board, so I'd recommend to redirect the question to https://forum.seeedstudio.com/ or the Adafruit library repo on how to reduce the dependencies. The dependencies might however also not be "real" in the sense that PlatformIO includes them when really they're behind some #ifdef MACRO that is actually false. You can counteract that with one of the other lib_ldf_mode values.

@leroyle
Copy link

leroyle commented Oct 4, 2023

@mrWheel, if you don't want the overhead of the Arduino libs then you might take a look at using the nordic build tools or Zephyr. both with the newer NRF Connect SDK if you are just getting started, rather than PlatformIO or Arduino.

It does look like they have a steeper learning curve though.

As an aside in my experience the nordic files contained in the Adafruit runtime are out of sync with the current version of nRF SDK and of course the newer nRF Connect, a few api are incompatible, how many to what extent I did not go down that rabbit hole.

In trying to incorporate the Memfault SDK I had to manipulate include paths so the Memfault code built against the Nordic version while the Adafruit libs built against the Adafruit version. This is a just for grins project that I would not recommend for real work.

Bottom line might be if you like the Arduino environment and it not being real bleeding edge, yet. Stick with PIO/Arduino. If not then check out Zepher. Admittedly I know little about that environment but it's on my list and looks to be actively supported by Nordic.

That said I have no idea if bringing Nordic support upto date in either PIO or Arduino is being worked or is on anyone's radar.

@mrWheel
Copy link

mrWheel commented Oct 4, 2023

@maxgerhardt & @leroyle

Thanks for your reply’s.
Recently I changed from ArduinoIDE to Visiual Studio Code/platformio.
I’m used to Atmel and Espressif which both have great support for there products. Nordic seems not to be interested in the Makers Community which is, I think, a missed change.

I don’t think I will investigate more time in the nRF52840 chips as every board has his own quirks and the information over bootloaders, soft devices and what not is very poor.

Regards

@doh38
Copy link

doh38 commented Oct 17, 2023

Why the heck this needed addition hasn't been merged? -.-'

@QuantumCypher
Copy link

Can this get merged?

@harrison-denton
Copy link

Any update on a merge? @FernandoPerezLara

@zholdak
Copy link

zholdak commented Nov 24, 2023

Many people wait for this request will be merged... Why still not merged? Any reason?

@vlad-the-compiler
Copy link

I've noticed people addressing the issue of merging by pinging the current reviewer of this PR.

Only members of the PIO organization can merge, if we wish to get this merged we have to bring them up to speed with the fact that the work for this is done.

That being said, @ivankravets this PR has been looking good for some time, perhaps we could get it merged. Thank you in advance!

@black-ghost-off
Copy link

@ivankravets , any updates about this merge?

@mohammad-askari
Copy link

mohammad-askari commented Mar 18, 2024

@maxgerhardt, any chance of updating either (Adafruit / mbed) cores for this board? Both are outdated, and official support is non-existent after so long. I even attempted doing so myself, however, I ran into similar issues as explained here, which I could not fix.

The problem I had recently with the board was that hardware interrupts were causing it to freeze using the Adafruit variant, and it took me hours to fix. The issue was resolved once I used Arduino IDE to upload a sample code based on the recent version (1.1.8), and switching back to PlatformIO.

@tomasz90
Copy link

tomasz90 commented Jun 1, 2024

This PR is 2 years old, can you merge it finally?

@Amidair
Copy link

Amidair commented Jun 10, 2024

Please add Xiao nRF52840 (Sense) board support! Hundreds of people are waiting for this nRF52 jewel to be supported by PlatformIO...

@morgankenyon
Copy link

For anyone having issues with platformio and the Xiao nRF52840 Sense board, here is a fairly simple blink example showing the setup required to get it working.

I followed Max's original instructions and had to play around a little bit.

https://github.com/morgankenyon/OpenDataDisc/tree/main/software/examples/11_nrf52_blink

@limengdu
Copy link

@valeros Could you please take a look at this? We really need it.

@NicolARun06
Copy link

Oh I see. It has this macro

https://github.com/Seeed-Studio/Seeed_Arduino_LSM6DS3/blob/997df38fc15beeb2402232ba1ba5ff82b3296b7b/LSM6DS3.cpp#L35-L37

but maybe that's not set. Can you just add

build_flags = -DTARGET_SEEED_XIAO_NRF52840_SENSE

to the platformio.ini and retry?

Maybe just like this, when I was referencing the sample code of seeed-mic (https://github.com/Seeed-Studio/Seeed_Arduino_Mic/blob/master/examples/mic_Saved_OnSDcard/mic_Saved_OnSDcard.ino) and realized that successfully compiling it requires adding the definition of "ARDUINO_ARCH_NRF52840" to platformio.ini.

@paulhayes
Copy link

Another nudge to get the fork merged in. I've been using it successfully on projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Board Request Seeedstudio XIAO BLE