docs/renesas-ra: Add renesas-ra docs files.

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
This commit is contained in:
Takeo Takahashi 2022-04-29 10:52:16 +09:00
parent 3717d599e2
commit 1b61800530
11 changed files with 749 additions and 0 deletions

View File

@ -0,0 +1,42 @@
.. _renesas-ra_general:
General information about Renesas RA port
=========================================
Overview
--------
The renesas-ra port supports boards powered by Renesas Electronics's
the flexible Renesas Advanced (RA) 32-bit microcontrollers (MCUs) family,
industry-leading 32-bit MCUs with the Arm® Cortex®-M33, -M23 and -M4
processor cores and PSA certification.
The ported hardware functionalities are Pin, SPI, I2C, UART and RTC at this present.
Other hardware functionalities such as Timer, PWM, USB, CAN and WDT are not implemented yet.
The following boards are officially supported.
* RA4M1-CLICKER
For the manual and other references for the board and RA Family MCU, please refer to the web page: `EK-RA4M1 CLICKER <https://www.mikroe.com/ra4m1-clicker>`_
* EK-RA6M2
For the manual and other references for the board and RA Family MCU, please refer to the web page: `EK-RA6M2 <https://www.renesas.com/products/microcontrollers-microprocessors/ra-cortex-m-mcus/ek-ra6m2-ra6m2-mcu-group-evaluation-board>`_
The following boards are unofficially supported.
* EK-RA4M1
For the manual and other references for the board and RA Family MCU, please refer to the web page: `EK-RA4M1 <https://www.renesas.com/products/microcontrollers-microprocessors/ra-cortex-m-mcus/ek-ra4m1-ra4m1-mcu-group-evaluation-board>`_
* EK-RA4W1
For the manual and other references for the board and RA Family MCU, please refer to the web page: `EK-RA4W1 <https://www.renesas.com/products/microcontrollers-microprocessors/ra-cortex-m-mcus/ek-ra4w1-ra4w1-mcu-group-evaluation-board>`_
* EK-RA6M1
For the manual and other references for the board and RA Family MCU, please refer to the web page: `EK-RA6M1 <https://www.renesas.com/products/microcontrollers-microprocessors/ra-cortex-m-mcus/ek-ra6m1-ra6m1-mcu-group-evaluation-board>`_
For more information, please visit the web page: `<https://github.com/renesas/micropython/wiki>`_

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

View File

