Skip to content

Add support for Renesas RA4M1 and RA6M2 #7063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 29, 2022

Conversation

S-Nakamura-R
Copy link

This pull request adds support for Renesas RA4M1 and RA6M2 MCU as I mentioned in #7034.

@TakeoTakahashi2020 TakeoTakahashi2020 force-pushed the ra-development-v1.14 branch 4 times, most recently from 9bc7e61 to 43cdd0b Compare April 6, 2021 11:12
@dpgeorge dpgeorge added the ports Relates to multiple ports, or a new/proposed port label Apr 7, 2021
@dpgeorge
Copy link
Member

dpgeorge commented Apr 7, 2021

Thank you for this contribution. It would be a good addition to MicroPython to support Renesas MCUs.

I will need to make time to review this since it's a rather large PR.

@TakeoTakahashi2020 TakeoTakahashi2020 force-pushed the ra-development-v1.14 branch 2 times, most recently from d0d9323 to 9777f78 Compare April 19, 2021 02:18
@TakeoTakahashi2020
Copy link
Contributor

@dpgeorge
We are happy to support MicroPython for our RA MCUs.
I appreciate it if you give us any update status for our pulll request.
And also If you need our boards to confirm our porting, please feel free to let us know.

@S-Nakamura-R
Copy link
Author

Hi,
We have applied our modification to the latest files (v1.16).
Should we update the files in our branch (renesas:ra-development-v1.14)?

By the way, could you let us know your estimated time to review this?
If there is something we can do, for example, donating the board or dividing this pull-request into some smaller pull-requests, please feel free to ask us.
We are happy if we can contribute to MicroPython project!

@dpgeorge
Copy link
Member

Sorry I haven't had time to properly look at this yet. I am still very much interested in it and now have a RA4M1 clicker that I can test it on.

@TakeoTakahashi2020
Copy link
Contributor

TakeoTakahashi2020 commented Sep 21, 2021

@dpgeorge Thank you very much for your reply and getting RA4M1 clicker. I will keep following the latest update.

@dpgeorge
Copy link
Member

Could anyone give me some hints how to download the firmware to the RA4M1 Clicker board, under Linux? It has on-board J-link but I can't get JLinkExe to detect the device, and OpenOCD doesn't seem to support this board.

@TakeoTakahashi2020
Copy link
Contributor

TakeoTakahashi2020 commented Sep 22, 2021

@dpgeorge We have WIki pages on our GitHub https://github.com/renesas/micropython/wiki . The page https://github.com/renesas/micropython/wiki/How-to-use-MicroPython-for-RA-MCU describes how to program firmware.

You can get "J-Link Software and Documentation pack" from https://www.segger.com/downloads/jlink/ .
Under Linux, you need to do some operations described in README.txt and Invoke '"JFlashLiteExe" command and please specify R7FA4M1AB for target device. My confirmation environment is ubuntu 20.04 and JLink _Linux_V754c_x86_64.

Note that unfortunatelly our on-board J-link has no serial connection support.

@TakeoTakahashi2020
Copy link
Contributor

Hi @dpgeorge , I much appreciate it if you could let me know any update about our pull request. If I need to update our port to the latest, please kindly let me know. Thanks.

@dpgeorge
Copy link
Member

dpgeorge commented Feb 4, 2022

I have now managed to get this firmware running on the RA4M1 clicker board, with the REPL on UART at P401/P402. It works very well!

After a review of this PR, here are some of the main points I had:

  • I see there is a new ra-development-v1.18; does that change much from what is here?
  • The name of the port ra is too short and will be confusing to people who don't know that it is a Renesas port. Maybe it can be called the renesas port? Or something a bit more specific for this family of MCUs, eg r7fa?
  • It looks like the ports/ra/arm/CMSIS_5 code can be completely removed and the existing lib/cmsis/ code used instead.
  • The ports/ra/SEGGER_RTT code should go in lib/SEGGER_RTT because it's general 3rd-party code.
  • I think the ports/ra/boards/xxx/src/SEGGER_RTT code can be removed, it looks duplicate.
  • The [cr]build_*.sh scripts can all go, having these one per board doesn't scale to having lots of boards. Instead the README can explain in more detail how to build each board. If needed/useful you could keep the build_all_boards.sh script.
  • The tools/raboard.py script can go, it's a duplicate of tools/pyboard.py (and I recommend using mpremote instead, which is a nice wrapper around pyboard.py).
  • The rab module can go, it's just an alias to pyb. (And ideally pyb can eventually be removed once all its functions/classes are moved to machine or other places.)

