XIAO 52840 as BLE GATT Board

Description

I want to connect the XIAO 52840 board as a client to the bluetooth gateway I have (nrf9160/52840 dev board). What overlays or files do I need to make this work. Do I need to use a particular version of the nrf connect sdk?

Expected Behavior

I would like to get the pouch repo code to run on the XIAO 52840 board.

Actual Behavior

I got a project to build but I don’t think I have the memory space setup correctly because when I move the file over the board resets but then nothing happens.

Environment

Currently trying nrf sdk 2.9.1.

Logs and Console Output

/*

  • Partition overlay for Seeed XIAO BLE (nRF52840)
    */
    / {
    chosen {
    zephyr,code-partition = &slot0_partition;
    };
    };

&flash0 {
partitions {
// Remove default partition if present
/delete-node/ partition@0;

    slot0_partition: partition@0 {
        label = "slot0_partition";
        reg = <0x00000000 0x0007D000>; // 240 KB for slot0
    };

    slot1_partition: partition@7d000 {
        label = "slot1_partition";
        reg = <0x0007D000 0x0007D000>; // 240 KB for slot1
    };

Hey @wischmi2,

Are you trying to build the ble_gatt example from pouch repository, or working on your own project? The pouch repo is set up for NCS v3.0.1, as you can see in the west-ncs.yml file.

For the ble_gatt example, I don’t think you need any special overlay changes. I’ve successfully built and used it on Adafruit nRF52840 Feather board without modifying the example.

If you haven’t already, I’d suggest starting directly with the ble_gatt example, using the Pouch repo as your manifest and initializing with west-ncs.yml. After that, try building it for the XIAO board.

I’ll order a couple of XIAO boards myself so I can test it hands-on.

Yes, I’m using the ble_gatt example.

What does “initializing with west-ncs.yml” mean? Could you point me in the direction of some documentation?

So, what we want to do is create a fresh Zephyr workspace using the pouch repo as the west manifest , pull dependencies, set up Python tools and the build the example.

Below is a clean setup that pins the right NCS via west-ncs.yml:

  1. Create new workspace directory:
mkdir ~/pouch-env
  1. Create and activate a new virtual environment:
python -m venv ~/pouch-env/.venv
source ~/pouch-env/.venv/bin/activate
  1. Use pip to install west (beginning with the wheel dependency):
 pip install wheel west
  1. Use the pouch repo as the manifest:
west init -m https://github.com/golioth/pouch --mf west-ncs.yml ~/pouch-env
cd pouch-env
west update
pip install -r zephyr/scripts/requirements.txt
pip install -r pouch/requirements.txt
west zephyr-export

The xiao_ble ships with the Adafruit nRF52 bootloader, which supports flashing via UF2. Since it uses the Adafruit bootloader and not MCUboot (as the pouch example expects), you would need to reflash the board with MCUboot over SWD/JTAG if you want OTA updates through Golioth. Depending on the DTS files for the xiao_ble board, an overlay may also be needed to adjust the memory layout as in the your earlier post. How are you flashing the device and what image are you using?

I wasn’t aware it ships with the Adafruit bootloader instead of MCUboot, so I’ll test further once my boards arrive. If you figure it out before then, please share so others can benefit.

Thanks for the update. A few questions…

The west init sets up the zephyr workspace using west-ncs.yml to tell it what other repositories it needs correct?

After that you run west update to download all the packages that are contained in the west-ncs.yml. Why do you need a west.yml in the pouch repo?

Why do you need to do installs of the requirements files for both zephyr and pouch?

When I go to open the application in visual studio and I want to add build configuration it says you have to update the west workspace before you create a build? I don’t understand why that is?

Starting with “The xiao-ble ships” on downwards I’m lost. I know I have to build a file that I can drag over and drop in the xiao-ble folder when its in bootloader mode. What hardware do I need to flash with mcuboot over swd/jtag , a dev kit like 9160? I wouldn’t know where to start with a memory layout. Perhaps I’ll wait until you can get the hardware and tell me how you did it?

Thanks again!

One more question, is there a good source of training info on this. I have to say I have been trying to use Zephyr for years and I know there is info on the Zephyr website, nrf website, etc but none of it really does a good job in explaining how to go step by step of doing a build like this.

Hey @wischmi2, I see where you’re coming from. Let’s break it down and go through your questions one by one:

The west init sets up the zephyr workspace using west-ncs.yml to tell it what other repositories it needs correct?

When you do west init -m <manifest-repo>, you’re basically telling west where to find the manifest file, and the manifest file describes:

  • Which repositories are needed (Zephyr, nrfxlib, mcuboot, etc.)
  • Which revisions/branches of those repos should be checked out
  • How they’re layered together in the workspace

After west init you run west update, which pulls down all of those repos at the correct revisions and sets up the workspace.

So yes: west-ncs.yml is what drives which extra repos get cloned/managed for your Zephyr/NCS environment.

After that you run west update to download all the packages that are contained in the west-ncs.yml. Why do you need a west.yml in the pouch repo?

West uses one active manifest per workspace. In the pouch repo you can pick which “base” you want, so you can use west-ncs.yml which pulls the NCS stack (nRF Connect SDK) or you can use west.yml which pulls the vanilla Zephyr. Zephyr is the upstream open source RTOS project, maintained by the Zephyr Project under the Linux Foundation. NCS is Nordic’s “distribution” (or downstream) of Zephyr. It takes Zephyr as a module, then layers on their own closed or open source libraries for Bluetooth controller, LTE modem and so on. Therefore, you can build pouch repo using NCS or vanilla Zephyr. We are using NCS because of cryptography libraries available in NCS which speeds up the end-to end-encryption pouch offers.

Why do you need to do installs of the requirements files for both zephyr and pouch?

In short, both Zephyr and pouch have their own Python tooling requirements. For example, Pouch specifically depends on the zcbor package, which it uses to handle CBOR encoding of payloads sent to the cloud.

When I go to open the application in visual studio and I want to add build configuration it says you have to update the west workspace before you create a build? I don’t understand why that is?

I don’t personally use Visual Studio, so I might be slightly off here, but it looks like you need to run west update in the VS terminal to fetch all the dependencies listed in the manifest file. Keep in mind that whenever the manifest file changes, you need to run west update again to make sure everything is downloaded and up to date. In your case, it’s possible the workspace hasn’t been updated yet, or that some of the required repos are missing or checked out at the wrong revision.

Starting with “The xiao-ble ships” on downwards I’m lost. I know I have to build a file that I can drag over and drop in the xiao-ble folder when its in bootloader mode. What hardware do I need to flash with mcuboot over swd/jtag , a dev kit like 9160? I wouldn’t know where to start with a memory layout. Perhaps I’ll wait until you can get the hardware and tell me how you did it?

Check out the Zephyr docs for UF2 Flashing and External debugger. It should work with the nRF9160 DK as it has Segger J-Link on-board for programming external targets.

Additionally, we host Zephyr training sessions once a quarter, in fact, we just had one yesterday. You can go through the material yourself at any time using our Zephyr training docs. Also, if you’d like a deeper dive into manifest files, Mike Szczys gave a talk on the topic a couple of years ago, which you can check out here. I am also of the opinion that our blog is a great starting point for getting to grips with Zephyr. It helps you build a solid understanding of the basics, which then makes it easier to dive deeper and explore the official Zephyr docs.

Excellent, thank you for the thorough explanation. I was actually watching the talk that Mike gave the day before and it was very good. I appreciate all the info you have given me. I would still like it if you would let me know what you find out when your hardware arrives and I will do the same if I get my setup working.

Thanks again!

I finally got something working with this (thank you AI). Well, I walked away for a while and came back to it recently. I had AI help me with the code and part of the issue was getting it built in such a way that it would fit on the onboard flash. It actually set it up to where the onboard flash had slot0 and the external flash had slot1 and the /lfs1 storage area. I almost have the pouch server/client running. I have gateway as my nrf9160dk and the xiao 52840 as my pouch client. They are talking but I’m having an issue with certificates right now. I generated certs for the xiao but used psks for my 9160. I’m wondering if somehow that is the issue. Just wanted to give an update on this problem.

1 Like

Hey @wischmi2,

Using certificates on the BLE leaf node and PSK on the nRF9160 DK acting as a gateway is totally fine. You can always switch the gateway over to certificates later if needed.

What kind of issues are you running into?

Also, not sure if you’ve seen it yet, but you can now generate certificates directly in the console; it’s about as straightforward as it gets. There’s a blog post that walks through it step by step.

Well right now I’m having an issue with the gateway I can’t seem to get fixed. Here is the terminal output.

[00:12:06.850,677] scan: Scanning successfully started
[00:12:07.951,446] main: Connected: CD:0C:F3:59:5C:32 (random)
[00:12:37.952,026] bt_smp: SMP Timeout
[00:12:37.952,117] main: BT security change failed. Current level: 1, err: BT_SECURITY_ERR_UNSPECIFIED(9)
[00:12:37.955,810] main: Pairing Failed (9). Disconnecting.
[00:12:38.056,091] main: Disconnected: CD:0C:F3:59:5C:32 (random), reason 0x16
[00:12:38.067,535] scan: Scanning successfully started
[00:12:39.274,597] main: Connected: CD:0C:F3:59:5C:32 (random)
[00:13:09.275,207] bt_smp: SMP Timeout
[00:13:09.275,299] main: BT security change failed. Current level: 1, err: BT_SECURITY_ERR_UNSPECIFIED(9)
[00:13:09.276,672] main: Pairing Failed (9). Disconnecting.
[00:13:09.329,284] main: Disconnected: CD:0C:F3:59:5C:32 (random), reason 0x16
[00:13:09.340,820] scan: Scanning successfully started
[00:13:10.658,386] main: Connected: CD:0C:F3:59:5C:32 (random)

I’ve been trying to get AI to assist but it isn’t coming up with anything that is working.