platform-nordicnrf52 icon indicating copy to clipboard operation
platform-nordicnrf52 copied to clipboard

Support for Arduino Nano 33 BLE (Sense)

Open manuelbl opened this issue 6 years ago • 80 comments

Now that the Arduino Nano 33 BLE and Arduino Nano 33 BLE Sense have been released and introduce:

Are there any plans to bring them to PlatformIO? What will be needed? How can it be supported?

manuelbl avatar Aug 12 '19 21:08 manuelbl

What would be needed to add support and close this issue? We're designing a nano 33 shield, and I would love to add PlatformIO support to the library. Is it a matter of adding a configuration file to the boards folder? or are there other changes that need to be made? If there is any way we can help add the nano 33 BLE boards to the PlatformIO system we'd be happy to help.

clwillingham avatar Sep 14 '19 23:09 clwillingham

Should it rely on the ArduinoCore running on MBEDos or directly on MBEDos ?

charly37 avatar Sep 30 '19 19:09 charly37

I would prefer if priority was given to the Arduino core based on Mbed OS framework. This is likely the better solution for most users and in particular for users coming from the Arduino IDE.

manuelbl avatar Sep 30 '19 19:09 manuelbl

In case anyone starts to work on this: the Arduino guys managed to build the nRF52 Arduino core upon an untagged branch of the Arduino Core API, namely the arduino_namespace branch. Those sources are needed and not part of the Arduino core based on Mbed OS framework.

manuelbl avatar Sep 30 '19 20:09 manuelbl

This have anything to do with anything? https://github.com/arduino/ArduinoCore-nRF528x-mbedos

j0rd avatar Oct 07 '19 13:10 j0rd

Yes, that's one piece. Many more are needed...

manuelbl avatar Oct 07 '19 14:10 manuelbl

I would also love to see these boards supported

luke-shields avatar Nov 13 '19 20:11 luke-shields

We've added support for this board, but we didn't try it on real hardware, so it would be great if someone could try to compile and upload a basic example.

Thanks!

valeros avatar Nov 29 '19 19:11 valeros

Thanks, @valeros! Please note that you will need to use development version of platform:

[env:myenv]
platform = https://github.com/platformio/platform-nordicnrf52.git
framework = arduino
board = nano33ble

ivankravets avatar Nov 29 '19 20:11 ivankravets

I just happened to play with a NANO33BLE board this evening and ran into this thread. Using the platformio config above, it compiles for me.

Uploading didn't work for me yet. The first problem is that ~/.platformio/platforms/nordicnrf52/builder/main.py has an unresolved symbol basename (line 48). I fixed that by changing a line from from os.path import isdir, join to from os.path import isdir, join, basename

The second problem is some kind of uploading problem:

Building in release mode
Compiling .pio/build/default/src/BatteryMonitor.ino.cpp.o
Checking size .pio/build/default/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
DATA:    [===       ]  25.1% (used 65752 bytes from 262144 bytes)
PROGRAM: [===       ]  29.0% (used 285036 bytes from 983040 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, jlink, nrfjprog, nrfutil, sam-ba
CURRENT: upload_protocol = sam-ba
Looking for upload port...
Auto-detected: /dev/ttyACM0
Uploading .pio/build/default/firmware.bin
No device found on ttyACM0
*** [upload] Error 1

bertrik avatar Nov 29 '19 21:11 bertrik

I do have the same problem as @bertrik. Importing basename from os.path fixed initial Python Error, but now I am getting No device found on ... error. I have manually selected upload_port in ini file but the problem remains. Building seems alright.

EDIT: Added log

Verbose Upload Log
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/nano33ble.html
PLATFORM: Nordic nRF52 3.8.0 #8ca39f0 (git+https://github.com/platformio/platform-nordicnrf52.git) > Arduino Nano 33 BLE
HARDWARE: NRF52840 64MHz, 256KB RAM, 960KB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.80201.181220 (8.2.1), framework-arduino-nrf52-mbedos 1.1.3, tool-sreccat 1.164.0 (1.64), tool-openocd 2.1000.190707 (10.0), tool-bossac-nordicnrf52 1.10866.191129 (1.8.66)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Framework incompatible library /home/vojtech/.platformio/packages/framework-arduino-nrf52-mbedos/libraries/mbed-memory-status
Found 5 compatible libraries
More details about "Library Compatibility Mode": https://docs.platformio.org/page/librarymanager/ldf.html#ldf-compat-mode
Scanning dependencies...
No dependencies
Building in release mode
MethodWrapper(["checkprogsize"], [".pio/build/nano33ble/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  16.1% (used 42168 bytes from 262144 bytes)
Flash: [=         ]   7.7% (used 76052 bytes from 983040 bytes)
.pio/build/nano33ble/firmware.elf  :
section              size        addr
.text               74636       65536
.ARM.exidx              8      140172
.data                1408   536871424
.nvictable            256   536870912
.crash_data_ram       256   536871168
.bss                40760   536872832
.heap              217416   536913592
.stack               2048   537131008
.ARM.attributes        46           0
.comment              146           0
.debug_info        162719           0
.debug_abbrev       35457           0
.debug_aranges      27440           0
.debug_ranges       44280           0
.debug_line        193310           0
.debug_str         539403           0
.debug_frame        82984           0
.stab                  60           0
.stabstr              118           0
Total             1422751
<lambda>(["upload"], [".pio/build/nano33ble/firmware.bin"])
AVAILABLE: cmsis-dap, jlink, nrfjprog, nrfutil, sam-ba
CURRENT: upload_protocol = sam-ba
BeforeUpload(["upload"], [".pio/build/nano33ble/firmware.bin"])
Use manually specified: /dev/ttyACM0
bossac --info --debug --port "ttyACM0" --write --reset -U --reset .pio/build/nano33ble/firmware.bin
No device found on ttyACM0
Set binary mode
Send auto-baud
Set binary mode
*** [upload] Error 1

vaetas avatar Nov 29 '19 22:11 vaetas

Thanks @bertrik @vaetas. I fixed missing basename import and also added some modifications to the upload process. Could you please pull the latest changes and try again? Simple pio update command should be enough if there is no conflicts with your changes.

valeros avatar Nov 29 '19 22:11 valeros

Thanks for the work on the Arduino Nano 33. I've tested it and it looks quite good already. The project compiles and compilation times are much faster than in Arduino IDE (where it's extremly slow).

There are a number of issues though:

1. Upload

Same problem as @bertrik and @vaetas. The path to the USB port is correct. And upload works from the Arduino IDE.

The output from pio run -v -t upload is:

<lambda>(["upload"], [".pio/build/nano33ble/firmware.bin"])
AVAILABLE: cmsis-dap, jlink, nrfjprog, nrfutil, sam-ba
CURRENT: upload_protocol = sam-ba
BeforeUpload(["upload"], [".pio/build/nano33ble/firmware.bin"])
Auto-detected: /dev/cu.usbmodem144401
bossac --info --debug --port "cu.usbmodem144401" --write --reset -U --reset .pio/build/nano33ble/firmware.bin
No device found on cu.usbmodem144401
Set binary mode
Send auto-baud
Set binary mode
*** [upload] Error 1

As a comparison, the Arudino IDE uses the below command:

/Users/me/Library/Arduino15/packages/arduino/tools/bossac/1.9.1-arduino1/bossac --port=cu.usbmodem144401 -U -i -e -w /var/folders/z2/t5tl6v7d2k95p70t98gd_wqw0000gn/T/arduino_build_635165/BatteryMonitor.ino.bin -R

I tried a similar command using the PlatformIO's bossac, and it worked once and then stopped to work (No device found...).

But PlatformIO's upload task works if I double click the board's reset button first. The LED then goes in a fade in / fade out mode.

2. Intellisense

In a simple Blink sketch, #include <Arduino.h> has squiggly red lines and the error message is

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/me/Documents/PlatformIO/Projects/Nano-33-BLE/src/main.cpp).
cannot open source file "USBDescriptor.h" (dependency of "Arduino.h")

The missing file changed over time. It was mbed.h earlier.

In c_cpp_properties.json, the following include paths are listed:

"/Users/me/Documents/PlatformIO/Projects/Nano-33-BLE/include",
"/Users/me/Documents/PlatformIO/Projects/Nano-33-BLE/src",
"/Users/me/.platformio/packages/framework-arduino-nrf52-mbedos/cores/arduino",
"/Users/me/.platformio/packages/framework-arduino-nrf52-mbedos/cores/arduino/api/deprecated",
"/Users/me/.platformio/packages/framework-arduino-nrf52-mbedos/variants/ARDUINO_NANO33BLE",
"/Users/me/.platformio/packages/framework-arduino-nrf52-mbedos/libraries/PDM/src",
"/Users/me/.platformio/packages/framework-arduino-nrf52-mbedos/libraries/SPI",
"/Users/me/.platformio/packages/framework-arduino-nrf52-mbedos/libraries/USBHID",
"/Users/me/.platformio/packages/framework-arduino-nrf52-mbedos/libraries/USBMSD",
"/Users/me/.platformio/packages/framework-arduino-nrf52-mbedos/libraries/Wire",
 "/Users/me/.platformio/packages/tool-unity",
 ""

Possibly, directories are missing such as cores/arduino/mbed and cores/arduino/mebed/drivers/internal.

3. Create a new project

Creating a new project with the nano33ble board from PIO Home fails. The project is successfully created. But instead of opening it, an error message is displayed:

Could not initialize project

PIO Core Call Error: "The current working directory /Users/me/Documents/PlatformIO/Projects/Nano-33-Test2 will be used for the project.\n\nThe next files/directories have been created in /Users/me/Documents/PlatformIO/Projects/Nano-33-Test2\ninclude - Put project header files here\nlib - Put here project specific (private) libraries\nsrc - Put project source files here\nplatformio.ini - Project Configuration File\n\n\nError: Unknown board ID 'nano33ble'"

More or is likely to come... I will continue to test.

manuelbl avatar Nov 29 '19 22:11 manuelbl

Thanks for your help @valeros. I have pulled your changed but the error persisted.

<lambda>(["upload"], [".pio/build/nano33ble/firmware.bin"])
AVAILABLE: cmsis-dap, jlink, nrfjprog, nrfutil, sam-ba
CURRENT: upload_protocol = sam-ba
BeforeUpload(["upload"], [".pio/build/nano33ble/firmware.bin"])
Use manually specified: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
bossac --info --debug --port "ttyACM0" --write --erase -U --reset .pio/build/nano33ble/firmware.bin
No device found on ttyACM0
*** [upload] Error 1

vaetas avatar Nov 29 '19 22:11 vaetas

I have the upload working now. I uploaded the BatteryMonitor example from the ArduinoBLE library and I can see a "BatteryMonitor" device now in a BLE scanner on my Android phone.

bertrik avatar Nov 29 '19 22:11 bertrik

What have you changed @bertrik. The Arduino gets into bootloader mode when I press Upload (led starts slowly blinking) but immediately fails.

vaetas avatar Nov 29 '19 22:11 vaetas

OK, I am not sure what happened but I tried to upload it again and it worked!

vaetas avatar Nov 29 '19 23:11 vaetas

@bertrik @vaetas Thanks!

Thanks @manuelbl, good points!

  1. The uploading should be fixed in the latest version.
  2. I think that's fixable, this Arduino core has quite unusual form of include flags and that requires some modifications to VSCode project template.
  3. That's strange, I cannot reproduce it, maybe you have two nordicnrf52 platforms and the stable one is used instead of the latest one from the repository?

valeros avatar Nov 29 '19 23:11 valeros

Thanks a lot for making this work @valeros!

However, I have one weird problem. When I try to upload binary, Nano will switch to bootloader mode (not sure the correct name) and upload from PIO will then fail with No device found on ttyACM0 error. But when I press Upload again, it will successfully upload. Third upload will again fail and so on.

I have tested this on two different Nano 33 BLEs and the bug appears on both of them. It seems like a problem with Arduino because it apparently closes connection when switching modes before upload. Does this happen to anybody else or is it only my problem? I am currently on Arch Linux.

vaetas avatar Nov 30 '19 00:11 vaetas

On my system (debian bullseye/sid) I noticed that I had modemmanager installed. I don't really trust it in the sense that I'm really sure it's not messing with anything that looks like a serial port (/dev/ttyUSBx or /dev/ttyACMx), so I made sure it was not running and uninstalled it. Perhaps this is something you can try too and see if it has an effect on upload success.

bertrik avatar Nov 30 '19 00:11 bertrik

Thanks @valeros for the quick response. Regarding my issues:

  1. Uploading: It's better now but in only works every other time (same as for @vaetas). I think I know why... see below.
  2. Intellisense: I'm looking forward to a fix.
  3. Opening project: Yes, I had two platforms (the productive one and the one declared in platformio.ini according to Ivan's instructions). So it won't be an issue anymore once it's officially released?

In the mean time I have also tested it on Windows. It behaves the same (same things working, same open issues). I've also tested J-Link upload and debugging and it works.

Upload

In the Arduino IDE, it works. So what's the difference? It's not the command line arguments for bossac. It seems that the Arduino IDE first resets the board before it starts bossac.

The clue is if the serial port is busy. Then you don't get an error message from bossac but from the Arduino IDE:

processing.app.debug.RunnerException
	at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152)
	at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77)
	at processing.app.SketchController.upload(SketchController.java:732)
	at processing.app.SketchController.exportApplet(SketchController.java:703)
	at processing.app.Editor$UploadHandler.run(Editor.java:2075)
	at java.lang.Thread.run(Thread.java:748)
