Compiling for XIAO nRF52840 Sense fails: "undefined reference to `Serial'"

for the longest time,, i had the same problem and by looking at @sterretje , i did what was asked, and well i stopped getting that particular error but now, im getting this error instead

c:/users/insaa/appdata/local/arduino15/packages/seeeduino/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\insaa\AppData\Local\arduino\sketches\39EB3CDEED9082B21D0A0316ECEA99E0\sketch\arduino-test.ino.cpp.o: in function `setup':
C:\Users\insaa\OneDrive\Arduino\libraries\base64\arduino-test/arduino-test.ino:24: undefined reference to `Serial'
c:/users/insaa/appdata/local/arduino15/packages/seeeduino/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\insaa\OneDrive\Arduino\libraries\base64\arduino-test/arduino-test.ino:24: undefined reference to `Adafruit_USBD_CDC::begin(unsigned long)'
c:/users/insaa/appdata/local/arduino15/packages/seeeduino/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\insaa\AppData\Local\arduino\sketches\39EB3CDEED9082B21D0A0316ECEA99E0\sketch\arduino-test.ino.cpp.o: in function `loop':
C:\Users\insaa\OneDrive\Arduino\libraries\base64\arduino-test/arduino-test.ino:28: undefined reference to `Adafruit_USBD_CDC::read()'
c:/users/insaa/appdata/local/arduino15/packages/seeeduino/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\insaa\OneDrive\Arduino\libraries\base64\arduino-test/arduino-test.ino:57: undefined reference to `Serial'
collect2.exe: error: ld returned 1 exit status
exit status 1

Compilation error: exit status 1

I do not know what the problem is.


Earlier, arduinoble library didnt really work on my pc, as no such file or directory, but I fixed it by following the instructions here:

But now instead of that, im getting

WARNING: library ArduinoBLE claims to run on samd, megaavr, mbed, apollo3, mbed_nano, mbed_portenta, mbed_nicla, esp32, mbed_giga, renesas, renesas_portenta, mbed_opta, renesas_uno, silabs architecture(s) and may be incompatible with your current board which runs on nrf52 architecture(s).
c:\Users\insaa\OneDrive\Arduino\libraries\ArduinoBLE\src\utility\HCIUartTransport.cpp:39:2: error: #error "Unsupported board selected!"
   39 | #error "Unsupported board selected!"
      |  ^~~~~
c:\Users\insaa\OneDrive\Arduino\libraries\ArduinoBLE\src\utility\HCIUartTransport.cpp:105:40: error: 'SerialHCI' was not declared in this scope; did you mean 'Serial'?
  105 | HCIUartTransportClass HCIUartTransport(SerialHCI, 912600);
      |                                        ^~~~~~~~~
      |                                        Serial
exit status 1

Compilation error: exit status 1 

I'm using seeed nrf52840 sense so unsupported board is out of the question. please help

Hi @browtfseriously. It is explained here in the documentation for the Seeed XIAO nRF52840 Sense board:

https://wiki.seeedstudio.com/XIAO_BLE/#two-arduino-libraries


:light_bulb: TIP

  1. If you use the onboard package of Seeed nRF52 Boards, the Serial function may not compile. The solution is to add the line "#include <Adafruit_TinyUSB.h>" in your code. You can download this package from: GitHub - adafruit/Adafruit_TinyUSB_Arduino: Arduino library for TinyUSB
  2. If you prefer a simpler approach, you can choose Seeed nRF52 mbed-enabled Boards from the beginning. It supports the compilation of the Serial function without the need for additional modifications.

This is not written very clearly. What they are trying to communicate is that this is a known limitation of the 3rd party "Seeed nRF52 Boards" platform that the Seeed Studio company provides to add support to Arduino IDE for their Seeed XIAO nRF52840 Sense board. They provide two alternative solutions. You can chose whichever one of those solutions you like:

  • Install the "Adafruit TinyUSB Library" library and then add an #include directive to your sketch for that library's Adafruit_TinyUSB.h header file.
  • Use the "Seeed nRF52 mbed-enabled Boards" platform instead of the "Seeed nRF52 Boards" platform.

I'll provide more simple and higher quality instructions you can follow if you want to use the first solution:

  1. Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus to open the "Library Manager" view in the left side panel.
  2. Type Adafruit TinyUSB Library in the "Filter your search..." field.
  3. Find the "Adafruit TinyUSB Library" entry in the list of search results.
  4. You will see an "INSTALL" button at the bottom of the entry. Click the button.
    An "Install library dependencies" dialog will open.
  5. Click the "INSTALL ALL" button in the "Install library dependencies" dialog.
    The dialog will close.
  6. Wait for the installation process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    โ“˜ Successfully installed library ...

  7. Add the following line of code to the top of your sketch:
    #include <Adafruit_TinyUSB.h>
    

Now try compiling or uploading the sketch again, just as you did before when you encountered the error. Hopefully this time everything will work as expected.


If you prefer to use the second solution instead of the first one, and would like guidance in how to do that, just let use know and we'll provide instructions.

oh i see what you mean and well, i installed the library for tinyusb and followed all your steps but now im getting this error

WARNING: library ArduinoBLE claims to run on samd, megaavr, mbed, apollo3, mbed_nano, mbed_portenta, mbed_nicla, esp32, mbed_giga, renesas, renesas_portenta, mbed_opta, renesas_uno, silabs architecture(s) and may be incompatible with your current board which runs on nrf52 architecture(s).
c:\Users\insaa\OneDrive\Arduino\libraries\ArduinoBLE\src\utility\HCIUartTransport.cpp:39:2: error: #error "Unsupported board selected!"
   39 | #error "Unsupported board selected!"
      |  ^~~~~
c:\Users\insaa\OneDrive\Arduino\libraries\ArduinoBLE\src\utility\HCIUartTransport.cpp:105:40: error: 'SerialHCI' was not declared in this scope; did you mean 'Serial'?
  105 | HCIUartTransportClass HCIUartTransport(SerialHCI, 912600);
      |                                        ^~~~~~~~~
      |                                        Serial
Multiple libraries were found for "Adafruit_TinyUSB.h"
  Used: C:\Users\insaa\OneDrive\Arduino\libraries\Adafruit_TinyUSB_Library
  Not used: C:\Users\insaa\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.10\libraries\Adafruit_TinyUSB_Arduino
exit status 1

Compilation error: exit status 1

im using one of the examples arduinoble provides, of rawdataadvertising

#include <SI114X.h>
#include <Si115X.h>

#include <ArduinoBLE.h>
#include <Adafruit_TinyUSB.h>


BLEService myService("fff0");
BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast);

// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop'
const uint8_t completeRawAdvertisingData[] = {0x02,0x01,0x06,0x09,0xff,0x01,0x01,0x00,0x01,0x02,0x03,0x04,0x05};

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!BLE.begin()) {
    Serial.println("failed to initialize BLE!");
    while (1);
  }

  myService.addCharacteristic(myCharacteristic);
  BLE.addService(myService);

  // Build advertising data packet
  BLEAdvertisingData advData;
  // If a packet has a raw data parameter, then all the other parameters of the packet will be ignored
  advData.setRawData(completeRawAdvertisingData, sizeof(completeRawAdvertisingData));
  // Copy set parameters in the actual advertising packet
  BLE.setAdvertisingData(advData);

  // Build scan response data packet
  BLEAdvertisingData scanData;
  scanData.setLocalName("Test advertising raw data");
  // Copy set parameters in the actual scan response packet
  BLE.setScanResponseData(scanData);

  BLE.advertise();

  Serial.println("advertising ...");
}

void loop() {
  BLE.poll();
}

this one when i got the error
i guess i also already had a library installed of tinyusb thingy somewhere. i dont understand what the problem is

The reason for this error is that the "ArduinoBLE" library is not compatible with the "Seeed nRF52 Boards" platform you are using to add support to Arduino IDE for the Seeed XIAO nRF52840 Sense board.

If you want to use the ArduinoBLE library in your sketch, you must install and use the alternative "Seeed nRF52 mbed-enabled Boards" platform instead of the "Seeed nRF52 Boards" platform. I'll provide instructions you can follow to do that:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Enter the following URL into the "Additional Boards Manager URLs" field in the "Preferences" dialog:
    https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
    
    :red_exclamation_mark: If there are already Boards Manager URLs in the field, separate them with commas.
  3. Click the "OK" button.
    The "Preferences" dialog will close.
  4. You will now see a "Downloading index: ..." notification at the bottom right corner of the IDE window. Wait for that notification to close.
  5. Select Tools > Board > Boards Manager... from the Arduino IDE menus to open the "Boards Manager" view in the left side panel.
  6. Find the "Seeed nRF52 mbed-enabled Boards" entry in the list of boards platforms.
  7. Click the "INSTALL" button at the bottom of the entry.
  8. Wait for the installation process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    Successfully installed platform ...

  9. Select Tools > Board > Seeed nRF52 mbed-enabled Boards > Seeed XIAO nRF52840 Sense (No Updates) from the Arduino IDE menus.
  10. Delete the following line from your sketch:
    #include <Adafruit_TinyUSB.h>
    

Now try compiling or uploading the sketch again, just as you did before when you encountered the error. Hopefully this time everything will work as expected.

1 Like

thank you, i get it now

You are welcome. I'm glad if I was able to be of assistance.

Regards, Per

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.