From fae96b17a762608224a133067810ac461c3de14e Mon Sep 17 00:00:00 2001 From: mbedNoobNinja Date: Thu, 2 Mar 2023 18:08:31 +0200 Subject: [PATCH 1/2] renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. This commit adds support for a new processor RA6M5. It also adds the following classes to the machine module: PWM, DAC, SDCard. Signed-off-by: mbedNoobNinja --- ports/renesas-ra/Makefile | 78 +-- ports/renesas-ra/RA4M1_hal.h | 7 +- ports/renesas-ra/RA4W1_hal.h | 7 +- ports/renesas-ra/RA6M1_hal.h | 7 +- ports/renesas-ra/RA6M2_hal.h | 7 +- ports/renesas-ra/RA6M5_hal.h | 109 +++ ports/renesas-ra/README.md | 6 +- .../boards/EK_RA4M1/mpconfigboard.mk | 3 + .../boards/EK_RA4W1/mpconfigboard.mk | 2 + .../boards/EK_RA6M1/mpconfigboard.mk | 2 + .../boards/EK_RA6M2/mpconfigboard.mk | 2 + .../boards/RA4M1_CLICKER/mpconfigboard.mk | 3 + ports/renesas-ra/boards/manifest.py | 1 - ports/renesas-ra/boards/ra6m5_af.csv | 193 ++++++ ports/renesas-ra/flashbdev.c | 13 +- ports/renesas-ra/fsp_cfg/r_agt_cfg.h | 14 + ports/renesas-ra/fsp_cfg/r_dtc_cfg.h | 13 + ports/renesas-ra/fsp_cfg/r_icu_cfg.h | 12 + ports/renesas-ra/fsp_cfg/r_iic_master_cfg.h | 14 + ports/renesas-ra/fsp_cfg/r_rtc_cfg.h | 13 + ports/renesas-ra/fsp_cfg/r_sdhi_cfg.h | 19 + ports/renesas-ra/fsp_cfg/r_spi_cfg.h | 17 + ports/renesas-ra/machine_dac.c | 183 +++++ ports/renesas-ra/machine_pwm.c | 357 ++++++++++ ports/renesas-ra/machine_sdcard.c | 338 ++++++++++ ports/renesas-ra/machine_spi.c | 103 ++- ports/renesas-ra/modmachine.c | 13 + ports/renesas-ra/mpconfigboard_common.h | 46 ++ ports/renesas-ra/mpconfigport.h | 9 + ports/renesas-ra/powerctrl.c | 2 +- ports/renesas-ra/ra/ra_adc.c | 85 ++- ports/renesas-ra/ra/ra_adc.h | 61 ++ ports/renesas-ra/ra/ra_config.h | 6 + ports/renesas-ra/ra/ra_dac.c | 168 +++++ ports/renesas-ra/ra/ra_dac.h | 41 ++ ports/renesas-ra/ra/ra_flash.c | 166 ++++- ports/renesas-ra/ra/ra_flash.h | 19 + ports/renesas-ra/ra/ra_gpio.h | 62 +- ports/renesas-ra/ra/ra_gpt.c | 626 ++++++++++++++++++ ports/renesas-ra/ra/ra_gpt.h | 43 ++ ports/renesas-ra/ra/ra_i2c.c | 69 +- ports/renesas-ra/ra/ra_i2c.h | 7 + ports/renesas-ra/ra/ra_icu.c | 174 +++++ ports/renesas-ra/ra/ra_int.h | 2 +- ports/renesas-ra/ra/ra_rtc.c | 2 +- ports/renesas-ra/ra/ra_sci.c | 213 +++++- ports/renesas-ra/ra/ra_spi.c | 281 ++++++-- ports/renesas-ra/ra/ra_spi.h | 12 +- ports/renesas-ra/ra/ra_timer.c | 4 +- ports/renesas-ra/ra/ra_utils.c | 14 +- ports/renesas-ra/ra/ra_utils.h | 2 + ports/renesas-ra/spi.h | 3 - 52 files changed, 3403 insertions(+), 250 deletions(-) create mode 100644 ports/renesas-ra/RA6M5_hal.h create mode 100644 ports/renesas-ra/boards/ra6m5_af.csv create mode 100644 ports/renesas-ra/fsp_cfg/r_agt_cfg.h create mode 100644 ports/renesas-ra/fsp_cfg/r_dtc_cfg.h create mode 100644 ports/renesas-ra/fsp_cfg/r_icu_cfg.h create mode 100644 ports/renesas-ra/fsp_cfg/r_iic_master_cfg.h create mode 100644 ports/renesas-ra/fsp_cfg/r_rtc_cfg.h create mode 100644 ports/renesas-ra/fsp_cfg/r_sdhi_cfg.h create mode 100644 ports/renesas-ra/fsp_cfg/r_spi_cfg.h create mode 100644 ports/renesas-ra/machine_dac.c create mode 100644 ports/renesas-ra/machine_pwm.c create mode 100644 ports/renesas-ra/machine_sdcard.c create mode 100644 ports/renesas-ra/ra/ra_dac.c create mode 100644 ports/renesas-ra/ra/ra_dac.h create mode 100644 ports/renesas-ra/ra/ra_gpt.c create mode 100644 ports/renesas-ra/ra/ra_gpt.h diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index 7ffb3b1d0ec75..71d0a2d667bdd 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -16,41 +16,6 @@ endif # If the build directory is not given, make it reflect the board name. BUILD ?= build-$(BOARD) -ifeq ($(BOARD),RA4M1_CLICKER) -BOARD_LOW = ra4m1_ek -CMSIS_MCU_LOW = ra4m1 -CMSIS_MCU_CAP = RA4M1 -USE_FSP_LPM = 0 -endif - -ifeq ($(BOARD),EK_RA4M1) -BOARD_LOW = ra4m1_ek -CMSIS_MCU_LOW = ra4m1 -CMSIS_MCU_CAP = RA4M1 -USE_FSP_LPM = 0 -endif - -ifeq ($(BOARD),EK_RA4W1) -BOARD_LOW = ra4w1_ek -CMSIS_MCU_LOW = ra4w1 -CMSIS_MCU_CAP = RA4W1 -USE_FSP_LPM = 1 -endif - -ifeq ($(BOARD),EK_RA6M1) -BOARD_LOW = ra6m1_ek -CMSIS_MCU_LOW = ra6m1 -CMSIS_MCU_CAP = RA6M1 -USE_FSP_LPM = 1 -endif - -ifeq ($(BOARD),EK_RA6M2) -BOARD_LOW = ra6m2_ek -CMSIS_MCU_LOW = ra6m2 -CMSIS_MCU_CAP = RA6M2 -USE_FSP_LPM = 1 -endif - # select use wrapper function of FSP library USE_FSP_FLASH = 1 @@ -58,6 +23,10 @@ include ../../py/mkenv.mk -include mpconfigport.mk include $(BOARD_DIR)/mpconfigboard.mk +USE_FSP_LPM ?= 1 +USE_FSP_QSPI ?= 0 +FSP_BOARD_NAME ?= $(shell echo $(BOARD) | tr '[:upper:]' '[:lower:]') + # Files that are generated and needed before the QSTR build. #QSTR_GENERATED_HEADERS = $(BUILD)/pins_qstr.h $(BUILD)/modstm_qstr.h QSTR_GENERATED_HEADERS = $(BUILD)/pins_qstr.h @@ -101,16 +70,18 @@ INC += -I$(TOP)/$(HAL_DIR)/ra/fsp/inc/api INC += -I$(TOP)/$(HAL_DIR)/ra/fsp/inc/instances INC += -I$(TOP)/$(HAL_DIR)/ra/fsp/src/bsp/cmsis/Device/RENESAS/Include #INC += -Ilwip_inc -ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA4M1 RA4W1 RA6M1 RA6M2)) +ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA4M1 RA4W1 RA6M1 RA6M2 RA6M5)) INC += -Ira endif INC += -I$(BOARD_DIR)/ra_gen +INC += -I$(BOARD_DIR)/ra_cfg/driver INC += -I$(BOARD_DIR)/ra_cfg/fsp_cfg INC += -I$(BOARD_DIR)/ra_cfg/fsp_cfg/bsp INC += -Idebug CFLAGS += -D$(CMSIS_MCU) CFLAGS += -DRA_HAL_H='<$(CMSIS_MCU)_hal.h>' +CFLAGS += -DRA_CFG_H='<$(FSP_BOARD_NAME)_conf.h>' # Basic Cortex-M flags CFLAGS_CORTEX_M = -mthumb @@ -123,12 +94,19 @@ CFLAGS_CORTEX_M += -mfpu=fpv4-sp-d16 -mfloat-abi=hard SUPPORTS_HARDWARE_FP_SINGLE = 1 endif +ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),m33)) +CFLAGS_CORTEX_M += -mfpu=fpv5-sp-d16 -mfloat-abi=hard +SUPPORTS_HARDWARE_FP_SINGLE = 1 +endif + # Options for particular MCU series CFLAGS_MCU_RA4M1 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 CFLAGS_MCU_RA4W1 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 CFLAGS_MCU_RA6M1 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 CFLAGS_MCU_RA6M2 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 +CFLAGS_MCU_RA6M5 = $(CFLAGS_CORTEX_M) -mtune=cortex-m33 -mcpu=cortex-m33 +ASFLAGS += $(CFLAGS_CORTEX_M) -mcpu=cortex-$(MCU_SERIES) CFLAGS += $(INC) -Wall -Wpointer-arith -Werror -Wdouble-promotion -Wfloat-conversion -std=gnu99 -nostdlib $(CFLAGS_EXTRA) #CFLAGS += -D$(CMSIS_MCU) CFLAGS += $(CFLAGS_MCU_$(CMSIS_MCU)) @@ -315,11 +293,13 @@ SRC_C += \ gccollect.c \ help.c \ machine_adc.c \ + machine_dac.c \ machine_i2c.c \ machine_spi.c \ machine_uart.c \ machine_pin.c \ machine_rtc.c \ + machine_sdcard.c \ modmachine.c \ extint.c \ usrsw.c \ @@ -365,6 +345,17 @@ HAL_SRC_C += $(addprefix $(HAL_DIR)/ra/fsp/src/,\ CFLAGS_FSP = -Wno-unused-variable -Wno-unused-function $(BUILD)/lib/fsp/ra/fsp/src/r_sci_uart/r_sci_uart.o: CFLAGS += $(CFLAGS_FSP) +ifeq ($(USE_FSP_QSPI), 1) +CFLAGS += -DUSE_FSP_QSPI +HAL_SRC_C += $(HAL_DIR)/ra/fsp/src/r_qspi/r_qspi.c +endif + +ifeq ($(USE_FSP_SDHI), 1) +CFLAGS += -DUSE_FSP_SDHI +HAL_SRC_C += $(HAL_DIR)/ra/fsp/src/r_sdhi/r_sdhi.c \ + $(HAL_DIR)/ra/fsp/src/r_dtc/r_dtc.c +endif + ifeq ($(USE_FSP_LPM), 1) CFLAGS += -DUSE_FSP_LPM HAL_SRC_C += $(HAL_DIR)/ra/fsp/src/r_lpm/r_lpm.c @@ -377,16 +368,17 @@ HAL_SRC_C += $(HAL_DIR)/ra/fsp/src/r_flash_lp/r_flash_lp.c endif endif -ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA6M1 RA6M2)) +ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA6M1 RA6M2 RA6M5)) ifeq ($(USE_FSP_FLASH), 1) CFLAGS += -DUSE_FSP_FLASH HAL_SRC_C += $(HAL_DIR)/ra/fsp/src/r_flash_hp/r_flash_hp.c endif endif -ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA4M1 RA4W1 RA6M1 RA6M2)) +ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA4M1 RA4W1 RA6M1 RA6M2 RA6M5)) HAL_SRC_C += $(addprefix ra/,\ ra_adc.c \ + ra_dac.c \ ra_flash.c \ ra_gpio.c \ ra_i2c.c \ @@ -397,6 +389,7 @@ HAL_SRC_C += $(addprefix ra/,\ ra_sci.c \ ra_spi.c \ ra_timer.c \ + ra_gpt.c \ ra_utils.c \ ) @@ -413,6 +406,12 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_O)) OBJ += $(BUILD)/pins_$(BOARD).o +ifeq ($(CMSIS_MCU),RA6M5) +$(BUILD)/shared/runtime/gchelper_thumb2.o: $(TOP)/shared/runtime/gchelper_thumb2.s + $(ECHO) "AS $<" + $(Q)$(AS) $(ASFLAGS) -o $@ $< +endif + # This file contains performance critical functions so turn up the optimisation # level. It doesn't add much to the code size and improves performance a bit. # Don't use -O3 with this file because gcc tries to optimise memset in terms of itself. @@ -486,6 +485,9 @@ endif ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA6M2)) AF_FILE = boards/ra6m2_af.csv endif +ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA6M5)) +AF_FILE = boards/ra6m5_af.csv +endif GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c GEN_PINS_HDR = $(HEADER_BUILD)/pins.h GEN_PINS_QSTR = $(BUILD)/pins_qstr.h diff --git a/ports/renesas-ra/RA4M1_hal.h b/ports/renesas-ra/RA4M1_hal.h index 7f0ad9666f47b..bdfa8cc75cf73 100644 --- a/ports/renesas-ra/RA4M1_hal.h +++ b/ports/renesas-ra/RA4M1_hal.h @@ -31,8 +31,11 @@ // #include "hal_data.h" #include "bsp_api.h" #include "common_data.h" +#if defined(USE_DBG_PRINT) +#include RA_CFG_H +#endif -#define SCI_CH 0 +#define SCI_CH DEFAULT_DBG_CH #define SCI_BAUD 115200 #define UART_CH SCI_CH #define UART_TxStr sci_tx_str @@ -56,8 +59,10 @@ #include "ra_config.h" #include "ra_adc.h" +#include "ra_dac.h" #include "ra_flash.h" #include "ra_gpio.h" +#include "ra_gpt.h" #include "ra_i2c.h" #include "ra_icu.h" #include "ra_init.h" diff --git a/ports/renesas-ra/RA4W1_hal.h b/ports/renesas-ra/RA4W1_hal.h index 774ec46b38196..930127c459114 100644 --- a/ports/renesas-ra/RA4W1_hal.h +++ b/ports/renesas-ra/RA4W1_hal.h @@ -31,8 +31,11 @@ // #include "hal_data.h" #include "bsp_api.h" #include "common_data.h" +#if defined(USE_DBG_PRINT) +#include RA_CFG_H +#endif -#define SCI_CH 0 +#define SCI_CH DEFAULT_DBG_CH #define SCI_BAUD 115200 #define UART_CH SCI_CH #define UART_TxStr sci_tx_str @@ -56,8 +59,10 @@ #include "ra_config.h" #include "ra_adc.h" +#include "ra_dac.h" #include "ra_flash.h" #include "ra_gpio.h" +#include "ra_gpt.h" #include "ra_i2c.h" #include "ra_icu.h" #include "ra_init.h" diff --git a/ports/renesas-ra/RA6M1_hal.h b/ports/renesas-ra/RA6M1_hal.h index 9929d29b5462a..6721a6fdb2b44 100644 --- a/ports/renesas-ra/RA6M1_hal.h +++ b/ports/renesas-ra/RA6M1_hal.h @@ -31,8 +31,11 @@ // #include "hal_data.h" #include "bsp_api.h" #include "common_data.h" +#if defined(USE_DBG_PRINT) +#include RA_CFG_H +#endif -#define SCI_CH 0 +#define SCI_CH DEFAULT_DBG_CH #define SCI_BAUD 115200 #define UART_CH SCI_CH #define UART_TxStr sci_tx_str @@ -56,8 +59,10 @@ #include "ra_config.h" #include "ra_adc.h" +#include "ra_dac.h" #include "ra_flash.h" #include "ra_gpio.h" +#include "ra_gpt.h" #include "ra_i2c.h" #include "ra_icu.h" #include "ra_init.h" diff --git a/ports/renesas-ra/RA6M2_hal.h b/ports/renesas-ra/RA6M2_hal.h index 75877cc0f6052..ffecacd2bab8b 100644 --- a/ports/renesas-ra/RA6M2_hal.h +++ b/ports/renesas-ra/RA6M2_hal.h @@ -31,8 +31,11 @@ // #include "hal_data.h" #include "bsp_api.h" #include "common_data.h" +#if defined(USE_DBG_PRINT) +#include RA_CFG_H +#endif -#define SCI_CH 0 +#define SCI_CH DEFAULT_DBG_CH #define SCI_BAUD 115200 #define UART_CH SCI_CH #define UART_TxStr sci_tx_str @@ -56,8 +59,10 @@ #include "ra_config.h" #include "ra_adc.h" +#include "ra_dac.h" #include "ra_flash.h" #include "ra_gpio.h" +#include "ra_gpt.h" #include "ra_i2c.h" #include "ra_icu.h" #include "ra_init.h" diff --git a/ports/renesas-ra/RA6M5_hal.h b/ports/renesas-ra/RA6M5_hal.h new file mode 100644 index 0000000000000..2e58dcb41db0f --- /dev/null +++ b/ports/renesas-ra/RA6M5_hal.h @@ -0,0 +1,109 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Renesas Electronics Corporation + * Copyright (c) 2023 Vekatech Ltd. + * + * 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. + */ + +#ifndef PORTS_RA_RA6M5_HAL_H_ +#define PORTS_RA_RA6M5_HAL_H_ + +#include +#include +#include +// #include "hal_data.h" +#include "bsp_api.h" +#include "common_data.h" +#if defined(USE_DBG_PRINT) +#include RA_CFG_H +#endif + +#define SCI_CH DEFAULT_DBG_CH +#define SCI_BAUD 115200 +#define UART_CH SCI_CH +#define UART_TxStr sci_tx_str +#define PCLK 100000000 + +#define RA_PRI_SYSTICK (0) +#define RA_PRI_UART (1) +#define RA_PRI_SDIO (4) +#define RA_PRI_DMA (5) +#define RA_PRI_FLASH (6) +#define RA_PRI_OTG_FS (6) +#define RA_PRI_OTG_HS (6) +#define RA_PRI_TIM5 (6) +#define RA_PRI_CAN (7) +#define RA_PRI_SPI (8) +#define RA_PRI_I2C (8) +#define RA_PRI_TIMX (13) +#define RA_PRI_EXTINT (14) +#define RA_PRI_PENDSV (15) +#define RA_PRI_RTC_WKUP (15) + +#include "ra_config.h" +#include "ra_adc.h" +#include "ra_dac.h" +#include "ra_flash.h" +#include "ra_gpio.h" +#include "ra_gpt.h" +#include "ra_i2c.h" +#include "ra_icu.h" +#include "ra_init.h" +#include "ra_int.h" +#include "ra_rtc.h" +#include "ra_sci.h" +#include "ra_spi.h" +#include "ra_timer.h" +#include "ra_utils.h" + +typedef enum { + HAL_OK = 0x00, + HAL_ERROR = 0x01, + HAL_BUSY = 0x02, + HAL_TIMEOUT = 0x03 +} HAL_StatusTypeDef; + +#define __IO volatile + +#if defined(USE_DBG_PRINT) +#if !defined(DEBUG_CH) +#define DEBUG_CH SCI_CH +#endif +#if (DEBUG_CH == 6) +#define DEBUG_TX_PIN P506 +#define DEBUG_RX_PIN P505 +#endif +#if (DEBUG_CH == 7) +#define DEBUG_TX_PIN P613 +#define DEBUG_RX_PIN P614 +#endif +#if (DEBUG_CH == 9) +#define DEBUG_TX_PIN P109 +#define DEBUG_RX_PIN P110 +#endif +#define DEBUG_TXSTR(s) ra_sci_tx_str(DEBUG_CH, (unsigned char *)s) +#define DEBUG_TXCH(c) ra_sci_tx_ch(DEBUG_CH, c) +#else +#define DEBUG_TXSTR(s) +#define DEBUG_TXCH(c) +#endif + +#endif /* PORTS_RA_RA6M5_HAL_H_ */ diff --git a/ports/renesas-ra/README.md b/ports/renesas-ra/README.md index 1e5e2ed0cf48d..4cd116a37f9eb 100644 --- a/ports/renesas-ra/README.md +++ b/ports/renesas-ra/README.md @@ -6,9 +6,9 @@ Currently supported features are: - Filesystem on the internal flash using FatFs. - `time` module with sleep, time, and ticks functions. - `os` module with VFS support. -- `machine` module with the following classes: `Pin`, `ADC`, `I2C`, `SPI`, - `SoftI2C`, `SoftSPI`, `UART`, `RTC` -- sdcard driver if frozen driver is installed. +- `machine` module with the following classes: `Pin`, `ADC`, `PWM`, `DAC`, `I2C`, + `SPI`, `SoftI2C`, `SoftSPI`, `UART`, `RTC`, `SDCard`. +- `sdcard` module for MCUs without native `machine.SDCard` support. Currently supported board product names are: diff --git a/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.mk b/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.mk index abc111d16e31e..71c004df81136 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.mk +++ b/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.mk @@ -4,6 +4,9 @@ LD_FILES = boards/EK_RA4M1/ra4m1_ek.ld # MicroPython settings MICROPY_VFS_FAT = 1 +USE_FSP_LPM = 0 + +CFLAGS+=-DDEFAULT_DBG_CH=0 # Don't include default frozen modules because MCU is tight on flash space FROZEN_MANIFEST ?= boards/EK_RA4M1/manifest.py diff --git a/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.mk b/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.mk index c4f95f79f4bb1..3a064e0e3545b 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.mk +++ b/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.mk @@ -4,3 +4,5 @@ LD_FILES = boards/EK_RA4W1/ra4w1_ek.ld # MicroPython settings MICROPY_VFS_FAT = 1 + +CFLAGS+=-DDEFAULT_DBG_CH=0 diff --git a/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.mk b/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.mk index 3f916eb8e3a4b..645daedc7b7f4 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.mk +++ b/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.mk @@ -4,3 +4,5 @@ LD_FILES = boards/EK_RA6M1/ra6m1_ek.ld # MicroPython settings MICROPY_VFS_FAT = 1 + +CFLAGS+=-DDEFAULT_DBG_CH=0 diff --git a/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.mk b/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.mk index a48ec6e50a878..983cbed119002 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.mk +++ b/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.mk @@ -4,3 +4,5 @@ LD_FILES = boards/EK_RA6M2/ra6m2_ek.ld # MicroPython settings MICROPY_VFS_FAT = 1 + +CFLAGS+=-DDEFAULT_DBG_CH=0 diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.mk b/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.mk index 1758ce67388d3..5d845d93c5178 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.mk +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.mk @@ -4,6 +4,9 @@ LD_FILES = boards/RA4M1_CLICKER/ra4m1_clicker.ld # MicroPython settings MICROPY_VFS_FAT = 1 +USE_FSP_LPM = 0 + +CFLAGS+=-DDEFAULT_DBG_CH=0 # Don't include default frozen modules because MCU is tight on flash space FROZEN_MANIFEST ?= boards/RA4M1_CLICKER/manifest.py diff --git a/ports/renesas-ra/boards/manifest.py b/ports/renesas-ra/boards/manifest.py index c650136f6648c..94457a4696286 100644 --- a/ports/renesas-ra/boards/manifest.py +++ b/ports/renesas-ra/boards/manifest.py @@ -1,4 +1,3 @@ include("$(MPY_DIR)/extmod/asyncio") require("dht") require("onewire") -require("sdcard") diff --git a/ports/renesas-ra/boards/ra6m5_af.csv b/ports/renesas-ra/boards/ra6m5_af.csv new file mode 100644 index 0000000000000..816a0c5001dae --- /dev/null +++ b/ports/renesas-ra/boards/ra6m5_af.csv @@ -0,0 +1,193 @@ +CPU_PIN,PORT_IDX,PORT_BIT,Analog,IRQ,AF0,AF1,AF2,AF3,AF4,AF5,AF6,AF7,AF8,AF9,AF10,AF11,AF12,AF13,AF14,AF15,AF16,AF17,AF18,AF19,AF20,AF21,AF22,AF23,AF24,AF25,AF26,AF27,AF28,AF29, +P000,0,0,AN000,IRQ6-DS,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P001,0,1,AN001,IRQ7-DS,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P002,0,2,AN002,IRQ8-DS,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P003,0,3,AN003,,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P004,0,4,AN004,IRQ9-DS,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P005,0,5,AN005,IRQ10-DS,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P006,0,6,AN006,IRQ11-DS,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P007,0,7,AN007,,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P008,0,8,AN008,IRQ12-DS,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P009,0,9,AN009,IRQ13-DS,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P010,0,10,AN010,IRQ14,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,0,11,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,0,12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,0,13,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P014,0,14,AN012,,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P015,0,15,AN013,IRQ13,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P100,1,0,,IRQ2,Hi-Z,AGTIO0,GTETRGA,GTIOC5B,RXD0/MISO0/SCL0,SCK1,MISOB_A,,,,,D00[A00/D00],,,,,,QSPCLK,,,,,,,,,,,OM_SCLK,, +P101,1,1,,IRQ1,Hi-Z,AGTEE0,GTETRGB,GTIOC5A,TXD0/MOSI0/SDA0,CTS1_RTS1/SS1,MOSIB_A,,,,,D01[A01/D01],,,,,,QIO1,,,,,,,,,,,OM_SIO7,, +P102,1,2,,,Hi-Z,AGTO0,GTOWLO,GTIOC2B,SCK0,,RSPCKB_A,,,,ADTRG0,D02[A02/D02],,,,,CRX0,QIO0,,,,,,,,,,,OM_SIO1,, +P103,1,3,,,Hi-Z,AGTIO2,GTOWUP,GTIOC2A,CTS0_RTS0/SS0,,SSLB0_A,,,,,D03[A03/D03],,,,,CTX0,QIO3,,,,,,,,,,,OM_SIO6,, +P104,1,4,,IRQ1,Hi-Z,AGTEE2,GTETRGB,GTIOC1B,RXD8/MISO8/SCL8,,SSLB1_A,,,,,D04[A04/D04],,,,,,QIO2,,,,,,,,,,,OM_DQS,, +P105,1,5,,IRQ0,Hi-Z,AGTO2,GTETRGA,GTIOC1A,TXD8/MOSI8/SDA8,,SSLB2_A,,,,,D05[A05/D05],,,,,,,,,,,,,,,,,OM_SIO5,, +P106,1,6,,,Hi-Z,AGTOB0,,GTIOC8B,SCK8,,SSLB3_A,,,,,D06[A06/D06],,,,,,,,,,,,,,,,,OM_SIO0,, +P107,1,7,,,Hi-Z,AGTOA0,,GTIOC8A,CTS8_RTS8/SS8,,,,,,,D07[A07/D07],,,,,,,,,,,,,,,,,OM_SIO3,, +P108,1,8,,,TMS/SWDIO,AGTOA3,GTOULO,GTIOC0B,,CTS9_RTS9/SS9,SSLA0_B,,,,,,,,,,,,,,,,,,,,,,,, +P109,1,9,,,TDO/SWO,AGTOB3,GTOVUP,GTIOC1A,,TXD9/MOSI9/SDA9,MOSIA_B,,,CLKOUT,,,,,,,CTX1,,,,,,,,,,,,,, +P110,1,10,,IRQ3,TDI,AGTEE3,GTOVLO,GTIOC1B,CTS2_RTS2/SS2,RXD9/MISO9/SCL9,MISOA_B,,,,,,,,,,CRX1,,,,,,,,,,,,,, +P111,1,11,,IRQ4,Hi-Z,AGTOA5,,GTIOC3A,SCK2,SCK9,RSPCKA_B,,,,,A05,,,,,,,,,,,,,,,,,,, +P112,1,12,,,Hi-Z,AGTOB5,,GTIOC3B,TXD2/MOSI2/SDA2/TXDX2/SIOX2,SCK1,SSLA0_B,,,,,A04,,,,,,QSSL,SSIBCK0_B,,,,,,,,,,OM_CS1,, +P113,1,13,,,Hi-Z,AGTEE5,,GTIOC2A,RXD2/MISO2/SCL2/RXDX2,,,,,,,A03,,,,,,,SSILRCK0/SSIFS0_B,,,,,,,,,,,, +P114,1,14,,,Hi-Z,AGTIO5,,GTIOC2B,,CTS9,,,,,,A02,,,,,,,SSIRXD0_B,,,,,,,,,,,, +P115,1,15,,,Hi-Z,,,GTIOC4A,,,,,,,,A01,,,,,,,SSITXD0_B,,,,,,,,,,,, +P200,2,0,,NMI,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P201,2,1,,,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P202,2,2,,IRQ3-DS,Hi-Z,AGTOB3,,GTIOC5B,SCK2,RXD9/MISO9/SCL9,MISOA_A,,,,,WR1/BC1,TS19,,,,CRX0,,,,,SD0DAT6_A,ET0_ERXD2,,,,,,,, +P203,2,3,,IRQ2-DS,Hi-Z,AGTOA3,,GTIOC5A,CTS2_RTS2/SS2,TXD9/MOSI9/SDA9,MOSIA_A,,,,,A19,TS18,,,,CTX0,,,,,SD0DAT5_A,ET0_COL,,,,,,,, +P204,2,4,,,Hi-Z,AGTIO1,GTIW,GTIOC4B,SCK4,SCK9,RSPCKA_A,,,,CACREF,A18,TS00,,,,,,SSIBCK0_C,USB_OVRCURB-DS,,SD0DAT4_A,ET0_RX_DV,,,,,,,, +P205,2,5,,IRQ1-DS,Hi-Z,AGTO1,GTIV,GTIOC4A,TXD4/MOSI4/SDA4,CTS9_RTS9/SS9,SSLA0_A,SCL1_B,,CLKOUT,,A16,TS01,,,,,,SSILRCK0/SSIFS0_C,USB_OVRCURA-DS,,SD0DAT3_A,ET0_WOL,ET0_WOL,,,,,,, +P206,2,6,,IRQ0-DS,Hi-Z,,GTIU,,RXD4/MISO4/SCL4,CTS9,SSLA1_A,SDA1_B,,,,WAIT,TS02,,,,,,SSIDATA0_C,USB_VBUSEN,,SD0DAT2_A,ET0_LINKSTA,ET0_LINKSTA,,,,,,CECIO_B, +P207,2,7,,,Hi-Z,,,,TXD4/MOSI4/SDA4,,SSLA2_A,,,,,A17,TSCAP,,,,,QSSL,,,,,,,,,,,,, +P208,2,8,,,Hi-Z,,GTOVLO,,,,,,,,,CS4,,,,,,QIO3,,,,SD0DAT0_B,ET0_LINKSTA,ET0_LINKSTA,,,TDATA3,,,, +P209,2,9,,,Hi-Z,AGTEE5,GTOVUP,,,,,,,,,CS5,,,,,,QIO2,,,,SD0WP,ET0_EXOUT,ET0_EXOUT,,,TDATA2,,,, +P210,2,10,,,Hi-Z,AGTOB5,GTIW,,,,,,,,,CS6,,,,,,QIO1,,,,SD0CD,ET0_WOL,ET0_WOL,,,TDATA1,,,, +P211,2,11,,,Hi-Z,AGTOA5,GTIV,,,,,,,,,CS7,,,,,,QIO0,,,,SD0CMD_B,ET0_MDIO,ET0_MDIO,,,TDATA0,,,, +P212,2,12,,IRQ3,Hi-Z,AGTEE1,GTETRGD,GTIOC0B,,RXD1/MISO1/SCL1/RXDX1,,,,,,,,,,,,,,,,,,,,,,,,, +P213,2,13,,IRQ2,Hi-Z,AGTEE2,GTETRGC,GTIOC0A,,TXD1/MOSI1/SDA1/TXDX1/SIOX1,,,,,ADTRG1,,,,,,,,,,,,,,,,,,,, +P214,2,14,,,Hi-Z,AGTO5,GTIU,,,,,,,,,,,,,,,QSPCLK,,,,SD0CLK_B,ET0_MDC,ET0_MDC,,,TCLK,,,, +-,2,15,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P300,3,0,,,TCK/SWCLK,,GTOUUP,GTIOC0A,,,SSLA1_B,,,,,,,,,,,,,,,,,,,,,,,, +P301,3,1,,IRQ6,Hi-Z,AGTIO0,GTOULO,GTIOC4B,RXD2/MISO2/SCL2/RXDX2,CTS9_RTS9/SS9,SSLA2_B,,,,,A06,,,,,,,,,,,,,,,,,,, +P302,3,2,,IRQ5,Hi-Z,,GTOUUP,GTIOC4A,TXD2/MOSI2/SDA2/TXDX2/SIOX2,,SSLA3_B,,,,,A07,,,,,,,,,,,,,,,,,,, +P303,3,3,,,Hi-Z,,,GTIOC7B,,CTS9,,,,,,A08,,,,,,,,,,,,,,,,,,, +P304,3,4,,IRQ9,Hi-Z,AGTEE2,GTOWLO,GTIOC7A,RXD6/MISO6/SCL6,,,,,,,A09,,,,,,,,,,,,,,,,,,, +P305,3,5,,IRQ8,Hi-Z,AGTOB2,GTOWUP,,TXD6/MOSI6/SDA6,,,,,,,A10,,,,,,QSPCLK,,,,,,,,,,,,, +P306,3,6,,,Hi-Z,AGTOA2,GTOULO,,SCK6,,,,,,,A11,,,,,,QSSL,,,,,,,,,,,,, +P307,3,7,,,Hi-Z,AGTEE4,GTOUUP,,CTS6_RTS6/SS6,,,,,,,A12,,,,,,QIO0,,,,,,,,,,,,, +P308,3,8,,,Hi-Z,AGTOB4,,,CTS6,CTS3,,,,,,A13,,,,,,QIO1,,,,,,,,,,,,, +P309,3,9,,,Hi-Z,AGTOA4,,,,RXD3/MISO3/SCL3,,,,,,A14,,,,,,QIO2,,,,,,,,,,,,, +P310,3,10,,,Hi-Z,AGTEE1,,,,TXD3/MOSI3/SDA3,,,,,,A15,,,,,,QIO3,,,,,,,,,,,,, +P311,3,11,,,Hi-Z,AGTOB1,,,,SCK3,,,,,,CS2,,,,,,,,,,,,,,,,,,, +P312,3,12,,,Hi-Z,AGTOA1,,,,CTS3_RTS3/SS3,,,,,,CS3,,,,,,,,,,,,,,,,,,, +P313,3,13,,,Hi-Z,,,,,,,,,,,A20,,,,,,,,,,SD0DAT7_A,ET0_ERXD3,,,,,,,, +P314,3,14,,,Hi-Z,,,,,,ADTRG0,,,,,A21,,,,,,,,,,,,,,,,,,, +P315,3,15,,,Hi-Z,,,,RXD4,,,,,,,A22,,,,,,,,,,,,,,,,,,, +P400,4,0,,IRQ0,Hi-Z,AGTIO1,,GTIOC6A,SCK4,SCK7,,SCL0_A,,,ADTRG1,,,,,,,,AUDIO_CLK,,,,ET0_WOL,ET0_WOL,,,,,,, +P401,4,1,,IRQ5-DS,Hi-Z,,GTETRGA,GTIOC6B,CTS4_RTS4/SS4,TXD7/MOSI7/SDA7,,SDA0_A,,,,,,,,,CTX0,,,,,,ET0_MDC,ET0_MDC,,,,,,, +P402,4,2,,IRQ4-DS,Hi-Z,,,,CTS4,RXD7/MISO7/SCL7,,,,,CACREF,,,,,,CRX0,,AUDIO_CLK,,,,ET0_MDIO,ET0_MDIO,,,,,,, +P403,4,3,,IRQ14-DS,Hi-Z,,,GTIOC3A,,CTS7_RTS7/SS7,,,,,,,,,,,,,SSIBCK0_A,,,,ET0_LINKSTA,ET0_LINKSTA,,,,,,, +P404,4,4,,IRQ15-DS,Hi-Z,,,GTIOC3B,,CTS7,,,,,,,,,,,,,SSILRCK0/SSIFS0_A,,,,ET0_EXOUT,ET0_EXOUT,,,,,,, +P405,4,5,,,Hi-Z,,,GTIOC1A,,,,,,,,,,,,,,,SSITXD0_A,,,,ET0_TX_EN,RMII0_TXD_EN_B,,,,,,, +P406,4,6,,,Hi-Z,AGTO5,,GTIOC1B,,,SSLA3_C,,,,,,,,,,,,SSIRXD0_A,,,,ET0_RX_ER,RMII0_TXD1_B,,,,,,, +P407,4,7,,,Hi-Z,AGTIO0,,GTIOC6A,CTS4_RTS4/SS4,,SSLA3_A,SDA0_B,,RTCOUT,ADTRG0,,TS03,,,,,,,USB_VBUS,,,ET0_EXOUT,ET0_EXOUT,,,,,,, +P408,4,8,,IRQ7,Hi-Z,AGTOB2,GTOWLO,GTIOC6B,CTS4,RXD3/MISO3/SCL3,,SCL0_B,,,,,TS04,,,,,,,USB_ID,USBHS_ID,,ET0_CRS,RMII0_CRS_DV_A,,,,,,, +P409,4,9,,IRQ6,Hi-Z,AGTOA2,GTOWUP,,,TXD3/MOSI3/SDA3,,SDA2_A,,,,,TS05,,,,,,,USB_EXICEN,USBHS_EXICEN,,ET0_RX_CLK,RMII0_RX_ER_A,,,,,,, +P410,4,10,,IRQ5,Hi-Z,AGTOB1,GTOVLO,GTIOC9B,RXD0/MISO0/SCL0,SCK3,MISOB_B,SCL2_A,,,,,TS06,,,,,,,,,SD0DAT1_A,ET0_ERXD0,RMII0_RXD1_A,,,,,,, +P411,4,11,,IRQ4,Hi-Z,AGTOA1,GTOVUP,GTIOC9A,TXD0/MOSI0/SDA0,CTS3_RTS3/SS3,MOSIB_B,,,,,,TS07,,,,,,,,,SD0DAT0_A,ET0_ERXD1,RMII0_RXD0_A,,,,,,, +P412,4,12,,,Hi-Z,AGTEE1,GTOULO,,SCK0,CTS3,RSPCKB_B,,,,,,TS08,,,,,,,,,SD0CMD_A,ET0_ETXD0,REF50CK0_A,,,,,,, +P413,4,13,,,Hi-Z,AGTEE3,GTOUUP,,CTS0_RTS0/SS0,,SSLB0_B,,,,,,TS09,,,,,,,,,SD0CLK_A,ET0_ETXD1,RMII0_TXD0_A,,,,,,, +P414,4,14,,IRQ9,Hi-Z,AGTIO5,,GTIOC0B,CTS0,,SSLB1_B,SDA2_B,,,,,TS10,,,,,,,,,SD0WP,ET0_RX_ER,RMII0_TXD1_A,,,,,,, +P415,4,15,,IRQ8,Hi-Z,AGTIO4,,GTIOC0A,,,SSLB2_B,SCL2_B,,,,,TS11,,,,,,,USB_VBUSEN,,SD0CD,ET0_TX_EN,RMII0_TXD_EN_A,,,,,,, +P500,5,0,AN116,,Hi-Z,AGTOA0,GTIU,,,CTS5,,,,,CACREF,,,,,,,QSPCLK,,USB_VBUSEN,,,,,,,,,,, +P501,5,1,AN117,IRQ11,Hi-Z,AGTOB0,GTIV,,,TXD5/MISO5/SDA5,,,,,,,,,,,,QSSL,,USB_OVRCURA,,,,,,,,,,, +P502,5,2,AN118,IRQ12,Hi-Z,AGTOA2,GTIW,,CTS6,RXD5/MISO5/SCL5,,,,,,,,,,,,QIO0,,USB_OVRCURB,,,,,,,,,,, +P503,5,3,AN119,,Hi-Z,AGTOB2,GTETRGC,,CTS6_RTS6/SS6,SCK5,,,,,,,,,,,,QIO1,,USB_EXICEN,,,,,,,,,,, +P504,5,4,AN120,,Hi-Z,AGTOA3,GTETRGD,,SCK6,CTS5_RTS5/SS5,,,,,,ALE,,,,,,QIO2,,USB_ID,,,,,,,,,,, +P505,5,5,AN121,IRQ14,Hi-Z,AGTOB3,,,RXD6/MISO6/SCL6,,,,,,,,,,,,,QIO3,,,,,,,,,,,,, +P506,5,6,AN122,IRQ15,Hi-Z,,,,TXD6/MOSI6/SDA6,,,,,,,,,,,,,,,,,,,,,,,,,, +P507,5,7,AN123,,Hi-Z,,,,SCK6,SCK5,,,,,,,,,,,,,,,,,,,,,,,,, +P508,5,8,AN124,,Hi-Z,,,,,CTS5_RTS5,,,,,,,,,,,,,,,,,,,,,,,,, +-,5,9,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,5,10,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P511,5,11,,IRQ15,Hi-Z,,,GTIOC0B,RXD4/MISO4/SCL4,,,SDA1_A,,,,,,,,,CRX1,,,,,,,,,,,,,, +P512,5,12,,IRQ14,Hi-Z,,,GTIOC0A,TXD4/MOSI4/SDA4,,,SCL1_A,,,,,,,,,CTX1,,,,,,,,,,,,,, +P513,5,13,,,Hi-Z,,,,,RXD5,,,,,,,,,,,,,,,,,,,,,,,,, +-,5,14,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,5,15,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P600,6,0,,,Hi-Z,AGTIO3,,GTIOC6B,,SCK9,,,,CLKOUT,CACREF,RD,,,,,,,,,,,,,,,,,OM_SIO4,, +P601,6,1,,,Hi-Z,AGTEE3,,GTIOC6A,,RXD9/MISO9/SCL9,,,,,,WR/WR0,,,,,,,,,,,,,,,,,OM_SIO2,, +P602,6,2,,,Hi-Z,AGTO3,,GTIOC7B,,TXD9/MOSI9/SDA9,,,,,,EBCLK,,,,,,,,,,,,,,,,,OM_CS1,, +P603,6,3,,,Hi-Z,AGTIO4,,GTIOC7A,,CTS9_RTS9/SS9,,,,,,D13[A13/D13],,,,,,,,,,,,,,,,,,, +P604,6,4,,,Hi-Z,AGTEE4,,GTIOC8B,,CTS9,,,,,,D12[A12/D12],,,,,,,,,,,,,,,,,,, +P605,6,5,,,Hi-Z,AGTO4,,GTIOC8A,CTS8,,,,,,,D11[A11/D11],,,,,,,,,,,,,,,,,,, +P606,6,6,,,Hi-Z,,,,CTS8_RTS8,,,,,RTCOUT,,,,,,,,,,,,,,,,,,,,, +P607,6,7,,,Hi-Z,,,,RXD8,,,,,,,,,,,,,,,,,,,,,,,,,, +P608,6,8,,,Hi-Z,,,GTIOC4B,,,,,,,,A00/BC0,,,,,,,,,,,,,,,,,,, +P609,6,9,,,Hi-Z,AGTO5,,GTIOC5A,,,,,,,,CS1,,,,,CTX1,,,,,,,,,,,,OM_ECS,, +P610,6,10,,,Hi-Z,AGTO4,,GTIOC5B,,CTS7,,,,,,CS0,,,,,CRX1,,,,,,,,,,,,OM_CS0,, +P611,6,11,,,Hi-Z,AGTO3,,,,CTS7_RTS7/SS7,,,,CLKOUT,CACREF,,,,,,,,,,,,,,,,,,,, +P612,6,12,,,Hi-Z,AGTO2,,,,SCK7,,,,,,D08[A08/D08],,,,,,,,,,,,,,,,,,, +P613,6,13,,,Hi-Z,AGTO1,,,,TXD7,,,,,,D09[A09/D09],,,,,,,,,,,,,,,,,,, +P614,6,14,,,Hi-Z,AGTO0,,,,RXD7,,,,,,D10[A10/D10],,,,,,,,,,,,,,,,,,, +P615,6,15,,IRQ7,Hi-Z,,,,,,,,,,,,,,,,,,,USB_VBUSEN,,,,,,,,,,, +P700,7,0,,,Hi-Z,AGTO4,,GTIOC5A,,,MISOA_C,,,,,,,,,,,,,,,,ET0_ETXD1,RMII0_TXD0_B,,,,,,, +P701,7,1,,,Hi-Z,AGTO3,,GTIOC5B,,,MOSIA_C,,,,,,,,,,,,,,,,ET0_ETXD0,REF50CK0_B,,,,,,, +P702,7,2,,,Hi-Z,AGTO2,,GTIOC6A,,,RSPCKA_C,,,,,,,,,,,,,,,,ET0_ERXD1,RMII0_RXD0_B,,,,,,, +P703,7,3,,,Hi-Z,AGTO1,,GTIOC6B,,,SSLA0_C,,,,,,,,,,,,,,,,ET0_ERXD0,RMII0_RXD1_B,,,,,,, +P704,7,4,,,Hi-Z,AGTO0,,,,,SSLA1_C,,,,,,,,,,CTX0,,,,,,ET0_RX_CLK,RMII0_RX_ER_B,,,,,,, +P705,7,5,,,Hi-Z,AGTIO0,,,,CTS3,SSLA2_C,,,,,,,,,,CRX0,,,,,,ET0_CRS,RMII0_CRS_DV_B,,,,,,, +P706,7,6,,IRQ7,Hi-Z,,,,,RXD3,,,,,,,,,,,,,,,USBHS_OVRCURB,,,,,,,,,, +P707,7,7,,IRQ8,Hi-Z,,,,,TXD3,,,,,,,,,,,,,,,USBHS_OVRCURA,,,,,,,,,, +P708,7,8,,IRQ11,Hi-Z,,,,,RXD1/MISO1/SCL1/RXDX1/SCL1,SSLB3_B,,,,CACREF,,TS12,,,,,,AUDIO_CLK,,,,ET0_ETXD3,,,,,,,CECIO_A, +P709,7,9,,IRQ10,Hi-Z,,,,,TXD1/MOSI1/SDA1/TXDX1/SIOX1/SDA1,,,,,,,TS13,,,,,,,,,,ET0_ETXD2,,,,,,,, +P710,7,10,,,Hi-Z,,,,,SCK1,,,,,,,TS14,,,,,,,,,,ET0_TX_ER,,,,,,,, +P711,7,11,,,Hi-Z,AGTEE0,,,,CTS1_RTS1/SS1,,,,,,,TS15,,,,,,,,,,ET0_TX_CLK,,,,,,,, +P712,7,12,,,Hi-Z,AGTOB0,,GTIOC2B,,,,,,,,,TS16,,,,,,,,,,,,,,,,,, +P713,7,13,,,Hi-Z,AGTOA0,,GTIOC2A,,,,,,,,,TS17,,,,,,,,,,,,,,,,,, +-,7,14,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,7,15,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P800,8,0,AN125,,Hi-Z,AGTOA4,,,CTS0,,,,,,,D14[A14/D14],,,,,,,,,,,,,,,,,,, +P801,8,1,AN126,,Hi-Z,AGTOB4,,,CTS8,,,,,,,D15[A15/D15],,,,,,,,,,,,,,,,,,, +P802,8,2,AN127,IRQ3,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P803,8,3,AN128,IRQ2,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P804,8,4,,IRQ1,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P805,8,5,,,Hi-Z,,,,,TXD5,,,,,,,,,,,,,,,,,,,,,,,,, +P806,8,6,,IRQ0,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,8,7,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,8,8,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,8,9,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,8,10,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,8,11,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,8,12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,8,13,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,8,14,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,8,15,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P900,9,0,,,Hi-Z,,,,TXD4,,,,,,,A23,,,,,,,,,,,,,,,,,,, +P901,9,1,,,Hi-Z,AGTIO,,,SCK4,,,,,,,,,,,,,,,,,,,,,,,,,, +-,9,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,9,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,9,4,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +P905,9,5,,IRQ8,Hi-Z,,,,,,,,,,,,,,,,,,,USB_ID,,,,,,,,,,, +P906,9,6,,IRQ9,Hi-Z,,,,,,,,,,,,,,,,,,,USB_EXICEN,,,,,,,,,,, +P907,9,7,,IRQ10,Hi-Z,,,,,,,,,,,,,,,,,,,,USBHS_ID,,,,,,,,,, +P908,9,8,,IRQ11,Hi-Z,,,,,,,,,,,,,,,,,,,,USBHS_EXICEN,,,,,,,,,, +-,9,9,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,9,10,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,9,11,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,9,12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,9,13,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,9,14,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,9,15,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +PA00,A,0,,,Hi-Z,,,,TXD8,,,,,,,,,,,,,,,,,,,,,,,,,, +PA01,A,1,,,Hi-Z,,,,SCK8,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,4,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,6,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,7,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +PA08,A,8,,IRQ6,Hi-Z,,,,,,,,,,,,,,,,,,,USB_OVRCURA,,,,,,,,,,, +PA09,A,9,,IRQ5,Hi-Z,,,,,,,,,,,,,,,,,,,USB_OVRCURB,,,,,,,,,,, +PA10,A,10,,IRQ4,Hi-Z,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,11,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,13,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,14,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,A,15,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +PB00,B,0,,,Hi-Z,,,,,SCK3,,,,,,,,,,,,,,,USBHS_VBUSEN,,,,,,,,,, +PB01,B,1,,,Hi-Z,,,,,CTS3_RTS3,,,,,,,,,,,,,,,USBHS_VBUS,,,,,,,,,, +-,B,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,4,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,6,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,7,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,8,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,9,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,10,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,11,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,13,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,14,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +-,B,15,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, diff --git a/ports/renesas-ra/flashbdev.c b/ports/renesas-ra/flashbdev.c index 3e890d31d9cab..c213ed8f9b89e 100644 --- a/ports/renesas-ra/flashbdev.c +++ b/ports/renesas-ra/flashbdev.c @@ -38,6 +38,16 @@ #if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE +#if MICROPY_HW_HAS_QSPI_FLASH +// The linker script specifies flash storage locations. +extern uint8_t _micropy_hw_external_flash_storage_start; +extern uint8_t _micropy_hw_external_flash_storage_end; + +#define FLASH_MEM_SEG1_START_ADDR \ + ((long)&_micropy_hw_external_flash_storage_start) +#define FLASH_MEM_SEG1_NUM_BLOCKS \ + ((&_micropy_hw_external_flash_storage_end - &_micropy_hw_external_flash_storage_start) / 512) +#else // The linker script specifies flash storage locations. extern uint8_t _micropy_hw_internal_flash_storage_start; extern uint8_t _micropy_hw_internal_flash_storage_end; @@ -46,10 +56,11 @@ extern uint8_t _micropy_hw_internal_flash_storage_end; ((long)&_micropy_hw_internal_flash_storage_start) #define FLASH_MEM_SEG1_NUM_BLOCKS \ ((&_micropy_hw_internal_flash_storage_end - &_micropy_hw_internal_flash_storage_start) / 512) +#endif #if defined(RA4M1) | defined(RA4M3) | defined(RA4W1) #define FLASH_SECTOR_SIZE_MAX (0x800) // 2k max -#elif defined(RA6M1) | defined(RA6M2) | defined(RA6M3) +#elif defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) #define FLASH_SECTOR_SIZE_MAX (0x8000) // 32k max #else #error "no internal flash storage support for this MCU" diff --git a/ports/renesas-ra/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/fsp_cfg/r_agt_cfg.h new file mode 100644 index 0000000000000..216b6a21d7ee5 --- /dev/null +++ b/ports/renesas-ra/fsp_cfg/r_agt_cfg.h @@ -0,0 +1,14 @@ +#ifndef R_AGT_CFG_H_ +#define R_AGT_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#define AGT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define AGT_CFG_OUTPUT_SUPPORT_ENABLE (0) +#define AGT_CFG_INPUT_SUPPORT_ENABLE (0) + +#ifdef __cplusplus +} +#endif +#endif /* R_AGT_CFG_H_ */ diff --git a/ports/renesas-ra/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/fsp_cfg/r_dtc_cfg.h new file mode 100644 index 0000000000000..c4237e7073fcd --- /dev/null +++ b/ports/renesas-ra/fsp_cfg/r_dtc_cfg.h @@ -0,0 +1,13 @@ +#ifndef R_DTC_CFG_H_ +#define R_DTC_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#define DTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define DTC_CFG_VECTOR_TABLE_SECTION_NAME ".fsp_dtc_vector_table" + +#ifdef __cplusplus +} +#endif +#endif /* R_DTC_CFG_H_ */ diff --git a/ports/renesas-ra/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/fsp_cfg/r_icu_cfg.h new file mode 100644 index 0000000000000..999692ed3ccb6 --- /dev/null +++ b/ports/renesas-ra/fsp_cfg/r_icu_cfg.h @@ -0,0 +1,12 @@ +#ifndef R_ICU_CFG_H_ +#define R_ICU_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#define ICU_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif +#endif /* R_ICU_CFG_H_ */ diff --git a/ports/renesas-ra/fsp_cfg/r_iic_master_cfg.h b/ports/renesas-ra/fsp_cfg/r_iic_master_cfg.h new file mode 100644 index 0000000000000..20f1445862b78 --- /dev/null +++ b/ports/renesas-ra/fsp_cfg/r_iic_master_cfg.h @@ -0,0 +1,14 @@ +#ifndef R_IIC_MASTER_CFG_H_ +#define R_IIC_MASTER_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#define IIC_MASTER_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define IIC_MASTER_CFG_DTC_ENABLE (0) +#define IIC_MASTER_CFG_ADDR_MODE_10_BIT_ENABLE (0) + +#ifdef __cplusplus +} +#endif +#endif /* R_IIC_MASTER_CFG_H_ */ diff --git a/ports/renesas-ra/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/fsp_cfg/r_rtc_cfg.h new file mode 100644 index 0000000000000..1f8ba25cdaa99 --- /dev/null +++ b/ports/renesas-ra/fsp_cfg/r_rtc_cfg.h @@ -0,0 +1,13 @@ +#ifndef R_RTC_CFG_H_ +#define R_RTC_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#define RTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define RTC_CFG_OPEN_SET_CLOCK_SOURCE (1) + +#ifdef __cplusplus +} +#endif +#endif /* R_RTC_CFG_H_ */ diff --git a/ports/renesas-ra/fsp_cfg/r_sdhi_cfg.h b/ports/renesas-ra/fsp_cfg/r_sdhi_cfg.h new file mode 100644 index 0000000000000..62049ed445016 --- /dev/null +++ b/ports/renesas-ra/fsp_cfg/r_sdhi_cfg.h @@ -0,0 +1,19 @@ +#ifndef R_SDHI_CFG_H_ +#define R_SDHI_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#define SDHI_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define SDMMC_CFG_UNALIGNED_ACCESS_ENABLE (1) +#ifndef SDHI_CFG_SD_SUPPORT_ENABLE +#define SDHI_CFG_SD_SUPPORT_ENABLE ((1)) +#endif +#ifndef SDHI_CFG_EMMC_SUPPORT_ENABLE +#define SDHI_CFG_EMMC_SUPPORT_ENABLE ((0)) +#endif + +#ifdef __cplusplus +} +#endif +#endif /* R_SDHI_CFG_H_ */ diff --git a/ports/renesas-ra/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/fsp_cfg/r_spi_cfg.h new file mode 100644 index 0000000000000..e228e1036abd3 --- /dev/null +++ b/ports/renesas-ra/fsp_cfg/r_spi_cfg.h @@ -0,0 +1,17 @@ +#ifndef R_SPI_CFG_H_ +#define R_SPI_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#define SPI_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define SPI_DMA_SUPPORT_ENABLE (1) +#define SPI_TRANSMIT_FROM_RXI_ISR (0) + +/* DEPRECATED: Use SPI_DMA_SUPPORT_ENABLE instead. */ +#define SPI_DTC_SUPPORT_ENABLE (SPI_DMA_SUPPORT_ENABLE) + +#ifdef __cplusplus +} +#endif +#endif /* R_SPI_CFG_H_ */ diff --git a/ports/renesas-ra/machine_dac.c b/ports/renesas-ra/machine_dac.c new file mode 100644 index 0000000000000..6fd23c23889db --- /dev/null +++ b/ports/renesas-ra/machine_dac.c @@ -0,0 +1,183 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Nick Moore + * Copyright (c) 2023 Vekatech Ltd. + * + * 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 +#include "py/runtime.h" +#include "py/mphal.h" +#include "py/mperrno.h" +#include "pin.h" +#include "ra/ra_dac.h" +#include "modmachine.h" + +#if MICROPY_PY_MACHINE_DAC + +typedef struct _machine_dac_obj_t { + mp_obj_base_t base; + uint8_t active; + uint8_t ch; + uint16_t mv; + mp_hal_pin_obj_t dac; +} machine_dac_obj_t; + +STATIC machine_dac_obj_t machine_dac_obj[] = { + #if defined(MICROPY_HW_DAC0) + {{&machine_dac_type}, 0, 0, 0, MICROPY_HW_DAC0}, + #endif + #if defined(MICROPY_HW_DAC1) + {{&machine_dac_type}, 0, 1, 0, MICROPY_HW_DAC1} + #endif +}; + +STATIC void machine_dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); // const char *qstr_str(qstr q); + mp_printf(print, "DAC(DA%d [#%d], runing=%u, out=%u mV)", self->ch, self->dac->pin, self->active, self->mv); +} + +STATIC mp_obj_t machine_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_hal_pin_obj_t pin_id = MP_OBJ_NULL; + machine_dac_obj_t *self = MP_OBJ_NULL; + + enum { ARG_pin }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} } + }; + + mp_arg_check_num(n_args, n_kw, 1, 1, true); + mp_arg_val_t init_args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, init_args); + + // Get GPIO and optional device to connect to DAC. + pin_id = mp_hal_get_pin_obj(init_args[ARG_pin].u_obj); + + if (pin_id) { + for (int i = 0; i < MP_ARRAY_SIZE(machine_dac_obj); i++) { + if (pin_id->pin == machine_dac_obj[i].dac->pin) { + self = &machine_dac_obj[i]; + break; + } + } + + if (self) { + if (ra_dac_is_dac_pin(self->dac->pin)) { + ra_dac_init(self->dac->pin, self->ch); + self->active = ra_dac_is_running(self->ch); + } else { + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Pin(%d) has no DAC output"), self->dac->pin); + } + } else { + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Pin(%d) is used with other peripheral"), pin_id->pin); + } + } else { + mp_raise_ValueError(MP_ERROR_TEXT("Pin doesn't exist")); + } + + return MP_OBJ_FROM_PTR(self); +} + +// DAC.deinit() +STATIC mp_obj_t machine_dac_deinit(mp_obj_t self_in) { + machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); + + ra_dac_deinit(self->dac->pin, self->ch); + self->active = ra_dac_is_running(self->ch); + self->ch = 0; + self->mv = 0; + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_dac_deinit_obj, machine_dac_deinit); + +// DAC.write(value) +STATIC mp_obj_t machine_dac_write(mp_obj_t self_in, mp_obj_t data) { // mp_obj_t value_in + machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_int_t value = mp_obj_get_int(data); + + if (value < 0 || value > 4095) { + mp_raise_ValueError(MP_ERROR_TEXT("value should be 0-4095")); + } else + if (self->active) { + ra_dac_write(self->ch, value); + self->mv = (value * 3300) / 4095; + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_dac_write_obj, machine_dac_write); + +// DAC.read() +STATIC mp_obj_t machine_dac_read(mp_obj_t self_in) { + machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return MP_OBJ_NEW_SMALL_INT(ra_dac_read(self->ch)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_dac_read_obj, machine_dac_read); + +// DAC.write_mv(Vout) +STATIC mp_obj_t machine_dac_write_mv(mp_obj_t self_in, mp_obj_t data) { // mp_obj_t self_in, mp_obj_t value_in + machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_int_t Vout = mp_obj_get_int(data); + + if (Vout < 0 || Vout > 3300) { + mp_raise_ValueError(MP_ERROR_TEXT("value should be 0-3300")); + } else + if (self->active) { + uint16_t Dout = (Vout * 4095) / 3300; + ra_dac_write(self->ch, Dout); + self->mv = Vout; + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_dac_write_mv_obj, machine_dac_write_mv); + +// DAC.read_mv() +STATIC mp_obj_t machine_dac_read_mv(mp_obj_t self_in) { + machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return MP_OBJ_NEW_SMALL_INT(self->mv); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_dac_read_mv_obj, machine_dac_read_mv); + +// MP_DEFINE_CONST_FUN_OBJ_2(mp_machine_dac_write_obj, mp_machine_dac_write); + +STATIC const mp_rom_map_elem_t machine_dac_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_dac_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&machine_dac_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&machine_dac_write_obj) }, + { MP_ROM_QSTR(MP_QSTR_read_mv), MP_ROM_PTR(&machine_dac_read_mv_obj) }, + { MP_ROM_QSTR(MP_QSTR_write_mv), MP_ROM_PTR(&machine_dac_write_mv_obj) } +}; + +STATIC MP_DEFINE_CONST_DICT(machine_dac_locals_dict, machine_dac_locals_dict_table); + +MP_DEFINE_CONST_OBJ_TYPE( + machine_dac_type, + MP_QSTR_DAC, + MP_TYPE_FLAG_NONE, + make_new, machine_dac_make_new, + print, machine_dac_print, + locals_dict, &machine_dac_locals_dict + ); + +#endif // MICROPY_PY_MACHINE_DAC diff --git a/ports/renesas-ra/machine_pwm.c b/ports/renesas-ra/machine_pwm.c new file mode 100644 index 0000000000000..f2199805a1e76 --- /dev/null +++ b/ports/renesas-ra/machine_pwm.c @@ -0,0 +1,357 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Damien P. George + * Copyright (c) 2023 Vekatech Ltd. + * + * 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/runtime.h" +#include "py/mphal.h" +#include "py/mperrno.h" +#include "extmod/machine_pwm.h" +#include "pin.h" +#include "ra/ra_gpt.h" +#include "modmachine.h" + +#if MICROPY_HW_ENABLE_HW_PWM + +typedef struct _machine_pwm_obj_t { + mp_obj_base_t base; + R_GPT0_Type *pwm_inst; + uint8_t active; + uint8_t ch; + uint8_t id; + uint8_t duty; + uint32_t freq; + mp_hal_pin_obj_t pwm; +} machine_pwm_obj_t; + +STATIC machine_pwm_obj_t machine_pwm_obj[] = { + #if defined(MICROPY_HW_PWM_0A) + {{&machine_pwm_type}, R_GPT0, 0, 0, 'A', 0, 0ul, MICROPY_HW_PWM_0A}, + #endif + #if defined(MICROPY_HW_PWM_0B) + {{&machine_pwm_type}, R_GPT0, 0, 0, 'B', 0, 0ul, MICROPY_HW_PWM_0B}, + #endif + #if defined(MICROPY_HW_PWM_1A) + {{&machine_pwm_type}, R_GPT1, 0, 1, 'A', 0, 0ul, MICROPY_HW_PWM_1A}, + #endif + #if defined(MICROPY_HW_PWM_1B) + {{&machine_pwm_type}, R_GPT1, 0, 1, 'B', 0, 0ul, MICROPY_HW_PWM_1B}, + #endif + #if defined(MICROPY_HW_PWM_2A) + {{&machine_pwm_type}, R_GPT2, 0, 2, 'A', 0, 0ul, MICROPY_HW_PWM_2A}, + #endif + #if defined(MICROPY_HW_PWM_2B) + {{&machine_pwm_type}, R_GPT2, 0, 2, 'B', 0, 0ul, MICROPY_HW_PWM_2B}, + #endif + #if defined(MICROPY_HW_PWM_3A) + {{&machine_pwm_type}, R_GPT3, 0, 3, 'A', 0, 0ul, MICROPY_HW_PWM_3A}, + #endif + #if defined(MICROPY_HW_PWM_3B) + {{&machine_pwm_type}, R_GPT3, 0, 3, 'B', 0, 0ul, MICROPY_HW_PWM_3B}, + #endif + #if defined(MICROPY_HW_PWM_4A) + {{&machine_pwm_type}, R_GPT4, 0, 4, 'A', 0, 0ul, MICROPY_HW_PWM_4A}, + #endif + #if defined(MICROPY_HW_PWM_4B) + {{&machine_pwm_type}, R_GPT4, 0, 4, 'B', 0, 0ul, MICROPY_HW_PWM_4B}, + #endif + #if defined(MICROPY_HW_PWM_5A) + {{&machine_pwm_type}, R_GPT5, 0, 5, 'A', 0, 0ul, MICROPY_HW_PWM_5A}, + #endif + #if defined(MICROPY_HW_PWM_5B) + {{&machine_pwm_type}, R_GPT5, 0, 5, 'B', 0, 0ul, MICROPY_HW_PWM_5B}, + #endif + #if defined(MICROPY_HW_PWM_6A) + {{&machine_pwm_type}, R_GPT6, 0, 6, 'A', 0, 0ul, MICROPY_HW_PWM_6A}, + #endif + #if defined(MICROPY_HW_PWM_6B) + {{&machine_pwm_type}, R_GPT6, 0, 6, 'B', 0, 0ul, MICROPY_HW_PWM_6B}, + #endif + #if defined(MICROPY_HW_PWM_7A) + {{&machine_pwm_type}, R_GPT7, 0, 7, 'A', 0, 0ul, MICROPY_HW_PWM_7A}, + #endif + #if defined(MICROPY_HW_PWM_7B) + {{&machine_pwm_type}, R_GPT7, 0, 7, 'B', 0, 0ul, MICROPY_HW_PWM_7B}, + #endif + #if defined(MICROPY_HW_PWM_8A) + {{&machine_pwm_type}, R_GPT8, 0, 8, 'A', 0, 0ul, MICROPY_HW_PWM_8A}, + #endif + #if defined(MICROPY_HW_PWM_8B) + {{&machine_pwm_type}, R_GPT8, 0, 8, 'B', 0, 0ul, MICROPY_HW_PWM_8B}, + #endif + #if defined(MICROPY_HW_PWM_9A) + {{&machine_pwm_type}, R_GPT9, 0, 9, 'A', 0, 0ul, MICROPY_HW_PWM_9A}, + #endif + #if defined(MICROPY_HW_PWM_9B) + {{&machine_pwm_type}, R_GPT9, 0, 9, 'B', 0, 0ul, MICROPY_HW_PWM_9B}, + #endif + #if defined(MICROPY_HW_PWM_10A) + {{&machine_pwm_type}, R_GPT10, 0, 10, 'A', 0, 0ul, MICROPY_HW_PWM_10A}, + #endif + #if defined(MICROPY_HW_PWM_10B) + {{&machine_pwm_type}, R_GPT10, 0, 10, 'B', 0, 0ul, MICROPY_HW_PWM_10B}, + #endif + #if defined(MICROPY_HW_PWM_11A) + {{&machine_pwm_type}, R_GPT11, 0, 11, 'A', 0, 0ul, MICROPY_HW_PWM_11A}, + #endif + #if defined(MICROPY_HW_PWM_11B) + {{&machine_pwm_type}, R_GPT11, 0, 11, 'B', 0, 0ul, MICROPY_HW_PWM_11B}, + #endif + #if defined(MICROPY_HW_PWM_12A) + {{&machine_pwm_type}, R_GPT12, 0, 12, 'A', 0, 0ul, MICROPY_HW_PWM_12A}, + #endif + #if defined(MICROPY_HW_PWM_12B) + {{&machine_pwm_type}, R_GPT12, 0, 12, 'B', 0, 0ul, MICROPY_HW_PWM_12B}, + #endif + #if defined(MICROPY_HW_PWM_13A) + {{&machine_pwm_type}, R_GPT13, 0, 13, 'A', 0, 0ul, MICROPY_HW_PWM_13A}, + #endif + #if defined(MICROPY_HW_PWM_13B) + {{&machine_pwm_type}, R_GPT13, 0, 13, 'B', 0, 0ul, MICROPY_HW_PWM_13B} + #endif +}; + +/******************************************************************************/ +// MicroPython bindings for PWM + +STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_printf(print, "PWM(GTIOC %d%c[#%d], runing=%u, freq=%u, duty=%u)", self->ch, self->id, self->pwm->pin, self->active, self->freq, self->duty); +} + +STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + uint32_t D = 0ul; + + enum { ARG_freq, ARG_duty }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_freq, MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_duty, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} } + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + if (args[ARG_freq].u_int != -1) { + if ((args[ARG_freq].u_int < 0) || (args[ARG_freq].u_int > 24000000)) { + mp_raise_ValueError(MP_ERROR_TEXT("freq should be 0-24000000")); + } else { + self->freq = args[ARG_freq].u_int; + } + } + + ra_gpt_timer_init(self->pwm->pin, self->ch, self->id, 0, (float)self->freq); + + if (args[ARG_duty].u_int != -1) { + if ((args[ARG_duty].u_int < 0) || (args[ARG_duty].u_int > 100)) { + mp_raise_ValueError(MP_ERROR_TEXT("duty should be 0-100")); + } else { + self->duty = args[ARG_duty].u_int; + } + } + + D = self->duty * ra_gpt_timer_get_period(self->ch); + ra_gpt_timer_set_duty(self->ch, self->id, (uint32_t)(D / 100)); + + if (self->duty && self->freq) { + ra_gpt_timer_start(self->ch); + self->active = 1; + } +} + +STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_hal_pin_obj_t pin_id = MP_OBJ_NULL; + machine_pwm_obj_t *self = MP_OBJ_NULL; + + enum { ARG_pin, ARG_freq, ARG_duty }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_freq, MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_duty, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} } + }; + + mp_arg_check_num(n_args, n_kw, 1, 3, true); + mp_arg_val_t init_args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, init_args); + + // Get GPIO and optional device to connect to PWM. + pin_id = mp_hal_get_pin_obj(init_args[ARG_pin].u_obj); + + if (pin_id) { + for (int i = 0; i < MP_ARRAY_SIZE(machine_pwm_obj); i++) { + if (pin_id->pin == machine_pwm_obj[i].pwm->pin) { + self = &machine_pwm_obj[i]; + break; + } + } + + if (self) { + if (ra_gpt_timer_is_pwm_pin(self->pwm->pin)) { + // start the PWM running for this channel + mp_map_t kw_args; + mp_map_init_fixed_table(&kw_args, n_kw, args + n_args); + mp_machine_pwm_init_helper(self, n_args - 1, args + 1, &kw_args); + } else { + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Pin(%d) has no timer output"), self->pwm->pin); + } + } else { + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Pin(%d) is used with other peripheral"), pin_id->pin); + } + } else { + mp_raise_ValueError(MP_ERROR_TEXT("Pin doesn't exist")); + } + + return MP_OBJ_FROM_PTR(self); +} + +STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { + ra_gpt_timer_deinit(self->pwm->pin, self->ch, self->id); + self->active = 0; + self->ch = 0; + self->id = ' '; + self->duty = 0; + self->freq = 0; +} + +STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { + return MP_OBJ_NEW_SMALL_INT((uint32_t)ra_gpt_timer_get_freq(self->ch)); +} + +STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { + if (freq) { + ra_gpt_timer_set_freq(self->ch, (float)freq); + self->freq = (uint32_t)ra_gpt_timer_get_freq(self->ch); + if (!self->freq) { + mp_raise_ValueError(MP_ERROR_TEXT("freq should be 0-24000000")); + } else + if (!self->active) { + ra_gpt_timer_start(self->ch); + self->active = 1; + } + } else { + ra_gpt_timer_stop(self->ch); + ra_gpt_timer_set_freq(self->ch, (float)freq); + self->freq = 0; + self->active = 0; + } +} + +STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { + // give the result in % + uint64_t Dc = ra_gpt_timer_get_duty(self->ch, self->id) * 100; + return MP_OBJ_NEW_SMALL_INT(Dc / ra_gpt_timer_get_period(self->ch)); +} + +STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { + // assume duty is in % + if (duty < 0 || duty > 100) { + mp_raise_ValueError(MP_ERROR_TEXT("duty should be 0-100")); + } else { + if (duty) { + uint64_t D = (uint8_t)(duty) * ra_gpt_timer_get_period(self->ch); + ra_gpt_timer_set_duty(self->ch, self->id, (uint32_t)(D / 100)); + self->duty = (uint8_t)duty; + + if (!self->active && self->freq) { + ra_gpt_timer_start(self->ch); + self->active = 1; + } + } else { + if (self->active) { + ra_gpt_timer_stop(self->ch); + ra_gpt_timer_set_duty(self->ch, self->id, 0); + self->duty = 0; + self->active = 0; + } + } + } +} + +STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { + // give the result in ratio (u16 / 65535) + uint64_t Dc = ra_gpt_timer_get_duty(self->ch, self->id) * 65535; + return MP_OBJ_NEW_SMALL_INT(Dc / ra_gpt_timer_get_period(self->ch)); +} + +STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { + // assume duty is a ratio (u16 / 65535) + if (duty_u16 < 0 || duty_u16 > 65535) { + mp_raise_ValueError(MP_ERROR_TEXT("duty should be 0-65535")); + } else { + if (duty_u16) { + uint64_t D = duty_u16 * ra_gpt_timer_get_period(self->ch); + ra_gpt_timer_set_duty(self->ch, self->id, (uint32_t)(D / 65535)); + self->duty = (uint8_t)((duty_u16 * 100) / 65535); + + if (!self->active && self->freq) { + ra_gpt_timer_start(self->ch); + self->active = 1; + } + } else { + if (self->active) { + ra_gpt_timer_stop(self->ch); + ra_gpt_timer_set_duty(self->ch, self->id, 0); + self->duty = 0; + self->active = 0; + } + } + } +} + +STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { + // give the result in ns + float ns = ra_gpt_timer_tick_time(self->ch); + ns *= (float)ra_gpt_timer_get_duty(self->ch, self->id); + return MP_OBJ_NEW_SMALL_INT(ns); +} + +STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { + // assume duty is ns + uint32_t ns_min = (uint32_t)ra_gpt_timer_tick_time(self->ch); + uint32_t ns_max = ns_min * ra_gpt_timer_get_period(self->ch); + if (duty_ns) { + if (duty_ns < ns_min || duty_ns > ns_max) { + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("duty should be in period range %d-%d"), ns_min, ns_max); + } else { + uint32_t D = (uint32_t)duty_ns / ns_min; + ra_gpt_timer_set_duty(self->ch, self->id, D); + D *= ns_min * 100; + self->duty = D / ns_max; + + if (!self->active && self->freq) { + ra_gpt_timer_start(self->ch); + self->active = 1; + } + } + } else { + if (self->active) { + ra_gpt_timer_stop(self->ch); + ra_gpt_timer_set_duty(self->ch, self->id, 0); + self->duty = 0; + self->active = 0; + } + } +} + +#endif // MICROPY_HW_ENABLE_HW_PWM diff --git a/ports/renesas-ra/machine_sdcard.c b/ports/renesas-ra/machine_sdcard.c new file mode 100644 index 0000000000000..2ed0d6653567a --- /dev/null +++ b/ports/renesas-ra/machine_sdcard.c @@ -0,0 +1,338 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Vekatech Ltd. + * + * 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/mpconfig.h" +#include "py/runtime.h" +#include "py/mphal.h" +#include "py/mperrno.h" +#include "modmachine.h" +#include "extmod/vfs.h" +#include "hal_data.h" +#include "led.h" + +#if MICROPY_HW_HAS_SDHI_CARD + +#define CARD_HOLDER 1000 // 500 ms +#define CARD_OPERATION 200 // 100 ms + +static volatile uint8_t OP_complete = 0; + +typedef struct _machine_sdcard_obj_t { + mp_obj_base_t base; + sdmmc_status_t status; + uint16_t block_len; + uint32_t block_count; +} machine_sdcard_obj_t; + +STATIC machine_sdcard_obj_t machine_sdcard_objs[] = { + {{&machine_sdcard_type}, {false, false, false}, 0, 0} +}; + +void sdhi_ISR(sdmmc_callback_args_t *p_args) { + switch (p_args->event) + { + case SDMMC_EVENT_CARD_INSERTED: + machine_sdcard_objs[0].status.card_inserted = true; + OP_complete = 0; + break; + + case SDMMC_EVENT_CARD_REMOVED: + machine_sdcard_objs[0].status.card_inserted = false; + machine_sdcard_objs[0].status.initialized = false; + machine_sdcard_objs[0].block_count = 0; + break; + + case SDMMC_EVENT_ERASE_COMPLETE: + case SDMMC_EVENT_TRANSFER_COMPLETE: + OP_complete = 0; + break; + + // case SDMMC_EVENT_ERASE_BUSY: + // case SDMMC_EVENT_TRANSFER_ERROR: + + default: + break; + } +} + +STATIC mp_obj_t machine_sdcard_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + fsp_err_t err = FSP_SUCCESS; + machine_sdcard_obj_t *self = mp_const_none; + + if (g_sdmmc0_ctrl.open) { + check: + if ((err = R_SDHI_StatusGet(&g_sdmmc0_ctrl, &self->status)) == FSP_SUCCESS) { + self = &machine_sdcard_objs[0]; + if (!self->status.initialized && self->status.card_inserted) { + if ((err = R_SDHI_MediaInit(&g_sdmmc0_ctrl, NULL)) == FSP_SUCCESS) { + self->status.initialized = true; + self->block_len = g_sdmmc0_ctrl.device.sector_size_bytes; + self->block_count = g_sdmmc0_ctrl.device.sector_count; + } else { + mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("can't init SDHI card, %d"), err); + } + } + } else { + mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("can't get SDHI Status, %d"), err); + } + } else { + if ((err = R_SDHI_Open(&g_sdmmc0_ctrl, &g_sdmmc0_cfg)) == FSP_SUCCESS) { + uint32_t Istamp = mp_hal_ticks_ms(); + OP_complete = 1; + while (OP_complete) { + if ((mp_hal_ticks_ms() - Istamp) > CARD_HOLDER) { + OP_complete = 0; + Istamp = 0; + } + } + + goto check; + } else { + mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("can't open SDHI controller, %d"), err); + } + } + + return MP_OBJ_FROM_PTR(self); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_sdcard_init_obj, 1, machine_sdcard_init); + +STATIC mp_obj_t sdcard_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + mp_map_t kw_args; + + mp_arg_check_num(n_args, n_kw, 0, 0, true); + mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); + return machine_sdcard_init(n_args, all_args, &kw_args); +} + +// deinit() +STATIC mp_obj_t machine_sdcard_deinit(mp_obj_t self_in) { + machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); + R_SDHI_Close(&g_sdmmc0_ctrl); + self->block_count = self->block_len = 0; + self->status.card_inserted = self->status.initialized = self->status.transfer_in_progress = false; + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_deinit_obj, machine_sdcard_deinit); + +// present() +STATIC mp_obj_t machine_sdcard_present(mp_obj_t self_in) { + fsp_err_t err = FSP_SUCCESS; + machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); + if ((err = R_SDHI_StatusGet(&g_sdmmc0_ctrl, &self->status)) == FSP_SUCCESS) { + return mp_obj_new_bool(self->status.card_inserted); + } else { + mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("can't get SDHI Status, %d"), err); + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_present_obj, machine_sdcard_present); + +STATIC mp_obj_t machine_sdcard_info(mp_obj_t self_in) { + machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); + + if (self->status.card_inserted && self->status.initialized) { + uint32_t log_block_nbr = self->block_count; + uint32_t log_block_size = self->block_len; + + mp_obj_t tuple[2] = { + mp_obj_new_int_from_ull((uint64_t)log_block_nbr * (uint64_t)log_block_size), + mp_obj_new_int_from_uint(log_block_size), + }; + return mp_obj_new_tuple(2, tuple); + } else { + return mp_const_none; + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_info_obj, machine_sdcard_info); + +// readblocks(block_num, buf) +STATIC mp_obj_t machine_sdcard_readblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { + mp_buffer_info_t bufinfo; + machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); + + if ((self->status.initialized) && (FSP_SUCCESS == R_SDHI_Read(&g_sdmmc0_ctrl, bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / g_sdmmc0_cfg.block_size))) { + uint32_t Rstamp = mp_hal_ticks_ms(); + OP_complete = 1; + while (OP_complete) { + if ((mp_hal_ticks_ms() - Rstamp) > CARD_OPERATION) { + OP_complete = 0; + Rstamp = 0; + } + } + + return Rstamp? MP_OBJ_NEW_SMALL_INT(0) : MP_OBJ_NEW_SMALL_INT(-MP_EIO); + } else { + return MP_OBJ_NEW_SMALL_INT(-MP_EIO); + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_readblocks_obj, machine_sdcard_readblocks); + +// writeblocks(block_num, buf) +STATIC mp_obj_t machine_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { + mp_buffer_info_t bufinfo; + machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); + + if ((self->status.initialized) && (FSP_SUCCESS == R_SDHI_Write(&g_sdmmc0_ctrl, bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / g_sdmmc0_cfg.block_size))) { + uint32_t Wstamp = mp_hal_ticks_ms(); + OP_complete = 1; + while (OP_complete) { + if ((mp_hal_ticks_ms() - Wstamp) > CARD_OPERATION) { + OP_complete = 0; + Wstamp = 0; + } + } + + return Wstamp? MP_OBJ_NEW_SMALL_INT(0) : MP_OBJ_NEW_SMALL_INT(-MP_EIO); + } else { + return MP_OBJ_NEW_SMALL_INT(-MP_EIO); + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_writeblocks_obj, machine_sdcard_writeblocks); + +// ioctl(op, arg) +STATIC mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { + machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_int_t cmd = mp_obj_get_int(cmd_in); + + switch (cmd) { + case MP_BLOCKDEV_IOCTL_INIT: { + if (!g_sdmmc0_ctrl.open) { + if (FSP_SUCCESS == R_SDHI_Open(&g_sdmmc0_ctrl, &g_sdmmc0_cfg)) { + uint32_t Istamp = mp_hal_ticks_ms(); + OP_complete = 1; + while (OP_complete) { + if ((mp_hal_ticks_ms() - Istamp) > CARD_OPERATION) { + OP_complete = 0; + Istamp = 0; + } + } + } else { + return MP_OBJ_NEW_SMALL_INT(-MP_EIO); + } + } + + R_SDHI_StatusGet(&g_sdmmc0_ctrl, &self->status); + + if (self->status.card_inserted) { + if (!self->status.initialized) { + if (FSP_SUCCESS == R_SDHI_MediaInit(&g_sdmmc0_ctrl, NULL)) { + self->status.initialized = true; + self->block_len = g_sdmmc0_ctrl.device.sector_size_bytes; + self->block_count = g_sdmmc0_ctrl.device.sector_count; + return MP_OBJ_NEW_SMALL_INT(0); + } else { + return MP_OBJ_NEW_SMALL_INT(-MP_EIO); // Initialization failed + } + } else { + return MP_OBJ_NEW_SMALL_INT(0); + } + } else { + return MP_OBJ_NEW_SMALL_INT(-MP_EIO); // Initialization failed + } + } + break; + + case MP_BLOCKDEV_IOCTL_DEINIT: { + if (g_sdmmc0_ctrl.open) { + R_SDHI_Close(&g_sdmmc0_ctrl); + self->block_count = self->block_len = 0; + self->status.card_inserted = self->status.initialized = self->status.transfer_in_progress = false; + return MP_OBJ_NEW_SMALL_INT(0); + } else { + return MP_OBJ_NEW_SMALL_INT(-MP_EIO); // Deinitialization failed + } + } + break; + + case MP_BLOCKDEV_IOCTL_SYNC: { + return MP_OBJ_NEW_SMALL_INT(0); + } + break; + + case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: { + if (self->status.initialized) { + return MP_OBJ_NEW_SMALL_INT(self->block_count); + } else { + return MP_OBJ_NEW_SMALL_INT(-MP_EIO); // Card not initialized + } + } + break; + + case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: { + if (self->status.initialized) { + return MP_OBJ_NEW_SMALL_INT(self->block_len); + } else { + return MP_OBJ_NEW_SMALL_INT(-MP_EIO); // Card not initialized + } + } + break; + + case MP_BLOCKDEV_IOCTL_BLOCK_ERASE: { + if (self->status.initialized) { + uint32_t Estamp = mp_hal_ticks_ms(); + OP_complete = 1; + while (OP_complete) { + if ((mp_hal_ticks_ms() - Estamp) > CARD_OPERATION) { + OP_complete = 0; + Estamp = 0; + } + } + + return Estamp? MP_OBJ_NEW_SMALL_INT(0) : MP_OBJ_NEW_SMALL_INT(-MP_EIO); + } else { + return MP_OBJ_NEW_SMALL_INT(-MP_EIO); // Card not initialized + } + } + + default: // unknown command + return mp_const_none; + break; + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_ioctl_obj, machine_sdcard_ioctl); + +STATIC const mp_rom_map_elem_t sdcard_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_sdcard_init_obj) }, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_sdcard_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_present), MP_ROM_PTR(&machine_sdcard_present_obj) }, + { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_sdcard_info_obj) }, + // block device protocol + { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&machine_sdcard_readblocks_obj) }, + { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&machine_sdcard_writeblocks_obj) }, + { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&machine_sdcard_ioctl_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(sdcard_locals_dict, sdcard_locals_dict_table); + +MP_DEFINE_CONST_OBJ_TYPE( + machine_sdcard_type, + MP_QSTR_SDCard, + MP_TYPE_FLAG_NONE, + make_new, sdcard_obj_make_new, + locals_dict, &sdcard_locals_dict + ); + +#endif // MICROPY_PY_MACHINE_SDCARD diff --git a/ports/renesas-ra/machine_spi.c b/ports/renesas-ra/machine_spi.c index 2c71c83b666c1..8c0c026d9a728 100644 --- a/ports/renesas-ra/machine_spi.c +++ b/ports/renesas-ra/machine_spi.c @@ -86,6 +86,47 @@ STATIC machine_hard_spi_obj_t machine_hard_spi_obj[] = { #endif }; +STATIC void spi_init(machine_hard_spi_obj_t *self) { + const machine_pin_obj_t *pins[4] = { NULL, NULL, NULL, NULL }; + + if (0) { + #if defined(MICROPY_HW_SPI0_RSPCK) + } else if (self->spi_id == 0) { + #if defined(MICROPY_HW_SPI0_SSL) + pins[0] = MICROPY_HW_SPI0_SSL; + #endif + #if defined(MICROPY_HW_SPI0_RSPCK) + pins[1] = MICROPY_HW_SPI0_RSPCK; + #endif + #if defined(MICROPY_HW_SPI0_MISO) + pins[2] = MICROPY_HW_SPI0_MISO; + #endif + #if defined(MICROPY_HW_SPI0_MOSI) + pins[3] = MICROPY_HW_SPI0_MOSI; + #endif + #endif + #if defined(MICROPY_HW_SPI1_RSPCK) + } else if (self->spi_id == 1) { + #if defined(MICROPY_HW_SPI1_SSL) + pins[0] = MICROPY_HW_SPI1_SSL; + #endif + #if defined(MICROPY_HW_SPI1_RSPCK) + pins[1] = MICROPY_HW_SPI1_RSPCK; + #endif + #if defined(MICROPY_HW_SPI1_MISO) + pins[2] = MICROPY_HW_SPI1_MISO; + #endif + #if defined(MICROPY_HW_SPI1_MOSI) + pins[3] = MICROPY_HW_SPI1_MOSI; + #endif + #endif + } else { + // SPI does not exist for this board (shouldn't get here, should be checked by caller) + return; + } + ra_spi_init(self->spi_id, pins[3]->pin, pins[2]->pin, pins[1]->pin, pins[0]->pin, self->baudrate, self->bits, self->polarity, self->phase, self->firstbit); +} + STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hard_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "SPI(%u, baudrate=%u, polarity=%u, phase=%u, bits=%u, firstbit=%u, sck=%q, mosi=%q, miso=%q)", @@ -189,10 +230,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz } } // init the SPI bus - spi_init(self->spi_id); - // set configurable paramaters - spi_set_params(self->spi_id, self->baudrate, self->polarity, - self->phase, self->bits, self->firstbit); + spi_init(self); return MP_OBJ_FROM_PTR(self); } @@ -275,10 +313,7 @@ STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const m } // init the SPI bus - spi_init(self->spi_id); - // set configurable paramaters - spi_set_params(self->spi_id, self->baudrate, self->polarity, - self->phase, self->bits, self->firstbit); + spi_init(self); } STATIC void machine_hard_spi_deinit(mp_obj_base_t *self_in) { @@ -310,58 +345,6 @@ MP_DEFINE_CONST_OBJ_TYPE( void spi_init0(void) { } -// sets the parameters in the SPI_InitTypeDef struct -// if an argument is -1 then the corresponding parameter is not changed -void spi_set_params(uint32_t ch, int32_t baudrate, - int32_t polarity, int32_t phase, int32_t bits, int32_t firstbit) { - ra_spi_set_mode(ch, polarity, phase); - ra_spi_set_clk(ch, baudrate); - ra_spi_set_bits(ch, bits); - ra_spi_set_lsb_first(ch, firstbit); -} - -void spi_init(uint32_t ch) { - const machine_pin_obj_t *pins[4] = { NULL, NULL, NULL, NULL }; - - if (0) { - #if defined(MICROPY_HW_SPI0_RSPCK) - } else if (ch == 0) { - #if defined(MICROPY_HW_SPI0_SSL) - pins[0] = MICROPY_HW_SPI0_SSL; - #endif - #if defined(MICROPY_HW_SPI0_RSPCK) - pins[1] = MICROPY_HW_SPI0_RSPCK; - #endif - #if defined(MICROPY_HW_SPI0_MISO) - pins[2] = MICROPY_HW_SPI0_MISO; - #endif - #if defined(MICROPY_HW_SPI0_MOSI) - pins[3] = MICROPY_HW_SPI0_MOSI; - #endif - ra_spi_init(ch, pins[3]->pin, pins[2]->pin, pins[1]->pin, pins[0]->pin, DEFAULT_SPI_BAUDRATE, DEFAULT_SPI_BITS, DEFAULT_SPI_POLARITY, DEFAULT_SPI_PHASE); - #endif - #if defined(MICROPY_HW_SPI1_RSPCK) - } else if (ch == 1) { - #if defined(MICROPY_HW_SPI1_SSL) - pins[0] = MICROPY_HW_SPI1_SSL; - #endif - #if defined(MICROPY_HW_SPI1_RSPCK) - pins[1] = MICROPY_HW_SPI1_RSPCK; - #endif - #if defined(MICROPY_HW_SPI1_MISO) - pins[2] = MICROPY_HW_SPI1_MISO; - #endif - #if defined(MICROPY_HW_SPI1_MOSI) - pins[3] = MICROPY_HW_SPI1_MOSI; - #endif - ra_spi_init(ch, pins[3]->pin, pins[2]->pin, pins[1]->pin, pins[0]->pin, DEFAULT_SPI_BAUDRATE, DEFAULT_SPI_BITS, DEFAULT_SPI_POLARITY, DEFAULT_SPI_PHASE); - #endif - } else { - // SPI does not exist for this board (shouldn't get here, should be checked by caller) - return; - } -} - void spi_deinit(uint32_t ch) { if (0) { #if defined(MICROPY_HW_SPI0_RSPCK) diff --git a/ports/renesas-ra/modmachine.c b/ports/renesas-ra/modmachine.c index 47f7e8c8057b4..bc85d9b7f88bb 100644 --- a/ports/renesas-ra/modmachine.c +++ b/ports/renesas-ra/modmachine.c @@ -5,6 +5,7 @@ * * Copyright (c) 2013-2015 Damien P. George * Copyright (c) 2021,2022 Renesas Electronics Corporation + * Copyright (c) 2023 Vekatech Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -39,6 +40,7 @@ #include "extmod/machine_pulse.h" #include "extmod/machine_i2c.h" #include "extmod/machine_spi.h" +#include "extmod/machine_pwm.h" #include "shared/runtime/pyexec.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" @@ -279,6 +281,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&machine_rtc_type) }, { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&machine_adc_type) }, + #if MICROPY_PY_MACHINE_DAC + { MP_ROM_QSTR(MP_QSTR_DAC), MP_ROM_PTR(&machine_dac_type) }, + #endif #if MICROPY_PY_MACHINE_I2C #if MICROPY_HW_ENABLE_HW_I2C { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_i2c_type) }, @@ -291,6 +296,14 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { #endif { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&machine_uart_type) }, { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) }, + #if MICROPY_PY_MACHINE_PWM + #if MICROPY_HW_ENABLE_HW_PWM + { MP_ROM_QSTR(MP_QSTR_PWM), MP_ROM_PTR(&machine_pwm_type) }, + #endif + #endif + #if MICROPY_HW_HAS_SDHI_CARD + { MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&machine_sdcard_type) }, + #endif { MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(PYB_RESET_POWER_ON) }, { MP_ROM_QSTR(MP_QSTR_HARD_RESET), MP_ROM_INT(PYB_RESET_HARD) }, { MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(PYB_RESET_WDT) }, diff --git a/ports/renesas-ra/mpconfigboard_common.h b/ports/renesas-ra/mpconfigboard_common.h index f63a924ad8e4d..f8990f489e3b2 100644 --- a/ports/renesas-ra/mpconfigboard_common.h +++ b/ports/renesas-ra/mpconfigboard_common.h @@ -5,6 +5,7 @@ * * Copyright (c) 2018 Damien P. George * Copyright (c) 2021,2022 Renesas Electronics Corporation + * Copyright (c) 2023 Vekatech Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -63,6 +64,16 @@ #define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE_SEGMENT2 (0) #endif +// Whether to enable storage on the external QSPI flash of the MCU, instead of the internal flash +#ifndef MICROPY_HW_HAS_QSPI_FLASH +#define MICROPY_HW_HAS_QSPI_FLASH (0) +#endif + +// Whether to enable access to SDCARD, through SDHI controller +#ifndef MICROPY_HW_HAS_SDHI_CARD +#define MICROPY_HW_HAS_SDHI_CARD (0) +#endif + // Whether to enable the RTC, exposed as pyb.RTC #ifndef MICROPY_HW_ENABLE_RTC #define MICROPY_HW_ENABLE_RTC (0) @@ -209,6 +220,16 @@ #define MICROPY_HW_MAX_UART (10) #define MICROPY_HW_MAX_LPUART (0) +#elif defined(RA6M5) + +#define MP_HAL_UNIQUE_ID_ADDRESS (0x1ffff7ac) /* To be fixed */ +// 16 IRQ + 1 EXTI_RTC_WAKEUP defined in exti.h +#define PYB_EXTI_NUM_VECTORS (17) +#define MICROPY_HW_MAX_TIMER (2) +#define MICROPY_HW_MAX_UART (10) +#define MICROPY_HW_MAX_LPUART (0) + +#else #error Unsupported MCU series #endif @@ -240,5 +261,30 @@ #define MICROPY_HW_ENABLE_HW_I2C (0) #endif +#if defined(MICROPY_HW_PWM_0A) || defined(MICROPY_HW_PWM_0B) \ + || defined(MICROPY_HW_PWM_1A) || defined(MICROPY_HW_PWM_1B) \ + || defined(MICROPY_HW_PWM_2A) || defined(MICROPY_HW_PWM_2B) \ + || defined(MICROPY_HW_PWM_3A) || defined(MICROPY_HW_PWM_3B) \ + || defined(MICROPY_HW_PWM_4A) || defined(MICROPY_HW_PWM_4B) \ + || defined(MICROPY_HW_PWM_5A) || defined(MICROPY_HW_PWM_5B) \ + || defined(MICROPY_HW_PWM_6A) || defined(MICROPY_HW_PWM_6B) \ + || defined(MICROPY_HW_PWM_7A) || defined(MICROPY_HW_PWM_7B) \ + || defined(MICROPY_HW_PWM_8A) || defined(MICROPY_HW_PWM_8B) \ + || defined(MICROPY_HW_PWM_9A) || defined(MICROPY_HW_PWM_9B) \ + || defined(MICROPY_HW_PWM_10A) || defined(MICROPY_HW_PWM_10B) \ + || defined(MICROPY_HW_PWM_11A) || defined(MICROPY_HW_PWM_11B) \ + || defined(MICROPY_HW_PWM_12A) || defined(MICROPY_HW_PWM_12B) \ + || defined(MICROPY_HW_PWM_13A) || defined(MICROPY_HW_PWM_13B) +#define MICROPY_HW_ENABLE_HW_PWM (1) +#else +#define MICROPY_HW_ENABLE_HW_PWM (0) +#endif + +#if defined(MICROPY_HW_DAC0) || defined(MICROPY_HW_DAC1) +#define MICROPY_HW_ENABLE_HW_DAC (1) +#else +#define MICROPY_HW_ENABLE_HW_DAC (0) +#endif + // Pin definition header file #define MICROPY_PIN_DEFS_PORT_H "pin_defs_ra.h" diff --git a/ports/renesas-ra/mpconfigport.h b/ports/renesas-ra/mpconfigport.h index 434bc00f1197a..a4a0caa373ba6 100644 --- a/ports/renesas-ra/mpconfigport.h +++ b/ports/renesas-ra/mpconfigport.h @@ -5,6 +5,7 @@ * * Copyright (c) 2013-2017 Damien P. George * Copyright (c) 2021,2022 Renesas Electronics Corporation + * Copyright (c) 2023 Vekatech Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -117,6 +118,14 @@ #define MICROPY_PY_MACHINE_SOFTSPI (1) #define MICROPY_PY_MACHINE_TIMER (1) #define MICROPY_SOFT_TIMER_TICKS_MS uwTick +#if MICROPY_HW_ENABLE_HW_PWM +#define MICROPY_PY_MACHINE_PWM (1) +#define MICROPY_PY_MACHINE_PWM_DUTY (1) +#define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/renesas-ra/machine_pwm.c" +#endif +#if MICROPY_HW_ENABLE_HW_DAC +#define MICROPY_PY_MACHINE_DAC (1) +#endif #endif #define MICROPY_HW_SOFTSPI_MIN_DELAY (0) #define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (48000000 / 48) diff --git a/ports/renesas-ra/powerctrl.c b/ports/renesas-ra/powerctrl.c index 8f9e25b7240af..26dc1cbe3a8f3 100644 --- a/ports/renesas-ra/powerctrl.c +++ b/ports/renesas-ra/powerctrl.c @@ -175,7 +175,7 @@ const lpm_instance_t g_lpm_standby = { #endif NORETURN void powerctrl_mcu_reset(void) { - #if BSP_FEATURE_TZ_HAS_TRUSTZONE + #if BSP_TZ_SECURE_BUILD R_BSP_NonSecureEnter(); #else NVIC_SystemReset(); diff --git a/ports/renesas-ra/ra/ra_adc.c b/ports/renesas-ra/ra/ra_adc.c index e7a270a19483c..fc6583e80e199 100644 --- a/ports/renesas-ra/ra/ra_adc.c +++ b/ports/renesas-ra/ra/ra_adc.c @@ -31,13 +31,13 @@ #include "ra_utils.h" #include "ra_adc.h" -static R_ADC0_Type *adc_reg = (R_ADC0_Type *)0x4005c000; +static R_ADC0_Type *adc_reg = R_ADC0; #if defined(RA4M1) | defined(RA4W1) static R_TSN_Type *tsn_reg = (R_TSN_Type *)0x407ec000; #endif -#if defined(RA6M1) | defined(RA6M2) -static R_TSN_CTRL_Type *tsn_ctrl_reg = (R_TSN_CTRL_Type *)0x4005D000; -static R_TSN_CAL_Type *tsn_cal_reg = (R_TSN_CAL_Type *)0x407FB17C; +#if defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) +static R_TSN_CTRL_Type *tsn_ctrl_reg = R_TSN_CTRL; +static R_TSN_CAL_Type *tsn_cal_reg = R_TSN_CAL; #endif static uint8_t resolution = RA_ADC_DEF_RESOLUTION; @@ -110,6 +110,63 @@ static const adc_pin_to_ch_t pin_to_ch[] = { { P506, AN019 }, { P509, AN020 }, + #elif defined(RA6M3) + { P000, AN000 }, + { P001, AN001 }, + { P002, AN002 }, + { P003, AN007 }, + { P004, AN100 }, + { P005, AN101 }, + { P006, AN102 }, + { P007, AN107 }, + { P008, AN003 }, + { P009, AN004 }, + { P010, AN103 }, + { P014, AN005 }, + { P014, AN105 }, + { P015, AN006 }, + { P015, AN106 }, + { P500, AN016 }, + { P501, AN116 }, + { P502, AN017 }, + { P503, AN117 }, + { P504, AN018 }, + { P505, AN118 }, + { P506, AN019 }, + { P507, AN119 }, + { P508, AN020 }, + + #elif defined(RA6M5) + { P000, AN000 }, + { P001, AN001 }, + { P002, AN002 }, + { P003, AN003 }, + { P004, AN004 }, + { P005, AN005 }, + { P006, AN006 }, + { P007, AN007 }, + { P008, AN008 }, + { P009, AN009 }, + { P010, AN010 }, + { P014, AN012 }, + { P015, AN013 }, + { P000, AN100 }, + { P001, AN101 }, + { P002, AN002 }, + { P500, AN116 }, + { P501, AN117 }, + { P502, AN118 }, + { P503, AN119 }, + { P504, AN120 }, + { P505, AN121 }, + { P506, AN122 }, + { P507, AN123 }, + { P508, AN124 }, + { P800, AN125 }, + { P801, AN126 }, + { P802, AN127 }, + { P803, AN128 }, + #elif defined(RA6M1) { P000, AN000 }, { P001, AN001 }, @@ -191,7 +248,7 @@ static void ra_adc0_module_stop(void) { ra_mstpcrd_stop(R_MSTP_MSTPCRD_MSTPD16_Msk); } -#if defined(RA6M1) | defined(RA6M2) +#if defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) static void ra_adc1_module_start(void) { ra_mstpcrd_start(R_MSTP_MSTPCRD_MSTPD15_Msk); } @@ -202,7 +259,7 @@ static void ra_adc1_module_stop(void) { #endif // For RA4M1 and RA4W1, there is no TSN configuration -#if defined(RA6M1) | defined(RA6M2) +#if defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) static void ra_tsn_module_start(void) { ra_mstpcrd_start(R_MSTP_MSTPCRD_MSTPD22_Msk); } @@ -324,7 +381,7 @@ uint8_t ra_adc_get_resolution(void) { uint16_t ra_adc_read_ch(uint8_t ch) { uint16_t value16 = 0; if ((ch == ADC_TEMP) | (ch == ADC_REF)) { - #if defined(RA6M1) | defined(RA6M2) + #if defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) if (ch == ADC_TEMP) { adc_reg->ADEXICR_b.TSSA = 1; tsn_ctrl_reg->TSCR_b.TSEN = 1; @@ -360,7 +417,7 @@ uint16_t ra_adc_read_ch(uint8_t ch) { } else { value16 = (uint16_t)adc_reg->ADDR[ch]; } - #if defined(RA6M1) | defined(RA6M2) + #if defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) if (ch == ADC_TEMP) { tsn_ctrl_reg->TSCR_b.TSOE = 0; while (tsn_ctrl_reg->TSCR_b.TSOE) { @@ -394,7 +451,7 @@ int16_t ra_adc_read_itemp(void) { int16_t v125 = (int16_t)(33 * cal125 / vmax / 10); int16_t vtemp = (int16_t)(33 * val / vmax / 10); temp = (int16_t)(125 + ((vtemp - v125) * 1000000 / (int16_t)BSP_FEATURE_ADC_TSN_SLOPE)); - #elif defined(RA6M1) | defined(RA6M2) + #elif defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) uint16_t cal127 = (uint16_t)tsn_cal_reg->TSCDR; uint16_t val = ra_adc_read_ch(ADC_TEMP); int16_t v127 = (int16_t)(33 * cal127 / vmax / 10); @@ -416,7 +473,7 @@ float ra_adc_read_ftemp(void) { float vtemp = (float)(3.3f * (float)val / vmax); temp = (float)(125.0f + ((vtemp - v125) * 1000000.0f / (float)BSP_FEATURE_ADC_TSN_SLOPE)); #endif - #if defined(RA6M1) | defined(RA6M2) + #if defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) uint16_t cal127 = (uint16_t)tsn_cal_reg->TSCDR; uint16_t val = ra_adc_read_ch(ADC_TEMP); float v127 = (float)(3.3f * (float)cal127 / vmax); @@ -487,7 +544,7 @@ void ra_adc_all(__attribute__((unused)) uint32_t resolution, uint32_t mask) { adc_reg->ADANSA[0] = 0; adc_reg->ADANSA[1] = 0; adc_reg->ADEXICR_b.TSSA = 1; - #if defined(RA6M1) | defined(RA6M2) + #if defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) tsn_ctrl_reg->TSCR_b.TSEN = 1; while (!tsn_ctrl_reg->TSCR_b.TSEN) { ; @@ -505,7 +562,7 @@ void ra_adc_all(__attribute__((unused)) uint32_t resolution, uint32_t mask) { } value16 = (uint16_t)adc_reg->ADTSDR; adc_values[ADC_TEMP] = value16; - #if defined(RA6M1) | defined(RA6M2) + #if defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) tsn_ctrl_reg->TSCR_b.TSOE = 0; while (tsn_ctrl_reg->TSCR_b.TSOE) { ; @@ -533,7 +590,7 @@ void ra_adc_all(__attribute__((unused)) uint32_t resolution, uint32_t mask) { bool ra_adc_init(void) { ra_adc0_module_start(); - #if defined(RA6M1) | defined(RA6M2) + #if defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) ra_adc1_module_start(); ra_tsn_module_start(); #endif @@ -544,7 +601,7 @@ bool ra_adc_init(void) { bool ra_adc_deinit(void) { ra_adc0_module_stop(); - #if defined(RA6M1) | defined(RA6M2) + #if defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) ra_adc1_module_stop(); ra_tsn_module_stop(); #endif diff --git a/ports/renesas-ra/ra/ra_adc.h b/ports/renesas-ra/ra/ra_adc.h index 4d56243d1eb7a..c6befa9f2787b 100644 --- a/ports/renesas-ra/ra/ra_adc.h +++ b/ports/renesas-ra/ra/ra_adc.h @@ -148,6 +148,67 @@ enum ADC14_PIN AN117 = 49, AN118 = 50, + #elif defined(RA6M3) + // Unit 0 + AN000 = 0, + AN001 = 1, + AN002 = 2, + AN003 = 3, + AN004 = 4, + AN005 = 5, + AN006 = 6, + AN007 = 7, + AN016 = 16, + AN017 = 17, + AN018 = 18, + AN019 = 19, + AN020 = 20, + // Unit 1 + AN100 = 32, + AN101 = 33, + AN102 = 34, + AN103 = 35, + AN105 = 37, + AN106 = 38, + AN107 = 39, + AN116 = 48, + AN117 = 49, + AN118 = 50, + AN119 = 51, + + #elif defined(RA6M5) + // Unit 0 + AN000 = 0, + AN001 = 1, + AN002 = 2, + AN003 = 3, + AN004 = 4, + AN005 = 5, + AN006 = 6, + AN007 = 7, + AN008 = 8, + AN009 = 9, + AN010 = 10, + AN012 = 12, + AN013 = 13, + // Unit 1 + AN100 = 32, + AN101 = 33, + AN102 = 34, + AN116 = 35, + AN117 = 37, + AN118 = 38, + AN119 = 39, + AN120 = 48, + AN121 = 49, + AN122 = 50, + AN123 = 51, + AN124 = 52, + AN125 = 53, + AN126 = 54, + AN127 = 55, + AN128 = 56, + #else #error "CMSIS MCU Series is not specified." #endif diff --git a/ports/renesas-ra/ra/ra_config.h b/ports/renesas-ra/ra/ra_config.h index c02947a47bc41..a2df775c8902b 100644 --- a/ports/renesas-ra/ra/ra_config.h +++ b/ports/renesas-ra/ra/ra_config.h @@ -39,6 +39,12 @@ #define SCI_TX_BUF_SIZE 128 #define SCI_RX_BUF_SIZE 256 #define PCLK 120000000 +#elif defined(RA6M5) +#define SCI_CH_MAX 10 +#define SCI_CH_NUM 4 +#define SCI_TX_BUF_SIZE 128 +#define SCI_RX_BUF_SIZE 256 +#define PCLK 100000000 #else #error "CMSIS MCU Series is not specified." #endif diff --git a/ports/renesas-ra/ra/ra_dac.c b/ports/renesas-ra/ra/ra_dac.c new file mode 100644 index 0000000000000..e1b2008f72f81 --- /dev/null +++ b/ports/renesas-ra/ra/ra_dac.c @@ -0,0 +1,168 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023 Vekatech Ltd. + * + * 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. + */ + +/* FSP has available API for DAC (r_dac) + +R_DAC_Open ( ... ) +R_DAC_Stop ( ... ) +R_DAC_Start ( ... ) +R_DAC_Write ( ... ) +R_DAC_Close ( ... ) + +and this is (The Lazy way) + + ... but looking to other drivers implementation (for example AGT [ra_timer.c/h]), Renesas want to be hard, so ... + + (The Hard way it is) +*/ + +#include "hal_data.h" +#include "ra_config.h" +#include "ra_gpio.h" +#include "ra_sci.h" +// #include "ra_int.h" +#include "ra_utils.h" +#include "ra_dac.h" + + + +#if defined(RA4M1) || defined(RA4W1) +#define DAC_CH_SIZE 1 +#elif defined(RA6M1) || defined(RA6M2) || defined(RA6M3) || defined(RA6M5) +#define DAC_CH_SIZE 2 +#else +#error "CMSIS MCU Series is not specified." +#endif + +#define DAC_PINS_SIZE sizeof(ra_dac_pins) / sizeof(ra_af_pin_t) + +static const ra_af_pin_t ra_dac_pins[] = { + #if defined(RA4M1) || defined(RA4W1) + { AF_GPIO, 0, P014 }, // (A3) + #elif defined(RA6M1) || defined(RA6M2) || defined(RA6M3) || defined(RA6M5) + { AF_GPIO, 0, P014 }, // (A4) + { AF_GPIO, 1, P015 }, // (A5) + #else + #error "CMSIS MCU Series is not specified." + #endif +}; + +static void ra_dac_set_pin(uint32_t pin) { + bool find = false; + uint32_t ch; + uint32_t af; + find = ra_af_find_ch_af((ra_af_pin_t *)&ra_dac_pins, DAC_PINS_SIZE, pin, &ch, &af); + if (find) { + ra_gpio_config(pin, GPIO_MODE_ANALOG, GPIO_NOPULL, GPIO_LOW_POWER, af); + // pwpr_unprotect(); + // _PXXPFS(GPIO_PORT(pin), GPIO_BIT(pin)) &= ~(PDR_MASK); + // _PXXPFS(GPIO_PORT(pin), GPIO_BIT(pin)) |= PDR_MASK; // output + // pwpr_protect(); + } +} + +static void ra_dac_release_pin(uint32_t pin) { + bool find = false; + uint32_t ch; + uint32_t af; + find = ra_af_find_ch_af((ra_af_pin_t *)&ra_dac_pins, DAC_PINS_SIZE, pin, &ch, &af); + if (find) { + ra_gpio_config(pin, GPIO_MODE_ANALOG, GPIO_NOPULL, GPIO_LOW_POWER, AF_GPIO); + // pwpr_unprotect(); + // _PXXPFS(GPIO_PORT(pin), GPIO_BIT(pin)) &= ~(PDR_MASK); + // pwpr_protect(); + } +} + +bool ra_dac_is_dac_pin(uint32_t pin) { + uint32_t ch; + uint32_t af; + return ra_af_find_ch_af((ra_af_pin_t *)&ra_dac_pins, DAC_PINS_SIZE, pin, &ch, &af); +} + +uint8_t ra_dac_is_running(uint8_t ch) { + if (ch < DAC_CH_SIZE) { + return ch? R_DAC->DACR_b.DAOE1 : R_DAC->DACR_b.DAOE0; + } else { + return 0; + } +} + +void ra_dac_start(uint8_t ch) { + if (ch < DAC_CH_SIZE) { + if (ch) { + R_DAC->DACR_b.DAOE1 = 1U; + } else { + R_DAC->DACR_b.DAOE0 = 1U; + } + } +} + +void ra_dac_stop(uint8_t ch) { + if (ch < DAC_CH_SIZE) { + if (ch) { + R_DAC->DACR_b.DAOE1 = 0U; + } else { + R_DAC->DACR_b.DAOE0 = 0U; + } + } +} + +void ra_dac_write(uint8_t ch, uint16_t val) { + if ((ch < DAC_CH_SIZE) || (val < 4096)) { + R_DAC->DADR[ch] = val; + } +} + +uint16_t ra_dac_read(uint8_t ch) { + if (ch < DAC_CH_SIZE) { + return R_DAC->DADR[ch]; + } else { + return 0; + } +} + +void ra_dac_init(uint32_t dac_pin, uint8_t ch) { + if (ch < DAC_CH_SIZE) { + ra_mstpcrd_start(R_MSTP_MSTPCRD_MSTPD20_Msk); + + R_DAC->DADPR_b.DPSEL = 0; // Right-justified format + R_DAC->DAADSCR_b.DAADST = 0; // Do not synchronize with ADC14 + R_DAC->DAVREFCR_b.REF = 1; // AVCC0/AVSS0 selected + R_DAC->DADR[ch] = 0; // Output 0 Volts + + ra_dac_set_pin(dac_pin); + ra_dac_start(ch); + } +} + +void ra_dac_deinit(uint32_t dac_pin, uint8_t ch) { + if (ch < DAC_CH_SIZE) { + ra_dac_stop(ch); + R_DAC->DAVREFCR_b.REF = 0; // No reference voltage selected + ra_dac_release_pin(dac_pin); + + ra_mstpcrd_stop(R_MSTP_MSTPCRD_MSTPD20_Msk); + } +} diff --git a/ports/renesas-ra/ra/ra_dac.h b/ports/renesas-ra/ra/ra_dac.h new file mode 100644 index 0000000000000..5afa11d9737f2 --- /dev/null +++ b/ports/renesas-ra/ra/ra_dac.h @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023 Vekatech Ltd. + * + * 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. + */ + + + +#ifndef RA_RA_DAC_H_ +#define RA_RA_DAC_H_ + +#include + +void ra_dac_start(uint8_t ch); +void ra_dac_stop(uint8_t ch); +uint8_t ra_dac_is_running(uint8_t ch); +uint16_t ra_dac_read(uint8_t ch); +void ra_dac_write(uint8_t ch, uint16_t val); +void ra_dac_init(uint32_t dac_pin, uint8_t ch); +void ra_dac_deinit(uint32_t dac_pin, uint8_t ch); +bool ra_dac_is_dac_pin(uint32_t pin); + +#endif /* RA_RA_DAC_H_ */ diff --git a/ports/renesas-ra/ra/ra_flash.c b/ports/renesas-ra/ra/ra_flash.c index e289f5f924b3c..933e3fef9e6b1 100644 --- a/ports/renesas-ra/ra/ra_flash.c +++ b/ports/renesas-ra/ra/ra_flash.c @@ -2,6 +2,7 @@ * The MIT License (MIT) * * Copyright (c) 2021 Renesas Electronics Corporation + * Copyright (c) 2023 Vekatech Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,6 +24,7 @@ */ #include +#include "py/mpconfig.h" #include "hal_data.h" #include "ra_config.h" #include "ra_utils.h" @@ -47,6 +49,115 @@ static volatile _Bool g_b_flash_event_write_complete = false; static uint8_t flash_buf[FLASH_BUF_SIZE] __attribute__((aligned(2))); +#ifdef USE_FSP_QSPI +#if MICROPY_HW_HAS_QSPI_FLASH +static bool r_qspi_get_QE(void) { + /* Enter direct communication mode */ + R_QSPI->SFMCMD = 1U; + + R_QSPI->SFMCOM = 0x35; + bool sts = (R_QSPI->SFMCOM >> 1) & 1; + + /* Close the SPI bus cycle. Reference section 39.10.3 "Generating the SPI Bus Cycle during Direct Communication" + * in the RA6M3 manual R01UH0886EJ0100. */ + R_QSPI->SFMCMD = 1U; + + /* Exit direct communication mode */ + R_QSPI->SFMCMD = 0U; + + return sts; +} + +static void r_qspi_set_QE(qspi_instance_ctrl_t *p_instance_ctrl) { + /* Enter direct communication mode */ + R_QSPI->SFMCMD = 1U; + + /* Enable write. */ + R_QSPI->SFMCOM = p_instance_ctrl->p_cfg->write_enable_command; + + /* Close the SPI bus cycle. Reference section 39.10.3 "Generating the SPI Bus Cycle during Direct Communication" + * in the RA6M3 manual R01UH0886EJ0100. */ + R_QSPI->SFMCMD = 1U; + + R_QSPI->SFMCOM = 0x31; + R_QSPI->SFMCOM = 0x02; + + /* Close the SPI bus cycle. Reference section 39.10.3 "Generating the SPI Bus Cycle during Direct Communication" + * in the RA6M3 manual R01UH0886EJ0100. */ + R_QSPI->SFMCMD = 1U; + + /* Exit direct communication mode */ + R_QSPI->SFMCMD = 0U; +} + +static void r_qspi_wait_WIP(qspi_instance_ctrl_t *p_instance_ctrl) { + /* Enter direct communication mode */ + R_QSPI->SFMCMD = 1U; + + R_QSPI->SFMCOM = p_instance_ctrl->p_cfg->status_command; + while ((R_QSPI->SFMCOM >> p_instance_ctrl->p_cfg->write_status_bit) & 1) { + ; + } + + /* Close the SPI bus cycle. Reference section 39.10.3 "Generating the SPI Bus Cycle during Direct Communication" + * in the RA6M3 manual R01UH0886EJ0100. */ + R_QSPI->SFMCMD = 1U; + + /* Exit direct communication mode */ + R_QSPI->SFMCMD = 0U; +} + +static fsp_err_t R_QSPI_QuadEnable(spi_flash_ctrl_t *p_ctrl) { + qspi_instance_ctrl_t *p_instance_ctrl = (qspi_instance_ctrl_t *)p_ctrl; + + #if QSPI_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_instance_ctrl); + FSP_ASSERT(NULL != p_status); + FSP_ERROR_RETURN(QSPI_PRV_OPEN == p_instance_ctrl->open, FSP_ERR_NOT_OPEN); + + /* Do not enter direct communication mode from XIP mode. Reference note in section 39.10.2 "Using Direct + * Communication Mode" in the RA6M3 manual R01UH0886EJ0100. */ + FSP_ERROR_RETURN(0U == R_QSPI->SFMSDC_b.SFMXST, FSP_ERR_INVALID_MODE); + #endif + + /* Read device status. */ + if (!r_qspi_get_QE()) { + r_qspi_set_QE(p_instance_ctrl); + } + + return FSP_SUCCESS; +} + +static fsp_err_t R_QSPI_Wait_WIP(spi_flash_ctrl_t *p_ctrl) { + qspi_instance_ctrl_t *p_instance_ctrl = (qspi_instance_ctrl_t *)p_ctrl; + + #if QSPI_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_instance_ctrl); + FSP_ASSERT(NULL != p_status); + FSP_ERROR_RETURN(QSPI_PRV_OPEN == p_instance_ctrl->open, FSP_ERR_NOT_OPEN); + + /* Do not enter direct communication mode from XIP mode. Reference note in section 39.10.2 "Using Direct + * Communication Mode" in the RA6M3 manual R01UH0886EJ0100. */ + FSP_ERROR_RETURN(0U == R_QSPI->SFMSDC_b.SFMXST, FSP_ERR_INVALID_MODE); + #endif + + /* Wait WIP flag to go 0 */ + r_qspi_wait_WIP(p_instance_ctrl); + + return FSP_SUCCESS; +} + +static bool lmemprob(void *dst, size_t len) { + uint8_t *p; + for (p = (uint8_t *)dst; ((len > 0) && (p[0] == 0xFF)); len--) { + p++; + } + + return len? false : true; +} +#endif +#endif + void *FLASH_SECTION lmemset(void *dst, int c, size_t len) { char *p; for (p = (char *)dst; len > 0; len--) { @@ -80,7 +191,7 @@ int FLASH_SECTION lmemcmp(const void *p1, const void *p2, size_t len) { return (int)0; } -#if defined(RA4M1) | defined(RA4M3) | defined(RA4W1) +#if defined(RA4M1) | defined(RA4M3) | defined(RA4W1) | MICROPY_HW_HAS_QSPI_FLASH uint32_t FLASH_SECTION sector_size(uint32_t addr) { return FLASH_SECTOR_SIZE; @@ -94,7 +205,7 @@ uint32_t FLASH_SECTION sector_index(uint32_t addr) { return (addr - 0x00000000) / FLASH_SECTOR_SIZE; } -#elif defined(RA6M1) | defined(RA6M2) +#elif defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) #define REGION1_SECTOR_SIZE 0x8000 // 32K #define REGION1_SECTOR_MAX 14 @@ -102,7 +213,7 @@ uint32_t FLASH_SECTION sector_index(uint32_t addr) { #define REGION0_SECTOR_MAX 8 uint32_t FLASH_SECTION sector_size(uint32_t addr) { - if (addr <= 0x00010000) { + if (addr < 0x00010000) { return REGION0_SECTOR_SIZE; } else { return REGION1_SECTOR_SIZE; @@ -110,7 +221,7 @@ uint32_t FLASH_SECTION sector_size(uint32_t addr) { } uint32_t FLASH_SECTION sector_start(uint32_t addr) { - if (addr <= 0x00010000) { + if (addr < 0x00010000) { return addr & ~(REGION0_SECTOR_SIZE - 1); } else { return addr & ~(REGION1_SECTOR_SIZE - 1); @@ -118,10 +229,10 @@ uint32_t FLASH_SECTION sector_start(uint32_t addr) { } uint32_t FLASH_SECTION sector_index(uint32_t addr) { - if (addr <= 0x00010000) { - return (addr - 0x00010000) / REGION0_SECTOR_SIZE; + if (addr < 0x00010000) { + return (addr - 0x00000000) / REGION0_SECTOR_SIZE; } else { - return (addr - 0x000100000) / REGION1_SECTOR_SIZE; + return ((addr - 0x00010000) / REGION1_SECTOR_SIZE) + REGION0_SECTOR_SIZE; } } @@ -169,15 +280,23 @@ bool internal_flash_writex(uint8_t *addr, uint32_t NumBytes, uint8_t *pSectorBuf } g_b_flash_event_write_complete = false; uint8_t *flash_addr = (uint8_t *)((uint32_t)startaddr & FLASH_BUF_ADDR_MASK); + #if MICROPY_HW_HAS_QSPI_FLASH + for (uint16_t idx = 0; ((err == FSP_SUCCESS) && (idx < FLASH_SECTOR_SIZE)); idx += FLASH_PAGE_SIZE) + { + err = R_QSPI_Write(&g_qspi0_ctrl, &buf_addr[idx], &flash_addr[idx], FLASH_PAGE_SIZE); + err = R_QSPI_Wait_WIP(&g_qspi0_ctrl); + } + #else uint32_t state = ra_disable_irq(); #if defined(RA4M1) | defined(RA4M3) | defined(RA4W1) err = R_FLASH_LP_Write(&g_flash0_ctrl, (uint32_t const)buf_addr, (uint32_t)flash_addr, FLASH_SECTOR_SIZE); - #elif defined(RA6M1) | defined(RA6M2) + #elif defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) err = R_FLASH_HP_Write(&g_flash0_ctrl, (uint32_t const)buf_addr, (uint32_t)flash_addr, FLASH_SECTOR_SIZE); #else #error "CMSIS MCU Series is not specified." #endif ra_enable_irq(state); + #endif if (FSP_SUCCESS != err) { error_code = 1; goto WriteX_exit; @@ -205,14 +324,17 @@ bool internal_flash_memset(uint8_t *addr, uint8_t Data, uint32_t NumBytes) { } bool internal_flash_isblockerased(uint8_t *addr, uint32_t BlockLength) { - fsp_err_t err = FSP_SUCCESS; - flash_result_t blankCheck = FLASH_RESULT_BLANK; g_b_flash_event_not_blank = false; g_b_flash_event_blank = false; + #if MICROPY_HW_HAS_QSPI_FLASH + return lmemprob((uint8_t *)((uint32_t)addr & FLASH_BUF_ADDR_MASK), FLASH_SECTOR_SIZE); + #else + fsp_err_t err = FSP_SUCCESS; + flash_result_t blankCheck = FLASH_RESULT_BLANK; uint32_t state = ra_disable_irq(); #if defined(RA4M1) | defined(RA4M3) | defined(RA4W1) err = R_FLASH_LP_BlankCheck(&g_flash0_ctrl, (uint32_t const)((uint32_t)addr & FLASH_BUF_ADDR_MASK), FLASH_SECTOR_SIZE, &blankCheck); - #elif defined(RA6M1) | defined(RA6M2) + #elif defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) err = R_FLASH_HP_BlankCheck(&g_flash0_ctrl, (uint32_t const)((uint32_t)addr & FLASH_BUF_ADDR_MASK), FLASH_SECTOR_SIZE, &blankCheck); #else #error "CMSIS MCU Series is not specified." @@ -227,21 +349,29 @@ bool internal_flash_isblockerased(uint8_t *addr, uint32_t BlockLength) { } else { return false; } + #endif } bool internal_flash_eraseblock(uint8_t *addr) { uint32_t error_code = 0; fsp_err_t err = FSP_SUCCESS; g_b_flash_event_erase_complete = false; + #if MICROPY_HW_HAS_QSPI_FLASH + if (!lmemprob((uint8_t *)((uint32_t)addr & FLASH_BUF_ADDR_MASK), FLASH_SECTOR_SIZE)) { + err = R_QSPI_Erase(&g_qspi0_ctrl, (uint8_t *const)addr, FLASH_SECTOR_SIZE); + err = R_QSPI_Wait_WIP(&g_qspi0_ctrl); + } + #else uint32_t state = ra_disable_irq(); #if defined(RA4M1) | defined(RA4M3) | defined(RA4W1) err = R_FLASH_LP_Erase(&g_flash0_ctrl, (uint32_t const)addr, 1); - #elif defined(RA6M1) | defined(RA6M2) + #elif defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) err = R_FLASH_HP_Erase(&g_flash0_ctrl, (uint32_t const)addr, 1); #else #error "CMSIS MCU Series is not specified." #endif ra_enable_irq(state); + #endif if (err == FSP_SUCCESS) { error_code = 0; } else { @@ -277,9 +407,18 @@ void callback_flash(flash_callback_args_t *p_args) { bool internal_flash_init(void) { fsp_err_t err = FSP_SUCCESS; + #if MICROPY_HW_HAS_QSPI_FLASH + err = R_QSPI_Open(&g_qspi0_ctrl, &g_qspi0_cfg); + if (err == FSP_SUCCESS) { + R_QSPI_QuadEnable(&g_qspi0_ctrl); + return true; + } else { + return false; + } + #else #if defined(RA4M1) | defined(RA4M3) | defined(RA4W1) err = R_FLASH_LP_Open(&g_flash0_ctrl, &g_flash0_cfg); - #elif defined(RA6M1) | defined(RA6M2) + #elif defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) err = R_FLASH_HP_Open(&g_flash0_ctrl, &g_flash0_cfg); #else #error "CMSIS MCU Series is not specified." @@ -289,6 +428,7 @@ bool internal_flash_init(void) { } else { return false; } + #endif } #else diff --git a/ports/renesas-ra/ra/ra_flash.h b/ports/renesas-ra/ra/ra_flash.h index f9afef2a948f6..f6e01daff5bf8 100644 --- a/ports/renesas-ra/ra/ra_flash.h +++ b/ports/renesas-ra/ra/ra_flash.h @@ -29,8 +29,27 @@ #include #include +#if MICROPY_HW_HAS_QSPI_FLASH +#define SELECT(ic, attr) ic##_##attr +#define FLASH(ic, attr) SELECT(ic, attr) +#define CHIP AT25SF128A +// #define CHIP W25Q128JV + +#define W25Q128JV_SECTOR_SIZE 4096ul +#define W25Q128JV_NUM_BLOCKS 4096ul +#define W25Q128JV_PAGE_SIZE 256ul + +#define AT25SF128A_SECTOR_SIZE 4096ul +#define AT25SF128A_NUM_BLOCKS 4096ul +#define AT25SF128A_PAGE_SIZE 256ul + +#define FLASH_SECTOR_SIZE FLASH(CHIP, SECTOR_SIZE) +#define FLASH_NUM_BLOCKS FLASH(CHIP, NUM_BLOCKS) +#define FLASH_PAGE_SIZE FLASH(CHIP, PAGE_SIZE) +#else #define FLASH_SECTOR_SIZE ((uint32_t)2048) #define FLASH_NUM_BLOCKS ((uint32_t)128) +#endif #define FLASH_BUF_OFF_MASK (FLASH_SECTOR_SIZE - 1) #define FLASH_BUF_ADDR_MASK (~FLASH_BUF_OFF_MASK) #define FLASH_BUF_SIZE FLASH_SECTOR_SIZE diff --git a/ports/renesas-ra/ra/ra_gpio.h b/ports/renesas-ra/ra/ra_gpio.h index 8c16fe3ba18c7..58df7aafe9987 100644 --- a/ports/renesas-ra/ra/ra_gpio.h +++ b/ports/renesas-ra/ra/ra_gpio.h @@ -42,10 +42,12 @@ enum CPU_PIN { P300 = 0x30, P301, P302, P303, P304, P305, P306, P307, P308, P309, P310, P311, P312, P313, P314, P315, P400 = 0x40, P401, P402, P403, P404, P405, P406, P407, P408, P409, P410, P411, P412, P413, P414, P415, P500 = 0x50, P501, P502, P503, P504, P505, P506, P507, P508, P509, P510, P511, P512, P513, P514, P515, - P600 = 0x90, P601, P602, P603, P604, P605, P606, P607, P608, P609, P610, P611, P612, P613, P614, P615, + P600 = 0x60, P601, P602, P603, P604, P605, P606, P607, P608, P609, P610, P611, P612, P613, P614, P615, P700 = 0x70, P701, P702, P703, P704, P705, P706, P707, P708, P709, P710, P711, P712, P713, P714, P715, P800 = 0x80, P801, P802, P803, P804, P805, P806, P807, P808, P809, P810, P811, P812, P813, P814, P815, P900 = 0x90, P901, P902, P903, P904, P905, P906, P907, P908, P909, P910, P911, P912, P913, P914, P915, + PA00 = 0xA0, PA01, PA02, PA03, PA04, PA05, PA06, PA07, PA08, PA09, PA10, PA11, PA12, PA13, PA14, PA15, + PB00 = 0xB0, PB01, PB02, PB03, PB04, PB05, PB06, PB07, PB08, PB09, PB10, PB11, PB12, PB13, PB14, PB15, PIN_END = 0xff, }; @@ -126,35 +128,35 @@ enum AF_INDEX { #define PMR_MASK (uint32_t)0x00010000 #define PSEL_MASK (uint32_t)0x1f000000 -#define _PWPR (*(volatile uint8_t *)(0x40040D03)) - -#define _PXXPFS(port, bit) (*(volatile uint32_t *)(0x40040800 + (0x40 * ((uint32_t)port)) + (0x4 * ((uint32_t)bit)))) -#define _PCNTR1(port) (*(volatile uint32_t *)(0x40040000 + (0x20 * (port)))) -#define _PODR(port) (*(volatile uint16_t *)(0x40040000 + (0x20 * (port)))) -#define _PDR(port) (*(volatile uint16_t *)(0x40040002 + (0x20 * (port)))) -#define _PCNTR2(port) (*(volatile uint32_t *)(0x40040004 + (0x20 * (port)))) -#define _EIDR(port) (*(volatile uint16_t *)(0x40040004 + (0x20 * (port)))) -#define _PIDR(port) (*(volatile uint16_t *)(0x40040006 + (0x20 * (port)))) -#define _PCNTR3(port) (*(volatile uint32_t *)(0x40040008 + (0x20 * (port)))) -#define _PORR(port) (*(volatile uint16_t *)(0x40040008 + (0x20 * (port)))) -#define _POSR(port) (*(volatile uint16_t *)(0x4004000a + (0x20 * (port)))) -#define _PCNTR4(port) (*(volatile uint32_t *)(0x4004000c + (0x20 * (port)))) -#define _EORR(port) (*(volatile uint16_t *)(0x4004000c + (0x20 * (port)))) -#define _EOSR(port) (*(volatile uint16_t *)(0x4004000e + (0x20 * (port)))) - -#define _PPXXPFS(port, bit) ((volatile uint32_t *)(0x40040800 + (0x40 * (port)) + (0x4 * (bit)))) -#define _PPCNTR1(port) ((volatile uint32_t *)(0x40040000 + (0x20 * (port)))) -#define _PPODR(port) ((volatile uint16_t *)(0x40040000 + (0x20 * (port)))) -#define _PPDR(port) ((volatile uint16_t *)(0x40040002 + (0x20 * (port)))) -#define _PPCNTR2(port) ((volatile uint32_t *)(0x40040004 + (0x20 * (port)))) -#define _PEIDR(port) ((volatile uint16_t *)(0x40040004 + (0x20 * (port)))) -#define _PPIDR(port) ((volatile uint16_t *)(0x40040006 + (0x20 * (port)))) -#define _PPCNTR3(port) ((volatile uint32_t *)(0x40040008 + (0x20 * (port)))) -#define _PPORR(port) ((volatile uint16_t *)(0x40040008 + (0x20 * (port)))) -#define _PPOSR(port) ((volatile uint16_t *)(0x4004000a + (0x20 * (port)))) -#define _PPCNTR4(port) ((volatile uint32_t *)(0x4004000c + (0x20 * (port)))) -#define _PEORR(port) ((volatile uint16_t *)(0x4004000c + (0x20 * (port)))) -#define _PEOSR(port) ((volatile uint16_t *)(0x4004000e + (0x20 * (port)))) +#define _PWPR (*(volatile uint8_t *)(R_PFS_BASE + 0x503)) + +#define _PXXPFS(port, bit) (*(volatile uint32_t *)(R_PFS_BASE + (0x40 * ((uint32_t)port)) + (0x4 * ((uint32_t)bit)))) +#define _PCNTR1(port) (*(volatile uint32_t *)(R_PORT0_BASE + (0x20 * (port)))) +#define _PODR(port) (*(volatile uint16_t *)(R_PORT0_BASE + (0x20 * (port)))) +#define _PDR(port) (*(volatile uint16_t *)(R_PORT0_BASE + 0x2 + (0x20 * (port)))) +#define _PCNTR2(port) (*(volatile uint32_t *)(R_PORT0_BASE + 0x4 + (0x20 * (port)))) +#define _EIDR(port) (*(volatile uint16_t *)(R_PORT0_BASE + 0x4 + (0x20 * (port)))) +#define _PIDR(port) (*(volatile uint16_t *)(R_PORT0_BASE + 0x6 + (0x20 * (port)))) +#define _PCNTR3(port) (*(volatile uint32_t *)(R_PORT0_BASE + 0x8 + (0x20 * (port)))) +#define _PORR(port) (*(volatile uint16_t *)(R_PORT0_BASE + 0x8 + (0x20 * (port)))) +#define _POSR(port) (*(volatile uint16_t *)(R_PORT0_BASE + 0xa + (0x20 * (port)))) +#define _PCNTR4(port) (*(volatile uint32_t *)(R_PORT0_BASE + 0xc + (0x20 * (port)))) +#define _EORR(port) (*(volatile uint16_t *)(R_PORT0_BASE + 0xc + (0x20 * (port)))) +#define _EOSR(port) (*(volatile uint16_t *)(R_PORT0_BASE + 0xe + (0x20 * (port)))) + +#define _PPXXPFS(port, bit) ((volatile uint32_t *)(R_PFS_BASE + (0x40 * (port)) + (0x4 * (bit)))) +#define _PPCNTR1(port) ((volatile uint32_t *)(R_PORT0_BASE + (0x20 * (port)))) +#define _PPODR(port) ((volatile uint16_t *)(R_PORT0_BASE + (0x20 * (port)))) +#define _PPDR(port) ((volatile uint16_t *)(R_PORT0_BASE + 0x2 + (0x20 * (port)))) +#define _PPCNTR2(port) ((volatile uint32_t *)(R_PORT0_BASE + 0x4 + (0x20 * (port)))) +#define _PEIDR(port) ((volatile uint16_t *)(R_PORT0_BASE + 0x4 + (0x20 * (port)))) +#define _PPIDR(port) ((volatile uint16_t *)(R_PORT0_BASE + 0x6 + (0x20 * (port)))) +#define _PPCNTR3(port) ((volatile uint32_t *)(R_PORT0_BASE + 0x8 + (0x20 * (port)))) +#define _PPORR(port) ((volatile uint16_t *)(R_PORT0_BASE + 0x8 + (0x20 * (port)))) +#define _PPOSR(port) ((volatile uint16_t *)(R_PORT0_BASE + 0xa + (0x20 * (port)))) +#define _PPCNTR4(port) ((volatile uint32_t *)(R_PORT0_BASE + 0xc + (0x20 * (port)))) +#define _PEORR(port) ((volatile uint16_t *)(R_PORT0_BASE + 0xc + (0x20 * (port)))) +#define _PEOSR(port) ((volatile uint16_t *)(R_PORT0_BASE + 0xe + (0x20 * (port)))) void ra_gpio_config(uint32_t pin, uint32_t mode, uint32_t pull, uint32_t drive, uint32_t alt); void ra_gpio_mode_output(uint32_t pin); diff --git a/ports/renesas-ra/ra/ra_gpt.c b/ports/renesas-ra/ra/ra_gpt.c new file mode 100644 index 0000000000000..cca32c4d82357 --- /dev/null +++ b/ports/renesas-ra/ra/ra_gpt.c @@ -0,0 +1,626 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023 Vekatech Ltd. + * + * 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. + */ + +/* FSP has available API for PWM (r_gpt) + +R_GPT_Open ( ... ) +R_GPT_Stop ( ... ) +R_GPT_Start ( ... ) +R_GPT_Reset ( ... ) +R_GPT_Enable ( ... ) +R_GPT_Disable ( ... ) +R_GPT_PeriodSet ( ... ) +R_GPT_DutyCycleSet ( ... ) +R_GPT_InfoGet ( ... ) +R_GPT_StatusGet ( ... ) +R_GPT_CounterSet ( ... ) +R_GPT_OutputEnable ( ... ) +R_GPT_OutputDisable ( ... ) +R_GPT_AdcTriggerSet ( ... ) +R_GPT_CallbackSet ( ... ) +R_GPT_Close ( ... ) + +and this is (The Lazy way) + + ... but looking to other drivers implementation (for example AGT [ra_timer.c/h]), Renesas want to be hard, so ... + + (The Hard way it is) +*/ + +#include "hal_data.h" +#include "ra_config.h" +#include "ra_gpio.h" +#include "ra_sci.h" +// #include "ra_int.h" +#include "ra_utils.h" +#include "ra_gpt.h" + + + +#if defined(RA4M1) +#define GPT_CH_SIZE 8 +#define CH_GAP 0 +#elif defined(RA4W1) +#define GPT_CH_SIZE 9 +#define CH_GAP (ch == 6) || (ch == 7) +#elif defined(RA6M1) +#define GPT_CH_SIZE 13 +#define CH_GAP 0 +#elif defined(RA6M2) || defined(RA6M3) +#define GPT_CH_SIZE 14 +#define CH_GAP 0 +#elif defined(RA6M5) +#define GPT_CH_SIZE 10 +#define CH_GAP 0 +#else +#error "CMSIS MCU Series is not specified." +#endif + +enum GPT_SOURCE { + GPT_PCLKD = 0, + GPT_PCLKD4, + GPT_PCLKD16, + GPT_PCLKD64, + GPT_PCLKD256, + GPT_PCLKD1024 +}; + +static R_GPT0_Type *gpt_regs[GPT_CH_SIZE] = { + #if defined(RA4M1) + R_GPT0, // GPT320 General PWM Timer 0 (32-bit) + R_GPT1, // GPT321 General PWM Timer 1 (32-bit) + R_GPT2, // GPT162 General PWM Timer 2 (16-bit) + R_GPT3, // GPT163 General PWM Timer 3 (16-bit) + R_GPT4, // GPT164 General PWM Timer 4 (16-bit) + R_GPT5, // GPT165 General PWM Timer 5 (16-bit) + R_GPT6, // GPT166 General PWM Timer 6 (16-bit) + R_GPT7, // GPT167 General PWM Timer 7 (16-bit) + #elif defined(RA4W1) + R_GPT0, // GPT320 General PWM Timer 0 (32-bit) + R_GPT1, // GPT321 General PWM Timer 1 (32-bit) + R_GPT2, // GPT322 General PWM Timer 2 (32-bit) + R_GPT3, // GPT323 General PWM Timer 3 (32-bit) + R_GPT4, // GPT164 General PWM Timer 4 (16-bit) + R_GPT5, // GPT165 General PWM Timer 5 (16-bit) + NULL, // N/A PWM Timer 6 (Does not exist) + NULL, // N/A PWM Timer 7 (Does not exist) + R_GPT8 // GPT168 General PWM Timer 8 (16-bit) + #elif defined(RA6M1) || defined(RA6M2) || defined(RA6M3) + R_GPT0, // GPT32EH0 General PWM Timer 0 (32-bit) + R_GPT1, // GPT32EH1 General PWM Timer 1 (32-bit) + R_GPT2, // GPT32EH2 General PWM Timer 2 (32-bit) + R_GPT3, // GPT32EH3 General PWM Timer 3 (32-bit) + R_GPT4, // GPT32E4 General PWM Timer 4 (32-bit) + R_GPT5, // GPT32E5 General PWM Timer 5 (32-bit) + R_GPT6, // GPT32E6 General PWM Timer 6 (32-bit) + R_GPT7, // GPT32E7 General PWM Timer 7 (32-bit) + R_GPT8, // GPT328 General PWM Timer 8 (32-bit) + R_GPT9, // GPT329 General PWM Timer 9 (32-bit) + R_GPT10, // GPT3210 General PWM Timer 10 (32-bit) + R_GPT11, // GPT3211 General PWM Timer 11 (32-bit) + R_GPT12, // GPT3212 General PWM Timer 12 (32-bit) + #if defined(RA6M2) || defined(RA6M3) + R_GPT13, // GPT3213 General PWM Timer 13 (32-bit) + #endif + #elif defined(RA6M5) + R_GPT0, // GPT320 General PWM Timer 0 (32-bit) + R_GPT1, // GPT321 General PWM Timer 1 (32-bit) + R_GPT2, // GPT322 General PWM Timer 2 (32-bit) + R_GPT3, // GPT323 General PWM Timer 3 (32-bit) + R_GPT4, // GPT164 General PWM Timer 4 (16-bit) + R_GPT5, // GPT165 General PWM Timer 5 (16-bit) + R_GPT6, // GPT166 General PWM Timer 6 (16-bit) + R_GPT7, // GPT167 General PWM Timer 7 (16-bit) + R_GPT8, // GPT168 General PWM Timer 8 (16-bit) + R_GPT9, // GPT169 General PWM Timer 9 (16-bit) + #else + #error "CMSIS MCU Series is not specified." + #endif +}; + +#define GPT_TMR_PINS_SIZE sizeof(ra_gpt_timer_pins) / sizeof(ra_af_pin_t) + +static const ra_af_pin_t ra_gpt_timer_pins[] = { + #if defined(RA4M1) + { AF_GPT2, 0, P107 }, { AF_GPT2, 0, P213 }, { AF_GPT2, 0, P300 }, { AF_GPT2, 0, P415 }, // GTIOC0A + { AF_GPT2, 0, P106 }, { AF_GPT2, 0, P108 }, { AF_GPT2, 0, P212 }, { AF_GPT2, 0, P414 }, // GTIOC0B + { AF_GPT2, 1, P105 }, { AF_GPT2, 1, P109 }, { AF_GPT2, 1, P405 }, // GTIOC1A + { AF_GPT2, 1, P104 }, { AF_GPT2, 1, P110 }, { AF_GPT2, 1, P406 }, // GTIOC1B + { AF_GPT2, 2, P103 }, { AF_GPT2, 2, P113 }, { AF_GPT2, 2, P500 }, // GTIOC2A + { AF_GPT2, 2, P102 }, { AF_GPT2, 2, P114 }, { AF_GPT2, 2, P501 }, // GTIOC2B + { AF_GPT2, 3, P111 }, { AF_GPT2, 3, P403 }, // GTIOC3A + { AF_GPT2, 3, P112 }, { AF_GPT2, 3, P404 }, { AF_GPT2, 3, P502 }, // GTIOC3B + { AF_GPT2, 4, P115 }, { AF_GPT2, 4, P205 }, { AF_GPT2, 4, P302 }, // GTIOC4A + { AF_GPT2, 4, P204 }, { AF_GPT2, 4, P301 }, { AF_GPT2, 4, P608 }, // GTIOC4B + { AF_GPT2, 5, P101 }, { AF_GPT2, 5, P203 }, { AF_GPT2, 5, P409 }, { AF_GPT2, 5, P609 }, // GTIOC5A + { AF_GPT2, 5, P100 }, { AF_GPT2, 5, P202 }, { AF_GPT2, 5, P408 }, { AF_GPT2, 5, P610 }, // GTIOC5B + { AF_GPT2, 6, P400 }, { AF_GPT2, 6, P411 }, { AF_GPT2, 6, P601 }, // GTIOC6A + { AF_GPT2, 6, P401 }, { AF_GPT2, 6, P410 }, { AF_GPT2, 6, P600 }, // GTIOC6B + { AF_GPT2, 7, P304 }, { AF_GPT2, 7, P603 }, // GTIOC7A + { AF_GPT2, 7, P303 }, { AF_GPT2, 7, P602 }, // GTIOC7B + #elif defined(RA4W1) + { AF_GPT2, 0, P213 }, { AF_GPT2, 0, P300 }, // GTIOC0A + { AF_GPT2, 0, P108 }, { AF_GPT2, 0, P212 }, { AF_GPT2, 0, P414 }, // GTIOC0B + { AF_GPT2, 1, P105 }, { AF_GPT2, 1, P109 }, // GTIOC1A + { AF_GPT2, 1, P104 }, { AF_GPT2, 1, P110 }, // GTIOC1B + { AF_GPT2, 2, P103 }, // GTIOC2A + { AF_GPT2, 2, P102 }, { AF_GPT2, 2, P501 }, // GTIOC2B + { AF_GPT2, 3, P111 }, // GTIOC3A + { AF_GPT2, 3, P404 }, // GTIOC3B + { AF_GPT2, 4, P205 }, // GTIOC4A + { AF_GPT2, 4, P204 }, // GTIOC4B + { AF_GPT2, 5, P101 }, { AF_GPT2, 5, P409 }, // GTIOC5A + { AF_GPT2, 5, P100 }, // GTIOC5B + { AF_GPT2, 8, P107 }, // GTIOC8A + { AF_GPT2, 8, P106 }, // GTIOC8B + #elif defined(RA6M1) + { AF_GPT2, 0, P213 }, { AF_GPT2, 0, P415 }, // GTIOC0A + { AF_GPT2, 0, P212 }, { AF_GPT2, 0, P414 }, // GTIOC0B + { AF_GPT2, 1, P105 }, { AF_GPT2, 1, P405 }, // GTIOC1A + { AF_GPT2, 1, P104 }, { AF_GPT2, 1, P406 }, // GTIOC1B + { AF_GPT2, 2, P113 }, // GTIOC2A + { AF_GPT2, 2, P114 }, // GTIOC2B + { AF_GPT2, 3, P403 }, // GTIOC3A + { AF_GPT2, 3, P404 }, // GTIOC3B + { AF_GPT2, 4, P115 }, { AF_GPT2, 4, P205 }, { AF_GPT2, 4, P302 }, // GTIOC4A + { AF_GPT2, 4, P301 }, { AF_GPT2, 4, P608 }, // GTIOC4B + { AF_GPT2, 5, P101 }, { AF_GPT2, 5, P609 }, // GTIOC5A + { AF_GPT2, 5, P100 }, { AF_GPT2, 5, P610 }, // GTIOC5B + { AF_GPT2, 6, P400 }, { AF_GPT2, 6, P601 }, // GTIOC6A + { AF_GPT2, 6, P401 }, { AF_GPT2, 6, P600 }, // GTIOC6B + { AF_GPT2, 7, P304 }, // GTIOC7A + { AF_GPT2, 7, P303 }, { AF_GPT2, 7, P602 }, // GTIOC7B + { AF_GPT2, 8, P107 }, // GTIOC8A + { AF_GPT2, 8, P106 }, // GTIOC8B + { AF_GPT2, 9, P411 }, // GTIOC9A + { AF_GPT2, 9, P410 }, // GTIOC9B + { AF_GPT2, 10, P409 }, // GTIOC10A + { AF_GPT2, 10, P408 }, // GTIOC10B + { AF_GPT2, 11, P500 }, // GTIOC11A + { AF_GPT2, 11, P501 }, // GTIOC11B + { AF_GPT2, 12, P502 }, // GTIOC12A + { AF_GPT2, 12, P503 }, // GTIOC12B + #elif defined(RA6M2) + { AF_GPT2, 0, P213 }, { AF_GPT2, 0, P415 }, { AF_GPT2, 0, P512 }, // GTIOC0A + { AF_GPT2, 0, P212 }, { AF_GPT2, 0, P414 }, { AF_GPT2, 0, P511 }, // GTIOC0B + { AF_GPT2, 1, P105 }, { AF_GPT2, 1, P405 }, // GTIOC1A + { AF_GPT2, 1, P104 }, { AF_GPT2, 1, P406 }, // GTIOC1B + { AF_GPT2, 2, P113 }, { AF_GPT2, 2, P713 }, // GTIOC2A + { AF_GPT2, 2, P114 }, { AF_GPT2, 2, P712 }, // GTIOC2B + { AF_GPT2, 3, P403 }, // GTIOC3A + { AF_GPT2, 3, P404 }, // GTIOC3B + { AF_GPT2, 4, P115 }, { AF_GPT2, 4, P205 }, { AF_GPT2, 4, P302 }, // GTIOC4A + { AF_GPT2, 4, P204 }, { AF_GPT2, 4, P301 }, { AF_GPT2, 4, P608 }, // GTIOC4B + { AF_GPT2, 5, P101 }, { AF_GPT2, 5, P203 }, { AF_GPT2, 5, P609 }, { AF_GPT2, 5, P700 }, // GTIOC5A + { AF_GPT2, 5, P100 }, { AF_GPT2, 5, P202 }, { AF_GPT2, 5, P610 }, { AF_GPT2, 5, P701 }, // GTIOC5B + { AF_GPT2, 6, P400 }, { AF_GPT2, 6, P601 }, { AF_GPT2, 6, P702 }, // GTIOC6A + { AF_GPT2, 6, P401 }, { AF_GPT2, 6, P600 }, { AF_GPT2, 6, P703 }, // GTIOC6B + { AF_GPT2, 7, P304 }, { AF_GPT2, 7, P603 }, // GTIOC7A + { AF_GPT2, 7, P303 }, { AF_GPT2, 7, P602 }, // GTIOC7B + { AF_GPT2, 8, P107 }, { AF_GPT2, 8, P605 }, // GTIOC8A + { AF_GPT2, 8, P106 }, { AF_GPT2, 8, P604 }, // GTIOC8B + { AF_GPT2, 9, P411 }, // GTIOC9A + { AF_GPT2, 9, P410 }, // GTIOC9B + { AF_GPT2, 10, P409 }, // GTIOC10A + { AF_GPT2, 10, P408 }, // GTIOC10B + { AF_GPT2, 11, P500 }, // GTIOC11A + { AF_GPT2, 11, P501 }, // GTIOC11B + { AF_GPT2, 12, P502 }, // GTIOC12A + { AF_GPT2, 12, P503 }, // GTIOC12B + { AF_GPT2, 13, P504 }, // GTIOC13A + { AF_GPT2, 13, P505 }, // GTIOC13B + #elif defined(RA6M3) + { AF_GPT2, 0, P213 }, { AF_GPT2, 0, P415 }, { AF_GPT2, 0, P512 }, // GTIOC0A + { AF_GPT2, 0, P212 }, { AF_GPT2, 0, P414 }, { AF_GPT2, 0, P511 }, // GTIOC0B + { AF_GPT2, 1, P105 }, { AF_GPT2, 1, P405 }, // GTIOC1A + { AF_GPT2, 1, P104 }, { AF_GPT2, 1, P406 }, // GTIOC1B + { AF_GPT2, 2, P113 }, { AF_GPT2, 2, P713 }, // GTIOC2A + { AF_GPT2, 2, P114 }, { AF_GPT2, 2, P712 }, // GTIOC2B + { AF_GPT2, 3, P403 }, // GTIOC3A + { AF_GPT2, 3, P404 }, // GTIOC3B + { AF_GPT2, 4, P115 }, { AF_GPT2, 4, P205 }, { AF_GPT2, 4, P302 }, // GTIOC4A + { AF_GPT2, 4, P204 }, { AF_GPT2, 4, P301 }, { AF_GPT2, 4, P608 }, // GTIOC4B + { AF_GPT2, 5, P101 }, { AF_GPT2, 5, P203 }, { AF_GPT2, 5, P609 }, { AF_GPT2, 5, P700 }, // GTIOC5A + { AF_GPT2, 5, P100 }, { AF_GPT2, 5, P202 }, { AF_GPT2, 5, P610 }, { AF_GPT2, 5, P701 }, // GTIOC5B + { AF_GPT2, 6, P400 }, { AF_GPT2, 6, P601 }, { AF_GPT2, 6, P702 }, // GTIOC6A + { AF_GPT2, 6, P401 }, { AF_GPT2, 6, P600 }, { AF_GPT2, 6, P703 }, // GTIOC6B + { AF_GPT2, 7, P304 }, { AF_GPT2, 7, P603 }, // GTIOC7A + { AF_GPT2, 7, P303 }, { AF_GPT2, 7, P602 }, // GTIOC7B + { AF_GPT2, 8, P107 }, { AF_GPT2, 8, P605 }, // GTIOC8A + { AF_GPT2, 8, P106 }, { AF_GPT2, 8, P604 }, // GTIOC8B + { AF_GPT2, 9, P411 }, // GTIOC9A + { AF_GPT2, 9, P410 }, // GTIOC9B + { AF_GPT2, 10, P409 }, // GTIOC10A + { AF_GPT2, 10, P408 }, // GTIOC10B + { AF_GPT2, 11, P500 }, // GTIOC11A + { AF_GPT2, 11, P501 }, // GTIOC11B + { AF_GPT2, 12, P502 }, { AF_GPT2, 12, P908 }, // GTIOC12A + { AF_GPT2, 12, P503 }, { AF_GPT2, 12, P907 }, // GTIOC12B + { AF_GPT2, 13, P504 }, { AF_GPT2, 13, P906 }, // GTIOC13A + { AF_GPT2, 13, P505 }, { AF_GPT2, 13, P905 }, // GTIOC13B + #elif defined(RA6M5) + { AF_GPT2, 0, P213 }, { AF_GPT2, 0, P300 }, { AF_GPT2, 0, P415 }, { AF_GPT2, 0, P512 }, // GTIOC0A + { AF_GPT2, 0, P108 }, { AF_GPT2, 0, P212 }, { AF_GPT2, 0, P414 }, { AF_GPT2, 0, P511 }, // GTIOC0B + { AF_GPT2, 1, P105 }, { AF_GPT2, 1, P109 }, { AF_GPT2, 1, P405 }, // GTIOC1A + { AF_GPT2, 1, P104 }, { AF_GPT2, 1, P110 }, { AF_GPT2, 1, P406 }, // GTIOC1B + { AF_GPT2, 2, P103 }, { AF_GPT2, 2, P113 }, { AF_GPT2, 2, P713 }, // GTIOC2A + { AF_GPT2, 2, P102 }, { AF_GPT2, 2, P114 }, { AF_GPT2, 2, P712 }, // GTIOC2B + { AF_GPT2, 3, P111 }, { AF_GPT2, 3, P403 }, // GTIOC3A + { AF_GPT2, 3, P112 }, { AF_GPT2, 3, P404 }, // GTIOC3B + { AF_GPT2, 4, P115 }, { AF_GPT2, 4, P205 }, { AF_GPT2, 4, P302 }, // GTIOC4A + { AF_GPT2, 4, P204 }, { AF_GPT2, 4, P301 }, { AF_GPT2, 4, P608 }, // GTIOC4B + { AF_GPT2, 5, P101 }, { AF_GPT2, 5, P203 }, { AF_GPT2, 5, P609 }, { AF_GPT2, 5, P700 }, // GTIOC5A + { AF_GPT2, 5, P100 }, { AF_GPT2, 5, P202 }, { AF_GPT2, 5, P610 }, { AF_GPT2, 5, P701 }, // GTIOC5B + { AF_GPT2, 6, P400 }, { AF_GPT2, 6, P407 }, { AF_GPT2, 6, P601 }, { AF_GPT2, 6, P702 }, // GTIOC6A + { AF_GPT2, 6, P401 }, { AF_GPT2, 6, P408 }, { AF_GPT2, 6, P600 }, { AF_GPT2, 6, P703 }, // GTIOC6B + { AF_GPT2, 7, P304 }, { AF_GPT2, 7, P603 }, // GTIOC7A + { AF_GPT2, 7, P303 }, { AF_GPT2, 7, P602 }, // GTIOC7B + { AF_GPT2, 8, P107 }, { AF_GPT2, 8, P605 }, // GTIOC8A + { AF_GPT2, 8, P106 }, { AF_GPT2, 8, P604 }, // GTIOC8B + { AF_GPT2, 9, P411 }, // GTIOC9A + { AF_GPT2, 9, P410 }, // GTIOC9B + #else + #error "CMSIS MCU Series is not specified." + #endif +}; + +static float ra_gpt_freq[GPT_CH_SIZE]; +static volatile uint16_t ra_gpt_div[GPT_CH_SIZE]; + +static void ra_gpt_timer_set_pin(uint32_t pin) { + bool find = false; + uint32_t ch; + uint32_t af; + find = ra_af_find_ch_af((ra_af_pin_t *)&ra_gpt_timer_pins, GPT_TMR_PINS_SIZE, pin, &ch, &af); + if (find) { // GPIO_MODE_OUTPUT_PP + ra_gpio_config(pin, GPIO_MODE_AF_PP, GPIO_NOPULL, GPIO_LOW_POWER, af); + } +} + +static void ra_gpt_timer_release_pin(uint32_t pin) { + bool find = false; + uint32_t ch; + uint32_t af; + find = ra_af_find_ch_af((ra_af_pin_t *)&ra_gpt_timer_pins, GPT_TMR_PINS_SIZE, pin, &ch, &af); + if (find) { // GPIO_PULLUP + ra_gpio_config(pin, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_LOW_POWER, AF_GPIO); + } +} + +bool ra_gpt_timer_is_pwm_pin(uint32_t pin) { + uint32_t ch; + uint32_t af; + return ra_af_find_ch_af((ra_af_pin_t *)&ra_gpt_timer_pins, GPT_TMR_PINS_SIZE, pin, &ch, &af); +} + +void ra_gpt_timer_start(uint32_t ch) { + if (CH_GAP || (ch >= GPT_CH_SIZE)) { + return; + } + gpt_regs[ch]->GTCR_b.CST = 1; +} + +void ra_gpt_timer_stop(uint32_t ch) { + if (CH_GAP || (ch >= GPT_CH_SIZE)) { + return; + } + gpt_regs[ch]->GTCR_b.CST = 0; +} + +void ra_gpt_timer_set_freq(uint32_t ch, float freq) { + R_GPT0_Type *gpt_reg = gpt_regs[ch]; + uint8_t source = 0; + uint32_t period = 0; + ra_gpt_freq[ch] = 0.0f; + + if ((!gpt_reg) || (ch >= GPT_CH_SIZE) || (freq == ra_gpt_freq[ch]) || (freq == 0.0f)) { + return; + } + + ra_gpt_div[ch] = 0; + + #ifdef RA4M1 + if (ch <= 1) { // 32bit + #elif defined(RA4W1) || defined(RA6M5) + if (ch <= 3) { // 32bit + #elif defined(RA6M1) || defined(RA6M2) || defined(RA6M3) + if (1) { // all is 32bit + #else + #error What is the width of the timer? (How many bits) + #endif + // float min_freq = ((float)PCLK)/4294967295.0f; + if ((freq > (float)(PCLK / 2)) || (freq <= 0.0f)) { + return; + } else { + source = GPT_PCLKD; + period = (uint32_t)((float)(PCLK) / freq); + } + } else { // 16bit + float min_freq = ((float)PCLK) / 65565.0f; + + if (freq > (float)(PCLK / 2)) { + return; + } else if (freq > min_freq) { + source = GPT_PCLKD; + period = (uint16_t)((float)(PCLK) / freq); + } else if (freq > (min_freq / 4.0f)) { + source = GPT_PCLKD4; + ra_gpt_div[ch] = 4; + period = (uint16_t)(((float)(PCLK) / 4.0f) / freq); + } else if (freq > (min_freq / 16.0f)) { + source = GPT_PCLKD16; + ra_gpt_div[ch] = 16; + period = (uint16_t)(((float)(PCLK) / 16.0f) / freq); + } else if (freq > (min_freq / 64.0f)) { + source = GPT_PCLKD64; + ra_gpt_div[ch] = 64; + period = (uint16_t)(((float)(PCLK) / 64.0f) / freq); + } else if (freq > (min_freq / 256.0f)) { + source = GPT_PCLKD256; + ra_gpt_div[ch] = 256; + period = (uint16_t)(((float)(PCLK) / 256.0f) / freq); + } else if (freq > (min_freq / 1024.0f)) { + source = GPT_PCLKD1024; + ra_gpt_div[ch] = 1024; + period = (uint16_t)(((float)(PCLK) / 1024.0f) / freq); + } else { + return; + } + } + + ra_gpt_freq[ch] = freq; + + float dutyA = (gpt_reg->GTIOR_b.OAE && gpt_reg->GTCCR[0] && gpt_reg->GTPR)? (float)(gpt_reg->GTCCR[0] + 1) / (float)(gpt_reg->GTPR + 1) : 0.0f; + float dutyB = (gpt_reg->GTIOR_b.OBE && gpt_reg->GTCCR[0] && gpt_reg->GTPR)? (float)(gpt_reg->GTCCR[1] + 1) / (float)(gpt_reg->GTPR + 1) : 0.0f; + + if (gpt_reg->GTCR_b.CST) { // running + if ((gpt_reg->GTCR >> 23) != source) { // Can't use gpt_reg->GTCR_b.TPCS this structure is declared wrong by FPS v2.3.0 so get the whole reg + gpt_reg->GTCR_b.CST = 0; // stop counter + gpt_reg->GTCR_b.TPCS = source << 1; // Again gpt_reg->GTCR_b.TPCS is wrong and incoming value should be shifted + gpt_reg->GTPR = period - 1; + gpt_reg->GTPBR = period - 1; + + if (dutyA > 0.0f) { + dutyA = dutyA * ((float)(period)); + gpt_reg->GTCCR[0] = (uint32_t)(dutyA - 1.0f); + gpt_reg->GTCCR[2] = gpt_reg->GTCCR[0]; + } + + if (dutyB > 0.0f) { + dutyB = dutyB * ((float)(period)); + gpt_reg->GTCCR[1] = (uint32_t)(dutyB - 1.0f); + gpt_reg->GTCCR[3] = gpt_reg->GTCCR[1]; + } + + gpt_reg->GTCNT = 0ul; // clear counter + gpt_reg->GTCR_b.CST = 1; // start counter + } else { + // gpt_reg->GTPR = period-1; + gpt_reg->GTPBR = period - 1; + + if (dutyA > 0.0f) { + dutyA = dutyA * ((float)(period)); + // gpt_reg->GTCCR[0] = (uint32_t)(dutyA - 1.0f); + gpt_reg->GTCCR[2] = (uint32_t)(dutyA - 1.0f); + } + + if (dutyB > 0.0f) { + dutyB = dutyB * ((float)(period)); + // gpt_reg->GTCCR[1] = (uint32_t)(dutyB - 1.0f); + gpt_reg->GTCCR[3] = (uint32_t)(dutyB - 1.0f); + } + } + } else { // stopped + gpt_reg->GTCR_b.TPCS = source << 1; + gpt_reg->GTPR = period - 1; + gpt_reg->GTPBR = period - 1; + + if (dutyA > 0.0f) { + dutyA = dutyA * ((float)(period)); + gpt_reg->GTCCR[0] = (uint32_t)(dutyA - 1.0f); + gpt_reg->GTCCR[2] = gpt_reg->GTCCR[0]; + } + + if (dutyB > 0.0f) { + dutyB = dutyB * ((float)(period)); + gpt_reg->GTCCR[1] = (uint32_t)(dutyB - 1.0f); + gpt_reg->GTCCR[3] = gpt_reg->GTCCR[1]; + } + } +} + +float ra_gpt_timer_get_freq(uint32_t ch) { + return (CH_GAP || (ch >= GPT_CH_SIZE))? 0.0f : ra_gpt_freq[ch]; +} + +float ra_gpt_timer_tick_time(uint32_t ch) { + if (CH_GAP || (ch >= GPT_CH_SIZE)) { + return 0.0f; + } else { + float NS = 1000000000.0f; + if (ra_gpt_div[ch]) { + NS *= (float)ra_gpt_div[ch]; + } + return NS / (float)(PCLK); + } +} + +/* +void ra_gpt_timer_set_period(uint32_t ch, uint32_t ns) +{ + R_GPT0_Type *gpt_reg = gpt_regs[ch]; + + if((!gpt_reg) || (ch >= GPT_CH_SIZE)) + return; + + if(ch <= 3) + { //32bit + } + else + { //16bit + } +} +*/ + +uint32_t ra_gpt_timer_get_period(uint32_t ch) { + R_GPT0_Type *gpt_reg = gpt_regs[ch]; + + if ((!gpt_reg) || (ch >= GPT_CH_SIZE)) { + return 0ul; + } else { + return gpt_reg->GTPR + 1; + } +} + +void ra_gpt_timer_set_duty(uint32_t ch, uint8_t id, uint32_t duty) { + R_GPT0_Type *gpt_reg = gpt_regs[ch]; + + if ((!gpt_reg) || (ch >= GPT_CH_SIZE)) { + return; + } else { + if (gpt_reg->GTCR_b.CST) { + gpt_reg->GTCCR[(id == 'A')? 2 : 3] = duty? duty - 1 : duty; + } else { + gpt_reg->GTCCR[(id == 'A')? 0 : 1] = duty? duty - 1 : duty; + if (id == 'A') { + gpt_reg->GTCCR[2] = gpt_reg->GTCCR[0]; + } else { + gpt_reg->GTCCR[3] = gpt_reg->GTCCR[1]; + } + } + } +} + +uint32_t ra_gpt_timer_get_duty(uint32_t ch, uint8_t id) { + R_GPT0_Type *gpt_reg = gpt_regs[ch]; + if ((!gpt_reg) || (ch >= GPT_CH_SIZE)) { + return 0ul; + } else + if (id == 'A') { + return (gpt_reg->GTCCR[0])? gpt_reg->GTCCR[0] + 1 : 0; + } else { + return (gpt_reg->GTCCR[1])? gpt_reg->GTCCR[1] + 1 : 0; + } +} + +void ra_gpt_timer_init(uint32_t pwm_pin, uint32_t ch, uint8_t id, uint32_t duty, float freq) { + R_GPT0_Type *gpt_reg = gpt_regs[ch]; + + if ((!gpt_reg) || (ch >= GPT_CH_SIZE)) { + return; + } + + #ifdef RA4M1 + if (ch <= 1) { + #elif defined(RA4W1) + if (ch <= 3) { + #elif defined(RA6M1) || defined(RA6M2) || defined(RA6M3) + if (ch <= 7) { + #elif defined(RA6M5) + if (ch <= 9) { + #else + #error Choose proper clock enable BIT! + #endif + #ifdef RA6M5 + // R_MSTP_MSTPCRE_MSTPE22_Msk - R_MSTP_MSTPCRE_MSTPE31_Msk + ra_mstpcre_start(1UL << (31 - ch)); + #else + ra_mstpcrd_start(R_MSTP_MSTPCRD_MSTPD5_Msk); + #endif + } else { + ra_mstpcrd_start(R_MSTP_MSTPCRD_MSTPD6_Msk); + } + + ra_gpt_timer_stop(ch); // Stop the timer + gpt_reg->GTCR_b.MD = 0; // Set operating mode + gpt_reg->GTUDDTYC_b.UD = 1; // Set count direction + gpt_reg->GTBER_b.PR = 1; // Set buffer operation for the period + ra_gpt_timer_set_freq(ch, freq); // Set count clock & cycle + + gpt_reg->GTCNT = 0; // Set initial value for counter + if (id == 'A') { + gpt_reg->GTIOR_b.GTIOA = 0x9; // Set GTIOC pin function (Initial low -> Low at GTCCRA/B compare match -> High at cycle end) + gpt_reg->GTIOR_b.OAE = 1; // Enable GTIOC pin output + gpt_reg->GTBER_b.CCRA = 1; // Set buffer operation for the duty + gpt_reg->GTCCR[0] = duty? duty - 1 : duty; // Set compare match value + gpt_reg->GTCCR[2] = gpt_reg->GTCCR[0]; + } else { + gpt_reg->GTIOR_b.GTIOB = 0x9; + gpt_reg->GTIOR_b.OBE = 1; + gpt_reg->GTBER_b.CCRB = 1; + gpt_reg->GTCCR[1] = duty? duty - 1 : duty; + gpt_reg->GTCCR[3] = gpt_reg->GTCCR[1]; + } + + ra_gpt_timer_set_pin(pwm_pin); + + if (gpt_reg->GTPR && gpt_reg->GTCCR[(id == 'A')? 0 : 1]) { + ra_gpt_timer_start(ch); + } +} + +void ra_gpt_timer_deinit(uint32_t pwm_pin, uint32_t ch, uint8_t id) { + if (CH_GAP || (ch >= GPT_CH_SIZE)) { + return; + } + ra_gpt_timer_stop(ch); + + ra_gpt_div[ch] = 0; + ra_gpt_freq[ch] = 0; + + gpt_regs[ch]->GTPR = 0; + gpt_regs[ch]->GTPBR = 0; + + if (id == 'A') { + gpt_regs[ch]->GTIOR_b.OAE = 0; + gpt_regs[ch]->GTCCR[0] = 0; + gpt_regs[ch]->GTCCR[2] = 0; + } else { + gpt_regs[ch]->GTIOR_b.OBE = 0; + gpt_regs[ch]->GTCCR[1] = 0; + gpt_regs[ch]->GTCCR[3] = 0; + } + + #ifdef RA4M1 + if (ch <= 1) { + #elif defined(RA4W1) + if (ch <= 3) { + #elif defined(RA6M1) || defined(RA6M2) || defined(RA6M3) + if (ch <= 7) { + #elif defined(RA6M5) + if (ch <= 9) { + #else + #error Choose proper clock enable BIT! + #endif + #ifdef RA6M5 + ra_mstpcre_stop(1UL << (31 - ch)); + #else + ra_mstpcrd_stop(R_MSTP_MSTPCRD_MSTPD5_Msk); + #endif + } else { + ra_mstpcrd_stop(R_MSTP_MSTPCRD_MSTPD6_Msk); + } + + ra_gpt_timer_release_pin(pwm_pin); +} diff --git a/ports/renesas-ra/ra/ra_gpt.h b/ports/renesas-ra/ra/ra_gpt.h new file mode 100644 index 0000000000000..9f88acbbf3753 --- /dev/null +++ b/ports/renesas-ra/ra/ra_gpt.h @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023 Vekatech Ltd. + * + * 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. + */ + +#ifndef RA_RA_GPT_H_ +#define RA_RA_GPT_H_ + +#include + +void ra_gpt_timer_start(uint32_t ch); +void ra_gpt_timer_stop(uint32_t ch); +void ra_gpt_timer_set_freq(uint32_t ch, float freq); +float ra_gpt_timer_get_freq(uint32_t ch); +float ra_gpt_timer_tick_time(uint32_t ch); +void ra_gpt_timer_set_period(uint32_t ch, uint32_t ns); +uint32_t ra_gpt_timer_get_period(uint32_t ch); +void ra_gpt_timer_set_duty(uint32_t ch, uint8_t id, uint32_t duty); +uint32_t ra_gpt_timer_get_duty(uint32_t ch, uint8_t id); +void ra_gpt_timer_init(uint32_t pwm_pin, uint32_t ch, uint8_t id, uint32_t duty, float freq); +void ra_gpt_timer_deinit(uint32_t pwm_pin, uint32_t ch, uint8_t id); +bool ra_gpt_timer_is_pwm_pin(uint32_t pin); + +#endif /* RA_RA_GPT_H_ */ diff --git a/ports/renesas-ra/ra/ra_i2c.c b/ports/renesas-ra/ra/ra_i2c.c index ad1e3a74e0de3..783c0c921543b 100644 --- a/ports/renesas-ra/ra/ra_i2c.c +++ b/ports/renesas-ra/ra/ra_i2c.c @@ -68,7 +68,7 @@ static const ra_af_pin_t scl_pins[] = { { AF_I2C, 1, P100 }, { AF_I2C, 1, P205 }, - #elif defined(RA6M2) + #elif defined(RA6M2) || defined(RA6M3) { AF_I2C, 0, P204 }, { AF_I2C, 0, P400 }, @@ -76,6 +76,16 @@ static const ra_af_pin_t scl_pins[] = { { AF_I2C, 1, P100 }, { AF_I2C, 1, P205 }, { AF_I2C, 2, P512 }, + + #elif defined(RA6M5) + + { AF_I2C, 0, P400 }, + { AF_I2C, 0, P408 }, + { AF_I2C, 1, P205 }, + { AF_I2C, 1, P512 }, + { AF_I2C, 2, P410 }, + { AF_I2C, 2, P415 }, + #else #error "CMSIS MCU Series is not specified." #endif @@ -103,7 +113,7 @@ static const ra_af_pin_t sda_pins[] = { { AF_I2C, 1, P101 }, { AF_I2C, 1, P206 }, - #elif defined(RA6M2) + #elif defined(RA6M2) || defined(RA6M3) { AF_I2C, 0, P401 }, { AF_I2C, 0, P407 }, @@ -111,6 +121,15 @@ static const ra_af_pin_t sda_pins[] = { { AF_I2C, 1, P206 }, { AF_I2C, 2, P511 }, + #elif defined(RA6M5) + + { AF_I2C, 0, P401 }, + { AF_I2C, 0, P407 }, + { AF_I2C, 1, P206 }, + { AF_I2C, 1, P511 }, + { AF_I2C, 2, P409 }, + { AF_I2C, 2, P414 }, + #else #error "CMSIS MCU Series is not specified." #endif @@ -305,11 +324,16 @@ static void ra_i2c_clock_calc(uint32_t baudrate, uint8_t *cks, uint8_t *brh, uin *cks = 1; *brh = 9; *brl = 20; - } else { + } else if (baudrate >= 100000) { // assume clock is 100000Hz (PCLKB 32MHz) *cks = 3; *brh = 15; *brl = 18; + } else { + // assume clock is 50000Hz (PCLKB 32MHz) + *cks = 4; + *brh = 15; + *brl = 18; } #elif defined(RA6M1) // PCLKB 60MHz SCLE=0 @@ -328,7 +352,7 @@ static void ra_i2c_clock_calc(uint32_t baudrate, uint8_t *cks, uint8_t *brh, uin *brh = 14; *brl = 17; } - #elif defined(RA6M2) + #elif defined(RA6M2) || defined(RA6M3) // PCLKB 60MHz SCLE=0 if (baudrate >= RA_I2C_CLOCK_MAX) { *cks = 0; @@ -339,11 +363,38 @@ static void ra_i2c_clock_calc(uint32_t baudrate, uint8_t *cks, uint8_t *brh, uin *cks = 2; *brh = 8; *brl = 19; - } else { + } else if (baudrate >= 100000) { // assume clock is 100000Hz *cks = 4; *brh = 14; *brl = 17; + } else { + // assume clock is 50000Hz + *cks = 5; + *brh = 14; + *brl = 17; + } + #elif defined(RA6M5) + // PCLKB 50MHz SCLE=0 + if (baudrate >= RA_I2C_CLOCK_MAX) { + *cks = 0; + *brh = 12; + *brl = 24; + } else if (baudrate >= 400000) { + // assume clock is 400000Hz + *cks = 2; + *brh = 7; + *brl = 15; + } else if (baudrate >= 100000) { + // assume clock is 100000Hz + *cks = 3; + *brh = 24; + *brl = 30; + } else { + // assume clock is 50000Hz + *cks = 4; + *brh = 24; + *brl = 30; } #else #error "CMSIS MCU Series is not specified." @@ -458,7 +509,9 @@ static void ra_i2c_iceri_isr(R_IIC0_Type *i2c_inst) { } // Check Start if (i2c_inst->ICSR2_b.START != 0) { - action->m_status = RA_I2C_STATUS_Started; + if (action->m_status == RA_I2C_STATUS_Idle) { + action->m_status = RA_I2C_STATUS_Started; + } i2c_inst->ICSR2_b.START = 0; } // Check Stop @@ -504,8 +557,8 @@ static void ra_i2c_icrxi_isr(R_IIC0_Type *i2c_inst) { static void ra_i2c_ictxi_isr(R_IIC0_Type *i2c_inst) { xaction_t *action = current_xaction; xaction_unit_t *unit = current_xaction_unit; - - if (action->m_status == RA_I2C_STATUS_Started) { + // When STIE is already checked. When TIE occurs before STIE + if (action->m_status == RA_I2C_STATUS_Started || action->m_status == RA_I2C_STATUS_Idle) { i2c_inst->ICDRT = action->m_address; // I2C send slave address action->m_status = RA_I2C_STATUS_AddrWriteCompleted; return; diff --git a/ports/renesas-ra/ra/ra_i2c.h b/ports/renesas-ra/ra/ra_i2c.h index 93a170ab8a678..e2432675a001e 100644 --- a/ports/renesas-ra/ra/ra_i2c.h +++ b/ports/renesas-ra/ra/ra_i2c.h @@ -28,6 +28,13 @@ #include #include +#ifdef RA6M5 +// #define R_IIC2_BASE 0x4009F200 +#ifndef R_IIC2 +#define R_IIC2 ((R_IIC0_Type *)0x4009F200) +#endif +#endif + #define RA_I2C_DEF_TIMEOUT 1000 // 1000 ms #define RA_I2C_TIMEOUT_STOP_CONDITION 100000 // counts #define RA_I2C_TIMEOUT_BUS_BUSY 100000 // counts diff --git a/ports/renesas-ra/ra/ra_icu.c b/ports/renesas-ra/ra/ra_icu.c index 000667b4c6732..caac8bfe221e2 100644 --- a/ports/renesas-ra/ra/ra_icu.c +++ b/ports/renesas-ra/ra/ra_icu.c @@ -345,6 +345,180 @@ static const ra_icu_pin_t ra_irq_pins[] = { { 15, P511 }, #endif + #elif defined(RA6M3) + + #if defined(VECTOR_NUMBER_ICU_IRQ0) + { 0, P105 }, + { 0, P206 }, /* DS */ + { 0, P400 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ1) + { 1, P101 }, + { 1, P104 }, + { 1, P205 }, /* DS */ + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ2) + { 2, P100 }, + { 2, P213 }, + { 2, P203 }, /* DS */ + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ3) + { 3, P110 }, + { 3, P212 }, + { 3, P202 }, /* DS */ + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ4) + { 4, P111 }, + { 4, P402 }, /* DS */ + { 4, P411 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ5) + { 5, P302 }, + { 5, P401 }, /* DS */ + { 5, P410 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ6) + { 6, P000 }, /* DS */ + { 6, P301 }, + { 6, P409 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ7) + { 7, P001 }, /* DS */ + { 7, P408 }, + { 7, P706 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ8) + { 8, P002 }, /* DS */ + { 8, P305 }, + { 8, P415 }, + { 8, P707 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ9) + { 9, P004 }, /* DS */ + { 9, P304 }, + { 9, P414 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ10) + { 10, P005 }, /* DS */ + { 10, P709 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ11) + { 11, P006 }, /* DS */ + { 11, P501 }, + { 11, P708 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ12) + { 12, P008 }, /* DS */ + { 12, P502 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ13) + { 13, P009 }, /* DS */ + { 13, P015 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ14) + { 14, P505 }, + { 14, P512 }, + { 14, P010 }, /* DS */ + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ15) + { 15, P506 }, + { 15, P511 }, + #endif + + #elif defined(RA6M5) + + #if defined(VECTOR_NUMBER_ICU_IRQ0) + { 0, P105 }, + { 0, P206 }, /* DS */ + { 0, P400 }, + { 0, P806 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ1) + { 1, P101 }, + { 1, P104 }, + { 1, P205 }, /* DS */ + { 1, P804 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ2) + { 2, P100 }, + { 2, P203 }, /* DS */ + { 2, P213 }, + { 2, P803 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ3) + { 3, P110 }, + { 3, P202 }, /* DS */ + { 3, P212 }, + { 3, P802 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ4) + { 4, P111 }, + { 4, P402 }, /* DS */ + { 4, P411 }, + { 4, PA10 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ5) + { 5, P302 }, + { 5, P401 }, /* DS */ + { 5, P410 }, + { 5, PA09 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ6) + { 6, P000 }, /* DS */ + { 6, P301 }, + { 6, P409 }, + { 6, PA08 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ7) + { 7, P001 }, /* DS */ + { 7, P408 }, + { 7, P706 }, + { 7, P615 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ8) + { 8, P002 }, /* DS */ + { 8, P305 }, + { 8, P415 }, + { 8, P707 }, + { 8, P905 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ9) + { 9, P004 }, /* DS */ + { 9, P304 }, + { 9, P414 }, + { 9, P906 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ10) + { 10, P005 }, /* DS */ + { 10, P709 }, + { 10, P907 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ11) + { 11, P006 }, /* DS */ + { 11, P501 }, + { 11, P708 }, + { 11, P908 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ12) + { 12, P008 }, /* DS */ + { 12, P502 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ13) + { 13, P009 }, /* DS */ + { 13, P015 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ14) + { 14, P010 }, + { 14, P403 }, /* DS */ + { 14, P505 }, + { 14, P512 }, + #endif + #if defined(VECTOR_NUMBER_ICU_IRQ15) + { 15, P404 }, /* DS */ + { 15, P506 }, + { 15, P511 }, + #endif + #else #error "CMSIS MCU Series is not speficied." #endif diff --git a/ports/renesas-ra/ra/ra_int.h b/ports/renesas-ra/ra/ra_int.h index cd12908bcd75a..1b92db99ccc67 100644 --- a/ports/renesas-ra/ra/ra_int.h +++ b/ports/renesas-ra/ra/ra_int.h @@ -29,7 +29,7 @@ #if defined(RA4M1) | defined(RA4W1) #define IRQ_MAX 48 -#elif defined(RA6M1) | defined(RA6M2) +#elif defined(RA6M1) | defined(RA6M2) | defined(RA6M3) | defined(RA6M5) #define IRQ_MAX 128 #else #error "CMSIS MCU Series is not specified." diff --git a/ports/renesas-ra/ra/ra_rtc.c b/ports/renesas-ra/ra/ra_rtc.c index f108de568d1b8..e23a4d42d2f06 100644 --- a/ports/renesas-ra/ra/ra_rtc.c +++ b/ports/renesas-ra/ra/ra_rtc.c @@ -34,7 +34,7 @@ #include "hal_data.h" #include "ra_rtc.h" -static R_RTC_Type *rtc_reg = (R_RTC_Type *)0x40044000; +static R_RTC_Type *rtc_reg = R_RTC; static R_SYSTEM_Type *system_reg = (R_SYSTEM_Type *)0x4001E000; #if defined(VECTOR_NUMBER_RTC_ALARM) diff --git a/ports/renesas-ra/ra/ra_sci.c b/ports/renesas-ra/ra/ra_sci.c index 5d1406724868c..81f3ff9675b5e 100644 --- a/ports/renesas-ra/ra/ra_sci.c +++ b/ports/renesas-ra/ra/ra_sci.c @@ -265,34 +265,34 @@ static uint32_t ch_to_idx[SCI_CH_MAX] = { static R_SCI0_Type *sci_regs[] = { #if defined(VECTOR_NUMBER_SCI0_RXI) - (R_SCI0_Type *)0x40070000, + R_SCI0, #endif #if defined(VECTOR_NUMBER_SCI1_RXI) - (R_SCI0_Type *)0x40070020, + R_SCI1, #endif #if defined(VECTOR_NUMBER_SCI2_RXI) - (R_SCI0_Type *)0x40070040, + R_SCI2, #endif #if defined(VECTOR_NUMBER_SCI3_RXI) - (R_SCI0_Type *)0x40070060, + R_SCI3, #endif #if defined(VECTOR_NUMBER_SCI4_RXI) - (R_SCI0_Type *)0x40070080, + R_SCI4, #endif #if defined(VECTOR_NUMBER_SCI5_RXI) - (R_SCI0_Type *)0x400700a0, + R_SCI5, #endif #if defined(VECTOR_NUMBER_SCI6_RXI) - (R_SCI0_Type *)0x400700c0, + R_SCI6, #endif #if defined(VECTOR_NUMBER_SCI7_RXI) - (R_SCI0_Type *)0x400700e0, + R_SCI7, #endif #if defined(VECTOR_NUMBER_SCI8_RXI) - (R_SCI0_Type *)0x40070100, + R_SCI8, #endif #if defined(VECTOR_NUMBER_SCI9_RXI) - (R_SCI0_Type *)0x40070120, + R_SCI9, #endif }; @@ -408,6 +408,77 @@ static const ra_af_pin_t ra_sci_tx_pins[] = { { AF_SCI2, 9, P203 }, { AF_SCI2, 9, P602 }, + #elif defined(RA6M3) + + { AF_SCI1, 0, P101 }, + { AF_SCI1, 0, P411 }, + + { AF_SCI2, 1, P213 }, + { AF_SCI2, 1, P709 }, + + { AF_SCI1, 2, P112 }, + { AF_SCI1, 2, P302 }, + + { AF_SCI2, 3, P310 }, + { AF_SCI2, 3, P409 }, + { AF_SCI2, 3, P707 }, + + { AF_SCI1, 4, P205 }, + { AF_SCI1, 4, P512 }, + { AF_SCI1, 4, P900 }, + + { AF_SCI2, 5, P501 }, + { AF_SCI2, 5, P805 }, + + { AF_SCI1, 6, P305 }, + { AF_SCI1, 6, P506 }, + + { AF_SCI2, 7, P401 }, + { AF_SCI2, 7, P613 }, + + { AF_SCI1, 8, P105 }, + { AF_SCI1, 8, PA00 }, + + { AF_SCI2, 9, P109 }, + { AF_SCI2, 9, P203 }, + { AF_SCI2, 9, P602 }, + + #elif defined(RA6M5) + + { AF_SCI1, 0, P101 }, + { AF_SCI1, 0, P411 }, + + { AF_SCI2, 1, P213 }, + { AF_SCI2, 1, P709 }, + + { AF_SCI1, 2, P112 }, + { AF_SCI1, 2, P302 }, + + { AF_SCI2, 3, P310 }, + { AF_SCI2, 3, P409 }, + { AF_SCI2, 3, P707 }, + + { AF_SCI1, 4, P205 }, + { AF_SCI1, 4, P207 }, + { AF_SCI1, 4, P512 }, + { AF_SCI1, 4, P900 }, + + { AF_SCI2, 5, P501 }, + { AF_SCI2, 5, P805 }, + + { AF_SCI1, 6, P305 }, + { AF_SCI1, 6, P506 }, + + { AF_SCI2, 7, P401 }, + { AF_SCI2, 7, P613 }, + + { AF_SCI1, 8, P105 }, + { AF_SCI1, 8, PA00 }, + + { AF_SCI2, 9, P109 }, + { AF_SCI2, 9, P203 }, + { AF_SCI2, 9, P602 }, + #else #error "CMSIS MCU Series is not specified." #endif @@ -496,6 +567,41 @@ static const ra_af_pin_t ra_sci_rx_pins[] = { { AF_SCI2, 9, P202 }, { AF_SCI2, 9, P601 }, + #elif defined(RA6M3) || defined(RA6M5) + + { AF_SCI1, 0, P100 }, + { AF_SCI1, 0, P410 }, + + { AF_SCI2, 1, P212 }, + { AF_SCI2, 1, P708 }, + + { AF_SCI1, 2, P113 }, + { AF_SCI1, 2, P301 }, + + { AF_SCI2, 3, P309 }, + { AF_SCI2, 3, P408 }, + { AF_SCI2, 3, P706 }, + + { AF_SCI1, 4, P206 }, + { AF_SCI1, 4, P315 }, + { AF_SCI1, 4, P511 }, + + { AF_SCI2, 5, P502 }, + { AF_SCI2, 5, P513 }, + + { AF_SCI1, 6, P304 }, + { AF_SCI1, 6, P505 }, + + { AF_SCI2, 7, P402 }, + { AF_SCI2, 7, P614 }, + + { AF_SCI1, 8, P104 }, + { AF_SCI1, 8, P607 }, + + { AF_SCI2, 9, P110 }, + { AF_SCI2, 9, P202 }, + { AF_SCI2, 9, P601 }, + #else #error "CMSIS MCU Series is not specified." #endif @@ -584,6 +690,93 @@ static const ra_af_pin_t ra_sci_cts_pins[] = { { AF_SCI2, 9, P301 }, { AF_SCI2, 9, P603 }, + #elif defined(RA6M3) + + { AF_SCI1, 0, P103 }, + { AF_SCI1, 0, P413 }, + + { AF_SCI2, 1, P101 }, + { AF_SCI2, 1, P711 }, + + { AF_SCI1, 2, P110 }, + { AF_SCI1, 2, P203 }, + + { AF_SCI2, 3, P312 }, + { AF_SCI2, 3, P411 }, + { AF_SCI2, 3, PB01 }, + + { AF_SCI1, 4, P401 }, + { AF_SCI1, 4, P407 }, + + { AF_SCI2, 5, P504 }, + { AF_SCI2, 5, P507 }, + + { AF_SCI1, 6, P307 }, + { AF_SCI1, 6, P503 }, + + { AF_SCI2, 7, P403 }, + { AF_SCI2, 7, P611 }, + + { AF_SCI1, 8, P107 }, + { AF_SCI1, 8, P606 }, + + { AF_SCI2, 9, P108 }, + { AF_SCI2, 9, P205 }, + { AF_SCI2, 9, P301 }, + { AF_SCI2, 9, P603 }, + + #elif defined(RA6M5) + + { AF_SCI1, 0, P103 }, + { AF_SCI1, 0, P413 }, + { AF_SCI1, 0, P414 }, /* CTS only */ + { AF_SCI1, 0, P800 }, /* CTS only */ + + { AF_SCI2, 1, P101 }, + { AF_SCI2, 1, P711 }, + + { AF_SCI1, 2, P110 }, + { AF_SCI1, 2, P203 }, + + { AF_SCI2, 3, P308 }, /* CTS only */ + { AF_SCI2, 3, P312 }, + { AF_SCI2, 3, P411 }, + { AF_SCI2, 3, P412 }, /* CTS only */ + { AF_SCI2, 3, P705 }, /* CTS only */ + + { AF_SCI1, 4, P401 }, + { AF_SCI1, 4, P402 }, /* CTS only */ + { AF_SCI1, 4, P407 }, + { AF_SCI1, 4, P408 }, /* CTS only */ + + { AF_SCI2, 5, P500 }, /* CTS only */ + { AF_SCI2, 5, P504 }, + { AF_SCI2, 5, P508 }, + + { AF_SCI1, 6, P307 }, + { AF_SCI1, 6, P308 }, /* CTS only */ + { AF_SCI1, 6, P502 }, /* CTS only */ + { AF_SCI1, 6, P503 }, + + { AF_SCI2, 7, P403 }, + { AF_SCI2, 7, P404 }, /* CTS only */ + { AF_SCI2, 7, P610 }, /* CTS only */ + { AF_SCI2, 7, P611 }, + + { AF_SCI1, 8, P107 }, + { AF_SCI1, 8, P605 }, /* CTS only */ + { AF_SCI1, 8, P606 }, + { AF_SCI1, 8, P801 }, /* CTS only */ + + { AF_SCI2, 9, P108 }, + { AF_SCI2, 9, P114 }, /* CTS only */ + { AF_SCI2, 9, P205 }, + { AF_SCI2, 9, P206 }, /* CTS only */ + { AF_SCI2, 9, P301 }, + { AF_SCI2, 9, P303 }, /* CTS only */ + { AF_SCI2, 9, P603 }, + { AF_SCI2, 9, P604 }, /* CTS only */ + #else #error "CMSIS MCU Series is not specified." #endif diff --git a/ports/renesas-ra/ra/ra_spi.c b/ports/renesas-ra/ra/ra_spi.c index 096519ffd6402..b0bb01bfb9172 100644 --- a/ports/renesas-ra/ra/ra_spi.c +++ b/ports/renesas-ra/ra/ra_spi.c @@ -38,8 +38,8 @@ #endif static R_SPI0_Type *spi_regs[] = { - (R_SPI0_Type *)0x40072000, - (R_SPI0_Type *)0x40072100, + R_SPI0, + R_SPI1, }; static const ra_af_pin_t mosi_pins[] = { @@ -61,7 +61,7 @@ static const ra_af_pin_t mosi_pins[] = { { AF_SPI, 0, P411 }, /* MOSIA_B */ { AF_SPI, 1, P109 }, /* MOSIB_B */ - #elif defined(RA6M2) + #elif defined(RA6M2) || defined(RA6M3) { AF_SPI, 0, P101 }, /* MOSIA_A */ { AF_SPI, 0, P411 }, /* MOSIA_B */ @@ -69,6 +69,14 @@ static const ra_af_pin_t mosi_pins[] = { { AF_SPI, 1, P203 }, /* MOSIB_A */ { AF_SPI, 1, P701 }, /* MOSIB_C */ + #elif defined(RA6M5) + + { AF_SPI, 0, P109 }, /* MOSIA_B */ + { AF_SPI, 0, P203 }, /* MOSIA_A */ + { AF_SPI, 0, P701 }, /* MOSIA_C */ + { AF_SPI, 1, P101 }, /* MOSIB_A */ + { AF_SPI, 1, P411 }, /* MOSIB_B */ + #else #error "CMSIS MCU Series is not specified." #endif @@ -94,7 +102,7 @@ static const ra_af_pin_t miso_pins[] = { { AF_SPI, 0, P410 }, /* MISOA_B */ { AF_SPI, 1, P110 }, /* MISOB_B */ - #elif defined(RA6M2) + #elif defined(RA6M2) || defined(RA6M3) { AF_SPI, 0, P100 }, /* MISOA_A */ { AF_SPI, 0, P410 }, /* MISOA_B */ @@ -102,6 +110,14 @@ static const ra_af_pin_t miso_pins[] = { { AF_SPI, 1, P202 }, /* MISOB_A */ { AF_SPI, 1, P700 }, /* MISOB_C */ + #elif defined(RA6M5) + + { AF_SPI, 0, P110 }, /* MISOA_B */ + { AF_SPI, 0, P202 }, /* MISOA_A */ + { AF_SPI, 0, P700 }, /* MISOA_C */ + { AF_SPI, 1, P100 }, /* MISOB_A */ + { AF_SPI, 1, P410 }, /* MISOB_B */ + #else #error "CMSIS MCU Series is not specified." #endif @@ -127,7 +143,7 @@ static const ra_af_pin_t sck_pins[] = { { AF_SPI, 0, P412 }, /* RSPCKA_B */ { AF_SPI, 1, P111 }, /* RSPCKB_B */ - #elif defined(RA6M2) + #elif defined(RA6M2) || defined(RA6M3) { AF_SPI, 0, P102 }, /* RSPCKA_A */ { AF_SPI, 0, P412 }, /* RSPCKA_B */ @@ -135,12 +151,144 @@ static const ra_af_pin_t sck_pins[] = { { AF_SPI, 1, P204 }, /* RSPCKB_A */ { AF_SPI, 1, P702 }, /* RSPCKB_C */ + #elif defined(RA6M5) + + { AF_SPI, 0, P111 }, /* RSPCKA_B */ + { AF_SPI, 0, P204 }, /* RSPCKA_A */ + { AF_SPI, 0, P702 }, /* RSPCKA_C */ + { AF_SPI, 1, P102 }, /* RSPCKB_A */ + { AF_SPI, 1, P412 }, /* RSPCKB_B */ + #else #error "CMSIS MCU Series is not specified." #endif }; #define SCK_PINS_SIZE sizeof(sck_pins) / sizeof(ra_af_pin_t) +typedef struct ra_ssl_pin { + uint8_t ssln; + uint32_t pin; +} ra_ssl_pin_t; + +static const ra_ssl_pin_t ssl_pins[] = { + #if defined(RA4M1) + + { 0, P103 }, /* SSLA0 */ + { 1, P104 }, /* SSLA1 */ + { 2, P105 }, /* SSLA2 */ + { 3, P106 }, /* SSLA3 */ + { 0, P108 }, /* SSLB0 */ + { 0, P112 }, /* SSLB0 */ + + { 0, P205 }, /* SSLB0 */ + { 1, P206 }, /* SSLB1 */ + + { 1, P300 }, /* SSLB1 */ + { 2, P301 }, /* SSLB2 */ + { 3, P302 }, /* SSLB3 */ + + { 3, P407 }, /* SSLB3 */ + { 0, P413 }, /* SSLA0 */ + { 1, P414 }, /* SSLA1 */ + { 2, P415 }, /* SSLA2 */ + + #elif defined(RA4W1) + + { 0, P103 }, /* SSLA0 */ + { 1, P104 }, /* SSLA1 */ + { 2, P105 }, /* SSLA2 */ + { 3, P106 }, /* SSLA3 */ + { 0, P108 }, /* SSLB0 */ + + { 0, P205 }, /* SSLB0 */ + { 1, P206 }, /* SSLB1 */ + + { 1, P300 }, /* SSLB1 */ + + { 3, P407 }, /* SSLB3 */ + { 1, P414 }, /* SSLA1 */ + + #elif defined(RA6M1) + + { 0, P103 }, /* SSLA0_A */ + { 1, P104 }, /* SSLA1_A */ + { 2, P105 }, /* SSLA2_A */ + { 3, P106 }, /* SSLA3_A */ + { 0, P108 }, /* SSLB0_B */ + { 0, P112 }, /* SSLB0_B */ + + { 1, P300 }, /* SSLB1_B */ + { 2, P301 }, /* SSLB2_B */ + { 3, P302 }, /* SSLB3_B */ + + { 0, P413 }, /* SSLA0_B */ + { 1, P414 }, /* SSLA1_B */ + { 2, P415 }, /* SSLA2_B */ + + { 3, P708 }, /* SSLA3_B */ + + #elif defined(RA6M2) || defined(RA6M3) + + { 0, P103 }, /* SSLA0_A */ + { 1, P104 }, /* SSLA1_A */ + { 2, P105 }, /* SSLA2_A */ + { 3, P106 }, /* SSLA3_A */ + { 0, P108 }, /* SSLB0_B */ + { 0, P112 }, /* SSLB0_B */ + + { 0, P205 }, /* SSLB0_A */ + { 1, P206 }, /* SSLB1_A */ + { 2, P207 }, /* SSLB2_A */ + + { 1, P300 }, /* SSLB1_B */ + { 2, P301 }, /* SSLB2_B */ + { 3, P302 }, /* SSLB3_B */ + + { 3, P406 }, /* SSLB3_C */ + { 3, P407 }, /* SSLB3_A */ + { 0, P413 }, /* SSLA0_B */ + { 1, P414 }, /* SSLA1_B */ + { 2, P415 }, /* SSLA2_B */ + + { 0, P703 }, /* SSLB0_C */ + { 1, P704 }, /* SSLB1_C */ + { 2, P705 }, /* SSLB2_C */ + { 3, P708 }, /* SSLA3_B */ + + #elif defined(RA6M5) + + { 0, P103 }, /* SSLB0_A */ + { 1, P104 }, /* SSLB1_A */ + { 2, P105 }, /* SSLB2_A */ + { 3, P106 }, /* SSLB3_A */ + { 0, P108 }, /* SSLA0_B */ + { 0, P112 }, /* SSLA0_B */ + + { 0, P205 }, /* SSLA0_A */ + { 1, P206 }, /* SSLA1_A */ + { 2, P207 }, /* SSLA2_A */ + + { 1, P300 }, /* SSLA1_B */ + { 2, P301 }, /* SSLA2_B */ + { 3, P302 }, /* SSLA3_B */ + + { 3, P406 }, /* SSLA3_C */ + { 3, P407 }, /* SSLA3_A */ + { 0, P413 }, /* SSLB0_B */ + { 1, P414 }, /* SSLB1_B */ + { 2, P415 }, /* SSLB2_B */ + + { 0, P703 }, /* SSLA0_C */ + { 1, P704 }, /* SSLA1_C */ + { 2, P705 }, /* SSLA2_C */ + { 3, P708 }, /* SSLB3_B */ + + #else + #error "CMSIS MCU Series is not specified." + #endif +}; +#define SSL_PINS_SIZE sizeof(ssl_pins) / sizeof(ra_ssl_pin_t) + bool ra_af_find_ch(ra_af_pin_t *af_pin, uint32_t size, uint32_t pin, uint8_t *ch) { bool find = false; uint32_t i; @@ -178,6 +326,25 @@ bool ra_spi_find_af_ch(uint32_t mosi, uint32_t miso, uint32_t sck, uint8_t *ch) return find; } +static bool ra_spi_pin_to_ssln(uint32_t pin, uint8_t *ssln) { + ra_ssl_pin_t *ssl_pin = (ra_ssl_pin_t *)&ssl_pins; + bool find = false; + uint32_t i; + for (i = 0; i < SSL_PINS_SIZE; i++) { + if (ssl_pin->pin == pin) { + find = true; + if (find) { + *ssln = ssl_pin->ssln; + } else { + *ssln = 0; + } + break; + } + ssl_pin++; + } + return find; +} + static void ra_spi_module_start(uint32_t ch) { if (ch == 0) { ra_mstpcrb_start(R_MSTP_MSTPCRB_MSTPB19_Msk); @@ -202,7 +369,7 @@ static void ra_spi_set_pin(uint32_t pin, bool miso) { } } -void ra_spi_set_bits(uint32_t ch, uint32_t bits) { +static void ra_spi_set_bits(uint32_t ch, uint32_t bits) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; if (bits == 8) { spi_reg->SPDCR_b.SPBYT = 1; @@ -219,17 +386,7 @@ void ra_spi_set_bits(uint32_t ch, uint32_t bits) { } } -void ra_spi_set_clk(uint32_t ch, uint32_t baud) { - R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; - if (baud == 0) { - return; - } - spi_reg->SPCR_b.SPE = 0; - spi_reg->SPBR = (PCLK / 2 / baud) - 1; - spi_reg->SPCR_b.SPE = 1; -} - -void ra_spi_set_lsb_first(uint32_t ch, uint32_t lsb_first) { +static void ra_spi_set_lsb_first(uint32_t ch, uint32_t lsb_first) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; if (lsb_first) { spi_reg->SPCMD_b[0].LSBF = 1; // LSB first @@ -238,7 +395,7 @@ void ra_spi_set_lsb_first(uint32_t ch, uint32_t lsb_first) { } } -void ra_spi_set_mode(uint32_t ch, uint32_t polarity, uint32_t phase) { +static void ra_spi_set_mode(uint32_t ch, uint32_t polarity, uint32_t phase) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; if (polarity != 0) { // CPOL(Clock Polarity) @@ -254,18 +411,6 @@ void ra_spi_set_mode(uint32_t ch, uint32_t polarity, uint32_t phase) { } } -void ra_spi_set_ch(uint32_t ch) { - R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; - spi_reg->SPCR = 0x00; // disable SPI - spi_reg->SPSR = 0xa0; - spi_reg->SPPCR = 0x00; // fixed idle value, disable loop-back mode - spi_reg->SPSCR = 0x00; // Disable sequence control - spi_reg->SPDCR = 0x40; // SPBYT=1, SPLW=0 byte access - spi_reg->SPCMD[0] = 0xe700; // LSBF=0, SPB=7, BRDV=0, CPOL=0, CPHA=0 - spi_reg->SPCR2 = 0x10; - spi_reg->SPCR = 0x48; // Start SPI in master mode -} - uint8_t ra_spi_write_byte(uint32_t ch, uint8_t b) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; while (spi_reg->SPSR_b.SPTEF == 0) { @@ -280,7 +425,6 @@ uint8_t ra_spi_write_byte(uint32_t ch, uint8_t b) { void ra_spi_write_bytes8(uint32_t ch, uint8_t *buf, uint32_t count) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; - ra_spi_set_bits(ch, 8); while (count-- > 0) { while (spi_reg->SPSR_b.SPTEF == 0) { ; @@ -295,7 +439,6 @@ void ra_spi_write_bytes8(uint32_t ch, uint8_t *buf, uint32_t count) { void ra_spi_read_bytes8(uint32_t ch, uint8_t *buf, uint32_t count) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; - ra_spi_set_bits(ch, 8); while (count-- > 0) { while (spi_reg->SPSR_b.SPTEF == 0) { ; @@ -310,7 +453,6 @@ void ra_spi_read_bytes8(uint32_t ch, uint8_t *buf, uint32_t count) { void ra_spi_write_bytes16(uint32_t ch, uint16_t *buf, uint32_t count) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; - ra_spi_set_bits(ch, 16); while (count-- > 0) { while (spi_reg->SPSR_b.SPTEF == 0) { ; @@ -325,7 +467,6 @@ void ra_spi_write_bytes16(uint32_t ch, uint16_t *buf, uint32_t count) { void ra_spi_write_bytes32(uint32_t ch, uint32_t *buf, uint32_t count) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; - ra_spi_set_bits(ch, 32); while (count-- > 0) { while (spi_reg->SPSR_b.SPTEF == 0) { ; @@ -350,7 +491,6 @@ void ra_spi_write_bytes(uint32_t ch, uint32_t bits, uint8_t *buf, uint32_t count void ra_spi_transfer8(uint32_t ch, uint8_t *dst, uint8_t *src, uint32_t count) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; - ra_spi_set_bits(ch, 8); while (count-- > 0) { while (spi_reg->SPSR_b.SPTEF == 0) { ; @@ -359,13 +499,16 @@ void ra_spi_transfer8(uint32_t ch, uint8_t *dst, uint8_t *src, uint32_t count) { while (spi_reg->SPSR_b.SPRF == 0) { ; } - *dst++ = (uint8_t)(spi_reg->SPDR_BY); + if (dst) { + *dst++ = (uint8_t)(spi_reg->SPDR_BY); + } else { + spi_reg->SPDR_BY; + } } } void ra_spi_transfer16(uint32_t ch, uint16_t *dst, uint16_t *src, uint32_t count) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; - ra_spi_set_bits(ch, 16); while (count-- > 0) { while (spi_reg->SPSR_b.SPTEF == 0) { ; @@ -374,13 +517,16 @@ void ra_spi_transfer16(uint32_t ch, uint16_t *dst, uint16_t *src, uint32_t count while (spi_reg->SPSR_b.SPRF == 0) { ; } - *dst++ = (uint16_t)(spi_reg->SPDR_HA); + if (dst) { + *dst++ = (uint16_t)(spi_reg->SPDR_HA); + } else { + spi_reg->SPDR_HA; + } } } void ra_spi_transfer32(uint32_t ch, uint32_t *dst, uint32_t *src, uint32_t count) { R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; - ra_spi_set_bits(ch, 32); while (count-- > 0) { while (spi_reg->SPSR_b.SPTEF == 0) { ; @@ -389,7 +535,11 @@ void ra_spi_transfer32(uint32_t ch, uint32_t *dst, uint32_t *src, uint32_t count while (spi_reg->SPSR_b.SPRF == 0) { ; } - *dst++ = (uint32_t)(spi_reg->SPDR); + if (dst) { + *dst++ = (uint32_t)(spi_reg->SPDR); + } else { + spi_reg->SPDR; + } } } @@ -421,18 +571,53 @@ void ra_spi_get_conf(uint32_t ch, uint16_t *spcmd, uint8_t *spbr) { *spbr = spi_reg->SPBR; } -void ra_spi_init(uint32_t ch, uint32_t mosi, uint32_t miso, uint32_t sck, uint32_t cs, uint32_t baud, uint32_t bits, uint32_t polarity, uint32_t phase) { - ra_gpio_mode_output(cs); - ra_gpio_write(cs, 1); +void ra_spi_init(uint32_t ch, uint32_t mosi, uint32_t miso, uint32_t sck, uint32_t cs, uint32_t baud, uint32_t bits, uint32_t polarity, uint32_t phase, uint32_t firstbit) { + R_SPI0_Type *spi_reg = (R_SPI0_Type *)spi_regs[ch]; + uint8_t ssln = 0; + uint8_t sslp = 0; + + ra_spi_pin_to_ssln(cs, &ssln); + sslp &= ~0x0fU; + sslp |= (uint8_t)polarity << ssln; + ra_spi_module_start(ch); + + spi_reg->SPSR; // dummy read to clear OVRF + spi_reg->SPSR = 0xa0; // clear all status + + spi_reg->SPCR = 0x00; // disable SPI + spi_reg->SSLP = sslp; // select slave active polarity + spi_reg->SPPCR = 0x00; // fixed idle value, disable loop-back mode + spi_reg->SPBR = (PCLK / 2 / baud) - 1; // Set baudrate + spi_reg->SPDCR = 0x40; // SPBYT=1, SPLW=0 byte access + spi_reg->SPCKD = 0x00; // 1RSPCK + spi_reg->SPDCR = 0x00; // 1RSPCK + spi_reg->SPND = 0x00; // 1RSPCK + 2PCLKA + spi_reg->SPCR2 = 0x10; // SCKASE=1 + spi_reg->SPSCR = 0x00; // Disable sequence control + spi_reg->SPCMD[0] = (0xe700 | (ssln << 4)); // LSBF=0, SPB=7, SSLA:ssln, BRDV=0, CPOL=0, CPHA=0 + spi_reg->SPDCR2 = 0x00; // BYSW=0, SINV=0(RA6M5) + + /* set other setting */ + ra_spi_set_mode(ch, polarity, phase); + ra_spi_set_bits(ch, bits); + ra_spi_set_lsb_first(ch, firstbit); + + /* NIVC, DMAC setting */ + + /* I/O port setting */ ra_spi_set_pin(mosi, false); ra_spi_set_pin(miso, true); ra_spi_set_pin(sck, false); - ra_spi_set_mode(ch, polarity, phase); - ra_spi_set_ch(ch); - ra_spi_set_clk(ch, baud); - ra_spi_set_bits(ch, bits); - ra_spi_set_lsb_first(ch, 0); // MSB first + ra_spi_set_pin(cs, false); + + #if defined(RA6M5) + spi_reg->SPCR3 = 0x00; // default + #endif + + spi_reg->SPCR = 0x48; // Start SPI in master mode + spi_reg->SPCR; // wait for completion + return; } diff --git a/ports/renesas-ra/ra/ra_spi.h b/ports/renesas-ra/ra/ra_spi.h index e75acf8701bb9..c33120a863d28 100644 --- a/ports/renesas-ra/ra/ra_spi.h +++ b/ports/renesas-ra/ra/ra_spi.h @@ -34,16 +34,6 @@ bool ra_af_find_ch(ra_af_pin_t *af_pin, uint32_t size, uint32_t pin, uint8_t *ch); bool ra_spi_find_af_ch(uint32_t mosi, uint32_t miso, uint32_t sck, uint8_t *ch); -// static void ra_spi_module_start(uint32_t ch); -// static void ra_spi_module_stop(uint32_t ch); -// static void ra_spi_set_pin(uint8_t pin); - -void ra_spi_set_bits(uint32_t ch, uint32_t bits); -void ra_spi_set_clk(uint32_t ch, uint32_t baud); -void ra_spi_set_lsb_first(uint32_t ch, uint32_t lsb_first); -void ra_spi_set_mode(uint32_t ch, uint32_t polarity, uint32_t phase); -void ra_spi_set_ch(uint32_t ch); - uint8_t ra_spi_write_byte(uint32_t ch, uint8_t b); void ra_spi_read_bytes8(uint32_t ch, uint8_t *buf, uint32_t count); void ra_spi_write_bytes8(uint32_t ch, uint8_t *buf, uint32_t count); @@ -57,7 +47,7 @@ void ra_spi_transfer(uint32_t ch, uint32_t bits, uint8_t *dst, uint8_t *src, uin void ra_spi_start_xfer(uint32_t ch, uint16_t spcmd, uint8_t spbr); void ra_spi_end_xfer(uint32_t ch); void ra_spi_get_conf(uint32_t ch, uint16_t *spcmd, uint8_t *spbr); -void ra_spi_init(uint32_t ch, uint32_t mosi, uint32_t miso, uint32_t sck, uint32_t cs, uint32_t baud, uint32_t bits, uint32_t polarity, uint32_t phase); +void ra_spi_init(uint32_t ch, uint32_t mosi, uint32_t miso, uint32_t sck, uint32_t cs, uint32_t baud, uint32_t bits, uint32_t polarity, uint32_t phase, uint32_t firstbit); void ra_spi_deinit(uint32_t ch, uint32_t cs); #endif /* RA_RA_SPI_H_ */ diff --git a/ports/renesas-ra/ra/ra_timer.c b/ports/renesas-ra/ra/ra_timer.c index 9c2a3c010e045..fc01862706786 100644 --- a/ports/renesas-ra/ra/ra_timer.c +++ b/ports/renesas-ra/ra/ra_timer.c @@ -43,8 +43,8 @@ enum AGT_SOURCE { }; static R_AGTX0_AGT16_Type *agt_regs[AGT_CH_SIZE] = { - (R_AGTX0_AGT16_Type *)0x40084000, - (R_AGTX0_AGT16_Type *)0x40084100 + (R_AGTX0_AGT16_Type *)R_AGTX0, + (R_AGTX0_AGT16_Type *)R_AGTX1 }; static uint8_t ch_to_irq[AGT_CH_SIZE] = { diff --git a/ports/renesas-ra/ra/ra_utils.c b/ports/renesas-ra/ra/ra_utils.c index ae91427eec2b8..db59c1bb6fc4c 100644 --- a/ports/renesas-ra/ra/ra_utils.c +++ b/ports/renesas-ra/ra/ra_utils.c @@ -27,7 +27,7 @@ #include "ra_utils.h" static R_SYSTEM_Type *system_reg = (R_SYSTEM_Type *)0x4001E000; -static R_MSTP_Type *mstp_reg = (R_MSTP_Type *)R_MSTP; +static R_MSTP_Type *mstp_reg = R_MSTP; void ra_mstpcra_stop(uint32_t mod_mask) { system_reg->PRCR = 0xa502; @@ -77,6 +77,18 @@ void ra_mstpcrd_start(uint32_t mod_mask) { system_reg->PRCR = 0xa500; } +void ra_mstpcre_stop(uint32_t mod_mask) { + system_reg->PRCR = 0xa502; + mstp_reg->MSTPCRE |= mod_mask; + system_reg->PRCR = 0xa500; +} + +void ra_mstpcre_start(uint32_t mod_mask) { + system_reg->PRCR = 0xa502; + mstp_reg->MSTPCRE &= ~mod_mask; + system_reg->PRCR = 0xa500; +} + __WEAK void ctsu_write_isr(void) { // dummy } diff --git a/ports/renesas-ra/ra/ra_utils.h b/ports/renesas-ra/ra/ra_utils.h index 3ff0f3a3718e9..3f954dee726da 100644 --- a/ports/renesas-ra/ra/ra_utils.h +++ b/ports/renesas-ra/ra/ra_utils.h @@ -52,6 +52,8 @@ void ra_mstpcrc_stop(uint32_t mod_mask); void ra_mstpcrc_start(uint32_t mod_mask); void ra_mstpcrd_stop(uint32_t mod_mask); void ra_mstpcrd_start(uint32_t mod_mask); +void ra_mstpcre_stop(uint32_t mod_mask); +void ra_mstpcre_start(uint32_t mod_mask); /* mask bit definition for Module Stop Control Register B */ #ifndef R_MSTP_MSTPCRB_MSTPB7_Msk diff --git a/ports/renesas-ra/spi.h b/ports/renesas-ra/spi.h index 47d9c13567e36..04be9f9b64e2b 100644 --- a/ports/renesas-ra/spi.h +++ b/ports/renesas-ra/spi.h @@ -34,11 +34,8 @@ #define SPI_TRANSFER_TIMEOUT(len) ((len) + 100) void spi_init0(void); -void spi_init(uint32_t ch); void spi_deinit(uint32_t ch); int spi_find_index(mp_obj_t id); -void spi_set_params(uint32_t ch, int32_t baudrate, - int32_t polarity, int32_t phase, int32_t bits, int32_t firstbit); void spi_transfer(uint32_t ch, uint32_t bits, size_t len, const uint8_t *src, uint8_t *dest, uint32_t timeout); #endif // MICROPY_INCLUDED_RA_SPI_H From 761d86ae56d6b64f792df3a770167bfa05f3d0db Mon Sep 17 00:00:00 2001 From: mbedNoobNinja Date: Thu, 2 Mar 2023 18:08:31 +0200 Subject: [PATCH 2/2] renesas-ra/boards/VK_RA6M5: Add new board definition. Signed-off-by: mbedNoobNinja --- ports/renesas-ra/boards/VK_RA6M5/README.md | 2 + ports/renesas-ra/boards/VK_RA6M5/board.json | 23 + .../boards/VK_RA6M5/mpconfigboard.h | 86 ++ .../boards/VK_RA6M5/mpconfigboard.mk | 12 + ports/renesas-ra/boards/VK_RA6M5/pins.csv | 166 ++++ .../VK_RA6M5/ra_cfg/driver/r_qspi_cfg.h | 14 + .../VK_RA6M5/ra_cfg/fsp_cfg/bsp/board_cfg.h | 13 + .../VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_cfg.h | 62 ++ .../ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h | 5 + .../fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h | 11 + .../ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h | 386 +++++++++ .../VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_pin_cfg.h | 42 + .../boards/VK_RA6M5/ra_gen/bsp_clock_cfg.h | 35 + .../boards/VK_RA6M5/ra_gen/common_data.c | 70 ++ .../boards/VK_RA6M5/ra_gen/common_data.h | 48 ++ .../boards/VK_RA6M5/ra_gen/hal_data.c | 774 ++++++++++++++++++ .../boards/VK_RA6M5/ra_gen/hal_data.h | 205 +++++ .../boards/VK_RA6M5/ra_gen/pin_data.c | 227 +++++ .../boards/VK_RA6M5/ra_gen/vector_data.c | 73 ++ .../boards/VK_RA6M5/ra_gen/vector_data.h | 98 +++ ports/renesas-ra/boards/VK_RA6M5/vk_ra6m5.ld | 308 +++++++ .../boards/VK_RA6M5/vk_ra6m5_conf.h | 30 + 22 files changed, 2690 insertions(+) create mode 100644 ports/renesas-ra/boards/VK_RA6M5/README.md create mode 100644 ports/renesas-ra/boards/VK_RA6M5/board.json create mode 100644 ports/renesas-ra/boards/VK_RA6M5/mpconfigboard.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/mpconfigboard.mk create mode 100644 ports/renesas-ra/boards/VK_RA6M5/pins.csv create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_cfg/driver/r_qspi_cfg.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/board_cfg.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_cfg.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_pin_cfg.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_gen/bsp_clock_cfg.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_gen/common_data.c create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_gen/common_data.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_gen/hal_data.c create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_gen/hal_data.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_gen/pin_data.c create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_gen/vector_data.c create mode 100644 ports/renesas-ra/boards/VK_RA6M5/ra_gen/vector_data.h create mode 100644 ports/renesas-ra/boards/VK_RA6M5/vk_ra6m5.ld create mode 100644 ports/renesas-ra/boards/VK_RA6M5/vk_ra6m5_conf.h diff --git a/ports/renesas-ra/boards/VK_RA6M5/README.md b/ports/renesas-ra/boards/VK_RA6M5/README.md new file mode 100644 index 0000000000000..a743a0bbe0fb3 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/README.md @@ -0,0 +1,2 @@ +In case you need to debug something in `VK_RA6M5` board, make sure the contents of +[project repo](https://github.com/Vekatech/VK_RA6M5) is cloned in to **this** directory. diff --git a/ports/renesas-ra/boards/VK_RA6M5/board.json b/ports/renesas-ra/boards/VK_RA6M5/board.json new file mode 100644 index 0000000000000..ae11d52213476 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/board.json @@ -0,0 +1,23 @@ +{ + "deploy": [ + "../deploy.md" + ], + "docs": "", + "features": [ + "UART", + "SPI", + "I2C", + "ADC", + "DAC", + "PWM" + ], + "id": "VK-RA6M5", + "images": [ + "VK-RA6M5.jpg" + ], + "mcu": "RA6M5", + "product": "VK-RA6M5", + "thumbnail": "", + "url": "https://vekatech.com/VK-RA6M5_docs/brochures/VK-RA6M5%20Flyer%20R2.pdf", + "vendor": "Vekatech" +} diff --git a/ports/renesas-ra/boards/VK_RA6M5/mpconfigboard.h b/ports/renesas-ra/boards/VK_RA6M5/mpconfigboard.h new file mode 100644 index 0000000000000..f5daf06b5b867 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/mpconfigboard.h @@ -0,0 +1,86 @@ +// MCU config +#define MICROPY_HW_BOARD_NAME "VK-RA6M5" +#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 + +// peripheral config +#define MICROPY_HW_ENABLE_RTC (1) +#define MICROPY_HW_RTC_SOURCE (1) // 0: subclock +#define MICROPY_HW_ENABLE_ADC (1) +#define MICROPY_HW_HAS_FLASH (1) +#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1) +#define MICROPY_HW_HAS_QSPI_FLASH (1) +#define MICROPY_HW_HAS_SDHI_CARD (1) + +// board config + +// UART +#define MICROPY_HW_UART7_TX (pin_P613) // D1 +#define MICROPY_HW_UART7_RX (pin_P614) // D0 +#define MICROPY_HW_UART6_TX (pin_P506) // Modbus (RS485) +#define MICROPY_HW_UART6_RX (pin_P505) // Modbus (RS485) +#define MICROPY_HW_UART9_TX (pin_P109) // REPL +#define MICROPY_HW_UART9_RX (pin_P110) // REPL +#define MICROPY_HW_UART_REPL HW_UART_9 +#define MICROPY_HW_UART_REPL_BAUD 115200 + +// I2C +#define MICROPY_HW_I2C2_SCL (pin_P415) +#define MICROPY_HW_I2C2_SDA (pin_P414) + +// SPI +#define MICROPY_HW_SPI0_SSL (pin_P301) // D10 +#define MICROPY_HW_SPI0_RSPCK (pin_P204) // D13 +#define MICROPY_HW_SPI0_MISO (pin_P202) // D12 +#define MICROPY_HW_SPI0_MOSI (pin_P203) // D11 + +// PWM +#define MICROPY_HW_PWM_2A (pin_P113) // D5 +#define MICROPY_HW_PWM_2B (pin_P114) // D6 +#define MICROPY_HW_PWM_3A (pin_P111) // D3 +// #define MICROPY_HW_PWM_3A (pin_P403) // PN3_6 +#define MICROPY_HW_PWM_3B (pin_P112) // D4 +// #define MICROPY_HW_PWM_3B (pin_P404) // PN3_7 +#define MICROPY_HW_PWM_4A (pin_P115) // D9 +// #define MICROPY_HW_PWM_4A (pin_P302) // H6_4 +#define MICROPY_HW_PWM_4B (pin_P608) // D7 +// #define MICROPY_HW_PWM_4B (pin_P301) // D10 +// #define MICROPY_HW_PWM_4B (pin_P204) // D13 +// #define MICROPY_HW_PWM_5A (pin_P203) // D11 +// #define MICROPY_HW_PWM_5B (pin_P202) // D12 +#define MICROPY_HW_PWM_6B (pin_P408) // PN3_8 +#define MICROPY_HW_PWM_7A (pin_P304) // H6_5 +#define MICROPY_HW_PWM_7B (pin_P303) // H6_3 +#define MICROPY_HW_PWM_8A (pin_P605) // PN4_4 +#define MICROPY_HW_PWM_8B (pin_P604) // PN4_3 + +// DAC +#define MICROPY_HW_DAC0 (pin_P014) // A4 +#define MICROPY_HW_DAC1 (pin_P015) // A5 + +// Switch +#define MICROPY_HW_HAS_SWITCH (1) +#define MICROPY_HW_USRSW_PIN (pin_P010) +// #define MICROPY_HW_USRSW_PIN (pin_P009) +#define MICROPY_HW_USRSW_PULL (MP_HAL_PIN_PULL_NONE) +#define MICROPY_HW_USRSW_EXTI_MODE (MP_HAL_PIN_TRIGGER_FALLING) +#define MICROPY_HW_USRSW_PRESSED (0) + +// LEDs +#define MICROPY_HW_LED1 (pin_P006) +#define MICROPY_HW_LED2 (pin_P007) +#define MICROPY_HW_LED3 (pin_P008) +#define MICROPY_HW_LED_ON(pin) mp_hal_pin_high(pin) +#define MICROPY_HW_LED_OFF(pin) mp_hal_pin_low(pin) +#define MICROPY_HW_LED_TOGGLE(pin) mp_hal_pin_toggle(pin) diff --git a/ports/renesas-ra/boards/VK_RA6M5/mpconfigboard.mk b/ports/renesas-ra/boards/VK_RA6M5/mpconfigboard.mk new file mode 100644 index 0000000000000..5cbe7b5fa5271 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/mpconfigboard.mk @@ -0,0 +1,12 @@ +CMSIS_MCU = RA6M5 +MCU_SERIES = m33 +LD_FILES = boards/VK_RA6M5/vk_ra6m5.ld + +# MicroPython settings +MICROPY_VFS_FAT = 1 + +# FSP settings +USE_FSP_QSPI = 1 +USE_FSP_SDHI = 1 + +CFLAGS+=-DDEFAULT_DBG_CH=9 diff --git a/ports/renesas-ra/boards/VK_RA6M5/pins.csv b/ports/renesas-ra/boards/VK_RA6M5/pins.csv new file mode 100644 index 0000000000000..d3760ef315104 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/pins.csv @@ -0,0 +1,166 @@ +P000,P000 +P001,P001 +P002,P002 +P003,P003 +P004,P004 +P005,P005 +P006,P006 +P007,P007 +P008,P008 +P009,P009 +P010,P010 +P014,P014 +P015,P015 +P100,P100 +P101,P101 +P102,P102 +P103,P103 +P104,P104 +P105,P105 +P106,P106 +P107,P107 +P108,P108 +P109,P109 +P110,P110 +P111,P111 +P112,P112 +P113,P113 +P114,P114 +P115,P115 +P200,P200 +P201,P201 +P202,P202 +P203,P203 +P204,P204 +P205,P205 +P206,P206 +P207,P207 +P208,P208 +P209,P209 +P210,P210 +P211,P211 +P212,P212 +P213,P213 +P214,P214 +P300,P300 +P301,P301 +P302,P302 +P303,P303 +P304,P304 +P305,P305 +P306,P306 +P307,P307 +P308,P308 +P309,P309 +P310,P310 +P311,P311 +P312,P312 +P313,P313 +P314,P314 +P315,P315 +P400,P400 +P401,P401 +P402,P402 +P403,P403 +P404,P404 +P405,P405 +P406,P406 +P407,P407 +P408,P408 +P409,P409 +P410,P410 +P411,P411 +P412,P412 +P413,P413 +P414,P414 +P415,P415 +P500,P500 +P501,P501 +P502,P502 +P503,P503 +P504,P504 +P505,P505 +P506,P506 +P507,P507 +P508,P508 +P511,P511 +P512,P512 +P513,P513 +P600,P600 +P601,P601 +P602,P602 +P603,P603 +P604,P604 +P605,P605 +P606,P606 +P607,P607 +P608,P608 +P609,P609 +P610,P610 +P611,P611 +P612,P612 +P613,P613 +P614,P614 +P615,P615 +P700,P700 +P701,P701 +P702,P702 +P703,P703 +P704,P704 +P705,P705 +P706,P706 +P707,P707 +P708,P708 +P800,P800 +P801,P801 +P802,P802 +P803,P803 +P804,P804 +P805,P805 +P806,P806 +P900,P900 +P901,P901 +P905,P905 +P906,P906 +P907,P907 +P908,P908 +PA00,PA00 +PA01,PA01 +PA08,PA08 +PA09,PA09 +PA10,PA10 +PB00,PB00 +PB01,PB01 +A0,P000 +A1,P001 +A2,P002 +A3,P003 +A4,P014 +A5,P015 +D0,P614 +D1,P613 +D2,P409 +D3,P111 +D4,P112 +D5,P113 +D6,P114 +D7,P608 +D8,P207 +D9,P115 +D10,P301 +D11,P203 +D12,P202 +D13,P204 +SW1,P010 +SW2,P009 +LED1,P006 +LED2,P007 +LED3,P008 +SDA2,P414 +SCL2,P415 +SWDIO,P108 +SWCLK,P300 +MD,P201 +LED_B,P006 +LED_G,P007 +LED_R,P008 diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/driver/r_qspi_cfg.h b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/driver/r_qspi_cfg.h new file mode 100644 index 0000000000000..ff436867fae9d --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/driver/r_qspi_cfg.h @@ -0,0 +1,14 @@ +/* generated configuration header file - do not edit */ +#ifndef R_QSPI_CFG_H_ +#define R_QSPI_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#define QSPI_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define QSPI_CFG_SUPPORT_EXTENDED_SPI_MULTI_LINE_PROGRAM (1) + +#ifdef __cplusplus +} +#endif +#endif /* R_QSPI_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/board_cfg.h b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/board_cfg.h new file mode 100644 index 0000000000000..a57cf3249e386 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/board_cfg.h @@ -0,0 +1,13 @@ +/* generated configuration header file - do not edit */ +#ifndef BOARD_CFG_H_ +#define BOARD_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +void bsp_init(void *p_args); + +#ifdef __cplusplus +} +#endif +#endif /* BOARD_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_cfg.h new file mode 100644 index 0000000000000..9952bf9b15c80 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_cfg.h @@ -0,0 +1,62 @@ +/* generated configuration header file - do not edit */ +#ifndef BSP_CFG_H_ +#define BSP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#include "bsp_clock_cfg.h" +#include "bsp_mcu_family_cfg.h" +#include "board_cfg.h" +#define RA_NOT_DEFINED 0 +#ifndef BSP_CFG_RTOS +#if (RA_NOT_DEFINED) != (RA_NOT_DEFINED) +#define BSP_CFG_RTOS (2) +#elif (RA_NOT_DEFINED) != (RA_NOT_DEFINED) +#define BSP_CFG_RTOS (1) +#else +#define BSP_CFG_RTOS (0) +#endif +#endif +#ifndef BSP_CFG_RTC_USED +#define BSP_CFG_RTC_USED (1) +#endif +#undef RA_NOT_DEFINED +#if defined(_RA_BOOT_IMAGE) +#define BSP_CFG_BOOT_IMAGE (1) +#endif +#define BSP_CFG_MCU_VCC_MV (3300) +#define BSP_CFG_STACK_MAIN_BYTES (0x4000) +#define BSP_CFG_HEAP_BYTES (0x4d000) +#define BSP_CFG_PARAM_CHECKING_ENABLE (0) +#define BSP_CFG_ASSERT (0) +#define BSP_CFG_ERROR_LOG (0) + +#define BSP_CFG_PFS_PROTECT ((1)) + +#define BSP_CFG_C_RUNTIME_INIT ((1)) +#define BSP_CFG_EARLY_INIT ((0)) + +#define BSP_CFG_STARTUP_CLOCK_REG_NOT_RESET ((0)) + +#ifndef BSP_CLOCK_CFG_MAIN_OSC_POPULATED +#define BSP_CLOCK_CFG_MAIN_OSC_POPULATED (1) +#endif + +#ifndef BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE +#define BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE (0) +#endif +#ifndef BSP_CLOCK_CFG_SUBCLOCK_DRIVE +#define BSP_CLOCK_CFG_SUBCLOCK_DRIVE (0) +#endif +#ifndef BSP_CLOCK_CFG_SUBCLOCK_POPULATED +#define BSP_CLOCK_CFG_SUBCLOCK_POPULATED (1) +#endif +#ifndef BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS +#define BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS 1000 +#endif + +#ifdef __cplusplus +} +#endif +#endif /* BSP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h new file mode 100644 index 0000000000000..bd6a901c32d6e --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h @@ -0,0 +1,5 @@ +/* generated configuration header file - do not edit */ +#ifndef BSP_MCU_DEVICE_CFG_H_ +#define BSP_MCU_DEVICE_CFG_H_ +#define BSP_CFG_MCU_PART_SERIES (6) +#endif /* BSP_MCU_DEVICE_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h new file mode 100644 index 0000000000000..6845183db5c6a --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h @@ -0,0 +1,11 @@ +/* generated configuration header file - do not edit */ +#ifndef BSP_MCU_DEVICE_PN_CFG_H_ +#define BSP_MCU_DEVICE_PN_CFG_H_ +#define BSP_MCU_R7FA6M5BH3CFC +#define BSP_MCU_FEATURE_SET ('B') +#define BSP_ROM_SIZE_BYTES (2097152) +#define BSP_RAM_SIZE_BYTES (524288) +#define BSP_DATA_FLASH_SIZE_BYTES (8192) +#define BSP_PACKAGE_LQFP +#define BSP_PACKAGE_PINS (176) +#endif /* BSP_MCU_DEVICE_PN_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h new file mode 100644 index 0000000000000..c6bda8f8fbd45 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h @@ -0,0 +1,386 @@ +/* generated configuration header file - do not edit */ +#ifndef BSP_MCU_FAMILY_CFG_H_ +#define BSP_MCU_FAMILY_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#include "bsp_mcu_device_pn_cfg.h" +#include "bsp_mcu_device_cfg.h" +#include "../../../ra/fsp/src/bsp/mcu/ra6m5/bsp_mcu_info.h" +#include "bsp_clock_cfg.h" +#define BSP_MCU_GROUP_RA6M5 (1) +#define BSP_LOCO_HZ (32768) +#define BSP_MOCO_HZ (8000000) +#define BSP_SUB_CLOCK_HZ (32768) +#if BSP_CFG_HOCO_FREQUENCY == 0 +#define BSP_HOCO_HZ (16000000) +#elif BSP_CFG_HOCO_FREQUENCY == 1 +#define BSP_HOCO_HZ (18000000) +#elif BSP_CFG_HOCO_FREQUENCY == 2 +#define BSP_HOCO_HZ (20000000) +#else +#error "Invalid HOCO frequency chosen (BSP_CFG_HOCO_FREQUENCY) in bsp_clock_cfg.h" +#endif + +#define BSP_CFG_FLL_ENABLE (0) + +#define BSP_CORTEX_VECTOR_TABLE_ENTRIES (16U) +#define BSP_VECTOR_TABLE_MAX_ENTRIES (112U) + +#if defined(_RA_TZ_SECURE) +#define BSP_TZ_SECURE_BUILD (1) +#define BSP_TZ_NONSECURE_BUILD (0) +#elif defined(_RA_TZ_NONSECURE) +#define BSP_TZ_SECURE_BUILD (0) +#define BSP_TZ_NONSECURE_BUILD (1) +#else +#define BSP_TZ_SECURE_BUILD (0) +#define BSP_TZ_NONSECURE_BUILD (0) +#endif + +/* TrustZone Settings */ +#define BSP_TZ_CFG_INIT_SECURE_ONLY (BSP_CFG_CLOCKS_SECURE || (!BSP_CFG_CLOCKS_OVERRIDE)) +#define BSP_TZ_CFG_SKIP_INIT (BSP_TZ_NONSECURE_BUILD && BSP_TZ_CFG_INIT_SECURE_ONLY) +#define BSP_TZ_CFG_EXCEPTION_RESPONSE (0) + +/* CMSIS TrustZone Settings */ +#define SCB_CSR_AIRCR_INIT (1) +#define SCB_AIRCR_BFHFNMINS_VAL (0) +#define SCB_AIRCR_SYSRESETREQS_VAL (1) +#define SCB_AIRCR_PRIS_VAL (0) +#define TZ_FPU_NS_USAGE (1) +#ifndef SCB_NSACR_CP10_11_VAL +#define SCB_NSACR_CP10_11_VAL (3U) +#endif + +#ifndef FPU_FPCCR_TS_VAL +#define FPU_FPCCR_TS_VAL (1U) +#endif +#define FPU_FPCCR_CLRONRETS_VAL (1) + +#ifndef FPU_FPCCR_CLRONRET_VAL +#define FPU_FPCCR_CLRONRET_VAL (1) +#endif + +/* The C-Cache line size that is configured during startup. */ +#ifndef BSP_CFG_C_CACHE_LINE_SIZE +#define BSP_CFG_C_CACHE_LINE_SIZE (1U) +#endif + +/* Type 1 Peripheral Security Attribution */ + +/* Peripheral Security Attribution Register (PSAR) Settings */ +#ifndef BSP_TZ_CFG_PSARB +#define BSP_TZ_CFG_PSARB ( \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 1) /* CAN1 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 2) /* CAN0 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 8) /* IIC1 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 9) /* IIC0 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 11) /* USBFS */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 18) /* SPI1 */ | \ + (((1 > 0) ? 0U : 1U) << 19) /* SPI0 */ | \ + (((1 > 0) ? 0U : 1U) << 22) /* SCI9 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 23) /* SCI8 */ | \ + (((1 > 0) ? 0U : 1U) << 24) /* SCI7 */ | \ + (((1 > 0) ? 0U : 1U) << 25) /* SCI6 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 26) /* SCI5 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 27) /* SCI4 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 28) /* SCI3 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 29) /* SCI2 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 30) /* SCI1 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 31) /* SCI0 */ | \ + 0x33f4f9) /* Unused */ +#endif +#ifndef BSP_TZ_CFG_PSARC +#define BSP_TZ_CFG_PSARC ( \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 0) /* CAC */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 1) /* CRC */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 3) /* CTSU */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 8) /* SSIE0 */ | \ + (((1 > 0) ? 0U : 1U) << 12) /* SDHI0 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 13) /* DOC */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 31) /* SCE9 */ | \ + 0x7fffcef4) /* Unused */ +#endif +#ifndef BSP_TZ_CFG_PSARD +#define BSP_TZ_CFG_PSARD ( \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 0) /* AGT3 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 1) /* AGT2 */ | \ + (((1 > 0) ? 0U : 1U) << 2) /* AGT1 */ | \ + (((1 > 0) ? 0U : 1U) << 3) /* AGT0 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 11) /* POEG3 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 12) /* POEG2 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 13) /* POEG1 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 14) /* POEG0 */ | \ + (((1 > 0) ? 0U : 1U) << 15) /* ADC1 */ | \ + (((1 > 0) ? 0U : 1U) << 16) /* ADC0 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 20) /* DAC */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 22) /* TSN */ | \ + 0xffae07f0) /* Unused */ +#endif +#ifndef BSP_TZ_CFG_PSARE +#define BSP_TZ_CFG_PSARE ( \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 0) /* WDT */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 1) /* IWDT */ | \ + (((1 > 0) ? 0U : 1U) << 2) /* RTC */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 14) /* AGT5 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 15) /* AGT4 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 22) /* GPT9 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 23) /* GPT8 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 24) /* GPT7 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 25) /* GPT6 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 26) /* GPT5 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 27) /* GPT4 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 28) /* GPT3 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 29) /* GPT2 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 30) /* GPT1 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 31) /* GPT0 */ | \ + 0x3f3ff8) /* Unused */ +#endif +#ifndef BSP_TZ_CFG_MSSAR +#define BSP_TZ_CFG_MSSAR ( \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 0) /* ELC */ | \ + (((3 > 0) ? 0U : 1U) << 1) /* DTC_DMAC */ | \ + 0xfffffffc) /* Unused */ +#endif + +/* Type 2 Peripheral Security Attribution */ + +/* Security attribution for Cache registers. */ +#ifndef BSP_TZ_CFG_CSAR +#define BSP_TZ_CFG_CSAR (0xFFFFFFFFU) +#endif + +/* Security attribution for RSTSRn registers. */ +#ifndef BSP_TZ_CFG_RSTSAR +#define BSP_TZ_CFG_RSTSAR (0xFFFFFFFFU) +#endif + +/* Security attribution for registers of LVD channels. */ +#ifndef BSP_TZ_CFG_LVDSAR +#define BSP_TZ_CFG_LVDSAR ( \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 0) | /* LVD Channel 1 */ \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 1) | /* LVD Channel 2 */ \ + 0xFFFFFFFCU) +#endif + +/* Security attribution for LPM registers. */ +#ifndef BSP_TZ_CFG_LPMSAR +#define BSP_TZ_CFG_LPMSAR ((1 > 0) ? 0xFFFFFCEAU : 0xFFFFFFFFU) +#endif +/* Deep Standby Interrupt Factor Security Attribution Register. */ +#ifndef BSP_TZ_CFG_DPFSAR +#define BSP_TZ_CFG_DPFSAR ((1 > 0) ? 0xF2E00000U : 0xFFFFFFFFU) +#endif + +/* Security attribution for CGC registers. */ +#ifndef BSP_TZ_CFG_CGFSAR +#if BSP_CFG_CLOCKS_SECURE +/* Protect all CGC registers from Non-secure write access. */ +#define BSP_TZ_CFG_CGFSAR (0xFFFCE402U) +#else +/* Allow Secure and Non-secure write access. */ +#define BSP_TZ_CFG_CGFSAR (0xFFFFFFFFU) +#endif +#endif + +/* Security attribution for Battery Backup registers. */ +#ifndef BSP_TZ_CFG_BBFSAR +#define BSP_TZ_CFG_BBFSAR (0x00FFFFFF) +#endif + +/* Security attribution for registers for IRQ channels. */ +#ifndef BSP_TZ_CFG_ICUSARA +#define BSP_TZ_CFG_ICUSARA ( \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 0U) /* External IRQ0 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 1U) /* External IRQ1 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 2U) /* External IRQ2 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 3U) /* External IRQ3 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 4U) /* External IRQ4 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 5U) /* External IRQ5 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 6U) /* External IRQ6 */ | \ + (((1 > 0) ? 0U : 1U) << 7U) /* External IRQ7 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 8U) /* External IRQ8 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 9U) /* External IRQ9 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 10U) /* External IRQ10 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 11U) /* External IRQ11 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 12U) /* External IRQ12 */ | \ + (((1 > 0) ? 0U : 1U) << 13U) /* External IRQ13 */ | \ + (((1 > 0) ? 0U : 1U) << 14U) /* External IRQ14 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 15U) /* External IRQ15 */ | \ + 0xFFFF0000U) +#endif + +/* Security attribution for NMI registers. */ +#ifndef BSP_TZ_CFG_ICUSARB +#define BSP_TZ_CFG_ICUSARB (0 | 0xFFFFFFFEU) /* Should match AIRCR.BFHFNMINS. */ +#endif + +/* Security attribution for registers for DMAC channels */ +#ifndef BSP_TZ_CFG_ICUSARC +#define BSP_TZ_CFG_ICUSARC ( \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 0U) /* DMAC Channel 0 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 1U) /* DMAC Channel 1 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 2U) /* DMAC Channel 2 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 3U) /* DMAC Channel 3 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 4U) /* DMAC Channel 4 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 5U) /* DMAC Channel 5 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 6U) /* DMAC Channel 6 */ | \ + (((RA_NOT_DEFINED > 0) ? 0U : 1U) << 7U) /* DMAC Channel 7 */ | \ + 0xFFFFFF00U) +#endif + +/* Security attribution registers for SELSR0. */ +#ifndef BSP_TZ_CFG_ICUSARD +#define BSP_TZ_CFG_ICUSARD ((1 > 0) ? 0xFFFFFFFEU : 0xFFFFFFFFU) +#endif + +/* Security attribution registers for WUPEN0. */ +#ifndef BSP_TZ_CFG_ICUSARE +#define BSP_TZ_CFG_ICUSARE ((1 > 0) ? 0x04F2FFFFU : 0xFFFFFFFFU) +#endif + +/* Security attribution registers for WUPEN1. */ +#ifndef BSP_TZ_CFG_ICUSARF +#define BSP_TZ_CFG_ICUSARF ((1 > 0) ? 0xFFFFFFF8U : 0xFFFFFFFFU) +#endif + +/* Set DTCSTSAR if the Secure program uses the DTC. */ +#if 3 == RA_NOT_DEFINED + #define BSP_TZ_CFG_DTC_USED (0U) +#else +#define BSP_TZ_CFG_DTC_USED (1U) +#endif + +/* Security attribution of FLWT and FCKMHZ registers. */ +#ifndef BSP_TZ_CFG_FSAR +/* If the CGC registers are only accessible in Secure mode, than there is no + * reason for nonsecure applications to access FLWT and FCKMHZ. */ +#if BSP_CFG_CLOCKS_SECURE +/* Protect FLWT and FCKMHZ registers from nonsecure write access. */ +#define BSP_TZ_CFG_FSAR (0xFEFEU) +#else +/* Allow Secure and Non-secure write access. */ +#define BSP_TZ_CFG_FSAR (0xFFFFU) +#endif +#endif + +/* Security attribution for SRAM registers. */ +#ifndef BSP_TZ_CFG_SRAMSAR +/* If the CGC registers are only accessible in Secure mode, than there is no reason for Non Secure applications to access + * SRAM0WTEN and therefore there is no reason to access PRCR2. */ +#define BSP_TZ_CFG_SRAMSAR ( \ + 1 | \ + ((BSP_CFG_CLOCKS_SECURE == 0) ? (1U << 1U) : 0U) | \ + 4 | \ + 0xFFFFFFF8U) +#endif + +/* Security attribution for Standby RAM registers. */ +#ifndef BSP_TZ_CFG_STBRAMSAR +#define BSP_TZ_CFG_STBRAMSAR (0 | 0xFFFFFFF0U) +#endif + +/* Security attribution for the DMAC Bus Master MPU settings. */ +#ifndef BSP_TZ_CFG_MMPUSARA +/* The DMAC Bus Master MPU settings should align with the DMAC channel settings. */ +#define BSP_TZ_CFG_MMPUSARA (BSP_TZ_CFG_ICUSARC) +#endif + +/* Security Attribution Register A for BUS Control registers. */ +#ifndef BSP_TZ_CFG_BUSSARA +#define BSP_TZ_CFG_BUSSARA (0xFFFFFFFFU) +#endif +/* Security Attribution Register B for BUS Control registers. */ +#ifndef BSP_TZ_CFG_BUSSARB +#define BSP_TZ_CFG_BUSSARB (0xFFFFFFFFU) +#endif + +/* Enable Uninitialized Non-Secure Application Fallback. */ +#ifndef BSP_TZ_CFG_NON_SECURE_APPLICATION_FALLBACK +#define BSP_TZ_CFG_NON_SECURE_APPLICATION_FALLBACK (1U) +#endif + +#define OFS_SEQ1 0xA001A001 | (1 << 1) | (3 << 2) +#define OFS_SEQ2 (15 << 4) | (3 << 8) | (3 << 10) +#define OFS_SEQ3 (1 << 12) | (1 << 14) | (1 << 17) +#define OFS_SEQ4 (3 << 18) | (15 << 20) | (3 << 24) | (3 << 26) +#define OFS_SEQ5 (1 << 28) | (1 << 30) +#define BSP_CFG_ROM_REG_OFS0 (OFS_SEQ1 | OFS_SEQ2 | OFS_SEQ3 | OFS_SEQ4 | OFS_SEQ5) + +/* Option Function Select Register 1 Security Attribution */ +#ifndef BSP_CFG_ROM_REG_OFS1_SEL +#if defined(_RA_TZ_SECURE) || defined(_RA_TZ_NONSECURE) + #define BSP_CFG_ROM_REG_OFS1_SEL (0xFFFFF8F8U | ((BSP_CFG_CLOCKS_SECURE == 0) ? 0x700U : 0U) | ((RA_NOT_DEFINED > 0) ? 0U : 0x7U)) +#else +#define BSP_CFG_ROM_REG_OFS1_SEL (0xFFFFF8F8U) +#endif +#endif + +#define BSP_CFG_ROM_REG_OFS1 (0xFFFFFEF8 | (1 << 2) | (3) | (1 << 8)) + +/* Used to create IELS values for the interrupt initialization table g_interrupt_event_link_select. */ +#define BSP_PRV_IELS_ENUM(vector) (ELC_##vector) + +/* Dual Mode Select Register */ +#ifndef BSP_CFG_ROM_REG_DUALSEL +#define BSP_CFG_ROM_REG_DUALSEL (0xFFFFFFF8U | (0x7U)) +#endif + +/* Block Protection Register 0 */ +#ifndef BSP_CFG_ROM_REG_BPS0 +#define BSP_CFG_ROM_REG_BPS0 (~(0U)) +#endif +/* Block Protection Register 1 */ +#ifndef BSP_CFG_ROM_REG_BPS1 +#define BSP_CFG_ROM_REG_BPS1 (~(0U)) +#endif +/* Block Protection Register 2 */ +#ifndef BSP_CFG_ROM_REG_BPS2 +#define BSP_CFG_ROM_REG_BPS2 (~(0U)) +#endif +/* Block Protection Register 3 */ +#ifndef BSP_CFG_ROM_REG_BPS3 +#define BSP_CFG_ROM_REG_BPS3 (0xFFFFFFFFU) +#endif +/* Permanent Block Protection Register 0 */ +#ifndef BSP_CFG_ROM_REG_PBPS0 +#define BSP_CFG_ROM_REG_PBPS0 (~(0U)) +#endif +/* Permanent Block Protection Register 1 */ +#ifndef BSP_CFG_ROM_REG_PBPS1 +#define BSP_CFG_ROM_REG_PBPS1 (~(0U)) +#endif +/* Permanent Block Protection Register 2 */ +#ifndef BSP_CFG_ROM_REG_PBPS2 +#define BSP_CFG_ROM_REG_PBPS2 (~(0U)) +#endif +/* Permanent Block Protection Register 3 */ +#ifndef BSP_CFG_ROM_REG_PBPS3 +#define BSP_CFG_ROM_REG_PBPS3 (0xFFFFFFFFU) +#endif +/* Security Attribution for Block Protection Register 0 (If any blocks are marked as protected in the secure application, then mark them as secure) */ +#ifndef BSP_CFG_ROM_REG_BPS_SEL0 +#define BSP_CFG_ROM_REG_BPS_SEL0 (BSP_CFG_ROM_REG_BPS0 & BSP_CFG_ROM_REG_PBPS0) +#endif +/* Security Attribution for Block Protection Register 1 (If any blocks are marked as protected in the secure application, then mark them as secure) */ +#ifndef BSP_CFG_ROM_REG_BPS_SEL1 +#define BSP_CFG_ROM_REG_BPS_SEL1 (BSP_CFG_ROM_REG_BPS1 & BSP_CFG_ROM_REG_PBPS1) +#endif +/* Security Attribution for Block Protection Register 2 (If any blocks are marked as protected in the secure application, then mark them as secure) */ +#ifndef BSP_CFG_ROM_REG_BPS_SEL2 +#define BSP_CFG_ROM_REG_BPS_SEL2 (BSP_CFG_ROM_REG_BPS2 & BSP_CFG_ROM_REG_PBPS2) +#endif +/* Security Attribution for Block Protection Register 3 (If any blocks are marked as protected in the secure application, then mark them as secure) */ +#ifndef BSP_CFG_ROM_REG_BPS_SEL3 +#define BSP_CFG_ROM_REG_BPS_SEL3 (BSP_CFG_ROM_REG_BPS3 & BSP_CFG_ROM_REG_PBPS3) +#endif +#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT +#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) +#endif + +#ifdef __cplusplus +} +#endif +#endif /* BSP_MCU_FAMILY_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_pin_cfg.h b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_pin_cfg.h new file mode 100644 index 0000000000000..46d4602641dc8 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_cfg/fsp_cfg/bsp/bsp_pin_cfg.h @@ -0,0 +1,42 @@ +/* generated configuration header file - do not edit */ +#ifndef BSP_PIN_CFG_H_ +#define BSP_PIN_CFG_H_ +#include "r_ioport.h" + +/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_HEADER + +#define A0 (BSP_IO_PORT_00_PIN_00) +#define A1 (BSP_IO_PORT_00_PIN_01) +#define A2 (BSP_IO_PORT_00_PIN_02) +#define A3 (BSP_IO_PORT_00_PIN_03) +#define LED_B (BSP_IO_PORT_00_PIN_06) +#define LED_G (BSP_IO_PORT_00_PIN_07) +#define LED_R (BSP_IO_PORT_00_PIN_08) +#define BTN_2 (BSP_IO_PORT_00_PIN_09) +#define BTN_1 (BSP_IO_PORT_00_PIN_10) +#define A4 (BSP_IO_PORT_00_PIN_14) +#define A5 (BSP_IO_PORT_00_PIN_15) +#define D3 (BSP_IO_PORT_01_PIN_11) +#define D4 (BSP_IO_PORT_01_PIN_12) +#define D5 (BSP_IO_PORT_01_PIN_13) +#define D6 (BSP_IO_PORT_01_PIN_14) +#define D9 (BSP_IO_PORT_01_PIN_15) +#define D12 (BSP_IO_PORT_02_PIN_02) +#define D11 (BSP_IO_PORT_02_PIN_03) +#define D13 (BSP_IO_PORT_02_PIN_04) +#define D8 (BSP_IO_PORT_02_PIN_07) +#define D10 (BSP_IO_PORT_03_PIN_01) +#define D2 (BSP_IO_PORT_04_PIN_09) +#define CAN_STBY (BSP_IO_PORT_05_PIN_13) +#define D7 (BSP_IO_PORT_06_PIN_08) +#define D1 (BSP_IO_PORT_06_PIN_13) +#define D0 (BSP_IO_PORT_06_PIN_14) +extern const ioport_cfg_t g_bsp_pin_cfg; /* VK-RA6M5_v2.0(R7FA6M5BH3CFC).pincfg */ + +void BSP_PinConfigSecurityInit(); + +/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ +FSP_FOOTER + +#endif /* BSP_PIN_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/bsp_clock_cfg.h new file mode 100644 index 0000000000000..c586b0603db02 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/bsp_clock_cfg.h @@ -0,0 +1,35 @@ +/* generated configuration header file - do not edit */ +#ifndef BSP_CLOCK_CFG_H_ +#define BSP_CLOCK_CFG_H_ +#define BSP_CFG_CLOCKS_SECURE (0) +#define BSP_CFG_CLOCKS_OVERRIDE (0) +#define BSP_CFG_XTAL_HZ (24000000) /* XTAL 24000000Hz */ +#define BSP_CFG_HOCO_FREQUENCY (2) /* HOCO 20MHz */ +#define BSP_CFG_PLL_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_MAIN_OSC) /* PLL Src: XTAL */ +#define BSP_CFG_PLL_DIV (BSP_CLOCKS_PLL_DIV_3) /* PLL Div /3 */ +#define BSP_CFG_PLL_MUL BSP_CLOCKS_PLL_MUL(25U, 0U) /* PLL Mul x25.0 */ +#define BSP_CFG_PLL2_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_MAIN_OSC) /* PLL2 Src: XTAL */ +#define BSP_CFG_PLL2_DIV (BSP_CLOCKS_PLL_DIV_2) /* PLL2 Div /2 */ +#define BSP_CFG_PLL2_MUL BSP_CLOCKS_PLL_MUL(20U, 0U) /* PLL2 Mul x20.0 */ +#define BSP_CFG_CLOCK_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_PLL) /* Clock Src: PLL */ +#define BSP_CFG_CLKOUT_SOURCE (BSP_CLOCKS_CLOCK_DISABLED) /* CLKOUT Disabled */ +#define BSP_CFG_UCK_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_PLL2) /* UCLK Src: PLL2 */ +#define BSP_CFG_U60CK_SOURCE (BSP_CLOCKS_CLOCK_DISABLED) /* U60CK Disabled */ +#define BSP_CFG_OCTA_SOURCE (BSP_CLOCKS_CLOCK_DISABLED) /* OCTASPICLK Disabled */ +#define BSP_CFG_CANFDCLK_SOURCE (BSP_CLOCKS_CLOCK_DISABLED) /* CANFDCLK Disabled */ +#define BSP_CFG_CECCLK_SOURCE (BSP_CLOCKS_CLOCK_DISABLED) /* CECCLK Disabled */ +#define BSP_CFG_ICLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* ICLK Div /1 */ +#define BSP_CFG_PCLKA_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* PCLKA Div /2 */ +#define BSP_CFG_PCLKB_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_4) /* PCLKB Div /4 */ +#define BSP_CFG_PCLKC_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_4) /* PCLKC Div /4 */ +#define BSP_CFG_PCLKD_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* PCLKD Div /2 */ +#define BSP_CFG_BCLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* BCLK Div /2 */ +#define BSP_CFG_BCLK_OUTPUT (2) /* EBCLK Div /2 */ +#define BSP_CFG_FCLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_4) /* FCLK Div /4 */ +#define BSP_CFG_CLKOUT_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* CLKOUT Div /1 */ +#define BSP_CFG_UCK_DIV (BSP_CLOCKS_USB_CLOCK_DIV_5) /* UCLK Div /5 */ +#define BSP_CFG_U60CK_DIV (BSP_CLOCKS_USB60_CLOCK_DIV_1) /* U60CK Div /1 */ +#define BSP_CFG_OCTA_DIV (BSP_CLOCKS_OCTA_CLOCK_DIV_1) /* OCTASPICLK Div /1 */ +#define BSP_CFG_CANFDCLK_DIV (BSP_CLOCKS_CANFD_CLOCK_DIV_1) /* CANFDCLK Div /1 */ +#define BSP_CFG_CECCLK_DIV (BSP_CLOCKS_CEC_CLOCK_DIV_1) /* CECCLK Div /1 */ +#endif /* BSP_CLOCK_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_gen/common_data.c b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/common_data.c new file mode 100644 index 0000000000000..b70b403a910a3 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/common_data.c @@ -0,0 +1,70 @@ +/* generated common source file - do not edit */ +#include "common_data.h" +icu_instance_ctrl_t g_external_irq14_ctrl; +const external_irq_cfg_t g_external_irq14_cfg = { .channel = 14, .trigger = + EXTERNAL_IRQ_TRIG_RISING, .filter_enable = false, .pclk_div = + EXTERNAL_IRQ_PCLK_DIV_BY_64, .p_callback = callback_icu, +/** If NULL then do not add & */ + #if defined(NULL) + .p_context = NULL, + #else + .p_context = &NULL, + #endif + .p_extend = NULL, .ipl = (12), + #if defined(VECTOR_NUMBER_ICU_IRQ14) + .irq = VECTOR_NUMBER_ICU_IRQ14, + #else + .irq = FSP_INVALID_VECTOR, + #endif +}; +/* Instance structure to use this module. */ +const external_irq_instance_t g_external_irq14 = { .p_ctrl = + &g_external_irq14_ctrl, .p_cfg = &g_external_irq14_cfg, .p_api = + &g_external_irq_on_icu }; +icu_instance_ctrl_t g_external_irq13_ctrl; +const external_irq_cfg_t g_external_irq13_cfg = { .channel = 13, .trigger = + EXTERNAL_IRQ_TRIG_RISING, .filter_enable = false, .pclk_div = + EXTERNAL_IRQ_PCLK_DIV_BY_64, .p_callback = callback_icu, +/** If NULL then do not add & */ + #if defined(NULL) + .p_context = NULL, + #else + .p_context = &NULL, + #endif + .p_extend = NULL, .ipl = (12), + #if defined(VECTOR_NUMBER_ICU_IRQ13) + .irq = VECTOR_NUMBER_ICU_IRQ13, + #else + .irq = FSP_INVALID_VECTOR, + #endif +}; +/* Instance structure to use this module. */ +const external_irq_instance_t g_external_irq13 = { .p_ctrl = + &g_external_irq13_ctrl, .p_cfg = &g_external_irq13_cfg, .p_api = + &g_external_irq_on_icu }; +icu_instance_ctrl_t g_external_irq7_ctrl; +const external_irq_cfg_t g_external_irq7_cfg = { .channel = 7, .trigger = + EXTERNAL_IRQ_TRIG_RISING, .filter_enable = false, .pclk_div = + EXTERNAL_IRQ_PCLK_DIV_BY_64, .p_callback = callback_icu, +/** If NULL then do not add & */ + #if defined(NULL) + .p_context = NULL, + #else + .p_context = &NULL, + #endif + .p_extend = NULL, .ipl = (12), + #if defined(VECTOR_NUMBER_ICU_IRQ7) + .irq = VECTOR_NUMBER_ICU_IRQ7, + #else + .irq = FSP_INVALID_VECTOR, + #endif +}; +/* Instance structure to use this module. */ +const external_irq_instance_t g_external_irq7 = { .p_ctrl = + &g_external_irq7_ctrl, .p_cfg = &g_external_irq7_cfg, .p_api = + &g_external_irq_on_icu }; +ioport_instance_ctrl_t g_ioport_ctrl; +const ioport_instance_t g_ioport = { .p_api = &g_ioport_on_ioport, .p_ctrl = + &g_ioport_ctrl, .p_cfg = &g_bsp_pin_cfg, }; +void g_common_init(void) { +} diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_gen/common_data.h b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/common_data.h new file mode 100644 index 0000000000000..65674c8dfba5d --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/common_data.h @@ -0,0 +1,48 @@ +/* generated common header file - do not edit */ +#ifndef COMMON_DATA_H_ +#define COMMON_DATA_H_ +#include +#include "bsp_api.h" +#include "r_icu.h" +#include "r_external_irq_api.h" +#include "r_ioport.h" +#include "bsp_pin_cfg.h" +FSP_HEADER +/** External IRQ on ICU Instance. */ +extern const external_irq_instance_t g_external_irq14; + +/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ +extern icu_instance_ctrl_t g_external_irq14_ctrl; +extern const external_irq_cfg_t g_external_irq14_cfg; + +#ifndef callback_icu +void callback_icu(external_irq_callback_args_t *p_args); +#endif +/** External IRQ on ICU Instance. */ +extern const external_irq_instance_t g_external_irq13; + +/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ +extern icu_instance_ctrl_t g_external_irq13_ctrl; +extern const external_irq_cfg_t g_external_irq13_cfg; + +#ifndef callback_icu +void callback_icu(external_irq_callback_args_t *p_args); +#endif +/** External IRQ on ICU Instance. */ +extern const external_irq_instance_t g_external_irq7; + +/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ +extern icu_instance_ctrl_t g_external_irq7_ctrl; +extern const external_irq_cfg_t g_external_irq7_cfg; + +#ifndef callback_icu +void callback_icu(external_irq_callback_args_t *p_args); +#endif +/* IOPORT Instance */ +extern const ioport_instance_t g_ioport; + +/* IOPORT control structure. */ +extern ioport_instance_ctrl_t g_ioport_ctrl; +void g_common_init(void); +FSP_FOOTER +#endif /* COMMON_DATA_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_gen/hal_data.c b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/hal_data.c new file mode 100644 index 0000000000000..9a6204a0c4687 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/hal_data.c @@ -0,0 +1,774 @@ +/* generated HAL source file - do not edit */ +#include "hal_data.h" +/* Macros to tie dynamic ELC links to ADC_TRIGGER_SYNC_ELC option in adc_trigger_t. */ +#define ADC_TRIGGER_ADC0 ADC_TRIGGER_SYNC_ELC +#define ADC_TRIGGER_ADC0_B ADC_TRIGGER_SYNC_ELC +#define ADC_TRIGGER_ADC1 ADC_TRIGGER_SYNC_ELC +#define ADC_TRIGGER_ADC1_B ADC_TRIGGER_SYNC_ELC +dtc_instance_ctrl_t g_transfer2_ctrl; + +transfer_info_t g_transfer2_info = { .transfer_settings_word_b.dest_addr_mode = + TRANSFER_ADDR_MODE_FIXED, .transfer_settings_word_b.repeat_area = + TRANSFER_REPEAT_AREA_SOURCE, .transfer_settings_word_b.irq = + TRANSFER_IRQ_END, .transfer_settings_word_b.chain_mode = + TRANSFER_CHAIN_MODE_DISABLED, .transfer_settings_word_b.src_addr_mode = + TRANSFER_ADDR_MODE_INCREMENTED, .transfer_settings_word_b.size = + TRANSFER_SIZE_4_BYTE, .transfer_settings_word_b.mode = + TRANSFER_MODE_NORMAL, .p_dest = (void *)NULL, .p_src = + (void const *)NULL, .num_blocks = 0, .length = 128, }; + +const dtc_extended_cfg_t g_transfer2_cfg_extend = { .activation_source = + VECTOR_NUMBER_SDHIMMC0_DMA_REQ, }; +const transfer_cfg_t g_transfer2_cfg = { .p_info = &g_transfer2_info, + .p_extend = &g_transfer2_cfg_extend, }; + +/* Instance structure to use this module. */ +const transfer_instance_t g_transfer2 = { .p_ctrl = &g_transfer2_ctrl, .p_cfg = + &g_transfer2_cfg, .p_api = &g_transfer_on_dtc }; +#define RA_NOT_DEFINED (UINT32_MAX) +#if (RA_NOT_DEFINED) != (RA_NOT_DEFINED) + +/* If the transfer module is DMAC, define a DMAC transfer callback. */ +#include "r_dmac.h" +extern void r_sdhi_transfer_callback(sdhi_instance_ctrl_t *p_ctrl); + +void g_sdmmc0_dmac_callback(dmac_callback_args_t *p_args) { + r_sdhi_transfer_callback((sdhi_instance_ctrl_t *)p_args->p_context); +} +#endif +#undef RA_NOT_DEFINED + +sdhi_instance_ctrl_t g_sdmmc0_ctrl; +sdmmc_cfg_t g_sdmmc0_cfg = { .bus_width = SDMMC_BUS_WIDTH_4_BITS, .channel = 0, + .p_callback = sdhi_ISR, .p_context = NULL, .block_size = 512, + .card_detect = SDMMC_CARD_DETECT_CD, .write_protect = + SDMMC_WRITE_PROTECT_WP, + + .p_extend = NULL, .p_lower_lvl_transfer = &g_transfer2, + + .access_ipl = (12), .sdio_ipl = BSP_IRQ_DISABLED, .card_ipl = (12), + .dma_req_ipl = (12), + #if defined(VECTOR_NUMBER_SDHIMMC0_ACCS) + .access_irq = VECTOR_NUMBER_SDHIMMC0_ACCS, + #else + .access_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SDHIMMC0_CARD) + .card_irq = VECTOR_NUMBER_SDHIMMC0_CARD, + #else + .card_irq = FSP_INVALID_VECTOR, + #endif + .sdio_irq = FSP_INVALID_VECTOR, + #if defined(VECTOR_NUMBER_SDHIMMC0_DMA_REQ) + .dma_req_irq = VECTOR_NUMBER_SDHIMMC0_DMA_REQ, + #else + .dma_req_irq = FSP_INVALID_VECTOR, + #endif +}; +/* Instance structure to use this module. */ +const sdmmc_instance_t g_sdmmc0 = { .p_ctrl = &g_sdmmc0_ctrl, .p_cfg = + &g_sdmmc0_cfg, .p_api = &g_sdmmc_on_sdhi }; +qspi_instance_ctrl_t g_qspi0_ctrl; + +static const spi_flash_erase_command_t g_qspi0_erase_command_list[] = { + #if 4096 > 0 + { .command = 0x20, .size = 4096 }, + #endif + #if 32768 > 0 + { .command = 0x52, .size = 32768 }, + #endif + #if 65536 > 0 + { .command = 0xD8, .size = 65536 }, + #endif + #if 0xC7 > 0 + { .command = 0xC7, .size = SPI_FLASH_ERASE_SIZE_CHIP_ERASE }, + #endif +}; +static const qspi_extended_cfg_t g_qspi0_extended_cfg = { + .min_qssl_deselect_cycles = QSPI_QSSL_MIN_HIGH_LEVEL_9_QSPCLK, + .qspclk_div = QSPI_QSPCLK_DIV_2, +}; +const spi_flash_cfg_t g_qspi0_cfg = { .spi_protocol = + SPI_FLASH_PROTOCOL_EXTENDED_SPI, .read_mode = + SPI_FLASH_READ_MODE_FAST_READ_QUAD_IO, .address_bytes = + SPI_FLASH_ADDRESS_BYTES_3, .dummy_clocks = + SPI_FLASH_DUMMY_CLOCKS_DEFAULT, .page_program_address_lines = + SPI_FLASH_DATA_LINES_1, .page_size_bytes = 256, .page_program_command = + 0x32, .write_enable_command = 0x06, .status_command = 0x05, + .write_status_bit = 0, .xip_enter_command = 0x20, .xip_exit_command = + 0xFF, .p_erase_command_list = &g_qspi0_erase_command_list[0], + .erase_command_list_length = sizeof(g_qspi0_erase_command_list) + / sizeof(g_qspi0_erase_command_list[0]), .p_extend = + &g_qspi0_extended_cfg, }; +/** This structure encompasses everything that is needed to use an instance of this interface. */ +const spi_flash_instance_t g_qspi0 = { .p_ctrl = &g_qspi0_ctrl, .p_cfg = + &g_qspi0_cfg, .p_api = &g_qspi_on_spi_flash, }; +iic_master_instance_ctrl_t g_i2c_master2_ctrl; +const iic_master_extended_cfg_t g_i2c_master2_extend = +{ .timeout_mode = IIC_MASTER_TIMEOUT_MODE_SHORT, .timeout_scl_low = + IIC_MASTER_TIMEOUT_SCL_LOW_ENABLED, + /* Actual calculated bitrate: 98425. Actual calculated duty cycle: 50%. */ .clock_settings.brl_value = + 28, .clock_settings.brh_value = 28, + .clock_settings.cks_value = 3, }; +const i2c_master_cfg_t g_i2c_master2_cfg = { .channel = 2, .rate = + I2C_MASTER_RATE_STANDARD, .slave = 0x00, .addr_mode = + I2C_MASTER_ADDR_MODE_7BIT, +#define RA_NOT_DEFINED (1) + #if (RA_NOT_DEFINED == RA_NOT_DEFINED) + .p_transfer_tx = NULL, + #else + .p_transfer_tx = &RA_NOT_DEFINED, + #endif + #if (RA_NOT_DEFINED == RA_NOT_DEFINED) + .p_transfer_rx = NULL, + #else + .p_transfer_rx = &RA_NOT_DEFINED, + #endif +#undef RA_NOT_DEFINED + .p_callback = callback_iic, .p_context = NULL, + #if defined(VECTOR_NUMBER_IIC2_RXI) + .rxi_irq = VECTOR_NUMBER_IIC2_RXI, + #else + .rxi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_IIC2_TXI) + .txi_irq = VECTOR_NUMBER_IIC2_TXI, + #else + .txi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_IIC2_TEI) + .tei_irq = VECTOR_NUMBER_IIC2_TEI, + #else + .tei_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_IIC2_ERI) + .eri_irq = VECTOR_NUMBER_IIC2_ERI, + #else + .eri_irq = FSP_INVALID_VECTOR, + #endif + .ipl = (12), .p_extend = &g_i2c_master2_extend, }; +/* Instance structure to use this module. */ +const i2c_master_instance_t g_i2c_master2 = { .p_ctrl = &g_i2c_master2_ctrl, + .p_cfg = &g_i2c_master2_cfg, .p_api = &g_i2c_master_on_iic }; +adc_instance_ctrl_t g_adc1_ctrl; +const adc_extended_cfg_t g_adc1_cfg_extend = { .add_average_count = ADC_ADD_OFF, + .clearing = ADC_CLEAR_AFTER_READ_ON, .trigger_group_b = + ADC_TRIGGER_SYNC_ELC, .double_trigger_mode = + ADC_DOUBLE_TRIGGER_DISABLED, .adc_vref_control = + ADC_VREF_CONTROL_VREFH, .enable_adbuf = 0, + #if defined(VECTOR_NUMBER_ADC1_WINDOW_A) + .window_a_irq = VECTOR_NUMBER_ADC1_WINDOW_A, + #else + .window_a_irq = FSP_INVALID_VECTOR, + #endif + .window_a_ipl = (BSP_IRQ_DISABLED), + #if defined(VECTOR_NUMBER_ADC1_WINDOW_B) + .window_b_irq = VECTOR_NUMBER_ADC1_WINDOW_B, + #else + .window_b_irq = FSP_INVALID_VECTOR, + #endif + .window_b_ipl = (BSP_IRQ_DISABLED), }; +const adc_cfg_t g_adc1_cfg = { .unit = 1, .mode = ADC_MODE_SINGLE_SCAN, + .resolution = ADC_RESOLUTION_12_BIT, .alignment = + (adc_alignment_t)ADC_ALIGNMENT_RIGHT, .trigger = + ADC_TRIGGER_SOFTWARE, .p_callback = NULL, + /** If NULL then do not add & */ + #if defined(NULL) + .p_context = NULL, + #else + .p_context = &NULL, + #endif + .p_extend = &g_adc1_cfg_extend, + #if defined(VECTOR_NUMBER_ADC1_SCAN_END) + .scan_end_irq = VECTOR_NUMBER_ADC1_SCAN_END, + #else + .scan_end_irq = FSP_INVALID_VECTOR, + #endif + .scan_end_ipl = (BSP_IRQ_DISABLED), + #if defined(VECTOR_NUMBER_ADC1_SCAN_END_B) + .scan_end_b_irq = VECTOR_NUMBER_ADC1_SCAN_END_B, + #else + .scan_end_b_irq = FSP_INVALID_VECTOR, + #endif + .scan_end_b_ipl = (BSP_IRQ_DISABLED), }; +#if ((0) | (0)) +const adc_window_cfg_t g_adc1_window_cfg = +{ + .compare_mask = 0, + .compare_mode_mask = 0, + .compare_cfg = (0) | (0) | (0) | (ADC_COMPARE_CFG_EVENT_OUTPUT_OR), + .compare_ref_low = 0, + .compare_ref_high = 0, + .compare_b_channel = (ADC_WINDOW_B_CHANNEL_0), + .compare_b_mode = (ADC_WINDOW_B_MODE_LESS_THAN_OR_OUTSIDE), + .compare_b_ref_low = 0, + .compare_b_ref_high = 0, +}; +#endif +const adc_channel_cfg_t g_adc1_channel_cfg = { .scan_mask = 0, + .scan_mask_group_b = 0, .priority_group_a = ADC_GROUP_A_PRIORITY_OFF, + .add_mask = 0, .sample_hold_mask = 0, .sample_hold_states = 24, + #if ((0) | (0)) + .p_window_cfg = (adc_window_cfg_t *)&g_adc1_window_cfg, + #else + .p_window_cfg = NULL, + #endif +}; +/* Instance structure to use this module. */ +const adc_instance_t g_adc1 = { .p_ctrl = &g_adc1_ctrl, .p_cfg = &g_adc1_cfg, + .p_channel_cfg = &g_adc1_channel_cfg, .p_api = &g_adc_on_adc }; +adc_instance_ctrl_t g_adc0_ctrl; +const adc_extended_cfg_t g_adc0_cfg_extend = { .add_average_count = ADC_ADD_OFF, + .clearing = ADC_CLEAR_AFTER_READ_ON, .trigger_group_b = + ADC_TRIGGER_SYNC_ELC, .double_trigger_mode = + ADC_DOUBLE_TRIGGER_DISABLED, .adc_vref_control = + ADC_VREF_CONTROL_VREFH, .enable_adbuf = 0, + #if defined(VECTOR_NUMBER_ADC0_WINDOW_A) + .window_a_irq = VECTOR_NUMBER_ADC0_WINDOW_A, + #else + .window_a_irq = FSP_INVALID_VECTOR, + #endif + .window_a_ipl = (BSP_IRQ_DISABLED), + #if defined(VECTOR_NUMBER_ADC0_WINDOW_B) + .window_b_irq = VECTOR_NUMBER_ADC0_WINDOW_B, + #else + .window_b_irq = FSP_INVALID_VECTOR, + #endif + .window_b_ipl = (BSP_IRQ_DISABLED), }; +const adc_cfg_t g_adc0_cfg = { .unit = 0, .mode = ADC_MODE_SINGLE_SCAN, + .resolution = ADC_RESOLUTION_12_BIT, .alignment = + (adc_alignment_t)ADC_ALIGNMENT_RIGHT, .trigger = + ADC_TRIGGER_SOFTWARE, .p_callback = NULL, + /** If NULL then do not add & */ + #if defined(NULL) + .p_context = NULL, + #else + .p_context = &NULL, + #endif + .p_extend = &g_adc0_cfg_extend, + #if defined(VECTOR_NUMBER_ADC0_SCAN_END) + .scan_end_irq = VECTOR_NUMBER_ADC0_SCAN_END, + #else + .scan_end_irq = FSP_INVALID_VECTOR, + #endif + .scan_end_ipl = (BSP_IRQ_DISABLED), + #if defined(VECTOR_NUMBER_ADC0_SCAN_END_B) + .scan_end_b_irq = VECTOR_NUMBER_ADC0_SCAN_END_B, + #else + .scan_end_b_irq = FSP_INVALID_VECTOR, + #endif + .scan_end_b_ipl = (BSP_IRQ_DISABLED), }; +#if ((0) | (0)) +const adc_window_cfg_t g_adc0_window_cfg = +{ + .compare_mask = 0, + .compare_mode_mask = 0, + .compare_cfg = (0) | (0) | (0) | (ADC_COMPARE_CFG_EVENT_OUTPUT_OR), + .compare_ref_low = 0, + .compare_ref_high = 0, + .compare_b_channel = (ADC_WINDOW_B_CHANNEL_0), + .compare_b_mode = (ADC_WINDOW_B_MODE_LESS_THAN_OR_OUTSIDE), + .compare_b_ref_low = 0, + .compare_b_ref_high = 0, +}; +#endif +const adc_channel_cfg_t g_adc0_channel_cfg = { .scan_mask = 0, + .scan_mask_group_b = 0, .priority_group_a = ADC_GROUP_A_PRIORITY_OFF, + .add_mask = 0, .sample_hold_mask = 0, .sample_hold_states = 24, + #if ((0) | (0)) + .p_window_cfg = (adc_window_cfg_t *)&g_adc0_window_cfg, + #else + .p_window_cfg = NULL, + #endif +}; +/* Instance structure to use this module. */ +const adc_instance_t g_adc0 = { .p_ctrl = &g_adc0_ctrl, .p_cfg = &g_adc0_cfg, + .p_channel_cfg = &g_adc0_channel_cfg, .p_api = &g_adc_on_adc }; +lpm_instance_ctrl_t g_lpm0_ctrl; + +const lpm_cfg_t g_lpm0_cfg = { .low_power_mode = LPM_MODE_SLEEP, + .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM + | (lpm_standby_wake_source_t)0, + #if BSP_FEATURE_LPM_HAS_SNOOZE + .snooze_cancel_sources = LPM_SNOOZE_CANCEL_SOURCE_NONE, + .snooze_request_source = LPM_SNOOZE_REQUEST_RXD0_FALLING, + .snooze_end_sources = (lpm_snooze_end_t)0, + .dtc_state_in_snooze = LPM_SNOOZE_DTC_DISABLE, + #endif + #if BSP_FEATURE_LPM_HAS_SBYCR_OPE + .output_port_enable = LPM_OUTPUT_PORT_ENABLE_RETAIN, + #endif + #if BSP_FEATURE_LPM_HAS_DEEP_STANDBY + .io_port_state = LPM_IO_PORT_NO_CHANGE, + .power_supply_state = LPM_POWER_SUPPLY_DEEPCUT0, + .deep_standby_cancel_source = (lpm_deep_standby_cancel_source_t)0, + .deep_standby_cancel_edge = (lpm_deep_standby_cancel_edge_t)0, + #endif + #if BSP_FEATURE_LPM_HAS_PDRAMSCR + .ram_retention_cfg.ram_retention = (uint8_t)(0), + .ram_retention_cfg.tcm_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_DPSBYCR_SRKEEP + .ram_retention_cfg.standby_ram_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_LDO_CONTROL + .ldo_standby_cfg.pll1_ldo = false, + .ldo_standby_cfg.pll2_ldo = false, + .ldo_standby_cfg.hoco_ldo = false, + #endif + .p_extend = NULL, }; + +const lpm_instance_t g_lpm0 = { .p_api = &g_lpm_on_lpm, .p_ctrl = &g_lpm0_ctrl, + .p_cfg = &g_lpm0_cfg }; +dtc_instance_ctrl_t g_transfer1_ctrl; + +transfer_info_t g_transfer1_info = { .transfer_settings_word_b.dest_addr_mode = + TRANSFER_ADDR_MODE_INCREMENTED, .transfer_settings_word_b.repeat_area = + TRANSFER_REPEAT_AREA_DESTINATION, .transfer_settings_word_b.irq = + TRANSFER_IRQ_END, .transfer_settings_word_b.chain_mode = + TRANSFER_CHAIN_MODE_DISABLED, .transfer_settings_word_b.src_addr_mode = + TRANSFER_ADDR_MODE_FIXED, .transfer_settings_word_b.size = + TRANSFER_SIZE_2_BYTE, .transfer_settings_word_b.mode = + TRANSFER_MODE_NORMAL, .p_dest = (void *)NULL, .p_src = + (void const *)NULL, .num_blocks = 0, .length = 0, }; + +const dtc_extended_cfg_t g_transfer1_cfg_extend = { .activation_source = + VECTOR_NUMBER_SPI0_RXI, }; +const transfer_cfg_t g_transfer1_cfg = { .p_info = &g_transfer1_info, + .p_extend = &g_transfer1_cfg_extend, }; + +/* Instance structure to use this module. */ +const transfer_instance_t g_transfer1 = { .p_ctrl = &g_transfer1_ctrl, .p_cfg = + &g_transfer1_cfg, .p_api = &g_transfer_on_dtc }; +dtc_instance_ctrl_t g_transfer0_ctrl; + +transfer_info_t g_transfer0_info = { .transfer_settings_word_b.dest_addr_mode = + TRANSFER_ADDR_MODE_FIXED, .transfer_settings_word_b.repeat_area = + TRANSFER_REPEAT_AREA_SOURCE, .transfer_settings_word_b.irq = + TRANSFER_IRQ_END, .transfer_settings_word_b.chain_mode = + TRANSFER_CHAIN_MODE_DISABLED, .transfer_settings_word_b.src_addr_mode = + TRANSFER_ADDR_MODE_INCREMENTED, .transfer_settings_word_b.size = + TRANSFER_SIZE_2_BYTE, .transfer_settings_word_b.mode = + TRANSFER_MODE_NORMAL, .p_dest = (void *)NULL, .p_src = + (void const *)NULL, .num_blocks = 0, .length = 0, }; + +const dtc_extended_cfg_t g_transfer0_cfg_extend = { .activation_source = + VECTOR_NUMBER_SPI0_TXI, }; +const transfer_cfg_t g_transfer0_cfg = { .p_info = &g_transfer0_info, + .p_extend = &g_transfer0_cfg_extend, }; + +/* Instance structure to use this module. */ +const transfer_instance_t g_transfer0 = { .p_ctrl = &g_transfer0_ctrl, .p_cfg = + &g_transfer0_cfg, .p_api = &g_transfer_on_dtc }; +#define RA_NOT_DEFINED (UINT32_MAX) +#if (RA_NOT_DEFINED) != (RA_NOT_DEFINED) + +/* If the transfer module is DMAC, define a DMAC transfer callback. */ +#include "r_dmac.h" +extern void spi_tx_dmac_callback(spi_instance_ctrl_t const *const p_ctrl); + +void g_spi0_tx_transfer_callback(dmac_callback_args_t *p_args) { + FSP_PARAMETER_NOT_USED(p_args); + spi_tx_dmac_callback(&g_spi0_ctrl); +} +#endif + +#if (RA_NOT_DEFINED) != (RA_NOT_DEFINED) + +/* If the transfer module is DMAC, define a DMAC transfer callback. */ +#include "r_dmac.h" +extern void spi_rx_dmac_callback(spi_instance_ctrl_t const *const p_ctrl); + +void g_spi0_rx_transfer_callback(dmac_callback_args_t *p_args) { + FSP_PARAMETER_NOT_USED(p_args); + spi_rx_dmac_callback(&g_spi0_ctrl); +} +#endif +#undef RA_NOT_DEFINED + +spi_instance_ctrl_t g_spi0_ctrl; + +/** SPI extended configuration for SPI HAL driver */ +const spi_extended_cfg_t g_spi0_ext_cfg = { .spi_clksyn = SPI_SSL_MODE_CLK_SYN, + .spi_comm = SPI_COMMUNICATION_FULL_DUPLEX, .ssl_polarity = SPI_SSLP_LOW, + .ssl_select = SPI_SSL_SELECT_SSL0, .mosi_idle = + SPI_MOSI_IDLE_VALUE_FIXING_DISABLE, .parity = + SPI_PARITY_MODE_DISABLE, .byte_swap = SPI_BYTE_SWAP_DISABLE, + .spck_div = { + /* Actual calculated bitrate: 12500000. */ .spbr = 3, .brdv = 0 + }, + .spck_delay = SPI_DELAY_COUNT_1, + .ssl_negation_delay = SPI_DELAY_COUNT_1, .next_access_delay = + SPI_DELAY_COUNT_1 }; + +/** SPI configuration for SPI HAL driver */ +const spi_cfg_t g_spi0_cfg = { .channel = 0, + + #if defined(VECTOR_NUMBER_SPI0_RXI) + .rxi_irq = VECTOR_NUMBER_SPI0_RXI, + #else + .rxi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SPI0_TXI) + .txi_irq = VECTOR_NUMBER_SPI0_TXI, + #else + .txi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SPI0_TEI) + .tei_irq = VECTOR_NUMBER_SPI0_TEI, + #else + .tei_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SPI0_ERI) + .eri_irq = VECTOR_NUMBER_SPI0_ERI, + #else + .eri_irq = FSP_INVALID_VECTOR, + #endif + + .rxi_ipl = (12), .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), + + .operating_mode = SPI_MODE_MASTER, + + .clk_phase = SPI_CLK_PHASE_EDGE_ODD, .clk_polarity = + SPI_CLK_POLARITY_LOW, + + .mode_fault = SPI_MODE_FAULT_ERROR_DISABLE, .bit_order = + SPI_BIT_ORDER_MSB_FIRST, .p_transfer_tx = g_spi0_P_TRANSFER_TX, + .p_transfer_rx = g_spi0_P_TRANSFER_RX, .p_callback = spi_callback, + + .p_context = NULL, .p_extend = (void *)&g_spi0_ext_cfg, }; + +/* Instance structure to use this module. */ +const spi_instance_t g_spi0 = { .p_ctrl = &g_spi0_ctrl, .p_cfg = &g_spi0_cfg, + .p_api = &g_spi_on_spi }; +agt_instance_ctrl_t g_timer1_ctrl; +const agt_extended_cfg_t g_timer1_extend = +{ .count_source = AGT_CLOCK_PCLKB, .agto = AGT_PIN_CFG_DISABLED, + .agtoab_settings_b.agtoa = AGT_PIN_CFG_DISABLED, + .agtoab_settings_b.agtob = AGT_PIN_CFG_DISABLED, + .measurement_mode = AGT_MEASURE_DISABLED, .agtio_filter = + AGT_AGTIO_FILTER_NONE, .enable_pin = + AGT_ENABLE_PIN_NOT_USED, .trigger_edge = + AGT_TRIGGER_EDGE_RISING, }; +const timer_cfg_t g_timer1_cfg = { .mode = TIMER_MODE_PERIODIC, +/* Actual period: 0.00131072 seconds. Actual duty: 50%. */ .period_counts = + (uint32_t)0x10000, .duty_cycle_counts = 0x8000, .source_div = + (timer_source_div_t)0, .channel = 1, .p_callback = callback_agt, +/** If NULL then do not add & */ + #if defined(NULL) + .p_context = NULL, + #else + .p_context = &NULL, + #endif + .p_extend = &g_timer1_extend, .cycle_end_ipl = (5), + #if defined(VECTOR_NUMBER_AGT1_INT) + .cycle_end_irq = VECTOR_NUMBER_AGT1_INT, + #else + .cycle_end_irq = FSP_INVALID_VECTOR, + #endif +}; +/* Instance structure to use this module. */ +const timer_instance_t g_timer1 = { .p_ctrl = &g_timer1_ctrl, .p_cfg = + &g_timer1_cfg, .p_api = &g_timer_on_agt }; +agt_instance_ctrl_t g_timer0_ctrl; +const agt_extended_cfg_t g_timer0_extend = +{ .count_source = AGT_CLOCK_PCLKB, .agto = AGT_PIN_CFG_DISABLED, + .agtoab_settings_b.agtoa = AGT_PIN_CFG_DISABLED, + .agtoab_settings_b.agtob = AGT_PIN_CFG_DISABLED, + .measurement_mode = AGT_MEASURE_DISABLED, .agtio_filter = + AGT_AGTIO_FILTER_NONE, .enable_pin = + AGT_ENABLE_PIN_NOT_USED, .trigger_edge = + AGT_TRIGGER_EDGE_RISING, }; +const timer_cfg_t g_timer0_cfg = { .mode = TIMER_MODE_PERIODIC, +/* Actual period: 0.00131072 seconds. Actual duty: 50%. */ .period_counts = + (uint32_t)0x10000, .duty_cycle_counts = 0x8000, .source_div = + (timer_source_div_t)0, .channel = 0, .p_callback = callback_agt, +/** If NULL then do not add & */ + #if defined(NULL) + .p_context = NULL, + #else + .p_context = &NULL, + #endif + .p_extend = &g_timer0_extend, .cycle_end_ipl = (5), + #if defined(VECTOR_NUMBER_AGT0_INT) + .cycle_end_irq = VECTOR_NUMBER_AGT0_INT, + #else + .cycle_end_irq = FSP_INVALID_VECTOR, + #endif +}; +/* Instance structure to use this module. */ +const timer_instance_t g_timer0 = { .p_ctrl = &g_timer0_ctrl, .p_cfg = + &g_timer0_cfg, .p_api = &g_timer_on_agt }; +flash_hp_instance_ctrl_t g_flash0_ctrl; +const flash_cfg_t g_flash0_cfg = { .data_flash_bgo = false, .p_callback = NULL, + .p_context = NULL, + #if defined(VECTOR_NUMBER_FCU_FRDYI) + .irq = VECTOR_NUMBER_FCU_FRDYI, + #else + .irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_FCU_FIFERR) + .err_irq = VECTOR_NUMBER_FCU_FIFERR, + #else + .err_irq = FSP_INVALID_VECTOR, + #endif + .err_ipl = (BSP_IRQ_DISABLED), .ipl = (BSP_IRQ_DISABLED), }; +/* Instance structure to use this module. */ +const flash_instance_t g_flash0 = { .p_ctrl = &g_flash0_ctrl, .p_cfg = + &g_flash0_cfg, .p_api = &g_flash_on_flash_hp }; +rtc_instance_ctrl_t g_rtc0_ctrl; +const rtc_error_adjustment_cfg_t g_rtc0_err_cfg = { .adjustment_mode = + RTC_ERROR_ADJUSTMENT_MODE_AUTOMATIC, .adjustment_period = + RTC_ERROR_ADJUSTMENT_PERIOD_10_SECOND, .adjustment_type = + RTC_ERROR_ADJUSTMENT_NONE, .adjustment_value = 0, }; +const rtc_cfg_t g_rtc0_cfg = { .clock_source = RTC_CLOCK_SOURCE_LOCO, + .freq_compare_value_loco = 255, .p_err_cfg = &g_rtc0_err_cfg, + .p_callback = NULL, .p_context = NULL, .alarm_ipl = (14), + .periodic_ipl = (14), .carry_ipl = (14), + #if defined(VECTOR_NUMBER_RTC_ALARM) + .alarm_irq = VECTOR_NUMBER_RTC_ALARM, + #else + .alarm_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_RTC_PERIOD) + .periodic_irq = VECTOR_NUMBER_RTC_PERIOD, + #else + .periodic_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_RTC_CARRY) + .carry_irq = VECTOR_NUMBER_RTC_CARRY, + #else + .carry_irq = FSP_INVALID_VECTOR, + #endif +}; +/* Instance structure to use this module. */ +const rtc_instance_t g_rtc0 = { .p_ctrl = &g_rtc0_ctrl, .p_cfg = &g_rtc0_cfg, + .p_api = &g_rtc_on_rtc }; +sci_uart_instance_ctrl_t g_uart9_ctrl; + +baud_setting_t g_uart9_baud_setting = { +/* Baud rate calculated with 0.469% error. */ .semr_baudrate_bits_b.abcse = 0, + .semr_baudrate_bits_b.abcs = 0, .semr_baudrate_bits_b.bgdm = 1, + .cks = 0, .brr = 53, .mddr = (uint8_t)256, .semr_baudrate_bits_b.brme = + false +}; + +/** UART extended configuration for UARTonSCI HAL driver */ +const sci_uart_extended_cfg_t g_uart9_cfg_extend = { + .clock = SCI_UART_CLOCK_INT, .rx_edge_start = + SCI_UART_START_BIT_FALLING_EDGE, .noise_cancel = + SCI_UART_NOISE_CANCELLATION_DISABLE, .rx_fifo_trigger = + SCI_UART_RX_FIFO_TRIGGER_MAX, .p_baud_setting = + &g_uart9_baud_setting, + .flow_control = SCI_UART_FLOW_CONTROL_RTS, + #if 0xFF != 0xFF + .flow_control_pin = BSP_IO_PORT_FF_PIN_0xFF, + #else + .flow_control_pin = (bsp_io_port_pin_t)UINT16_MAX, + #endif + .rs485_setting = { .enable = SCI_UART_RS485_DISABLE, .polarity = + SCI_UART_RS485_DE_POLARITY_HIGH, + #if 0xFF != 0xFF + .de_control_pin = BSP_IO_PORT_FF_PIN_0xFF, + #else + .de_control_pin = (bsp_io_port_pin_t)UINT16_MAX, + #endif + }, +}; + +/** UART interface configuration */ +const uart_cfg_t g_uart9_cfg = { .channel = 9, .data_bits = UART_DATA_BITS_8, + .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = + user_uart_callback, .p_context = NULL, .p_extend = + &g_uart9_cfg_extend, +#define RA_NOT_DEFINED (1) + #if (RA_NOT_DEFINED == RA_NOT_DEFINED) + .p_transfer_tx = NULL, + #else + .p_transfer_tx = &RA_NOT_DEFINED, + #endif + #if (RA_NOT_DEFINED == RA_NOT_DEFINED) + .p_transfer_rx = NULL, + #else + .p_transfer_rx = &RA_NOT_DEFINED, + #endif +#undef RA_NOT_DEFINED + .rxi_ipl = (12), .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), + #if defined(VECTOR_NUMBER_SCI9_RXI) + .rxi_irq = VECTOR_NUMBER_SCI9_RXI, + #else + .rxi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI9_TXI) + .txi_irq = VECTOR_NUMBER_SCI9_TXI, + #else + .txi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI9_TEI) + .tei_irq = VECTOR_NUMBER_SCI9_TEI, + #else + .tei_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI9_ERI) + .eri_irq = VECTOR_NUMBER_SCI9_ERI, + #else + .eri_irq = FSP_INVALID_VECTOR, + #endif +}; + +/* Instance structure to use this module. */ +const uart_instance_t g_uart9 = { .p_ctrl = &g_uart9_ctrl, + .p_cfg = &g_uart9_cfg, .p_api = &g_uart_on_sci }; +sci_uart_instance_ctrl_t g_uart7_ctrl; + +baud_setting_t g_uart7_baud_setting = { +/* Baud rate calculated with 0.469% error. */ .semr_baudrate_bits_b.abcse = 0, + .semr_baudrate_bits_b.abcs = 0, .semr_baudrate_bits_b.bgdm = 1, + .cks = 0, .brr = 53, .mddr = (uint8_t)256, .semr_baudrate_bits_b.brme = + false +}; + +/** UART extended configuration for UARTonSCI HAL driver */ +const sci_uart_extended_cfg_t g_uart7_cfg_extend = { + .clock = SCI_UART_CLOCK_INT, .rx_edge_start = + SCI_UART_START_BIT_FALLING_EDGE, .noise_cancel = + SCI_UART_NOISE_CANCELLATION_DISABLE, .rx_fifo_trigger = + SCI_UART_RX_FIFO_TRIGGER_MAX, .p_baud_setting = + &g_uart7_baud_setting, + .flow_control = SCI_UART_FLOW_CONTROL_RTS, + #if 0xFF != 0xFF + .flow_control_pin = BSP_IO_PORT_FF_PIN_0xFF, + #else + .flow_control_pin = (bsp_io_port_pin_t)UINT16_MAX, + #endif + .rs485_setting = { .enable = SCI_UART_RS485_DISABLE, .polarity = + SCI_UART_RS485_DE_POLARITY_HIGH, + #if 0xFF != 0xFF + .de_control_pin = BSP_IO_PORT_FF_PIN_0xFF, + #else + .de_control_pin = (bsp_io_port_pin_t)UINT16_MAX, + #endif + }, +}; + +/** UART interface configuration */ +const uart_cfg_t g_uart7_cfg = { .channel = 7, .data_bits = UART_DATA_BITS_8, + .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = + user_uart_callback, .p_context = NULL, .p_extend = + &g_uart7_cfg_extend, +#define RA_NOT_DEFINED (1) + #if (RA_NOT_DEFINED == RA_NOT_DEFINED) + .p_transfer_tx = NULL, + #else + .p_transfer_tx = &RA_NOT_DEFINED, + #endif + #if (RA_NOT_DEFINED == RA_NOT_DEFINED) + .p_transfer_rx = NULL, + #else + .p_transfer_rx = &RA_NOT_DEFINED, + #endif +#undef RA_NOT_DEFINED + .rxi_ipl = (12), .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), + #if defined(VECTOR_NUMBER_SCI7_RXI) + .rxi_irq = VECTOR_NUMBER_SCI7_RXI, + #else + .rxi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI7_TXI) + .txi_irq = VECTOR_NUMBER_SCI7_TXI, + #else + .txi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI7_TEI) + .tei_irq = VECTOR_NUMBER_SCI7_TEI, + #else + .tei_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI7_ERI) + .eri_irq = VECTOR_NUMBER_SCI7_ERI, + #else + .eri_irq = FSP_INVALID_VECTOR, + #endif +}; + +/* Instance structure to use this module. */ +const uart_instance_t g_uart7 = { .p_ctrl = &g_uart7_ctrl, + .p_cfg = &g_uart7_cfg, .p_api = &g_uart_on_sci }; +sci_uart_instance_ctrl_t g_uart6_ctrl; + +baud_setting_t g_uart6_baud_setting = { +/* Baud rate calculated with 0.469% error. */ .semr_baudrate_bits_b.abcse = 0, + .semr_baudrate_bits_b.abcs = 0, .semr_baudrate_bits_b.bgdm = 1, + .cks = 0, .brr = 53, .mddr = (uint8_t)256, .semr_baudrate_bits_b.brme = + false +}; + +/** UART extended configuration for UARTonSCI HAL driver */ +const sci_uart_extended_cfg_t g_uart6_cfg_extend = { + .clock = SCI_UART_CLOCK_INT, .rx_edge_start = + SCI_UART_START_BIT_FALLING_EDGE, .noise_cancel = + SCI_UART_NOISE_CANCELLATION_DISABLE, .rx_fifo_trigger = + SCI_UART_RX_FIFO_TRIGGER_MAX, .p_baud_setting = + &g_uart6_baud_setting, + .flow_control = SCI_UART_FLOW_CONTROL_RTS, + #if 0xFF != 0xFF + .flow_control_pin = BSP_IO_PORT_FF_PIN_0xFF, + #else + .flow_control_pin = (bsp_io_port_pin_t)UINT16_MAX, + #endif + .rs485_setting = { .enable = SCI_UART_RS485_DISABLE, .polarity = + SCI_UART_RS485_DE_POLARITY_HIGH, + #if 0xFF != 0xFF + .de_control_pin = BSP_IO_PORT_FF_PIN_0xFF, + #else + .de_control_pin = (bsp_io_port_pin_t)UINT16_MAX, + #endif + }, +}; + +/** UART interface configuration */ +const uart_cfg_t g_uart6_cfg = { .channel = 6, .data_bits = UART_DATA_BITS_8, + .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = + user_uart_callback, .p_context = NULL, .p_extend = + &g_uart6_cfg_extend, +#define RA_NOT_DEFINED (1) + #if (RA_NOT_DEFINED == RA_NOT_DEFINED) + .p_transfer_tx = NULL, + #else + .p_transfer_tx = &RA_NOT_DEFINED, + #endif + #if (RA_NOT_DEFINED == RA_NOT_DEFINED) + .p_transfer_rx = NULL, + #else + .p_transfer_rx = &RA_NOT_DEFINED, + #endif +#undef RA_NOT_DEFINED + .rxi_ipl = (12), .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), + #if defined(VECTOR_NUMBER_SCI6_RXI) + .rxi_irq = VECTOR_NUMBER_SCI6_RXI, + #else + .rxi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI6_TXI) + .txi_irq = VECTOR_NUMBER_SCI6_TXI, + #else + .txi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI6_TEI) + .tei_irq = VECTOR_NUMBER_SCI6_TEI, + #else + .tei_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI6_ERI) + .eri_irq = VECTOR_NUMBER_SCI6_ERI, + #else + .eri_irq = FSP_INVALID_VECTOR, + #endif +}; + +/* Instance structure to use this module. */ +const uart_instance_t g_uart6 = { .p_ctrl = &g_uart6_ctrl, + .p_cfg = &g_uart6_cfg, .p_api = &g_uart_on_sci }; +void g_hal_init(void) { + g_common_init(); +} diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_gen/hal_data.h b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/hal_data.h new file mode 100644 index 0000000000000..9edcfdf4a0ebd --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/hal_data.h @@ -0,0 +1,205 @@ +/* generated HAL header file - do not edit */ +#ifndef HAL_DATA_H_ +#define HAL_DATA_H_ +#include +#include "bsp_api.h" +#include "common_data.h" +#include "r_dtc.h" +#include "r_transfer_api.h" +#include "r_sdhi.h" +#include "r_sdmmc_api.h" +#include "r_qspi.h" +#include "r_spi_flash_api.h" +#include "r_iic_master.h" +#include "r_i2c_master_api.h" +#include "r_adc.h" +#include "r_adc_api.h" +#include "r_lpm.h" +#include "r_lpm_api.h" +#include "r_spi.h" +#include "r_agt.h" +#include "r_timer_api.h" +#include "r_flash_hp.h" +#include "r_flash_api.h" +#include "r_rtc.h" +#include "r_rtc_api.h" +#include "r_sci_uart.h" +#include "r_uart_api.h" +FSP_HEADER +/* Transfer on DTC Instance. */ +extern const transfer_instance_t g_transfer2; + +/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ +extern dtc_instance_ctrl_t g_transfer2_ctrl; +extern const transfer_cfg_t g_transfer2_cfg; +/** SDMMC on SDMMC Instance. */ +extern const sdmmc_instance_t g_sdmmc0; + +/** Access the SDMMC instance using these structures when calling API functions directly (::p_api is not used). */ +extern sdhi_instance_ctrl_t g_sdmmc0_ctrl; +extern sdmmc_cfg_t g_sdmmc0_cfg; + +#ifndef sdhi_ISR +void sdhi_ISR(sdmmc_callback_args_t *p_args); +#endif +extern const spi_flash_instance_t g_qspi0; +extern qspi_instance_ctrl_t g_qspi0_ctrl; +extern const spi_flash_cfg_t g_qspi0_cfg; +/* I2C Master on IIC Instance. */ +extern const i2c_master_instance_t g_i2c_master2; + +/** Access the I2C Master instance using these structures when calling API functions directly (::p_api is not used). */ +extern iic_master_instance_ctrl_t g_i2c_master2_ctrl; +extern const i2c_master_cfg_t g_i2c_master2_cfg; + +#ifndef callback_iic +void callback_iic(i2c_master_callback_args_t *p_args); +#endif +/** ADC on ADC Instance. */ +extern const adc_instance_t g_adc1; + +/** Access the ADC instance using these structures when calling API functions directly (::p_api is not used). */ +extern adc_instance_ctrl_t g_adc1_ctrl; +extern const adc_cfg_t g_adc1_cfg; +extern const adc_channel_cfg_t g_adc1_channel_cfg; + +#ifndef NULL +void NULL(adc_callback_args_t *p_args); +#endif + +#ifndef NULL +#define ADC_DMAC_CHANNELS_PER_BLOCK_NULL 0 +#endif +/** ADC on ADC Instance. */ +extern const adc_instance_t g_adc0; + +/** Access the ADC instance using these structures when calling API functions directly (::p_api is not used). */ +extern adc_instance_ctrl_t g_adc0_ctrl; +extern const adc_cfg_t g_adc0_cfg; +extern const adc_channel_cfg_t g_adc0_channel_cfg; + +#ifndef NULL +void NULL(adc_callback_args_t *p_args); +#endif + +#ifndef NULL +#define ADC_DMAC_CHANNELS_PER_BLOCK_NULL 0 +#endif +/** lpm Instance */ +extern const lpm_instance_t g_lpm0; + +/** Access the LPM instance using these structures when calling API functions directly (::p_api is not used). */ +extern lpm_instance_ctrl_t g_lpm0_ctrl; +extern const lpm_cfg_t g_lpm0_cfg; +/* Transfer on DTC Instance. */ +extern const transfer_instance_t g_transfer1; + +/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ +extern dtc_instance_ctrl_t g_transfer1_ctrl; +extern const transfer_cfg_t g_transfer1_cfg; +/* Transfer on DTC Instance. */ +extern const transfer_instance_t g_transfer0; + +/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ +extern dtc_instance_ctrl_t g_transfer0_ctrl; +extern const transfer_cfg_t g_transfer0_cfg; +/** SPI on SPI Instance. */ +extern const spi_instance_t g_spi0; + +/** Access the SPI instance using these structures when calling API functions directly (::p_api is not used). */ +extern spi_instance_ctrl_t g_spi0_ctrl; +extern const spi_cfg_t g_spi0_cfg; + +/** Callback used by SPI Instance. */ +#ifndef spi_callback +void spi_callback(spi_callback_args_t *p_args); +#endif + +#define RA_NOT_DEFINED (1) +#if (RA_NOT_DEFINED == g_transfer0) + #define g_spi0_P_TRANSFER_TX (NULL) +#else +#define g_spi0_P_TRANSFER_TX (&g_transfer0) +#endif +#if (RA_NOT_DEFINED == g_transfer1) + #define g_spi0_P_TRANSFER_RX (NULL) +#else +#define g_spi0_P_TRANSFER_RX (&g_transfer1) +#endif +#undef RA_NOT_DEFINED +/** AGT Timer Instance */ +extern const timer_instance_t g_timer1; + +/** Access the AGT instance using these structures when calling API functions directly (::p_api is not used). */ +extern agt_instance_ctrl_t g_timer1_ctrl; +extern const timer_cfg_t g_timer1_cfg; + +#ifndef callback_agt +void callback_agt(timer_callback_args_t *p_args); +#endif +/** AGT Timer Instance */ +extern const timer_instance_t g_timer0; + +/** Access the AGT instance using these structures when calling API functions directly (::p_api is not used). */ +extern agt_instance_ctrl_t g_timer0_ctrl; +extern const timer_cfg_t g_timer0_cfg; + +#ifndef callback_agt +void callback_agt(timer_callback_args_t *p_args); +#endif +/* Flash on Flash HP Instance */ +extern const flash_instance_t g_flash0; + +/** Access the Flash HP instance using these structures when calling API functions directly (::p_api is not used). */ +extern flash_hp_instance_ctrl_t g_flash0_ctrl; +extern const flash_cfg_t g_flash0_cfg; + +#ifndef NULL +void NULL(flash_callback_args_t *p_args); +#endif +/* RTC Instance. */ +extern const rtc_instance_t g_rtc0; + +/** Access the RTC instance using these structures when calling API functions directly (::p_api is not used). */ +extern rtc_instance_ctrl_t g_rtc0_ctrl; +extern const rtc_cfg_t g_rtc0_cfg; + +#ifndef NULL +void NULL(rtc_callback_args_t *p_args); +#endif +/** UART on SCI Instance. */ +extern const uart_instance_t g_uart9; + +/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ +extern sci_uart_instance_ctrl_t g_uart9_ctrl; +extern const uart_cfg_t g_uart9_cfg; +extern const sci_uart_extended_cfg_t g_uart9_cfg_extend; + +#ifndef user_uart_callback +void user_uart_callback(uart_callback_args_t *p_args); +#endif +/** UART on SCI Instance. */ +extern const uart_instance_t g_uart7; + +/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ +extern sci_uart_instance_ctrl_t g_uart7_ctrl; +extern const uart_cfg_t g_uart7_cfg; +extern const sci_uart_extended_cfg_t g_uart7_cfg_extend; + +#ifndef user_uart_callback +void user_uart_callback(uart_callback_args_t *p_args); +#endif +/** UART on SCI Instance. */ +extern const uart_instance_t g_uart6; + +/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ +extern sci_uart_instance_ctrl_t g_uart6_ctrl; +extern const uart_cfg_t g_uart6_cfg; +extern const sci_uart_extended_cfg_t g_uart6_cfg_extend; + +#ifndef user_uart_callback +void user_uart_callback(uart_callback_args_t *p_args); +#endif +void g_hal_init(void); +FSP_FOOTER +#endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_gen/pin_data.c b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/pin_data.c new file mode 100644 index 0000000000000..54319a6aee6e7 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/pin_data.c @@ -0,0 +1,227 @@ +/* generated pin source file - do not edit */ +#include "bsp_api.h" +#include "r_ioport_api.h" + +const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = { { .pin = BSP_IO_PORT_00_PIN_00, + .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE) }, + { .pin = BSP_IO_PORT_00_PIN_01, .pin_cfg = + ((uint32_t)IOPORT_CFG_ANALOG_ENABLE) }, { .pin = + BSP_IO_PORT_00_PIN_02, .pin_cfg = + ((uint32_t)IOPORT_CFG_ANALOG_ENABLE) }, { .pin = + BSP_IO_PORT_00_PIN_03, .pin_cfg = + ((uint32_t)IOPORT_CFG_ANALOG_ENABLE) }, { .pin = + BSP_IO_PORT_00_PIN_06, .pin_cfg = + ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, { .pin = + BSP_IO_PORT_00_PIN_07, .pin_cfg = + ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, { .pin = + BSP_IO_PORT_00_PIN_08, .pin_cfg = + ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, { .pin = + BSP_IO_PORT_00_PIN_09, .pin_cfg = + ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, { + .pin = BSP_IO_PORT_00_PIN_10, .pin_cfg = + ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) + }, + { .pin = BSP_IO_PORT_00_PIN_14, .pin_cfg = + ((uint32_t)IOPORT_CFG_ANALOG_ENABLE) }, { .pin = + BSP_IO_PORT_00_PIN_15, .pin_cfg = + ((uint32_t)IOPORT_CFG_ANALOG_ENABLE) }, { .pin = + BSP_IO_PORT_01_PIN_00, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_01_PIN_01, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_01_PIN_02, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_01_PIN_03, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_01_PIN_04, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_01_PIN_05, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_01_PIN_06, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_01_PIN_07, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_01_PIN_08, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, { .pin = + BSP_IO_PORT_01_PIN_09, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, { .pin = + BSP_IO_PORT_01_PIN_10, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, { .pin = + BSP_IO_PORT_02_PIN_05, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SDHI_MMC) }, { .pin = + BSP_IO_PORT_02_PIN_06, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SDHI_MMC) }, { .pin = + BSP_IO_PORT_02_PIN_09, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SDHI_MMC) }, { .pin = + BSP_IO_PORT_02_PIN_10, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SDHI_MMC) }, { .pin = + BSP_IO_PORT_03_PIN_00, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, { .pin = + BSP_IO_PORT_03_PIN_05, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_QSPI) }, { .pin = + BSP_IO_PORT_03_PIN_06, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_QSPI) }, { .pin = + BSP_IO_PORT_03_PIN_07, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_QSPI) }, { .pin = + BSP_IO_PORT_03_PIN_08, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_QSPI) }, { .pin = + BSP_IO_PORT_03_PIN_09, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_QSPI) }, { .pin = + BSP_IO_PORT_03_PIN_10, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_QSPI) }, { .pin = + BSP_IO_PORT_04_PIN_01, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_ETHER_RMII) }, { .pin = + BSP_IO_PORT_04_PIN_02, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_ETHER_RMII) }, { .pin = + BSP_IO_PORT_04_PIN_05, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_ETHER_RMII) }, { .pin = + BSP_IO_PORT_04_PIN_06, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_ETHER_RMII) }, { .pin = + BSP_IO_PORT_04_PIN_07, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_USB_FS) }, { .pin = + BSP_IO_PORT_04_PIN_10, .pin_cfg = + ((uint32_t)IOPORT_CFG_DRIVE_MID + | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SDHI_MMC) }, { .pin = + BSP_IO_PORT_04_PIN_11, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SDHI_MMC) }, { .pin = + BSP_IO_PORT_04_PIN_12, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SDHI_MMC) }, { .pin = + BSP_IO_PORT_04_PIN_13, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SDHI_MMC) }, { .pin = + BSP_IO_PORT_04_PIN_14, .pin_cfg = + ((uint32_t)IOPORT_CFG_DRIVE_MID + | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_IIC) }, { .pin = + BSP_IO_PORT_04_PIN_15, .pin_cfg = + ((uint32_t)IOPORT_CFG_DRIVE_MID + | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_IIC) }, { .pin = + BSP_IO_PORT_05_PIN_05, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, { .pin = + BSP_IO_PORT_05_PIN_06, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, { .pin = + BSP_IO_PORT_05_PIN_11, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_CAN) }, { .pin = + BSP_IO_PORT_05_PIN_12, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_CAN) }, { .pin = + BSP_IO_PORT_06_PIN_00, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_06_PIN_01, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_06_PIN_02, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_06_PIN_10, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_OSPI) }, { .pin = + BSP_IO_PORT_06_PIN_13, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, { .pin = + BSP_IO_PORT_06_PIN_14, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, { .pin = + BSP_IO_PORT_07_PIN_00, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_ETHER_RMII) }, { .pin = + BSP_IO_PORT_07_PIN_01, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_ETHER_RMII) }, { .pin = + BSP_IO_PORT_07_PIN_02, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_ETHER_RMII) }, { .pin = + BSP_IO_PORT_07_PIN_03, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_ETHER_RMII) }, { .pin = + BSP_IO_PORT_07_PIN_04, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_ETHER_RMII) }, { .pin = + BSP_IO_PORT_07_PIN_05, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_ETHER_RMII) }, { .pin = + BSP_IO_PORT_07_PIN_06, .pin_cfg = + ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, { + .pin = BSP_IO_PORT_11_PIN_01, .pin_cfg = + ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_USB_HS) + }, }; + +const ioport_cfg_t g_bsp_pin_cfg = { .number_of_pins = + sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), .p_pin_cfg_data = + &g_bsp_pin_cfg_data[0], }; + +#if BSP_TZ_SECURE_BUILD + +void R_BSP_PinCfgSecurityInit(void); + +/* Initialize SAR registers for secure pins. */ +void R_BSP_PinCfgSecurityInit(void) { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + uint32_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #else + uint16_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #endif + memset(pmsar, 0xFF, BSP_FEATURE_BSP_NUM_PMSAR * sizeof(R_PMISC->PMSAR[0])); + + + for (uint32_t i = 0; i < g_bsp_pin_cfg.number_of_pins; i++) + { + uint32_t port_pin = g_bsp_pin_cfg.p_pin_cfg_data[i].pin; + uint32_t port = port_pin >> 8U; + uint32_t pin = port_pin & 0xFFU; + pmsar[port] &= (uint16_t) ~(1U << pin); + } + + for (uint32_t i = 0; i < BSP_FEATURE_BSP_NUM_PMSAR; i++) + { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + R_PMISC->PMSAR[i].PMSAR = (uint16_t)pmsar[i]; + #else + R_PMISC->PMSAR[i].PMSAR = pmsar[i]; + #endif + } + +} +#endif diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_gen/vector_data.c b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/vector_data.c new file mode 100644 index 0000000000000..3065f3b0138b5 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/vector_data.c @@ -0,0 +1,73 @@ +/* generated vector source file - do not edit */ +#include "bsp_api.h" +/* Do not build these data structures if no interrupts are currently allocated because IAR will have build errors. */ +#if VECTOR_DATA_IRQ_COUNT > 0 +BSP_DONT_REMOVE const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES] BSP_PLACE_IN_SECTION(BSP_SECTION_APPLICATION_VECTORS) = +{ + [0] = sci_uart_rxi_isr, /* SCI6 RXI (Received data full) */ + [1] = sci_uart_txi_isr, /* SCI6 TXI (Transmit data empty) */ + [2] = sci_uart_tei_isr, /* SCI6 TEI (Transmit end) */ + [3] = sci_uart_eri_isr, /* SCI6 ERI (Receive error) */ + [4] = sci_uart_rxi_isr, /* SCI7 RXI (Received data full) */ + [5] = sci_uart_txi_isr, /* SCI7 TXI (Transmit data empty) */ + [6] = sci_uart_tei_isr, /* SCI7 TEI (Transmit end) */ + [7] = sci_uart_eri_isr, /* SCI7 ERI (Receive error) */ + [8] = sci_uart_rxi_isr, /* SCI9 RXI (Received data full) */ + [9] = sci_uart_txi_isr, /* SCI9 TXI (Transmit data empty) */ + [10] = sci_uart_tei_isr, /* SCI9 TEI (Transmit end) */ + [11] = sci_uart_eri_isr, /* SCI9 ERI (Receive error) */ + [12] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ + [13] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ + [14] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ + [15] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ + [16] = agt_int_isr, /* AGT1 INT (AGT interrupt) */ + [17] = r_icu_isr, /* ICU IRQ7 (External pin interrupt 7) */ + [18] = r_icu_isr, /* ICU IRQ13 (External pin interrupt 13) */ + [19] = r_icu_isr, /* ICU IRQ14 (External pin interrupt 14) */ + [20] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ + [21] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ + [22] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ + [23] = spi_eri_isr, /* SPI0 ERI (Error) */ + [24] = iic_master_rxi_isr, /* IIC2 RXI (Receive data full) */ + [25] = iic_master_txi_isr, /* IIC2 TXI (Transmit data empty) */ + [26] = iic_master_tei_isr, /* IIC2 TEI (Transmit end) */ + [27] = iic_master_eri_isr, /* IIC2 ERI (Transfer error) */ + [28] = sdhimmc_accs_isr, /* SDHIMMC0 ACCS (Card access) */ + [29] = sdhimmc_card_isr, /* SDHIMMC0 CARD (Card detect) */ + [30] = sdhimmc_dma_req_isr, /* SDHIMMC0 DMA REQ (DMA transfer request) */ +}; +const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENTRIES] = +{ + [0] = BSP_PRV_IELS_ENUM(EVENT_SCI6_RXI), /* SCI6 RXI (Received data full) */ + [1] = BSP_PRV_IELS_ENUM(EVENT_SCI6_TXI), /* SCI6 TXI (Transmit data empty) */ + [2] = BSP_PRV_IELS_ENUM(EVENT_SCI6_TEI), /* SCI6 TEI (Transmit end) */ + [3] = BSP_PRV_IELS_ENUM(EVENT_SCI6_ERI), /* SCI6 ERI (Receive error) */ + [4] = BSP_PRV_IELS_ENUM(EVENT_SCI7_RXI), /* SCI7 RXI (Received data full) */ + [5] = BSP_PRV_IELS_ENUM(EVENT_SCI7_TXI), /* SCI7 TXI (Transmit data empty) */ + [6] = BSP_PRV_IELS_ENUM(EVENT_SCI7_TEI), /* SCI7 TEI (Transmit end) */ + [7] = BSP_PRV_IELS_ENUM(EVENT_SCI7_ERI), /* SCI7 ERI (Receive error) */ + [8] = BSP_PRV_IELS_ENUM(EVENT_SCI9_RXI), /* SCI9 RXI (Received data full) */ + [9] = BSP_PRV_IELS_ENUM(EVENT_SCI9_TXI), /* SCI9 TXI (Transmit data empty) */ + [10] = BSP_PRV_IELS_ENUM(EVENT_SCI9_TEI), /* SCI9 TEI (Transmit end) */ + [11] = BSP_PRV_IELS_ENUM(EVENT_SCI9_ERI), /* SCI9 ERI (Receive error) */ + [12] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ + [13] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ + [14] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ + [15] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ + [16] = BSP_PRV_IELS_ENUM(EVENT_AGT1_INT), /* AGT1 INT (AGT interrupt) */ + [17] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ7), /* ICU IRQ7 (External pin interrupt 7) */ + [18] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ13), /* ICU IRQ13 (External pin interrupt 13) */ + [19] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ14), /* ICU IRQ14 (External pin interrupt 14) */ + [20] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ + [21] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ + [22] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ + [23] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ + [24] = BSP_PRV_IELS_ENUM(EVENT_IIC2_RXI), /* IIC2 RXI (Receive data full) */ + [25] = BSP_PRV_IELS_ENUM(EVENT_IIC2_TXI), /* IIC2 TXI (Transmit data empty) */ + [26] = BSP_PRV_IELS_ENUM(EVENT_IIC2_TEI), /* IIC2 TEI (Transmit end) */ + [27] = BSP_PRV_IELS_ENUM(EVENT_IIC2_ERI), /* IIC2 ERI (Transfer error) */ + [28] = BSP_PRV_IELS_ENUM(EVENT_SDHIMMC0_ACCS), /* SDHIMMC0 ACCS (Card access) */ + [29] = BSP_PRV_IELS_ENUM(EVENT_SDHIMMC0_CARD), /* SDHIMMC0 CARD (Card detect) */ + [30] = BSP_PRV_IELS_ENUM(EVENT_SDHIMMC0_DMA_REQ), /* SDHIMMC0 DMA REQ (DMA transfer request) */ +}; +#endif diff --git a/ports/renesas-ra/boards/VK_RA6M5/ra_gen/vector_data.h b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/vector_data.h new file mode 100644 index 0000000000000..95f2226330912 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/ra_gen/vector_data.h @@ -0,0 +1,98 @@ +/* generated vector header file - do not edit */ +#ifndef VECTOR_DATA_H +#define VECTOR_DATA_H +#ifdef __cplusplus +extern "C" { +#endif +/* Number of interrupts allocated */ +#ifndef VECTOR_DATA_IRQ_COUNT +#define VECTOR_DATA_IRQ_COUNT (31) +#endif +/* ISR prototypes */ +void sci_uart_rxi_isr(void); +void sci_uart_txi_isr(void); +void sci_uart_tei_isr(void); +void sci_uart_eri_isr(void); +void rtc_alarm_periodic_isr(void); +void rtc_carry_isr(void); +void agt_int_isr(void); +void r_icu_isr(void); +void spi_rxi_isr(void); +void spi_txi_isr(void); +void spi_tei_isr(void); +void spi_eri_isr(void); +void iic_master_rxi_isr(void); +void iic_master_txi_isr(void); +void iic_master_tei_isr(void); +void iic_master_eri_isr(void); +void sdhimmc_accs_isr(void); +void sdhimmc_card_isr(void); +void sdhimmc_dma_req_isr(void); + +/* Vector table allocations */ +#define VECTOR_NUMBER_SCI6_RXI ((IRQn_Type)0) /* SCI6 RXI (Received data full) */ +#define SCI6_RXI_IRQn ((IRQn_Type)0) /* SCI6 RXI (Received data full) */ +#define VECTOR_NUMBER_SCI6_TXI ((IRQn_Type)1) /* SCI6 TXI (Transmit data empty) */ +#define SCI6_TXI_IRQn ((IRQn_Type)1) /* SCI6 TXI (Transmit data empty) */ +#define VECTOR_NUMBER_SCI6_TEI ((IRQn_Type)2) /* SCI6 TEI (Transmit end) */ +#define SCI6_TEI_IRQn ((IRQn_Type)2) /* SCI6 TEI (Transmit end) */ +#define VECTOR_NUMBER_SCI6_ERI ((IRQn_Type)3) /* SCI6 ERI (Receive error) */ +#define SCI6_ERI_IRQn ((IRQn_Type)3) /* SCI6 ERI (Receive error) */ +#define VECTOR_NUMBER_SCI7_RXI ((IRQn_Type)4) /* SCI7 RXI (Received data full) */ +#define SCI7_RXI_IRQn ((IRQn_Type)4) /* SCI7 RXI (Received data full) */ +#define VECTOR_NUMBER_SCI7_TXI ((IRQn_Type)5) /* SCI7 TXI (Transmit data empty) */ +#define SCI7_TXI_IRQn ((IRQn_Type)5) /* SCI7 TXI (Transmit data empty) */ +#define VECTOR_NUMBER_SCI7_TEI ((IRQn_Type)6) /* SCI7 TEI (Transmit end) */ +#define SCI7_TEI_IRQn ((IRQn_Type)6) /* SCI7 TEI (Transmit end) */ +#define VECTOR_NUMBER_SCI7_ERI ((IRQn_Type)7) /* SCI7 ERI (Receive error) */ +#define SCI7_ERI_IRQn ((IRQn_Type)7) /* SCI7 ERI (Receive error) */ +#define VECTOR_NUMBER_SCI9_RXI ((IRQn_Type)8) /* SCI9 RXI (Received data full) */ +#define SCI9_RXI_IRQn ((IRQn_Type)8) /* SCI9 RXI (Received data full) */ +#define VECTOR_NUMBER_SCI9_TXI ((IRQn_Type)9) /* SCI9 TXI (Transmit data empty) */ +#define SCI9_TXI_IRQn ((IRQn_Type)9) /* SCI9 TXI (Transmit data empty) */ +#define VECTOR_NUMBER_SCI9_TEI ((IRQn_Type)10) /* SCI9 TEI (Transmit end) */ +#define SCI9_TEI_IRQn ((IRQn_Type)10) /* SCI9 TEI (Transmit end) */ +#define VECTOR_NUMBER_SCI9_ERI ((IRQn_Type)11) /* SCI9 ERI (Receive error) */ +#define SCI9_ERI_IRQn ((IRQn_Type)11) /* SCI9 ERI (Receive error) */ +#define VECTOR_NUMBER_RTC_ALARM ((IRQn_Type)12) /* RTC ALARM (Alarm interrupt) */ +#define RTC_ALARM_IRQn ((IRQn_Type)12) /* RTC ALARM (Alarm interrupt) */ +#define VECTOR_NUMBER_RTC_PERIOD ((IRQn_Type)13) /* RTC PERIOD (Periodic interrupt) */ +#define RTC_PERIOD_IRQn ((IRQn_Type)13) /* RTC PERIOD (Periodic interrupt) */ +#define VECTOR_NUMBER_RTC_CARRY ((IRQn_Type)14) /* RTC CARRY (Carry interrupt) */ +#define RTC_CARRY_IRQn ((IRQn_Type)14) /* RTC CARRY (Carry interrupt) */ +#define VECTOR_NUMBER_AGT0_INT ((IRQn_Type)15) /* AGT0 INT (AGT interrupt) */ +#define AGT0_INT_IRQn ((IRQn_Type)15) /* AGT0 INT (AGT interrupt) */ +#define VECTOR_NUMBER_AGT1_INT ((IRQn_Type)16) /* AGT1 INT (AGT interrupt) */ +#define AGT1_INT_IRQn ((IRQn_Type)16) /* AGT1 INT (AGT interrupt) */ +#define VECTOR_NUMBER_ICU_IRQ7 ((IRQn_Type)17) /* ICU IRQ7 (External pin interrupt 7) */ +#define ICU_IRQ7_IRQn ((IRQn_Type)17) /* ICU IRQ7 (External pin interrupt 7) */ +#define VECTOR_NUMBER_ICU_IRQ13 ((IRQn_Type)18) /* ICU IRQ13 (External pin interrupt 13) */ +#define ICU_IRQ13_IRQn ((IRQn_Type)18) /* ICU IRQ13 (External pin interrupt 13) */ +#define VECTOR_NUMBER_ICU_IRQ14 ((IRQn_Type)19) /* ICU IRQ14 (External pin interrupt 14) */ +#define ICU_IRQ14_IRQn ((IRQn_Type)19) /* ICU IRQ14 (External pin interrupt 14) */ +#define VECTOR_NUMBER_SPI0_RXI ((IRQn_Type)20) /* SPI0 RXI (Receive buffer full) */ +#define SPI0_RXI_IRQn ((IRQn_Type)20) /* SPI0 RXI (Receive buffer full) */ +#define VECTOR_NUMBER_SPI0_TXI ((IRQn_Type)21) /* SPI0 TXI (Transmit buffer empty) */ +#define SPI0_TXI_IRQn ((IRQn_Type)21) /* SPI0 TXI (Transmit buffer empty) */ +#define VECTOR_NUMBER_SPI0_TEI ((IRQn_Type)22) /* SPI0 TEI (Transmission complete event) */ +#define SPI0_TEI_IRQn ((IRQn_Type)22) /* SPI0 TEI (Transmission complete event) */ +#define VECTOR_NUMBER_SPI0_ERI ((IRQn_Type)23) /* SPI0 ERI (Error) */ +#define SPI0_ERI_IRQn ((IRQn_Type)23) /* SPI0 ERI (Error) */ +#define VECTOR_NUMBER_IIC2_RXI ((IRQn_Type)24) /* IIC2 RXI (Receive data full) */ +#define IIC2_RXI_IRQn ((IRQn_Type)24) /* IIC2 RXI (Receive data full) */ +#define VECTOR_NUMBER_IIC2_TXI ((IRQn_Type)25) /* IIC2 TXI (Transmit data empty) */ +#define IIC2_TXI_IRQn ((IRQn_Type)25) /* IIC2 TXI (Transmit data empty) */ +#define VECTOR_NUMBER_IIC2_TEI ((IRQn_Type)26) /* IIC2 TEI (Transmit end) */ +#define IIC2_TEI_IRQn ((IRQn_Type)26) /* IIC2 TEI (Transmit end) */ +#define VECTOR_NUMBER_IIC2_ERI ((IRQn_Type)27) /* IIC2 ERI (Transfer error) */ +#define IIC2_ERI_IRQn ((IRQn_Type)27) /* IIC2 ERI (Transfer error) */ +#define VECTOR_NUMBER_SDHIMMC0_ACCS ((IRQn_Type)28) /* SDHIMMC0 ACCS (Card access) */ +#define SDHIMMC0_ACCS_IRQn ((IRQn_Type)28) /* SDHIMMC0 ACCS (Card access) */ +#define VECTOR_NUMBER_SDHIMMC0_CARD ((IRQn_Type)29) /* SDHIMMC0 CARD (Card detect) */ +#define SDHIMMC0_CARD_IRQn ((IRQn_Type)29) /* SDHIMMC0 CARD (Card detect) */ +#define VECTOR_NUMBER_SDHIMMC0_DMA_REQ ((IRQn_Type)30) /* SDHIMMC0 DMA REQ (DMA transfer request) */ +#define SDHIMMC0_DMA_REQ_IRQn ((IRQn_Type)30) /* SDHIMMC0 DMA REQ (DMA transfer request) */ +#ifdef __cplusplus +} +#endif +#endif /* VECTOR_DATA_H */ diff --git a/ports/renesas-ra/boards/VK_RA6M5/vk_ra6m5.ld b/ports/renesas-ra/boards/VK_RA6M5/vk_ra6m5.ld new file mode 100644 index 0000000000000..8363d2e743f24 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/vk_ra6m5.ld @@ -0,0 +1,308 @@ +/* + Linker File for RA6M5 MCU +*/ + +/* Linker script to configure memory regions. */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00100000 /* 1MB/2MB */ + FLASH_FS (r) : ORIGIN = 0x00100000, LENGTH = 0x00100000 /* 1MB/2MB */ + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00080000 /* 512KB */ + OSPI_RAM (rwx) : ORIGIN = 0x68000000, LENGTH = 0x00800000 /* 8MB/8MB */ + DATA_FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x00002000 /* 8KB */ + QSPI_FLASH (rx) : ORIGIN = 0x60000000, LENGTH = 0x01000000 /* 16MB/64MB */ + OSPI_FLASH (rx) : ORIGIN = 0x70000000, LENGTH = 0x01000000 /* 16MB/256MB */ + ID_CODE (rx) : ORIGIN = 0x00000000, LENGTH = 0x00000000 /* N/A */ +} + +/* Library configurations */ +/*GROUP(libgcc.a libc.a libm.a libnosys.a) */ + +/* Linker script to place sections and symbol values. Should be used together + * with other linker script that defines memory regions FLASH and RAM. + * It references following symbols, which must be defined in code: + * Reset_Handler : Entry of reset handler + * + * It defines following symbols, which code can use without definition: + * __exidx_start + * __exidx_end + * __copy_table_start__ + * __copy_table_end__ + * __zero_table_start__ + * __zero_table_end__ + * __etext + * __data_start__ + * __preinit_array_start + * __preinit_array_end + * __init_array_start + * __init_array_end + * __fini_array_start + * __fini_array_end + * __data_end__ + * __bss_start__ + * __bss_end__ + * __end__ + * end + * __HeapLimit + * __StackLimit + * __StackTop + * __stack + * __Vectors_End + * __Vectors_Size + */ +ENTRY(Reset_Handler) + +SECTIONS +{ + .text : + { + _stext = .; + __ROM_Start = .; + + /* Even though the vector table is not 256 entries (1KB) long, we still allocate that much + * space because ROM registers are at address 0x400 and there is very little space + * in between. */ + KEEP(*(.fixed_vectors*)) + KEEP(*(.application_vectors*)) + __Vectors_End = .; + __end__ = .; + + /* ROM Registers start at address 0x00000400 */ + . = __ROM_Start + 0x400; + KEEP(*(.rom_registers*)) + + /* Reserving 0x100 bytes of space for ROM registers. */ + . = __ROM_Start + 0x500; + + *(.text*) + + KEEP(*(.version)) + KEEP(*(.init)) + KEEP(*(.fini)) + + /* .ctors */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + + /* .dtors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.rodata*) + __usb_dev_descriptor_start_fs = .; + KEEP(*(.usb_device_desc_fs*)) + __usb_cfg_descriptor_start_fs = .; + KEEP(*(.usb_config_desc_fs*)) + __usb_interface_descriptor_start_fs = .; + KEEP(*(.usb_interface_desc_fs*)) + __usb_descriptor_end_fs = .; + __usb_dev_descriptor_start_hs = .; + KEEP(*(.usb_device_desc_hs*)) + __usb_cfg_descriptor_start_hs = .; + KEEP(*(.usb_config_desc_hs*)) + __usb_interface_descriptor_start_hs = .; + KEEP(*(.usb_interface_desc_hs*)) + __usb_descriptor_end_hs = .; + + KEEP(*(.eh_frame*)) + + __ROM_End = .; + _etext = .; + } > FLASH = 0xFF + + __Vectors_Size = __Vectors_End - __Vectors; + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* To copy multiple ROM to RAM sections, + * uncomment .copy.table section and, + * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */ + /* + .copy.table : + { + . = ALIGN(4); + __copy_table_start__ = .; + LONG (__etext) + LONG (__data_start__) + LONG (__data_end__ - __data_start__) + LONG (__etext2) + LONG (__data2_start__) + LONG (__data2_end__ - __data2_start__) + __copy_table_end__ = .; + } > FLASH + */ + + /* To clear multiple BSS sections, + * uncomment .zero.table section and, + * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */ + /* + .zero.table : + { + . = ALIGN(4); + __zero_table_start__ = .; + LONG (__bss_start__) + LONG (__bss_end__ - __bss_start__) + LONG (__bss2_start__) + LONG (__bss2_end__ - __bss2_start__) + __zero_table_end__ = .; + } > FLASH + */ + + __etext = .; + + /* If DTC is used, put the DTC vector table at the start of SRAM. + This avoids memory holes due to 1K alignment required by it. */ + .fsp_dtc_vector_table (NOLOAD) : + { + . = ORIGIN(RAM); + *(.fsp_dtc_vector_table) + } > RAM + + /* Initialized data section. */ + .data : + { + _sidata = .; + _sdata = .; + __data_start__ = .; + *(vtable) + *(.data.*) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + + KEEP(*(.jcr*)) + . = ALIGN(4); + + __Code_In_RAM_Start = .; + + KEEP(*(.code_in_ram*)) + __Code_In_RAM_End = .; + + /* All data end */ + __data_end__ = .; + _edata = .; + + } > RAM AT > FLASH + + + + .noinit (NOLOAD): + { + . = ALIGN(4); + __noinit_start = .; + KEEP(*(.noinit*)) + __noinit_end = .; + } > RAM + + .bss : + { + . = ALIGN(4); + _sbss = .; + __bss_start__ = .; + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + _ebss = .; + } > RAM + + .heap (NOLOAD): + { + . = ALIGN(8); + __HeapBase = .; + __end__ = .; + end = __end__; + KEEP(*(.heap*)) + __HeapLimit = .; + } > RAM + + /* Stacks are stored in this section. */ + .stack_dummy (NOLOAD): + { + . = ALIGN(8); + _sstack = .; + __StackLimit = .; + /* Main stack */ + KEEP(*(.stack)) + __StackTop = .; + /* Thread stacks */ + KEEP(*(.stack*)) + __StackTopAll = .; + _estack = .; + } > RAM + + PROVIDE(__stack = __StackTopAll); + + /* This symbol represents the end of user allocated RAM. The RAM after this symbol can be used + at run time for things such as ThreadX memory pool allocations. */ + __RAM_segment_used_end__ = ALIGN(__StackTopAll , 4); + + /* Data flash. */ + .data_flash : + { + __Data_Flash_Start = .; + KEEP(*(.data_flash*)) + __Data_Flash_End = .; + } > DATA_FLASH + + .id_code : + { + __ID_Code_Start = .; + KEEP(*(.id_code*)) + __ID_Code_End = .; + } > ID_CODE +} +/* produce a link error if there is not this amount of RAM for these sections */ +/* _minimum_stack_size = 2K; */ +/* _minimum_heap_size = 16K; */ + +/* Define tho top end of the stack. The stack is full descending so begins just + above last byte of RAM. Note that EABI requires the stack to be 8-byte + aligned for a call. */ +_estack = ORIGIN(RAM) + LENGTH(RAM); + +/* RAM extents for the garbage collector */ +_ram_start = ORIGIN(RAM); +_ram_end = ORIGIN(RAM) + LENGTH(RAM); +_heap_start = __HeapBase; /* heap starts just after statically allocated memory */ +_heap_end = __HeapLimit; /* tunable */ + +_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS); +_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS); + +_micropy_hw_external_flash_storage_start = ORIGIN(QSPI_FLASH); +_micropy_hw_external_flash_storage_end = ORIGIN(QSPI_FLASH) + LENGTH(QSPI_FLASH); diff --git a/ports/renesas-ra/boards/VK_RA6M5/vk_ra6m5_conf.h b/ports/renesas-ra/boards/VK_RA6M5/vk_ra6m5_conf.h new file mode 100644 index 0000000000000..1e08a19737f1b --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA6M5/vk_ra6m5_conf.h @@ -0,0 +1,30 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023 Vekatech Ltd. + * + * 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. + */ + +#ifndef VK_RA6M5_CONF_H +#define VK_RA6M5_CONF_H + +#define DEBUG_CH 7 + +#endif /* VK_RA6M5_CONF_H */ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy