Skip to content

Commit

Permalink
renesas-ra/boards/ARDUINO_PORTENTA_C33: Add support for Portenta C33.
Browse files Browse the repository at this point in the history
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
  • Loading branch information
iabdalkader authored and dpgeorge committed Sep 14, 2023
1 parent abd9bed commit 7802eed
Show file tree
Hide file tree
Showing 24 changed files with 2,323 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ports/renesas-ra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ Linux, Mac and Windows hosts via https://developer.arm.com/downloads/-/arm-gnu-t
The compiler can be changed using the `CROSS_COMPILE` variable
when invoking `make`.

* Protocol buffer compiler
Building for the `ARDUINO_PORTENTA_C33` board will build the `esp_hosted` driver, that depends
on the Protocol Buffer Compiler being installed. On Debian/Ubuntu, this can be installed with
`sudo apt-get install protobuf-compiler`.

* Obtain submodules
First the submodules must be obtained using:

Expand Down
23 changes: 23 additions & 0 deletions ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/board.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"deploy": [
"./deploy.md"
],
"docs": "",
"features": [
"512KB SRAM",
"2MB Flash",
"16MB QSPI Flash",
"USB High Speed Phy",
"10/100 Ethernet Phy",
"ESP32 WiFi/BT Module",
"NXP SE050 crypto device"
],
"images": [
"ABX00074_01.iso_1000x750.jpg"
],
"mcu": "RA6M5",
"product": "Arduino Portenta C33",
"thumbnail": "",
"url": "https://store.arduino.cc/pages/portenta-c33",
"vendor": "Arduino"
}
53 changes: 53 additions & 0 deletions ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/board_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2023 Arduino SA
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "py/mphal.h"
#include "r_sce.h"

// Key code for writing PRCR register.
#define BSP_PRV_PRCR_KEY (0xA500U)
#define BSP_PRV_PRCR_PRC1_UNLOCK ((BSP_PRV_PRCR_KEY) | 0x2U)
#define BSP_PRV_PRCR_LOCK ((BSP_PRV_PRCR_KEY) | 0x0U)
#define BOOT_DOUBLE_TAP_DATA (0x07738135)
#define BOOT_DOUBLE_TAP_ADDR (*((volatile uint32_t *)&R_SYSTEM->VBTBKR[0]))

void PORTENTA_C33_board_startup() {
// Enable USB_BASE
R_SYSTEM->PRCR = (uint16_t)BSP_PRV_PRCR_PRC1_UNLOCK;
R_MSTP->MSTPCRB &= ~(1U << 11U);
R_MSTP->MSTPCRB &= ~(1U << 12U);
R_SYSTEM->PRCR = (uint16_t)BSP_PRV_PRCR_LOCK;

// Re-enable IRQs after jump from the bootloader.
__enable_irq();
}

void PORTENTA_C33_board_enter_bootloader(void) {
R_SYSTEM->PRCR = (uint16_t)BSP_PRV_PRCR_PRC1_UNLOCK;
BOOT_DOUBLE_TAP_ADDR = BOOT_DOUBLE_TAP_DATA;
R_SYSTEM->PRCR = (uint16_t)BSP_PRV_PRCR_LOCK;
NVIC_SystemReset();
}
8 changes: 8 additions & 0 deletions ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### dfu-util

This board can programmed via DFU bootloader, using e.g. [dfu-util](http://dfu-util.sourceforge.net/).
To enter the DFU bootloader, double tap the reset (blue) button, or you can use `machine.bootloader()` from the MicroPython REPL.

```bash
dfu-util -a 0 -d 2341:0368 -D build-ARDUINO_PORTENTA_C33/firmware.bin -Q # -s :leave
```
12 changes: 12 additions & 0 deletions ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include("$(PORT_DIR)/boards/manifest.py")

# Networking
require("bundle-networking")

# Utils
require("time")
require("senml")
require("logging")

# Bluetooth
require("aioble")
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H
#define MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H

#define MBEDTLS_ECP_NIST_OPTIM

#include "ports/renesas-ra/mbedtls/mbedtls_config.h"

#endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H */
107 changes: 107 additions & 0 deletions ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
* The MIT License (MIT)
* Copyright (c) 2023 Arduino SA
*/

// MCU config
#define MICROPY_HW_BOARD_NAME "PORTENTA C33"
#define MICROPY_HW_MCU_NAME "RA6M5"
#define MICROPY_HW_MCU_SYSCLK 200000000
#define MICROPY_HW_MCU_PCLK 100000000

// module config
#define MICROPY_EMIT_THUMB (1)
#define MICROPY_EMIT_INLINE_THUMB (1)
#define MICROPY_PY_BUILTINS_COMPLEX (1)
#define MICROPY_PY_GENERATOR_PEND_THROW (1)
#define MICROPY_PY_MATH (1)
#define MICROPY_PY_UHEAPQ (1)
#define MICROPY_PY_UTIMEQ (1)
#define MICROPY_PY_THREAD (0) // disable ARM_THUMB_FP using vldr due to RA has single float only
#define MICROPY_PY_NETWORK (1)

// peripheral config
#define MICROPY_HW_ENABLE_RNG (1)
#define MICROPY_HW_ENABLE_RTC (1)
#define MICROPY_HW_RTC_SOURCE (1)
#define MICROPY_HW_ENABLE_ADC (1)
#define MICROPY_HW_HAS_FLASH (1)
#define MICROPY_HW_ENABLE_USBDEV (1)
#define MICROPY_HW_ENABLE_UART_REPL (0)
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1)