@ -0,0 +1,415 @@
.. _renesas-ra_quickref:
Quick reference for the Renesas RA
==================================
.. image:: img/ek_ra6m2_board.jpg
:alt: Renesas Evaluation Kit for RA6M2 MCU Group
:width: 640px
The Renesas EK-RA6M2 board.
Below is a quick reference for the Renesas RA boards. If it is your first time
working with this board, it may be useful to get an overview of the microcontroller and the board:
.. toctree::
:maxdepth: 1
general.rst
tutorial/index.rst
Installing MicroPython
----------------------
See the corresponding section of tutorial: :ref:`renesas-ra_intro`. It also includes a troubleshooting subsection.
General board control
---------------------
The MicroPython REPL is accessed via the USB serial port. Tab-completion is useful to find out what methods an object has. Paste mode (ctrl-E) is useful to paste a large slab of Python code into the REPL. Some of features are not implemented for Renesas RA boards yet, please refer to the tutorial for more details.
The :mod:`machine` module::
import machine
machine.freq() # get the current frequency of the CPU
Following functions are supported::
machine.freq()
machine.reset()
machine.soft_reset()
machine.unique_id()
Following functions are not supported at the present::
machine.reset_cause()
machine.bootloader([value])
machine.disable_irq()
machine.enable_irq(state)
machine.freq([hz])
machine.idle()
machine.sleep()
machine.lightsleep()
machine.lightsleep([time_ms])
machine.deepsleep()
machine.deepsleep([time_ms])
machine.wake_reason()
machine.time_pulse_us(pin, pulse_level, timeout_us=1000000,/)
machine.bitstream(pin, encoding, timing, data, /)
machine.rng()
Delay and timing
----------------
Use the :mod:`time <time>` module::
import time
time.sleep(1) # sleep for 1 second
time.sleep_ms(500) # sleep for 500 milliseconds
time.sleep_us(10) # sleep for 10 microseconds
start = time.ticks_ms() # get value of millisecond counter
delta = time.ticks_diff(time.ticks_ms(), start) # compute time difference
Timers
------
The RA MCU's system timer peripheral provides a global microsecond timebase and generates interrupts for it. The software timer is available currently and there are unlimited number of them (memory permitting). There is no need to specify the timer id (id=-1 is supported at the moment) as it will default to this.
Use the :mod:`machine.Timer` class::
from machine import Timer
tim = Timer(-1)
tim.init(period=5000, mode=Timer.ONE_SHOT, callback=lambda t:print(1))
tim.init(period=2000, mode=Timer.PERIODIC, callback=lambda t: print(2))
Following functions are not supported at the present::
Timer(id) # hardware timer is not supported.
Pins and GPIO
-------------
Use the :ref:`machine.Pin <machine.Pin>` class::
from machine import Pin
p0 = Pin('P000', Pin.OUT) # create output pin on P000
p0.on() # set pin to "on" (high) level
p0.off() # set pin to "off" (low) level
p0.value(1) # set pin to on/high
p2 = Pin(Pin.cpu.P002, Pin.IN) # create input pin on P002
print(p2.value()) # get value, 0 or 1
p4 = Pin('P004', Pin.PULL_UP) # enable internal pull-up register
p5 = Pin('P005', Pin.OUT, value=1) # set pin high on creation
Pin id is available corresponding to the RA MCU's pin name which are Pin.cpu.P106 and 'P106'. The RA MCU has many feature's pins. However, there are some cases that pin feature is fixed or not connected by the board. Please confirm the board manual for the pin mapping.
UART (serial bus)
-----------------
The RA MCU has some hardware UARTs called SCI (Serial Communication Interface).
UART id is available corresponding to the RA MCU's SCI number which are UART(0) as SCI0 and UART(1) as SCI1.
See :ref:`machine.UART <machine.UART>`. ::
from machine import UART
uart1 = UART(1, 115200)
uart1.write('hello') # write 5 bytes
uart1.read(5) # read up to 5 bytes
Available UARTs and pins on the board are fixed and follows. One of these UARTs is used for REPL.
============= ============== ============== ==============
EK-RA4M1 UART0(REPL) UART1 UART2
============= ============== ============== ==============
tx P411 P401 P302
rx P410 P402 P301
============= ============== ============== ==============
============= ============== ============== ==============
EK-RA4W1 UART1 UART4(REPL) UART9
============= ============== ============== ==============
tx P213 P204 P109
rx P212 P206 P110
============= ============== ============== ==============
============= ============== ============== ==============
EK-RA6M1 UART0(REPL) UART2 UART8
============= ============== ============== ==============
tx P411 P302 P105
rx P410 P301 P104
============= ============== ============== ==============
============= ============== ============== ==============
EK-RA6M2 UART0(REPL) UART7 UART9
============= ============== ============== ==============
tx P411 P401 P602
rx P410 P402 P601
============= ============== ============== ==============
============= ============== ==============
RA4M1-CLICKER UART0 UART1(REPL)
============= ============== ==============
tx P411 P401
rx P410 P402
============= ============== ==============
Following functions are not supported at the present::
UART.init(baudrate) # now only 115200 is confirmed
UART.init(cts, rts) # Pins are fixed.
UART.init(invert)
UART.init(tx,rx) # Pins are fixed.
UART.init(txbuf)
UART.init(flow)
UART.irq(handler)
UART.irq(trigger=RX_ANY)
UART.irq(priority)
UART.irq(wake=machine.IDLE)
Real time clock (RTC)
---------------------
See :ref:`machine.RTC <machine.RTC>` ::
from machine import RTC
rtc = RTC()
rtc.datetime((2017, 8, 23, 1, 12, 48, 0, 0)) # set a specific date and time
# time, eg 2017/8/23 1:12:48
rtc.datetime() # get date and time
Following functions are not supported at the present::
RTC.init(datetime)
RTC.now()
RTC.deinit()
RTC.alarm()
RTC.alarm_left()
RTC.cancel()
RTC.irq()
ADC (analog to digital conversion)
----------------------------------
See :ref:`machine.ADC <machine.ADC>` ::
from machine import ADC
adc = ADC('P000') # create an ADC object acting on a pin
adc.read_u16() # read a raw analog value in the range 0-65535
Pin id is available corresponding to the RA MCU's pin name which are 'P000' as AN000 (analog channel 000). The RA MCU has many analog channels. However, there are some cases that pin feature is fixed or not available by the board. Please confirm the MCU and board manual for the pin mapping.
Following functions are not supported at the present::
ADC.init()
ADC(sample_ns)
ADC(atten)
ADC.read_uv()
ADC.block()
SPI bus
-------
The RA MCU has some hardware SPIs (Serial Peripheral Interface).
SPI id is available corresponding to the RA MCU's SPI number which are SPI(0) as SPI0 and SPI(1) as SPI1. If with no additional parameters, machine.SoftSPI() is called.
See :ref:`machine.SPI <machine.SPI>`. ::
from machine import SPI, Pin
spi = SPI(0, baudrate=500000)
cs = Pin.cpu.P103
cs(0)
spi.write(b"12345678")
cs(1)
Available SPIs and pins on the board are fixed and follows.
============= ====
EK-RA4M1 SPI0
============= ====
sck P102
mosi P101
miso P100
cs P206
============= ====
============= ====
EK-RA4W1 SPI0
============= ====
sck P102
mosi P101
miso P100
cs P103
============= ====
============= ====
EK-RA6M1 SPI0
============= ====
sck P102
mosi P101
miso P100
cs P103
============= ====
============= ==== ====
EK-RA6M2 SPI0 SPI1
============= ==== ====
sck P102 P702
mosi P101 P701
miso P100 P700
cs P103 P703
============= ==== ====
============= ====
RA4M1-CLICKER SPI0
============= ====
sck P102
mosi P101
miso P100
cs P103
============= ====
Following functions are not supported at the present::
SPI.init(firstbit) # now fixed with SPI.LSB
SPI.init(baudrate) # now confirmed only 500000
I2C bus
-------
The RA MCU has some hardware IIC (Inter-Integrated Circuit Bus).
I2C id is available corresponding to the RA MCU's I2C number which are I2C(0) as IIC0 and I2C(1) as IIC1. If with no additional parameters, machine.SoftI2C() is called.
See :ref:`machine.I2C <machine.I2C>` ::
from machine import I2C
i2c = I2C(0)
i2c.scan() # returns list of slave addresses
i2c.readfrom_mem(0x50, 0x10, 2, addrsize=16) # read 2 bytes from slave 0x50, slave memory 0x10
Available I2Cs and pins on the board are fixed and follows.
============= =============
EK-RA4M1 -
============= =============
scl not supported
sda not supported
============= =============
============= ====
EK-RA4W1 I2C0
============= ====
scl P204
sda P407
============= ====
============= ====
EK-RA6M1 I2C0
============= ====
scl P400
sda P401
============= ====
============= ====
EK-RA6M2 I2C2
============= ====
scl P512
sda P511
============= ====
============= ====
RA4M1-CLICKER I2C1
============= ====
scl P205
sda P206
============= ====
Following functions are not supported at the present::
I2C.init(freq) # now confirmed only 400000
I2C.deinit()
I2C.start()
I2C.stop()
PWM (pulse width modulation)
----------------------------
PWM is not supported.
WDT (Watchdog timer)
--------------------
WDT is not supported.
SDCard
------
The frozen sdcard driver (drivers/sdcard/sdcard.py) is available by connecting microSD card device to hardware SPI0 pins.::
from machine import Pin, SPI
import os, sdcard
spi = SPI(0, baudrate=500000)
cs = Pin.cpu.P103
sd = sdcard.SDCard(spi, cs)
os.mount(sd, '/sd')
os.listdir('/')
os.chdir('/sd')
os.umount('/sd')
OneWire driver
--------------
The OneWire driver is implemented in software and works on all pins::
from machine import Pin
import onewire
ow = onewire.OneWire(Pin(P012)) # create a OneWire bus on P012
ow.scan() # return a list of devices on the bus
ow.reset() # reset the bus
ow.readbyte() # read a byte
ow.writebyte(0x12) # write a byte on the bus
ow.write('123') # write bytes on the bus
ow.select_rom(b'12345678') # select a specific device by its ROM code
There is a specific driver for DS18S20 and DS18B20 devices::
import time, ds18x20
ds = ds18x20.DS18X20(ow)
roms = ds.scan()
ds.convert_temp()
time.sleep_ms(750)
for rom in roms:
print(ds.read_temp(rom))
Be sure to put a 4.7k pull-up resistor on the data line. Note that
the ``convert_temp()`` method must be called each time you want to
sample the temperature.
NeoPixel and APA106 driver
--------------------------
NeoPixel is not supported currently.

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