@TakeoTakahashi2020
Copy link
Contributor

Thank you very much for your review and sorry for the delay in responding.
I have updated that all points and commited them. However, it seems there are something errors for tests and for importing frozen modules.

  • EK_RA6M2 board: "Import Error: no module named 'uasyncio' occurs. basics/class_reverse_op.py fails with "timeout waiting for first EOF reception".
  • RA4M1 CLICKER board: basics/gen_yield_from_executing.py fails with "timeout waiting for first EOF reception" and so on.
    I am still strugling to investigate them and solve.
    I really appreciate it if you could give me any advices to solve them.

@codecov-commenter
Copy link

codecov-commenter commented Feb 16, 2022

Codecov Report

Merging #7063 (70a7ca1) into master (5873390) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #7063   +/-   ##
=======================================
  Coverage   98.25%   98.25%           
=======================================
  Files         154      154           
  Lines       20288    20288           
=======================================
  Hits        19933    19933           
  Misses        355      355           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5873390...70a7ca1. Read the comment docs.

@mattytrentini
Copy link
Contributor

Hello @TakeoTakahashi2020, building for the EK-RA6M2 board was flawless however I can't seem to deploy the firmware.hex file using J-Flash-Lite v7.60b.

I built within a docker container (pwd is the root of a clone of the MicroPython repository with this ra-development-v1.14 PR active):

docker run -ti --rm -v $(pwd):/code -w /code micropython/build-micropython-arm make -C mpy-cross && make -C ports/renesas-ra submodules && make -C ports/renesas-ra BOARD=RA6M2_EK

And tried to deploy the firmware.hex that was generated:

image

I'm connected to the device over USB (to the DEBUG USB port) and erasing the chip appeared to work (the blinky application running on the EK stopped).

I've read the wiki and can't see anything obvious that I've done wrong. Do have any suggestions?

@TakeoTakahashi2020
Copy link
Contributor

Hello @mattytrentini san, Thank you for your confirmation and using EK-RA6M2 board.
I think your operation is completely correct. I have confirmed that both SEGGER J-Flash Lite V7.60b and V7.60h could download the firmware.hex in Documents/test folder on Windows 10 just in case. If you could send me your .hex file via email, I can confirm whether it works or not in my environment. Thanks.

@TakeoTakahashi2020
Copy link
Contributor

I have completed the update and testing. I would appreciate it if you could review it again. Thanks.

- 'extmod/**'
- 'lib/**'
- 'drivers/**'
- 'ports/ra/**'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be /ports/renesas-ra/**

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing that out. I have updated.

@@ -472,6 +472,13 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
for t in tests:
if t.startswith("basics/io_"):
skip_tests.add(t)
elif args.target == "renesas-ra":
skip_tests.add(
"basics/builtin_pow3_intbig.py"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test works and passes for me on a RA4M1 clicker board, so I think it should be included in the test run (ie this bit here removed)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also have confirmed that this test passes on a RA4M1 clicker board. I included it in the test run.

tools/ci.sh Outdated
function ci_renesas_ra_board_build {
make ${MAKEOPTS} -C mpy-cross
make ${MAKEOPTS} -C ports/renesas-ra submodules
git submodule update --init lib/fsp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this line is needed, the line above ("make submodules") should be enough

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing that out. I removed the duplicated submodule update.

#define MICROPY_PY_IO_FILEIO (MICROPY_VFS_FAT || MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2)
#ifndef MICROPY_PY_SYS_PLATFORM // let boards override it if they want
// #define MICROPY_PY_SYS_PLATFORM "pyboard"
#define MICROPY_PY_SYS_PLATFORM "raboard"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make this "renesas-ra"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have changed it to "renesas-ra" and checked by sys.platform.

#define RAB_BUILTIN_MODULE /* no module so far */
#else
#define RAB_BUILTIN_MODULE
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just remove these 5 lines

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have removed unused RAB_BUILTIN_MODULE.

STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) },
{ MP_ROM_QSTR(MP_QSTR_fault_debug), MP_ROM_PTR(&pyb_fault_debug_obj) },
#if MICROPY_PY_PYB_LEGACY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these legacy parts of this pyb module should be removed, they are deprecated and there are other ways to access these methods (eg machine.bootloader(), machine.freq()).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have remoted them.