#define MICROPY_BOARD_STARTUP PORTENTA_C33_board_startup
void PORTENTA_C33_board_startup(void);

#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) PORTENTA_C33_board_enter_bootloader()
void PORTENTA_C33_board_enter_bootloader(void);

// board config
// USB
#define MICROPY_HW_USB_VID (0x2341)
#define MICROPY_HW_USB_PID (0x0468)

// UART
#define MICROPY_HW_UART9_TX (pin_P602)
#define MICROPY_HW_UART9_RX (pin_P110)
#define MICROPY_HW_UART9_CTS (pin_P604)
#define MICROPY_HW_UART9_RTS (pin_P603)

#define MICROPY_HW_UART8_TX (pin_PA00)
#define MICROPY_HW_UART8_RX (pin_P607)
#define MICROPY_HW_UART8_CTS (pin_P801)
#define MICROPY_HW_UART8_RTS (pin_P606)

#if MICROPY_HW_ENABLE_UART_REPL
#define MICROPY_HW_UART_REPL (HW_UART_9)
#define MICROPY_HW_UART_REPL_BAUD (115200)
#endif

// I2C
#define MICROPY_HW_I2C2_SCL (pin_P407)
#define MICROPY_HW_I2C2_SDA (pin_P408)

// SPI
#define MICROPY_HW_SPI1_SSL (pin_P104)
#define MICROPY_HW_SPI1_RSPCK (pin_P102)
#define MICROPY_HW_SPI1_MISO (pin_P100)
#define MICROPY_HW_SPI1_MOSI (pin_P101)

// DAC
#define MICROPY_HW_DAC0 (pin_P014)
#define MICROPY_HW_DAC1 (pin_P015)

// PWM
#define MICROPY_HW_PWM_1A (pin_P105)
#define MICROPY_HW_PWM_8B (pin_P106)
#define MICROPY_HW_PWM_3A (pin_P111)
#define MICROPY_HW_PWM_7B (pin_P303)
#define MICROPY_HW_PWM_6B (pin_P401)
// #define MICROPY_HW_PWM (pin_P210) // AGT
#define MICROPY_HW_PWM_6A (pin_P601)

// LEDs
#define MICROPY_HW_LED1 (pin_P107)
#define MICROPY_HW_LED2 (pin_P400)
#define MICROPY_HW_LED3 (pin_P800)
#define MICROPY_HW_LED_ON(pin) mp_hal_pin_low(pin)
#define MICROPY_HW_LED_OFF(pin) mp_hal_pin_high(pin)
#define MICROPY_HW_LED_TOGGLE(pin) mp_hal_pin_toggle(pin)

// Bluetooth config.
#define MICROPY_HW_BLE_UART_ID (8)
#define MICROPY_HW_BLE_UART_RTS (MICROPY_HW_UART8_RTS)
#define MICROPY_HW_BLE_UART_BAUDRATE (115200)
#define MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY (921600)

// WiFi config.
#define MICROPY_HW_WIFI_SPI_ID (1)
#define MICROPY_HW_WIFI_SPI_CS (pin_P104)
#define MICROPY_HW_WIFI_SPI_BAUDRATE (30 * 1000 * 1000)
#define MICROPY_HW_WIFI_DATAREADY (pin_P803)
#define MICROPY_HW_WIFI_HANDSHAKE (pin_P806)

// ESP hosted control pins
#define MICROPY_HW_ESP_HOSTED_RESET (pin_P804)
#define MICROPY_HW_ESP_HOSTED_GPIO0 (pin_P803)
22 changes: 22 additions & 0 deletions ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CMSIS_MCU = RA6M5
MCU_SERIES = m33
LD_FILES = boards/ARDUINO_PORTENTA_C33/ra6m5.ld
CFLAGS += -DCFG_TUH_MAX_SPEED=OPT_MODE_FULL_SPEED \
-DCFG_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \
-DCFG_TUSB_RHPORT0_MODE=0\
-DCFG_TUSB_RHPORT1_MODE=OPT_MODE_DEVICE

# MicroPython settings
MICROPY_VFS_FAT = 1
MICROPY_HW_ENABLE_RNG = 1
MICROPY_PY_BLUETOOTH = 1
MICROPY_BLUETOOTH_NIMBLE = 1
MICROPY_BLUETOOTH_BTSTACK = 0
MICROPY_PY_LWIP = 1
MICROPY_PY_SSL = 1
MICROPY_SSL_MBEDTLS = 1
MICROPY_PY_NETWORK = 1
MICROPY_PY_NETWORK_ESP_HOSTED = 1

FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py
MBEDTLS_CONFIG_FILE = '"$(BOARD_DIR)/mbedtls_config_board.h"'
Loading

0 comments on commit 7802eed

Please sign in to comment.