Arduino Nano 33 BLE baremetal programming

Hi Forum,
I am trying out a baremetal programming to get Arduino Nano 33 BLE powered by nordic nRF52840 SoC. I tried various sources for baremetal program without the support of either mbedos or zephyr, but to my bad luck i couldn't find any such instance. If such an exercise is already done by someone else and if someone could point me towards exact resource, i would be very greatful.
Since i was unable to find anything so far, i started trying it out myself by keeping nRF5 SDK 17.0.2 as the base and added arduino related files.

  1. Added arduino_nano_33_ble_baremetal/components/boards/arduino_nano_33_ble.h containing the needed pin information.
  2. Added UART sample application ( arduino_nano_33_ble_baremetal/demo_appl/peripheral/uart/main.c)
  3. Added build files ( arduino_nano_33_ble_baremetal/demo_appl/peripheral/uart/arduino_nano_33_ble/armgcc)
  4. Connecting the Nano33BLE board via USB cable and flashing using the following command (using the arduino variant of bossac) command ~/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac -p /dev/ttyACM0 -R -e -w -v -b ./_build/*.bin
  5. Once the flashing is done, disconnect the USB-miniUSB cable and connect USB-TTL cable via 5V/GND/TX/RX pins on arduino board and expect output on minicom -D /dev/ttyUSB0 but no ouput is being displayed.

Can i get some helping hand in identify the problem so that i can be done with this?

One more observation what I found was, once flashing is done on USB-miniUSB cable, USB is going into infinite USB disconnect loop.

Sounds like you do not like what you are doing. Could you elaborate why you are trying to make life hard for yourself? Do you just like a challenge or is there an issue you try to solve by going bare metal and ignoring all the work the Arduino guys have done for us? Maybe there is another way to solve that.
The nRF52840 can do quite a lot of cool stuff without the CPU and mbedOS being involved too much.

@nageshshamnur
I also try to bypass mbedOS on the Nano 33 BLE (look here). But I do not want to leave the Arduino environment too far because of using some libraries (not depending on mbedOS) and not loosing the chance to use other Arduino boards with my sketches.
But I can help only for details near to the CPU and its periphery, not for other software modules.
Meanwhile I have my own routines for TWI/I2C, UART, and BLE-Beacons, just driving direct the registers of the CPU and using new interrupt handlers.
So if You have questions how to write programs based on the nRF52840 product description, I can help.

Hi @Klaus_K
Thanks for your message. I am trying to add Arduino Nano 33 BLE as a MCU support for a custom RTOS which we are building. That's why i am looking for a baremetal application.

1 Like

Thanks for the message. Can i get an access to the code for UART?

I've sent a personal message containing the code. Because of personal identities inside and many quick-and-dirty routines, I did not publish it here.

For bare metal development I would recommend to get an in-circuit debugger like Segger, ARM/Keil or IAR. They will allow you to directly talk to the processor and set breakpoints in the code, look at the registers, memory ...
This will cost a little be of money for the hardware. Most of the companies have a free version of their software for debugging sometimes with a memory limit. But that should not be a problem when you develop bare metal and can add and remove parts of your code.
The Nano 33 BLE has some test points at the bottom that allows you to connect a ARM Cortex-M Serial Wire Debugger.

with any empty main function as below, once flashed the board is getting into infinite CDC ACM disconnect and reconnect.

int main()
{
return 0;
}

logs:

[24888.377785] usb 1-3: new full-speed USB device number 72 using xhci_hcd
[24888.528866] usb 1-3: New USB device found, idVendor=2341, idProduct=005a, bcdDevice= 0.11
[24888.528869] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[24888.528870] usb 1-3: Product: Arduino Nano 33 BLE
[24888.528871] usb 1-3: Manufacturer: Arduino
[24888.528872] usb 1-3: SerialNumber: 0000000000000000768275C7726D618B
[24888.530854] cdc_acm 1-3:1.0: ttyACM1: USB ACM device
[24888.579867] usb 1-3: USB disconnect, device number 72
[24888.885787] usb 1-3: new full-speed USB device number 73 using xhci_hcd
[24889.036889] usb 1-3: New USB device found, idVendor=2341, idProduct=005a, bcdDevice= 0.11
[24889.036892] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[24889.036894] usb 1-3: Product: Arduino Nano 33 BLE
[24889.036895] usb 1-3: Manufacturer: Arduino
[24889.036896] usb 1-3: SerialNumber: 0000000000000000768275C7726D618B
[24889.038865] cdc_acm 1-3:1.0: ttyACM1: USB ACM device
[24889.090968] usb 1-3: USB disconnect, device number 73
[24889.397764] usb 1-3: new full-speed USB device number 74 using xhci_hcd
[24889.548753] usb 1-3: New USB device found, idVendor=2341, idProduct=005a, bcdDevice= 0.11
[24889.548756] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[24889.548757] usb 1-3: Product: Arduino Nano 33 BLE
[24889.548758] usb 1-3: Manufacturer: Arduino
[24889.548759] usb 1-3: SerialNumber: 0000000000000000768275C7726D618B
[24889.550686] cdc_acm 1-3:1.0: ttyACM1: USB ACM device
[24889.602053] usb 1-3: USB disconnect, device number 74
[24889.909682] usb 1-3: new full-speed USB device number 75 using xhci_hcd
[24890.064353] usb 1-3: New USB device found, idVendor=2341, idProduct=005a, bcdDevice= 0.11
[24890.064381] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[24890.064382] usb 1-3: Product: Arduino Nano 33 BLE
[24890.064383] usb 1-3: Manufacturer: Arduino
[24890.064384] usb 1-3: SerialNumber: 0000000000000000768275C7726D618B
[24890.067082] cdc_acm 1-3:1.0: ttyACM0: USB ACM device
[24890.113231] usb 1-3: USB disconnect, device number 75

Checked one discussion on zephyr thread about the bossac offset, but since i am using command line, even offset parameter is also not provided to bossac command.
~/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac -p /dev/ttyACM0 -R -e -w -v -b ./_build/*.bin

Unable to figure what might have causing the problem. Kindly suggest on what might be causing the problem.
attaching the path of my .ld and .S file as below:

Just pulling a wild guess out of my head. The Arduino bootloader calls your program and likely does not expect you to return. An Arduino sketch does not return but continuously executes loop() forever. When you return to the bootloader, maybe it executes a reset because I would design it that way.

Hi @Klaus_K
I suspected that, and ensured that i kept while(1) as below, still no luck

int main(void)
{
    while(1)
    {
        ;
    }
}

As I said before, an in-circuit debugger would likely point you in the right direction.

Are you sure you end up in your main?
Also the interrupt vector table may need to be switched.
And I am also not sure about USB. If the bootloader initializes USB and uses interrupts to handle USB. What happens when you switch to your interrupt vector table that does not contain the vectors for the USB routines?