View File

@ -0,0 +1,16 @@
.. _renesas-ra_tutorial:
MicroPython tutorial for Renesas RA port
========================================
This tutorial is intended to get you started using MicroPython on the Renesas RA port.
.. toctree::
:maxdepth: 1
:numbered:
intro.rst
using_peripheral.rst
program_in_flash.rst
reset.rst
troubleshooting.rst

View File

@ -0,0 +1,67 @@
.. _renesas-ra_intro:
Getting started with MicroPython on the Renesas RA
==================================================
This tutorial will guide you through setting up MicroPython,
getting a prompt, using the hardware peripherals, using internal
flash file system, reset and boot modes, and Factory reset the
internal file system.
Requirements
------------
You need a board. For the information of available boards,
please refer to the general information about Renesas RA port: :ref:`renesas-ra_general`.
You need a USB-Serial conversion cable to connect the board and your PC.
Please get a type with separate signal pins so that you can connect to
the UART TX and RX pins on the board.
Flashing the MicroPython image with J-Link OB
---------------------------------------------
The board has a builtin programmer interface called J-Link OB.
Using the J-Link Software, you can flash the binary image "firmware.hex"
of MicroPython on the board via J-Link OB.
You can download the J-Link Software and Documentation pack from https://www.segger.com/downloads/jlink/.
After installing J-Link Software, start J-Flash-Lite program. Then specify following device in Device select menu in J-Flash-Lite.
=============== ================
Board Device
--------------- ----------------
EK-RA4M1 R7FA4M1AB
EK-RA4W1 R7FA4W1AD2CNG
EK-RA6M1 R7FA6M1AD
EK-RA6M2 R7FA6M2AF
RA4M1 CLICKER R7FA4M1AB
=============== ================
Select a firmware hex file in Data File of J-Link-Lite, and push Program Device button to flash the firmware.
Getting a prompt of MicroPython
-------------------------------
Cross connect USB-Serial conversion cable RX/TX/GND pins to TX/RX/GND pins on the board.
=============== =============== ===============
Board USB Serial RX USB Serial TX
--------------- --------------- ---------------
EK-RA4M1 P411 P410
EK-RA4W1 P205 P206
EK-RA6M1 P411 P410
EK-RA6M2 P411 P410
RA4M1 CLICKER P401 P402
=============== =============== ===============
Access the MicroPython REPL (the Python prompt) via USB serial or UART with 115200 baud rate, 1 stop bit and no parity bit using your favorite terminal software, picocom on Linux or Tera Term on Windows. You can try on Linux::
$ picocom /dev/ttyACM0
You can see the MicroPython REPL prompt like below::
MicroPython v1.18-293-g339aa09b8-dirty on 2022-03-26; RA6M2_EK with RA6M2
Type "help()" for more information.
>>>