Caused by: processing.app.SerialException: Error touching serial port '/dev/cu.usbmodem144301'.
	at processing.app.Serial.touchForCDCReset(Serial.java:107)
	at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136)
	... 5 more
Caused by: jssc.SerialPortException: Port name - /dev/cu.usbmodem144301; Method name - openPort(); Exception type - Port busy.
	at jssc.SerialPort.openPort(SerialPort.java:164)
	at processing.app.Serial.touchForCDCReset(Serial.java:101)
	... 6 more

The exception is thrown on this line: https://github.com/arduino/Arduino/blob/master/arduino-core/src/processing/app/Serial.java#L107

It's the code for the board reset. It is run if the Arduino board definition contains:

upload.use_1200bps_touch=true

The setting upload.wait_for_upload_port=true is also relevant. It waits for the virtual serial port to reappear after the reset was triggered.

Could that be the missing piece?

manuelbl avatar Nov 30 '19 23:11 manuelbl

@manuelbl Thank you so much for the hint!

@valeros please use reset code from Atmel SAM dev/platform. See “BeforeUpload” pre-action.

ivankravets avatar Dec 01 '19 07:12 ivankravets

Sorry for the late reply, could someone retest uploading with the latest platform version?

valeros avatar Dec 16 '19 10:12 valeros

