6 Mass Storage Device

The Nano Debugger includes a simple Mass Storage Device implementation, which is accessible for read/write operations via the host operating system to which it is connected.

It provides:
  • Read access to basic text and HTML files for detailed kit information and support
  • Write access for programming Intel® HEX and UF2 formatted files into the target device’s memory
  • Write access for simple text files for utility purposes
Note: Support for the UF2 format is available in debugger firmware version 1.31 or later.

6.1 Mass Storage Device Implementation

The Nano Debugger implements a highly optimized variant of the FAT12 file system with several limitations, partly due to the nature of FAT12 itself and optimizations made to fulfill its purpose for its embedded application.

The Curiosity Nano USB device is USB Chapter 9-compliant as a mass storage device but does not, in any way, fulfill the expectations of a general purpose mass storage device. This behavior is intentional.

When using the Windows operating system, the Nano Debugger enumerates as a Curiosity Nano USB Device found in the disk drives section of the device manager. The CURIOSITY drive appears in the file manager and claims the following available drive letter in the system.

The CURIOSITY drive contains approximately 1 MB of free space and does not reflect the target device’s Flash size. When programming an Intel HEX or UF2 file, the binary data are encoded in ASCII with metadata providing significant overhead. Therefore, 1 MB is an arbitrarily chosen value for the disk size.

It is not possible to format the CURIOSITY drive. When programming a file to the target, the filename may appear in the disk directory listing; however, this is merely the operating system’s view of the directory, which in reality has not been updated. It is not possible to read out the file contents. Removing and replugging the board will return the file system to its original state, but the target will still contain the previously programmed application.

Copy a text file starting with “CMD:ERASE” onto the disk to erase the target device.

By default, the CURIOSITY drive contains several read-only files used for generating icons, reporting status, and linking to further information:

  • AUTORUN.ICO – icon file for the Microchip logo
  • AUTORUN.INF – system file required for Windows Explorer to show the icon file
  • CLICK-ME.HTM – redirect to a kit-specific web demo application
  • KIT-INFO.HTM – redirect to the development board website
  • KIT-INFO.TXT – a text file containing details about the board’s debugger firmware version, board name, USB serial number, device, and drag-and-drop support
  • PUBKEY.TXT – a text file containing the public key for data encryption
  • STATUS.TXT – a text file containing the programming status of the board
Info: The Nano Debugger dynamically updates STATUS.TXT. However, the contents may not reflect the correct status because the operating system may cache the file.
Tip: The presence of the CLICK-ME and PUBKEY files depends on the debugger board configuration.

6.2 Fuse/Configuration Bytes/Words

Fuse Bytes (AVR® MCU Targets)

When performing drag-and-drop programming, the Nano Debugger masks out any fuse bits that attempt to disable Unified Program and Debug Interface (UPDI), meaning that the UPDI pin cannot be used in its Reset or GPIO modes. Selecting one of the alternative functions of the UPDI pin will render the device inaccessible without using an external debugger capable of high-voltage UPDI activation.

Configuration Bytes/Words (PIC® MCU Targets)

When performing drag-and-drop programming, the debugger masks out any configuration bytes or words that attempt to disable the ICSP interface, or other One-Time Programmable (OTP) configurations.

6.3 Limitations of Drag-and-Drop Programming

ARM Cortex Devices

Drag-and-drop programming is not supported on ARM Cortex devices. Use one of the supported IDEs or command-line utilities for programming.

Lock Bits

Lock bits included in the hex file will be ignored when using drag-and-drop programming. To program lock bits, use one of the supported IDEs.

Enabling CRC Check in Fuses

It is not advisable to enable the CRC check fuses in the target device when using drag-and-drop programming because a subsequent chip erase (which does not affect fuse bits) will cause a CRC mismatch, and the application will fail to boot. A chip erase must be performed using a supported IDE, which automatically clears the CRC fuses after erasing to recover the target from this state.

6.4 Special Commands

Several utility commands are supported by copying text files to the mass storage disk. The filename or extension is irrelevant – the command handler reacts to content only.

Table 6-1. Special File Commands
Command ContentDescription
CMD:ERASE Executes a target chip erase
CMD:SEND_UART=Sends a string of characters to the CDC UART. See Advanced Use.

CMD:SEND_9600= CMD:SEND_115200= CMD:SEND_460800=

Sends a string of characters to the CDC UART at the specified baud rate. Note that only the baud rates explicitly specified here are supported. See Advanced Use (Debugger firmware v1.25 or newer.)
CMD:RESETResets the target device by entering Programming mode and then exiting Programming mode immediately afterwards. The exact timing may vary depending on the programming interface of the target device. (Debugger firmware v1.25 or newer.)
CMD:POWERTOGGLEPowers down the target and restores it after a 100 ms delay. If external power is provided, this command has no effect. (Debugger firmware v1.25 or newer.)
CMD:0VPowers down the target device by disabling the target supply regulator. If external power is provided, this has no effect. (Debugger firmware v1.25 or newer.)
CMD:1V8Sets the target voltage to 1.8V. If using external power, this has no effect. (Debugger firmware v1.25 or newer.)
CMD:3V3Sets the target voltage to 3.3V. If using external power, this has no effect. (Debugger firmware v1.25 or newer.)
CMD:5V0Sets the target voltage to 5.0V. If using external power, this command has no effect. (Debugger firmware v1.25 or newer.)
Info: The content sent to the emulated mass storage disk disk triggers the commands listed in the table above and does not provide feedback in the case of either success or failure.

6.5 Drag-and-Drop Programming Using UF2 Format

UF2 Format for Drag-and-Drop

Drag-and-Drop programming provides a simple mechanism for programming the non-volatile memories of the microcontroller on a development kit. This is typically done using the Intel® HEX format, which includes the necessary addresses and segmentation information as part of the format. Intel HEX files contain the memory contents encoded as ASCII characters, which must be parsed in strictly sequential order. This means that the host operating system must send the content in the correct sequence. This is not always the case for all variants of all operating systems. The UF2 format was developed by Microsoft as a means to allow memory to be transferred out of sequence. This is achieved by enforcing a fixed block size throughout the entire data transfer path, thereby preventing partial writes.

More information on the UF2 format is available on GitHub.

Generating a UF2 file

The result of a project compilation procedure is typically an Intel hex file, which can be converted into a UF2 file using a post-build step.

The pymcuprog package distributed on pypi.org includes a function to convert an Intel hex file to a UF2 file in version 3.17 or later.
Tip: This procedure requires the installation of a recent release of Python 3 and the pymcuprog package in that environment, as well as ensuring that the Python scripts folder is included in the system or user path.

An Intel HEX file can be converted into a UF2 file using the pymcuprog command-line interface:

pymcuprog makeuf2 -f app.hex --uf2file app.uf2
This process can be streamlined by adding a post-build step in MPLAB X IDE. In the Project Properties configuration dialog, select the Building tab and check Execute this line after build. Add the command to the edit box:
pymcuprog makeuf2 -f ${ImagePath} --uf2file ${ImageDir}\${ProjectName}.X.${IMAGE_TYPE}.uf2

Each time the application is built, the produced Intel hex file will automatically be converted to a UF2 file with the same filename but with a .uf2 file extension.