View File

@ -0,0 +1,62 @@
.. _renesas-ra_program_in_flash:
Write a program in internal file system
=======================================
Internal file system
--------------------
The FAT file system is created and initialized in the RA MCU's internal
flash when the MicroPython starts at the first time on the board.
The file system is mounted as "/flash", so you can access this flash system
and create a program file into the /flash directory.
As the factory setting, following size is allocated for the file system:
=============== ===================
Board File System Size
--------------- -------------------
EK-RA4M1 36KB ( 36864B)
EK-RA4W1 64KB ( 65536B)
EK-RA6M1 128KB (131072B)
EK-RA6M2 256KB (262144B)
RA4M1 CLICKER 36KB ( 36864B)
=============== ===================
As the factory setting, following 2 files are created in the file system:
* boot.py : executed first when the system starts
* main.py : executed after boot.py completes
Write a program in the internal file system
-------------------------------------------
You can write a program in main.py which is executed automatically
when the MicroPython starts. For example, you can write LED blinking
program like below::
import os
os.getcwd()
f = open('main.py', 'rw+')
print(f.read())
f.write('import time\n')
f.write('from machine import Pin\n')
f.write('led1 = Pin(Pin.cpu.P106)\n')
f.write('while True:\n')
f.write(' led1.on()\n')
f.write(' time.sleep(1)\n')
f.write(' led1.off()\n')
f.write(' time.sleep(1)\n')
f.close()
f = open('main.py', 'r')
print(f.read())
f.close()
Entering CTRL-D for software reset, the MicroPython reboots, displays
following messages::
MPY: sync filesystems
MPY: soft reboot
and main.py is executed and LED1 blinks per 1 second.
If you want to stop the program, please enter CTRL-C.

