I've recently acquired an Arduino Nano 33 BLE, and I'm trying to upload some code to it. With the IDE, everything works great, but I need to program bare-metal in order to get precise timing measurements and to reduce the code size.
When using this simple makefile, I expected the code (an empty main for now) to be uploaded:
What actually resulted was an error with the last line. Avrdude can't upload code to the arduino:
avrdude: Version 6.3-20171130
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "/etc/avrdude.conf"
User configuration file is "/home/slangster/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : /dev/ttyACM0
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: Send: 0 [30] [20]
avrdude: Send: 0 [30] [20]
avrdude: Send: 0 [30] [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
I have read online multiple threads about this particular error, but nothing made this work. The card has no connections, no shields, and it works perfectly fine with the IDE, so the problem does not come from the cable, the pins or the shields. Any help would be greatly appreciated, I'm quite out of options now (I've also tried overriding the Arduino IDE main to use the IDE without the OS running in the background, and I've also tried using a benchmarking software to get precise measurements, but I didn't manage to do either of those).
Hi @slangster. AVRDUDE uploader tool is a tool for uploading binaries to AVR microcontrollers. Unlike the classic Nano board, the Nano 33 BLE board does not use an AVR microcontroller so you can't use AVRDUDE to upload to it. So the error you got is normal and expected.
In addition, avr-gcc is a compiler toolchain for AVR microcontrollers. You can't use it to compile programs for use on the Nano 33 BLE.
So you're going to need to replace your entire toolchain with the right tools for the Nordic nRF52840 microcontroller on the Nano 33 BLE. If you have used the Nano 33 BLE with Arduino IDE then you already have that toolchain installed on your computer. You can learn the location by uploading any sketch to the Nano 33 BLE with the "verbose output" preference enabled in the Arduino IDE and then examining the commands Arduino IDE generated. You can then adapt your Makefile to use those commands. I'll provide instructions you can follow to do that:
Connect the USB cable of your Nano 33 BLE board to your computer.
Select File > New from the Arduino IDE menus.
Select the Nano 33 BLE board from the board selector dropdown menu on the Arduino IDE toolbar.
Select File > Preferences... from the Arduino IDE menus.
The "Preferences" dialog will open.
Check the box next to Show verbose output during: ☐ compilation in the "Preferences" dialog.
Check the box next to Show verbose output during: ☐ upload.
Click the OK button.
Select Sketch > Upload from the Arduino IDE menus.
Wait for the upload to finish.
Now study the contents of the black "Output" panel at the bottom of the Arduino IDE window. There you will see all the commands Arduino IDE ran to compile and upload your sketch.
Thanks @ptillisch , that was indeed the problem, I was mistaken in thinking that it was an AVR microcontroller. Using gcc and bossac worked for me.
By the way, is there a way to print the content of variables somewhere? Now that I'm not using an IDE anymore, It seems harder. I basically want to measure the time it takes for an assembly script to run and print that somewhere.
You are welcome. I'm glad you were able to find the correct tools and update your Makefile to use them. Nice work!
Even if you no longer use Arduino IDE, it is still possible to print debug output to serial. There are standalone applications that are equivalent to the Arduino IDE Serial Monitor.
If you like working from the command line, you can use screen, which you might already have installed on your system:
As for a GUI-based serial terminal application, I don't have any specific suggestions for Linux (the ones I'm familiar with are only for Windows) but I'm confident there are some good free open source options available. Maybe the other forum members have a suggestion.
Going further, you could connect a debug probe to the SWD pads on the bottom of the Nano 33 BLE board and use OpenOCD and GDB for debugging. You will find that **OpenOCD **is already installed under ~/.arduino15/packages/arduino/tools/openocd and arm-none-eabi-gdb is in the same folder as the other GCC tools you are using.
Here is the pinout of the test pads on the Nano 33 BLE:
Well, I don't really mind using the IDE, it's just that it's less practical to use if I'm compiling/flashing with command lines.
I tried using screen but if there's a serial monitor 'listening' to my port, it becomes unavailable when uploading code, resulting in a no device found on /dev/ttyACM0 error. Is there a way to circumvent this issue?
I would guess you can find a way to make your Makefile's upload process have the same behavior as Arduino IDE, where it closes an open screen terminal before invoking the bossac upload command and then opens a new terminal on the port after the completion of the bossac command.
Well, the other way around doesn't work either, if I upload my code first and open a new terminal with screen, then it's the terminal that doesn't find the port (and throws a cannot exec '/dev/ttyACM0').
The Arduino core that is part of the Arduino sketch program includes the code that cause the Nano 33 BLE board to produce a serial port while the sketch is running. But if you write your own "bare metal" program then it will only produce a serial port if your program contains the code to make that happen.
Ah, sorry, I didn't know that was required. Since I only used the IDE before, I didn't realize what was going on under the hood.
Is there some documentation or tutorials about how to do such a thing?