Arduino R4 (RA4M1) as mass storage device – Is it possible?

Hello,

I’d like to ask if it’s possible to use an Arduino R4 (Renesas RA4M1 microcontroller) as a mass storage device to receive and show files to an ordinary computer.

A bit of explanation:

I am currently working on a ROM burner project that, necessarily, will both need to receive and send binary data in large chunks (multiple kilobytes at a time, and single-digit megabytes in the worst case) to and from a regular PC.

I envision the workflow with this burner as follows:

  1. We send the burner a large chunk of data as big as the ROM is (multiple kilobytes)

  2. The ROM burner sequentially writes this data to the ROM.

When we then go to read the ROM:

  1. We push a button on the project

  2. We receive a sequentially read chunk of data with the ROM’s contents.

The sequential nature of this workflow is crucial here. We never need to see all of the data at once, we work with it on a byte-per-byte basis. That’s how a microcontroller with 32KB of memory can process megabytes worth of data, because it never has to store more than one byte.

The “obvious” solution:

The easiest way to handle communication like this is Serial, however I am not keen on using it. Serial requires specialised software on the PC to work as well as special drivers. For the people I want to build this project for, I’d really like something simpler, more reliable and more friendly.

What everyone universally knows how to do is save and read files from a pen drive.

My idea is then as follows:

When we want to burn a ROM we simply connect the burner to our PC where it appears as an empty mass storage device, we grab our binary file containing what we’d like to burn to the ROM and simply paste it onto the mass storage device.

While the file is “copying” the microcontroller is busy reading it byte after byte and writing this data to the ROM. The speed of the “copying” is equal to how fast the microcontroller can write data to the ROM.

After the file transfer is complete, the mass storage device appears as empty, ready to accept a new file.

When we want to read a ROM, we simply push a button on the burner and soon after a file appears on the mass storage device, we can then copy it to our computer, after which it gets automatically “deleted” and the burner is ready to accept new orders.

I’d like to ask if there are any projects or libraries that have achieved this kind of mass storage functionality. I am not confined to the Arduino IDE as I am using the MCU bare. If you know something that could fit this use case please let me know.

Thank You for your help,

Kuba.

Your's will be the first. Keep up updated with your progress.

Confused!

You say you don;t want special PC software, do not want drivers, do not want to use Serial.

What do you want to use? You mention USB but the S stands for Serial so ????

How will you connect the MCU to the PC if not with a USB (serial) cable?

Please explain more. The R4 with the Arduino Renesas Core is an unusual choice. In my opinion the board is not well supported, and underlying the Arduino core uses an outdated version of the Resesas FSP.

Why have you selected this board for your project?

Hi @kuba0040. It sounds like a great project!

In regards to implementing a USB mass storage device, I would suggest taking a look at the TinyUSB documentation:


As an alternative to the mass storage device approach, have you considered the more simple approach of storing the ROM on an SD card? It is fairly straightforward to work with SD cards using Arduino boards. You can connect the card to any board you like using a cheap widely available module or shield, or use a board that has an integrated SD card slot. High quality libraries are available that allow easily working with SD cards in your Arduino sketch program code.

The usage procedure for this system would be as follows:

  1. Plug an SD card into a standard consumer USB card reader.
  2. Plug the reader into your PC.
  3. Use a file manager application to copy the ROM file to the drive of the SD card.
  4. Disconnect the reader from your PC.
  5. Plug the SD card into a card holder that is connected to an Arduino board.

It is true that this approach is less convenient than the one you envisioned. However, I don't think it is too onerous for the user. It would certainly make the project easier to complete.

An added benefit is that this system should be usable with any Arduino board. That means the users could create a ROM burner with whatever hardware is accessible to them. Ideally the mass storage device approach would also be somewhat portable, but it is inherently limited to hardware with a native USB capability. In practice, it will also be even more limited than that, as the code for the USB stack is architecture-specific, and so will only support the targets for which explicit support has been added (for example, see the list here).

don't have a Arduino R4 but running
File>Examples>USB>USBMSC
on a ESP32-S3-DevKitC-1

Windows Device Manager shows

Windows Explorer shows a disk drive

the README.TXT file

This is tinyusb's MassStorage Class demo.

If you find any bugs or get any questions, feel free to file an
issue at github.com/hathach/tinyusb

From what you want to do, and with your choice of obsolete hardware, it is possible but likely to be very difficult.

If you want to avoid serial interfaces and transfer data using a thumb drive, I would consider using something with a more modern and compatible file system structure. The first thing that comes to mind is a Raspberry Pi.

A Raspberry Pi running Linux would have the ability to read and write many common file systems used on thumb drives. For inexpensive storage, you could use a low-cost SSD.

You would not even need a local terminal. You could use SSH to transfer files back and forth, as well as remotely control and configure the system. This would make it compatible with most modern computers, including Windows, Mac, and Linux systems. SSH would work over the internet or intranet net.

I would recommend going back and making a detailed pros-and-cons list for your processor choices before moving forward.

Not necessarily. Unless you consider terminal programs specialised software.

Most terminal programs support delays between characters/bytes when transmitting. So you can send a file of N bytes and the terminal program will add a delay between each byte giving your R4 time to process received data.
Some terminal programs might also support delays between packets; e.g. coolterm.

Most terminal programs also support the Xon/Xoff protocol. The receiving Arduino can e.g. issue a Xoff after it has received 32 bytes and after it has processed them issue a Xon. In my experience the sending system (Windows PC) might not immediately react on the Xoff so you might receive a bit more.

Notes:

  1. Not all boards support Xon/Xoff, it depends on the hardware. I only have AVR boards and the only ones that properly support Xon/Xoff use the FT232xx chip; Xon/Xoff does not function correctly on 32U4 processors (native USB), CH340 and 16U2. So So your mileage will vary.
  2. Don't use Xon/Xoff in a binary stream; the binary stream might contain those characters. If traffic is however basically one way, you can use it to stop and restart the sending from the receiver.

the UNO R4 WiFi has a Renesas RA4M microcontroller plus a ESP32-S3
although the ESP32S3 supports USB OTG and hence USBMSC (see post 7) it does not appear that it is possible to access it on the UNO R4 WiFi
looking at the reference posted by @ptillisch in post 6 it appears the Renesas RA4M supports USB OTG device and host, e.g.
image

is it possible to use USB OTG on UNO R4?
try a web search for UNO R4 USB OTG or maybe worth asking in the UNO R4 forum