Sure, I'll test it this evening (if I don't forget)!

bertrik avatar Dec 16 '19 13:12 bertrik

I will test it but won't have time before tomorrow evening...

manuelbl avatar Dec 16 '19 14:12 manuelbl

@valeros With your latest commit uploading works all the time! I have tested this with the latest development version for nordicnrf52 platform. Brilliant! Thanks.

vaetas avatar Dec 16 '19 18:12 vaetas

For me it also work very reliable now, thanks.

bertrik avatar Dec 16 '19 21:12 bertrik

I updated PlatformIO and the nRF52 package, but I still don't see Arduino Nano BLE Nano among the available boards. What am I doing wrong?

fgaetani avatar Dec 17 '19 08:12 fgaetani

Hi there, could anyone explain the benefits of using PlatformIO rather than the Microsoft Arduino extension? Thanks and great job getting this working!

luke-shields avatar Dec 17 '19 11:12 luke-shields

@fgaetani This feature is not released yet, so you need to use the upstream version of the platform:

[env:myenv]
platform = https://github.com/platformio/platform-nordicnrf52.git
framework = arduino
board = nano33ble

@luke-shields So in a nutshell, PlatformIO is more advanced and customizable ecosystem in comparison with a simple IDE extension like Microsoft Arduino. More detailed info you can find here.

valeros avatar Dec 17 '19 11:12 valeros