Using Not Connected Pins on RA4M1

The RA4M1 used in the R4 Minima has a lot of pins that are not connected. If I wanted to use 8 ADC pins and I2C plus 8 GPIO pins, can other pins not available to the UNO format be used/accessed using a sketch if I build my own board with a RA4M1?

P003, P004, P011, P012, P013 could be used as ADC.

Yes.
What is more if you choose the 100 pin chip you can access things that are not even possible on the 44 pin version. Like the I2S interface.

Thanks, do you have any examples of using pinMode(), digitalWrite() and analogRead() for pins outside of the range of the UNO R4?

There are no and can't be such examples, since the extra pins are not defined in arduino core files. You must first add the pin definitions (and perhaps edit a pin accessing functions) yourself.

1 Like

A couple of different ways:

Update pin tables: either directly in their variant or make your own variant.
for example to update MINIMA, go to the variant folder and update variant.cpp.
You will see a table near the start that looks like:

extern "C" const PinMuxCfg_t g_pin_cfg[] = { 
  { BSP_IO_PORT_03_PIN_01,    P301   }, /* (0) D0  -------------------------  DIGITAL  */
  { BSP_IO_PORT_03_PIN_02,    P302   }, /* (1) D1  */
  { BSP_IO_PORT_01_PIN_05,    P105   }, /* (2) D2  */
  { BSP_IO_PORT_01_PIN_04,    P104   }, /* (3) D3~ */
  { BSP_IO_PORT_01_PIN_03,    P103   }, /* (4) D4  */
  { BSP_IO_PORT_01_PIN_02,    P102   }, /* (5) D5~ */
  { BSP_IO_PORT_01_PIN_06,    P106   }, /* (6) D6~ */
  { BSP_IO_PORT_01_PIN_07,    P107   }, /* (7) D7  */
  { BSP_IO_PORT_03_PIN_04,    P304   }, /* (8) D8  */
  { BSP_IO_PORT_03_PIN_03,    P303   }, /* (9) D9~  */
  { BSP_IO_PORT_01_PIN_12,    P112   }, /* (10) D10~ */
  { BSP_IO_PORT_01_PIN_09,    P109   }, /* (11) D11~ */
  { BSP_IO_PORT_01_PIN_10,    P110   }, /* (12) D12 */
  { BSP_IO_PORT_01_PIN_11,    P111   }, /* (13) D13 */
  { BSP_IO_PORT_00_PIN_14,    P014   }, /* (14) A0  --------------------------  ANALOG  */
  { BSP_IO_PORT_00_PIN_00,    P000   }, /* (15) A1  */
  { BSP_IO_PORT_00_PIN_01,    P001   }, /* (16) A2  */
  { BSP_IO_PORT_00_PIN_02,    P002   }, /* (17) A3  */
  { BSP_IO_PORT_01_PIN_01,    P101   }, /* (18) A4/SDA  */
  { BSP_IO_PORT_01_PIN_00,    P100   }, /* (19) A5/SCL  */

  { BSP_IO_PORT_05_PIN_00,    P500   }, /* (20) Analog voltage measure pin  */
  { BSP_IO_PORT_00_PIN_12,    P012   }, /* (21) TX LED  */
  { BSP_IO_PORT_00_PIN_13,    P013   }, /* (22) RX LED  */

  { BSP_IO_PORT_05_PIN_01,    P501   }, /* (23) TX on SWD connector  */
  { BSP_IO_PORT_05_PIN_02,    P502   }, /* (24) RX on SWD connector  */
  { BSP_IO_PORT_01_PIN_08,    P108   }, /* (25) SWDIO  */
  { BSP_IO_PORT_03_PIN_00,    P300   }, /* (26) SWCLK  */
};

Add your new pins at the end.

You then go into the file pinmux.inc and add data for each of the pins.
Note the last pin in table above is P300 - port 3 pin 0
In the pinmux.inc you will find:

const uint16_t P300[] = {
PIN_PWM|CHANNEL_0|PWM_CHANNEL_A|GPT_ODD_CFG|LAST_ITEM_GUARD
};

The section depends on the pins capabilities. And you can hopefully deduce the data from other like pins that are defined.

unwind the calls like digitalWrite:
For example:

pinMode(0. OUTPUT);
digitalWrite(0, HIGH);

Could be replaced by:

R_IOPORT_PinCfg(NULL,BSP_IO_PORT_03_PIN_01,IOPORT_CFG_PORT_DIRECTION_OUTPUT | IOPORT_CFG_PMOS_ENABLE);
R_IOPORT_PinWrite(NULL, BSP_IO_PORT_03_PIN_01, BSP_IO_LEVEL_HIGH);`

Write your own tables and methods:
Combination of the two. - That is create your own table for the added pins,
And duplicate the functions like digitalWrite -> digitalWriteAdded
Where it looks at your table of added pins to then call off to the underlying system.

1 Like

Actually, there are/were examples, like in the thread @susan-parker :
showed an example of setting the TX/RX leds before the latest update was released.

Do RX/TX LEDS glow? - UNO R4 / UNO R4 Minima - Arduino Forum

Here is an alternative version of it, like I mentioned in previous post:

void setup() {
R_IOPORT_PinCfg(NULL,BSP_IO_PORT_00_PIN_12,IOPORT_CFG_PORT_DIRECTION_OUTPUT | IOPORT_CFG_PMOS_ENABLE); // TX LED
  R_IOPORT_PinCfg(NULL,BSP_IO_PORT_00_PIN_13,IOPORT_CFG_PORT_DIRECTION_OUTPUT | IOPORT_CFG_PMOS_ENABLE); // RX LED
}

void loop() {
  R_IOPORT_PinWrite(NULL, BSP_IO_PORT_00_PIN_12, BSP_IO_LEVEL_HIGH);
  R_IOPORT_PinWrite(NULL, BSP_IO_PORT_00_PIN_13, BSP_IO_LEVEL_LOW);
  delay(500);
  R_IOPORT_PinWrite(NULL, BSP_IO_PORT_00_PIN_12, BSP_IO_LEVEL_LOW);
  R_IOPORT_PinWrite(NULL, BSP_IO_PORT_00_PIN_13, BSP_IO_LEVEL_HIGH);
  delay(500);
}

It alternates turning TX and RX led on and off...

1 Like

It are not an examples of using digitalWrite() etc... functions. These lines uses a specific methods, unknown in arduino ecosystem.

Thank you @KurtE. All of these approaches are good for me. I want to try and limit my use of IDEs and didn't want to need to learn e2 which is the Renesas development platform for RA4M1.

1 Like

These alternate examples work in the Arduino IDE...

Point to note - the standard Arduino IDE pin write with digitalWrite(); IS VERY SLOW!!!

Thanks

Not doing any time critical pin control with digitalWrite().

1 Like

@KurtE I do not appear to have a variants.cpp file under the ArduinoData/packages folder. I have tried removing the support for Arduino R4 UNO boards and then re-installing but no such file is being installed? Any idea what is going on here?

Not sure what folder that is? Which OS are you using? What version of IDE?

Windows 10, Arduino IDE 2.2.1

It should be wherever your Arduino15 directory is:
On my machine W11, it is stored at:
C:\Users\kurte\AppData\Local\Arduino15

Obviously, your username will be different.
Under this directory you should see a structure like:
packages\arduino\hardware\renesas_uno
The next directory down should be which version of the board you installed,
In my case 1.0.4...

So the complete directory on machine for the MINIMA where the file exists is:
C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.4\variants\MINIMA