Seeed XIAO nrF52840 Sense break Serial (not recognized)

Hello,
I can’t get serial data on PlatformIO with Seeed XIAO nrF52840 Sense. The problems seems to comes from the way PlatformIO upload the firmware. It works on ArduinoIDE

Here is my PlatformIO configuration :

[env:seeed_xiao_nrf52840_sense]
platform = https://github.com/Seeed-Studio/platform-seeedboards.git
board = seeed-xiao-afruitnrf52-nrf52840-sense
framework = arduino
build_flags = 
	-w
	-DBOARD_HAS_PSRAM
	-DARDUINO_USB_CDC_ON_BOOT=1 ; Using Zadig to reinstall Driver
	-DCORE_DEBUG_LEVEL=1

And a very simple code :

#include <Arduino.h>
#include <Adafruit_TinyUSB.h>

void setup() {
  Serial.begin(115200);
  while (!Serial);  // Attendre la connexion série
  Serial.println("USB CDC actif");
}

void loop() {
  Serial.println("Ping");
  delay(1000);
}

:white_check_mark: Using latest version of Arduino IDE it works and serial communication display th Ping. Using Zadig I see a TinyUSB device. Perfect !

:x:Using PlatformIO the code is correctly pushed, installed, and run BUT the serial communication is broken, VSCode do not see board/port and Zadig see 2 nRF device (Interface 0 and 2)

I assume PlatformIO is doing something Wrong but ChatGPT loop with wrong advices … The board and setup seems ok. Any ideas ?

All of the build_flags should have 0 effect on the USB CDC because they’re all meant for ESP32 chips, the nRF cores ignore them.

What could have an effect is the linking of the Adafruit TinyUSB library: Set

lib_archive = no

in the platformio.ini and retry.

Thank You so much !!!
It works !!!

@maxgerhardt unfortunatly I stuck one more step I have a code working with ESP32 to connect to 4+ BLE Devices. I try to move to that Seeed Xiao nrf52840 in order to handle 10+ connections.

So I have to move from BLEDevice.h to a compatible library. But working around ChatGPT it seems Adafruit Bluefruit nRF52 is not compatible :rage: with PlatformIO and it seems you made something 3 years ago

[env:xiaoblesense_adafruit]
platform = https://github.com/maxgerhardt/platform-nordicnrf52.git
board = xiaoblesense_adafruit
framework = arduino
monitor_speed = 115200
lib_deps =
  adafruit/Adafruit TinyUSB Library

Is it still relevant or should I mix with latest Seeed boards of my PlatformIO package ?

Mhm I can build the libraries\Bluefruit52Lib\examples\Central\central_scan\central_scan.ino, but only after giving it a path for a linker directory it missed.

[env:seeed-xiao-afruitnrf52-nrf52840-sense]
platform = Seeed Studio
board = seeed-xiao-afruitnrf52-nrf52840-sense
framework = arduino
extra_scripts = pre:fix_link.py
lib_archive = no

with fix_link.py as

Import("env")
from os.path import join

platform = env.PioPlatform()
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoadafruitnrf52")
env.Append(
    LIBPATH=[join(FRAMEWORK_DIR, "libraries", "Adafruit_nRFCrypto", "src", "cortex-m4", "fpv4-sp-d16-hard")]
)

The issue with not linking TinyUSB correctly and not even testing a BluFruit52 example sketch tells me that Seeed didn’t do a good job of testing the platform here.

While I do have a fork that includes Xiao nRF52840 Sense board support, that is not also almost 2 years outdated since the last update: https://github.com/platformio/platform-nordicnrf52/pull/151. However, I made sure to actually test TinyUSB and Bluetooth sketches to compile properly.

Woah !!! I would never find that !
Many thanks it works and I retrieve the advertising data !

Now I’m stuck with a bug or limitation with bluefruit library that do not see my Service Data. I raise a bug here:

It used to work on ESP-32 but it seems it’s limited on bluefruit and the Service is not visible.

Side Note: ChatGPT (all version) is VERY VERY weak for all Arduino related stuff.