The Renesas RA2A1 microcontroller

Renesas produce an ARM Cortex M23 based microcontroller called the R7FA2A1AB3CFJ or RA2A1. This device has 256k of flash memory and 32k of RAM. It also has a number of peripherals and memory/security mechanisms. I was interested in learning about the device at a low level and so I did not use the extensive libraries and support files available from Renesas. Instead I decided to write my own device header file and linker and build scripts.

The breadboard circuit

The schematic and photograph of the breadboard kit are shown above. The RA2A1 chosen is housed in a 32 pin LQFP package and was broken out into a DIL arrangement using an adapter.

Option words

The post-reset state of the RA2A1 is configured using some option words that are located within the system flash memory. It is important that you avoid accidentally overwriting these bytes when writing your program to flash memory. The option setting memory words are at:0x400 and 0x404 i.e. 0x400-0x407 inclusive. I modified my usual linker script so that the program flash area starts after the option memory (with a little margin). The interrupt vectors must still be stored at address zero so a memory regision called “vector_area” is defined as shown. The linker will only position the interrupt vector table there.

When I started using this chip I accidentally overwrote the option memory and was left with a non-functioning chip. The support people in Renesas helped and provided a script that you can use to erase the lower parts of flash back to factory defaults. Details are here:

https://renesasrulz.com/ra/f/forum/17951/ram-is-not-writable-on-r7fa2a1ab/59092#59092

There is a zip file linked in this conversation which includes a Windows batch file. I use Linux and so ran this command instead:

JLinkExe -CommanderScript RA2A1_Erase_Block_0.JlinkScript.jlink

Interrupt system

The RA2A has a total of 32 interrupt vectors (beyond the 16 internal ARM Cortex ones). These interrupt vectors are mapped to peripheral events using 32 Event Link Setting Registers in the Interrupt Control Unit (one ELSR per interrupt vector). The ELSR’s allow you associate an event number with an interrupt vector. Each peripheral has one or more event numbers associated with it e.g. The Receive event for Serial Communications Interface 0 is event number 0x71. In the examples below, this is associated with interrupt vector 0 as follows:

ICU_IELSR[0] = 0x71;

When a byte is received by SCI0 the first (non-ARM) interrupt vector is fetched and the handler at that address is exectuted.

Pin Function Selection

Like most microcontrollers, the RA2A1 allows you assign pins to a selection of peripherals. The RA2A1 handles this by using a 16 word array for each port (there are 5 ports each with 16 bits). Each of these array elements allows you set pin direction, peripheral function, interrupt mode, pull-ups etc. The user manual provides a table with the peripherals that can be mapped to each I/O pin. There is a protection mechanism associated with the pin function selection system (as well as other systems). This requires writes to a couple of registers to unlock.

The SDADC24

The RA2A1 has a 24 bit Sigma Delta ADC which includes an instrumentation amplifier with a programmable gain and an offset adjustment system. This is potentially very interesting for instrumentation applications. The SDADC is also capable of averaging a number of input samples which reduces noise at the expense of frequency response. It is also possible to control the oversampling of the sigma delta adc to allow for further noise reduction. Included in the examples below is a program which sends the SDADC conversion result out over the SCI0 serial port.

Sample code

Sample code is available on github over here: https://github.com/fduignan/ra2a1

blinky : blinks and LED on P400

button_in : reads an input button and updates and LED in response

clocks : sets the clock speed to 32MHz

systick : implements an interrupt handler for the SysTick interrupt

serial : interrupt driven serial input /output

sdadc24_serial : printing the output from the SDADC to the serial port