View File

@ -0,0 +1,61 @@
.. _renesas-ra_reset:
Reset and boot mode
===================
Resetting the board
-------------------
If something goes wrong, you can reset the board in two ways. The first is
to press CTRL-D at the MicroPython prompt, which performs a soft reset.
You will see a message something like ::
MPY: sync filesystems
MPY: soft reboot
MicroPython v1.18-293-g339aa09b8-dirty on 2022-03-26; RA6M2_EK with RA6M2
Type "help()" for more information.
>>>
If that isn't working you can perform a hard reset (turn-it-off-and-on-again)
by pressing the RESET button. This will end your session, disconnecting
whatever program (PuTTY, screen, etc) that you used to connect to the board.
boot mode
---------
There are 3 boot modes:
* normal boot mode
* safe boot mode
* factory filesystem boot mode
boot.py and main.py are executed on "normal boot mode".
boot.py and main.py are *NOT* executed on "safe boot mode".
The file system of internal flash is initialized and *all files are erased* on "factory filesystem boot mode".
For changing boot mode, please push the RESET button with pressing USER SW1
on the board:
* For normal boot mode, release the USER SW1 after LED1 flashes 4 times or more
* For safe boot mode, release the USER SW1 after LED1 flashes 2 times
* For factory file system boot mode, release the USER SW1 after LED1 flashes 3 times.
You have created the main.py which executes LED1 blinking in the previous part.
If you change the boot mode to safe boot mode, the MicroPython starts without
the execution of main.py. Then you can remove the main.py by following
command or change the boot mode to factory file system boot mode.::
import os
os.remove('main.py')
or change the boot mode to factory file system boot mode.
You can confirm that the initialized file system that there are only boot.py and main.py files.::
import os
os.listdir()

View File

@ -0,0 +1,18 @@
.. _renesas-ra_troubleshooting:
Trouble Shooting
===================
Flash file system
-------------------
* MicroPython REPL prompt is not displayed.
- Re-program the MicroPython image file.
- Confirm serial port connection.
The connection must be crossed that the board TXD pin is connected with
USB-serial conversion's RXD signal pin.
- If the prompt is not displayed suddenly, try to do factory file
system boot mode as the final method. Please note that all files are removed forever.

View File

@ -0,0 +1,68 @@
.. _renesas-ra_using_peripheral:
Using peripherals
=================
For quick help information, please enter::
help()
You can access RA MCU's peripherals using MicroPython modules.
To list supported modules, please enter::
help('modules')
Especially `machine` module and class :ref:`machine.Pin <machine.Pin>` are very important for using
peripherals. Note that prefix 'u' is added to the module for MicroPython,
so you can see "umachine" in the list but you can use it like "import machine".
Using "from machine import Pin", Pin name is available corresponding to
the RA MCU's pin name which are Pin.cpu.P000 and 'P000'.
In addition, you can use 'LED1', 'LED2', 'SW1', and 'SW2' name if the board
has these LEDs and switches.
LED blinking
------------
As simple example, you can enter following program to blink LED1.
Please enter key 4 times after the input of last time.sleep(1). ::
import time
from machine import Pin
led1 = Pin('LED1')
print(led1)
while True:
led1.on()
time.sleep(1)
led1.off()
time.sleep(1)
You can see the LED1 blinking per 1 second.
If you want to stop the program, please enter CTRL-C. ::
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
KeyboardInterrupt:
This message is displayed, and the program stops.
The message means the program was interrupted at line 5 "while" statement.
Using print(led1), you can confirm that LED1 is assigned to Pin.cpu.P106
on the board.::
Pin(Pin.cpu.P106, mode=Pin.OUT, pull=Pin.PULL_NONE, drive=Pin.LOW_POWER)
So you can get the same result if Pin(Pin.cpu.P106) is specified
instead of Pin('LED1'). ::
import time
from machine import Pin
led1 = Pin(Pin.cpu.P106)
print(led1)
while True:
led1.on()
time.sleep(1)
led1.off()
time.sleep(1)