// Whether to enable USB support
#ifndef MICROPY_HW_ENABLE_USB
#define MICROPY_HW_ENABLE_USB (0)
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see support for USB anywhere in this port, and this config option is not enabled on any board. So I think all USB related things that remain in this port should be removed (eg remove `usb.h').

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. I have done.

@@ -0,0 +1,37 @@
// ra4m1_prefix.c becomes the initial portion of the generated pins file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this file is duplicated 4 times as ra*_prefix.c. I'd suggest renaming it to ra_pin_prefix.c and having only one copy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have done.

* and/or its licensors ("Renesas") and subject to statutory and contractual protections.
*
* This file is subject to a Renesas FSP license agreement. Unless otherwise agreed in an FSP license agreement with
* Renesas: 1) you may not use, copy, modify, distribute, display, or perform the contents; 2) you may not use any name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This license does not look very friendly to open source. Having this file in this repository seems to contradict this clause (1), that the file may not be used/copied/etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. I have removed board/*/ra and linke to lib/fsp files.

@mattytrentini
Copy link
Contributor

Hello Takeo-san,

I've observed an unusual error when importing a file. A minimal example is attached and the error is:

MicroPython v1.18-189-gc35601bb0 on 2022-02-27; RA6M2_EK with RA6M2
Type "help()" for more information.
>>> import overview
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "overview.py", line 1, in <module>
  File "check/pin.py", line 2, in <module>
  File "<stdin>", line 129, in readinto
  File "<stdin>", line 61, in rbytes
  File "<stdin>", line 51, in rs32
  File "<stdin>", line 23, in rinto
RuntimeError: maximum recursion depth exceeded
>>> output_pin = "P105"inpu

Note the corruption in the REPL. It looks like there may be an overwritten buffer somewhere?

The example can be executed with mpremote:

>mpremote connect <your_device> mount . exec "import overview"

I've tested the minimal example, without error, on the RP2 (Pico), ESP32 (TinyPICO) and STM32 (WB55) ports.

@TakeoTakahashi2020
Copy link
Contributor

Hello Matt-san,

Thank you for your report. I will investigate the issue.

@TakeoTakahashi2020
Copy link
Contributor

TakeoTakahashi2020 commented Mar 29, 2022

Hi @dpgeorge san, I have done migration from pyb to machine about Pin, SPI, I2C, UART, ADC, RTC and following updates.
Could you please review?

  • Update docs/renesas-ra's quick reference and tutorials, and change pyb example to machine example, describe current supported/unsupported function.
  • Change hardware id spec of class object so that id starts from 0 as same as hardware id.
  • Replace sdcard.c to sdcard.py.
  • Improve boot mode operation as described in tutorial.
  • Change pin configuration to avoid conflict settings.
  • Change UART print spec so that print displays pin information.
  • Update tests/renesas-ra/*, remove legacy test, update and add simple shareble tests.
  • Fix some issues.

@TakeoTakahashi2020
Copy link
Contributor

My base line is already little old, so I should update it to the latest and push it. I am going to do tomorrow.

@TakeoTakahashi2020
Copy link
Contributor

Hi @dpgeorge san, I have updated the base line to the latest and pushed.

@TakeoTakahashi2020
Copy link
Contributor

Update to the latest.

@dpgeorge
Copy link
Member

Now that the images are at micropython/micropython-media#18, please remove them from this PR.

@TakeoTakahashi2020
Copy link
Contributor

Removing the images which are moved to micropython/micropython-media#18 has done.

@TakeoTakahashi2020 TakeoTakahashi2020 force-pushed the ra-development-v1.14 branch 2 times, most recently from d1b2dc5 to 4691de0 Compare April 28, 2022 13:50
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
@dpgeorge dpgeorge merged commit 52add7b into micropython:master Apr 29, 2022
@dpgeorge
Copy link
Member

Thank you very much for the hard work on this, getting it to a state where it can be merged!

@TakeoTakahashi2020
Copy link
Contributor

Thank you so much for your strong supports and advices. We are so happy that Renesas RA port is merged.

@beyonlo
Copy link

beyonlo commented Apr 29, 2022

Thank you so much for your strong supports and advices. We are so happy that Renesas RA port is merged.

Great work guys!

@S-Nakamura-R
Copy link
Author

Great news!
I deeply appriciate all of you.

tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ports Relates to multiple ports, or a new/proposed port
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants