Arduino R4 WiFi 

02/02/2024


When I found that the Arduino folks had put out a new board with a processor

from a company other than Atmel/Microchip I had to get a look at it.

So it went on my Christmas wish list and my family took care of me.


First let’s talk about the board. There’s 2 versions that are quite different.

They both feature a Renasas R7FA4M1AB3CFM 32bit ARM Cortex-M4 running at 48 MHz 

but the WiFi version adds an ESP32-S3-MINI secondary processor and a  12x8 LED Matrix.


Here’s the main MCU features:  R7FA4M1AB3CFM

    • 48 MHz Arm® Cortex®-M4 microprocessor with a floating point unit (FPU)

    • 5 V operating voltage

    • Real-time Clock (RTC)

    • Memory Protection Unit (MPU)

    • Digital-to-analog Converter (DAC)

    • 256 kB Flash Memory

    • 32 kB SRAM

    • 8 kB Data Memory (EEPROM)

    • Capacitive Touch Sensing Unit (CTSU)

    • USB 2.0 Full-Speed Module (USBFS)

    • 14-bit ADC

    • Up to 12-bit DAC

    • Operational Amplifier (OPAMP)


And the secondary MCU: ESP32-S3-MINI-1-N8

    • Xtensa® dual-core 32-bit LX7 microprocessor

    • 3.3 V operating voltage

    • 40 MHz crystal oscillator

    • Wi-Fi® support with 802.11 b/g/n standard (Wi-Fi® 4)

    • Bit rate at up to 150 Mbps

    • 2.4 GHz band

    • Bluetooth® Bluetooth® 5





Looks pretty impressive. The main processor runs 3x faster then the UNO R3, has 

 8x more flash memory with 16x more RAM and finally a true D/A converter.

Plus the additional 96 on-board LED could be fun too.

But the Renesas RA4M1 has 49 I/O pins but we only get access to 19 of them :-( 


So what about this secondary processor?

In the R3 version of the Uno the ATMega328 was supported by an additional ATMega16 

processor that was mostly used as a USB-Serial converter.

The R4 WiFi uses the ESP32 in a similar way but we also get to use the WiFi capability of the

ESP32 module.

Now the ESP32 would be impressive by itself. It’s a Dual Core processor running at 160MHz 

with 512K Ram and 8MB of flash memory. Pretty impressive for a support chip.

The Mini version of this ESP32 has a limited number of GPIO pins, just enough for the basic 

connectivity needed to do the support job.


Back to the main RA4M1 processor. 

I suppose one of the reasons the Arduino designers chose this MCU was the fact that it was 

am ARM chip with 5v I/O pins, making it compatible with most all the 5v “Shields”  out there.

The additional analog components (DAC and OPAMP) are a welcome addition as is the 

Real Time clock with battery backup (to which, thankfully battery connection pins are supplied).
Plenty of UART,SPI,I2C and Timer peripherals are available although the I/O 

pins that they can be connected to are not as flexible as what some other MCUs offer.


I’m still unsure about how the flash memory on the RA4M1 is programmed by the Arduino 

software. I am sure there’s Arduino firmware on the ESP32 to communicate with the RA4M1’s
programming serial port and to switch the chip to “bootloader mode” via a specific serial command
but I don’t yet know if there’s Arduino bootloader code pre-flashed onto the RA4M1 

or if the ESP32 simply passes the appropriate serial data through to the RA4M1’s built in 

serial flash programming capability. More investigation is needed here.


WiFi Support is provided by the ESP32 through a serial port internally connected to the 

RA4M1. If you are familiar with the default AT firmware supplied with ESP8266 and ESP32 chips,
the Arduino R4 WiFi support works in much the same way. A collection of “command words”
are programmed into the ESP32 firmware which are recognized by the ESP32 and will

control the WiFi features supported. The Arduino WiFiS2 library supplies code that uses these
commands and gives the Arduino R4 it’s WiFi ability.

Although the ESP32 also supports Bluetooth it’s not yet available to the Arduino R4.

The source code for the ESP32 firmware is available online as are instructions on how to 

build and upload it so I foresee many clever revisions to be available soon.

One must take special care when modifying this firmware since it also controls the ability 

to communicate and upload code to the main MCU.


In the end I find myself wondering why the folks at Arduino decided to produce this particular 

design when the ESP32 alone (perhaps in the form of the ESP32 DEV KIT-C) is able to do pretty
much the same thing.



Using Renesas e2 Studio with the Arduino R4 WiFi


The Uno R4 is as simple as any other Arduino board to program using the Arduino IDE but 

to really become familiar with the Renesas family of MCUs I figured I’d need to work with the 

tools they provide. This comes in the form of an Eclipse based IDE called e2 Studio.

By now I’m pretty comfortable with Eclipse so I assumed it would be a breeze. Not so much…


I’ve used Eclipse to develop software on Arduino’s other 32bit ARM offering the Arduino Due 

which uses the Atmel SAM 3x8E microcontroller. It too has a special “bootloader mode” that 

you need to switch to before uploading code. The same command line tool BOSSAC.exe 

can be used to switch modes and upload code to the RA4M1 but it had some issues.

The Arduino Command Line Interface (CLI) worked much better so I could create a batch file 

callable from within Eclipse to upload the code with a couple clicks.

Too bad the uploaded code wouldn’t run….


The Renesas e2 Studio adds a “Configuration Utility” to the Eclipse IDE.  This utility allows one to
select a Renesas development board and pick a number of  peripherals, and set some 

properties and parameters then it will generate the appropriate code to get you started.

Unfortunately the Arduino R4 board is NOT available so your you must use the less friendly 

“Custom Board” option and select the correct MCU.

Of course this means all the Renesas example code also expects to run on one of the boards in the
list so much of the “generated” code is not supplied. (which of course has all the details 

you really need) 

So I started by watching a couple of YouTube videos explaining how to create a 

“Bare Metal Blinky” project in e2 Studio. It was pretty simple and everything compiled without 

error, but the uploaded code would still not run. (no blinking LED).

It took over a week of fiddling around to discover a way to get that LED to blink.


I discovered some files that came with the Arduino R4 board installation that looked exactly like
e2 Studio project files. While comparing them I found a couple of linker script files that were named the
same but quite a bit different than the ones in my e2 studio project.

So I swapped them and compiled but linking failed with a ton of error messages.

I systematically altered the linker script and configuration files until finally I got a successful 

build and once uploaded, …. The LED was BLINKING!!!

I continued to investigate each of the differences until I reducing the linker script modifications 

to a single line in one of the files "FLASH_IMAGE_START = 0x4000;"   

Since the original flash image start was 0x0000 this leads me to believe that there is 

Arduino bootloader code on that chip that we need to bypass with this setting.

So now I could move forward. With much more struggling I was able to get simple UART
communication working. Now when one uses the e2 Studio’s configuration  tool to enable a UART
the code generated includes using interrupts to handle the receiving and transmitting of  the UART
data. This is great because it’s the best way to design UART driver code.

EXCEPT when none of you interrupts will fire. This forced me to strip down the generated code to
handle the UART data myself carefully avoiding making changes to the generated code because it
gets re-generated with each build or configuration change.

But having a working terminal to debug with is quite helpful.


So why won’t the interrupts work…..


Another 4 or 5 days of messing around with settings and looking at example code but 

nothing seemed to work. I tried setting up code for a simple timer. I could see that the timer 

was counting and although it was configured to generate an overflow interrupt, nothing.
Then I set up a simple pin interrupt but shorting the pin did nothing.  

Finally, lying in bed at 3:30am I got to thinking there might be a 

global interrupt enable setting at the ARM level. A quick googling the next day revealed 

the answer.  A call the arm function  __enable_irq();     did the trick!! 

I suspect that the Arduino bootloader turns over control to the user’s code with interrupts disabled
since I don’t see this call being used is any of the example code.


With that mystery solved I was able to build samples of code using timers, UARTs, SPI and I2C
all using interrupts successfully.  Except for one of the 4 UARTs….

SCI9 is the peripheral configured as a UART that is connected (via the ESP32) to the USB serial port for
program upload and debugging. When I try to use code that relies on the interrupts generated by this
component, I see exactly ONE interrupt occurring, then they stop working.
Repeating the call to __enable_irq(); makes no difference, while the exact same code applied to
other UART ports work as expected. 

Could the suspected Arduino bootloader code still be having some effect?
(a J-Link debugger might be some help but I’m too cheap to spend the money for one).  

Maybe the answer to this one will come to me some other sleepless night.


Renesas E2 Studio is fine once you know how the configuration utility works.

For quite a while I was using it while missing an entire screen (tab) of settings.

I like Eclipse because I can incorporate my batch tools into the IDE and easily set build configurations.
It can get in the way when the code the configuration utility generates is NOT the code you really want.
You can modify the generated code but it will be replaced if you run the config utility again. 


WiFi with e2 Studio code.   Another big time sink…

I got the idea to figure out how to use the serial link between the RA4M1 and the ESP32.

Using the source code for the Arduino WiFiS2 library and a lot of experimentation I managed 

to re-create a few of the Arduino WiFi examples in e2 Studio code. Using these examples I 

can set the R4 up as a “Soft Access Point” (like a network router) and use telnet to send 

messages to/from my laptop or phone via WiFi.  Another makes the R4 appear as a 

local simple webserver the provides a webpage with 2 buttons that control the LED on the R4 board.



If you’re interested in trying e2 Studio with the Arduino R4 I’ve created a detailed document with
instructions that explain how to set up a project from scratch.

Alternately you could simply import one of the samples I’ve provided below.

You’ll still have to flash the device with the Arduino CLI tool so look to the instructions for the 

part that covers the e2 Studio changes.


Description of download links:
Arduino_R4_WiFi_on_e2_Studio.txt Instruction for setting up e2Studio for Arduino R4 WiFi
R4WiFi_Blinky_Template.zip                              Basic e2 Studio project to blink the on-board LED 
R4WiFi_Led_Matrix_Test.zip Demonstrates how to drive the 8x12 LED Matrix
R4WiFi_Uart_GPT_Demo.zip Demonstrates General Purpose Timer (with interrupts)
R4WiFi_Uart_SAP_TCP_Demo  Demo of a Soft Access Point & TCP Server
R4WiFi_Uart_Template  Project with UART support & a blinking LED
UnoR4_WiFi-schematic.pdf Uno R4 WiFi Schematic.