diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index dc4b158483499..842f5e5f3e53d 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),RA4M1_EK) -BOARD_LOW = ra4m1_ek -CMSIS_MCU_LOW = ra4m1 -CMSIS_MCU_CAP = RA4M1 -USE_FSP_LPM = 0 -endif - -ifeq ($(BOARD),RA4W1_EK) -BOARD_LOW = ra4w1_ek -CMSIS_MCU_LOW = ra4w1 -CMSIS_MCU_CAP = RA4W1 -USE_FSP_LPM = 1 -endif - -ifeq ($(BOARD),RA6M1_EK) -BOARD_LOW = ra6m1_ek -CMSIS_MCU_LOW = ra6m1 -CMSIS_MCU_CAP = RA6M1 -USE_FSP_LPM = 1 -endif - -ifeq ($(BOARD),RA6M2_EK) -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,9 @@ include ../../py/mkenv.mk -include mpconfigport.mk include $(BOARD_DIR)/mpconfigboard.mk +USE_FSP_LPM ?= 1 +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 @@ -109,6 +77,7 @@ 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 @@ -312,6 +281,7 @@ SRC_C += \ gccollect.c \ help.c \ machine_adc.c \ + machine_dac.c \ machine_i2c.c \ machine_spi.c \ machine_uart.c \ @@ -343,10 +313,13 @@ SRC_O += \ SRC_O += \ shared/runtime/gchelper_thumb2.o -HAL_SRC_C += $(addprefix $(HAL_DIR)/ra/board/$(BOARD_LOW)/,\ +FSP_BOARD_DIR = $(HAL_DIR)/ra/board/$(FSP_BOARD_NAME) +ifneq ($(wildcard $(TOP)/$(FSP_BOARD_DIR)/.),) +HAL_SRC_C += $(addprefix $(FSP_BOARD_DIR)/,\ board_init.c \ board_leds.c \ ) +endif HAL_SRC_C += $(addprefix $(HAL_DIR)/ra/fsp/src/bsp/mcu/all/,\ bsp_clocks.c \ @@ -388,6 +361,7 @@ endif ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA4M1 RA4W1 RA6M1 RA6M2)) HAL_SRC_C += $(addprefix ra/,\ ra_adc.c \ + ra_dac.c \ ra_flash.c \ ra_gpio.c \ ra_i2c.c \ @@ -398,6 +372,7 @@ HAL_SRC_C += $(addprefix ra/,\ ra_sci.c \ ra_spi.c \ ra_timer.c \ + ra_gpt.c \ ra_utils.c \ ) diff --git a/ports/renesas-ra/RA4M1_hal.h b/ports/renesas-ra/RA4M1_hal.h index 7f0ad9666f47b..e88ccef2063a3 100644 --- a/ports/renesas-ra/RA4M1_hal.h +++ b/ports/renesas-ra/RA4M1_hal.h @@ -56,8 +56,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..d1a23d2d352b0 100644 --- a/ports/renesas-ra/RA4W1_hal.h +++ b/ports/renesas-ra/RA4W1_hal.h @@ -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 @@ -31,6 +32,9 @@ // #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_BAUD 115200 @@ -56,8 +60,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" @@ -82,16 +88,16 @@ typedef enum { #define DEBUG_CH SCI_CH #endif #if (DEBUG_CH == 0) -#define DEBUG_TX_PIN P411 -#define DEBUG_RX_PIN P410 +#define DEBUG_TX_PIN DBG_TX0 +#define DEBUG_RX_PIN DBG_RX0 #endif #if (DEBUG_CH == 1) -#define DEBUG_TX_PIN P401 -#define DEBUG_RX_PIN P402 +#define DEBUG_TX_PIN DBG_TX1 +#define DEBUG_RX_PIN DBG_RX1 #endif #if (DEBUG_CH == 9) -#define DEBUG_TX_PIN P203 -#define DEBUG_RX_PIN P202 +#define DEBUG_TX_PIN DBG_TX9 +#define DEBUG_RX_PIN DBG_RX9 #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) diff --git a/ports/renesas-ra/RA6M1_hal.h b/ports/renesas-ra/RA6M1_hal.h index 9929d29b5462a..b6b2052686f0f 100644 --- a/ports/renesas-ra/RA6M1_hal.h +++ b/ports/renesas-ra/RA6M1_hal.h @@ -56,8 +56,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..c67001dc8dd3a 100644 --- a/ports/renesas-ra/RA6M2_hal.h +++ b/ports/renesas-ra/RA6M2_hal.h @@ -56,8 +56,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/boards/RA4M1_CLICKER/mpconfigboard.mk b/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.mk index 1758ce67388d3..fa1a3030a48e1 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.mk +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.mk @@ -4,6 +4,7 @@ LD_FILES = boards/RA4M1_CLICKER/ra4m1_clicker.ld # MicroPython settings MICROPY_VFS_FAT = 1 +USE_FSP_LPM = 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/RA4M1_EK/mpconfigboard.mk b/ports/renesas-ra/boards/RA4M1_EK/mpconfigboard.mk index 1213fa3229c0e..d60ff3b244bb3 100644 --- a/ports/renesas-ra/boards/RA4M1_EK/mpconfigboard.mk +++ b/ports/renesas-ra/boards/RA4M1_EK/mpconfigboard.mk @@ -4,6 +4,7 @@ LD_FILES = boards/RA4M1_EK/ra4m1_ek.ld # MicroPython settings MICROPY_VFS_FAT = 1 +USE_FSP_LPM = 0 # Don't include default frozen modules because MCU is tight on flash space FROZEN_MANIFEST ?= boards/RA4M1_EK/manifest.py diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra4w1_ek_conf.h b/ports/renesas-ra/boards/RA4W1_EK/ra4w1_ek_conf.h index 261073cfe98e8..4b159e138f81c 100644 --- a/ports/renesas-ra/boards/RA4W1_EK/ra4w1_ek_conf.h +++ b/ports/renesas-ra/boards/RA4W1_EK/ra4w1_ek_conf.h @@ -27,4 +27,13 @@ #define DEBUG_CH 0 +#define DBG_TX0 P411 +#define DBG_RX0 P410 + +#define DBG_TX1 P401 +#define DBG_RX1 P402 + +#define DBG_TX9 P203 +#define DBG_RX9 P202 + #endif /* RA4M1_EK_CONF_H */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/.cproject b/ports/renesas-ra/boards/VK_RA4W1/.cproject new file mode 100644 index 0000000000000..7d7f23fbd0460 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/.cproject @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${cross_make} + -j8 -C ../../.. + BOARD=${ProjName} V=1 + true + false + true + + + ${cross_make} + -j8 -C ../../.. + BOARD=${ProjName} clean V=1 + true + false + true + + + ${cross_make} + -j8 -C ../../../../../mpy-cross + V=1 + true + false + true + + + ${cross_make} + -j8 -C ../../../../../mpy-cross + clean V=1 + true + false + true + + + + \ No newline at end of file diff --git a/ports/renesas-ra/boards/VK_RA4W1/.project b/ports/renesas-ra/boards/VK_RA4W1/.project new file mode 100644 index 0000000000000..4a2bcd0a55673 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/.project @@ -0,0 +1,651 @@ + + + VK_RA4W1 + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + com.renesas.cdt.ddsc.contentgen.ddscBuilder + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + com.renesas.cdt.ddsc.contentgen.ddscInterlockBundleBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + com.renesas.cdt.ddsc.contentgen.ddscNature + com.renesas.cdt.ra.contentgen.raNature + org.eclipse.xtext.ui.shared.xtextNature + + + + drivers + 2 + PARENT-4-PROJECT_LOC/drivers + + + extmod + 2 + PARENT-4-PROJECT_LOC/extmod + + + lib + 2 + PARENT-4-PROJECT_LOC/lib + + + ports + 2 + virtual:/virtual + + + py + 2 + PARENT-4-PROJECT_LOC/py + + + shared + 2 + PARENT-4-PROJECT_LOC/shared + + + ports/renesas-ra + 2 + virtual:/virtual + + + ports/renesas-ra/Makefile + 1 + PARENT-2-PROJECT_LOC/Makefile + + + ports/renesas-ra/README.md + 1 + PARENT-2-PROJECT_LOC/README.md + + + ports/renesas-ra/RA4W1_hal.h + 1 + PARENT-2-PROJECT_LOC/RA4W1_hal.h + + + ports/renesas-ra/boardctrl.c + 1 + PARENT-2-PROJECT_LOC/boardctrl.c + + + ports/renesas-ra/boardctrl.h + 1 + PARENT-2-PROJECT_LOC/boardctrl.h + + + ports/renesas-ra/boards + 2 + virtual:/virtual + + + ports/renesas-ra/build-VK_RA4W1 + 2 + virtual:/virtual + + + ports/renesas-ra/build_all_boards.sh + 1 + PARENT-2-PROJECT_LOC/build_all_boards.sh + + + ports/renesas-ra/extint.c + 1 + PARENT-2-PROJECT_LOC/extint.c + + + ports/renesas-ra/extint.h + 1 + PARENT-2-PROJECT_LOC/extint.h + + + ports/renesas-ra/factoryreset.c + 1 + PARENT-2-PROJECT_LOC/factoryreset.c + + + ports/renesas-ra/factoryreset.h + 1 + PARENT-2-PROJECT_LOC/factoryreset.h + + + ports/renesas-ra/fatfs_port.c + 1 + PARENT-2-PROJECT_LOC/fatfs_port.c + + + ports/renesas-ra/flash.c + 1 + PARENT-2-PROJECT_LOC/flash.c + + + ports/renesas-ra/flash.h + 1 + PARENT-2-PROJECT_LOC/flash.h + + + ports/renesas-ra/flashbdev.c + 1 + PARENT-2-PROJECT_LOC/flashbdev.c + + + ports/renesas-ra/gccollect.c + 1 + PARENT-2-PROJECT_LOC/gccollect.c + + + ports/renesas-ra/gccollect.h + 1 + PARENT-2-PROJECT_LOC/gccollect.h + + + ports/renesas-ra/help.c + 1 + PARENT-2-PROJECT_LOC/help.c + + + ports/renesas-ra/irq.c + 1 + PARENT-2-PROJECT_LOC/irq.c + + + ports/renesas-ra/irq.h + 1 + PARENT-2-PROJECT_LOC/irq.h + + + ports/renesas-ra/led.c + 1 + PARENT-2-PROJECT_LOC/led.c + + + ports/renesas-ra/led.h + 1 + PARENT-2-PROJECT_LOC/led.h + + + ports/renesas-ra/machine_adc.c + 1 + PARENT-2-PROJECT_LOC/machine_adc.c + + + ports/renesas-ra/machine_dac.c + 1 + PARENT-2-PROJECT_LOC/machine_dac.c + + + ports/renesas-ra/machine_i2c.c + 1 + PARENT-2-PROJECT_LOC/machine_i2c.c + + + ports/renesas-ra/machine_pin.c + 1 + PARENT-2-PROJECT_LOC/machine_pin.c + + + ports/renesas-ra/machine_pwm.c + 1 + PARENT-2-PROJECT_LOC/machine_pwm.c + + + ports/renesas-ra/machine_rtc.c + 1 + PARENT-2-PROJECT_LOC/machine_rtc.c + + + ports/renesas-ra/machine_spi.c + 1 + PARENT-2-PROJECT_LOC/machine_spi.c + + + ports/renesas-ra/machine_uart.c + 1 + PARENT-2-PROJECT_LOC/machine_uart.c + + + ports/renesas-ra/main.c + 1 + PARENT-2-PROJECT_LOC/main.c + + + ports/renesas-ra/modmachine.c + 1 + PARENT-2-PROJECT_LOC/modmachine.c + + + ports/renesas-ra/modmachine.h + 1 + PARENT-2-PROJECT_LOC/modmachine.h + + + ports/renesas-ra/modutime.c + 1 + PARENT-2-PROJECT_LOC/modutime.c + + + ports/renesas-ra/mpconfigboard_common.h + 1 + PARENT-2-PROJECT_LOC/mpconfigboard_common.h + + + ports/renesas-ra/mpconfigport.h + 1 + PARENT-2-PROJECT_LOC/mpconfigport.h + + + ports/renesas-ra/mpconfigport.mk + 1 + PARENT-2-PROJECT_LOC/mpconfigport.mk + + + ports/renesas-ra/mphalport.c + 1 + PARENT-2-PROJECT_LOC/mphalport.c + + + ports/renesas-ra/mphalport.h + 1 + PARENT-2-PROJECT_LOC/mphalport.h + + + ports/renesas-ra/mpthreadport.c + 1 + PARENT-2-PROJECT_LOC/mpthreadport.c + + + ports/renesas-ra/mpthreadport.h + 1 + PARENT-2-PROJECT_LOC/mpthreadport.h + + + ports/renesas-ra/pendsv.c + 1 + PARENT-2-PROJECT_LOC/pendsv.c + + + ports/renesas-ra/pendsv.h + 1 + PARENT-2-PROJECT_LOC/pendsv.h + + + ports/renesas-ra/pin.h + 1 + PARENT-2-PROJECT_LOC/pin.h + + + ports/renesas-ra/powerctrl.c + 1 + PARENT-2-PROJECT_LOC/powerctrl.c + + + ports/renesas-ra/powerctrl.h + 1 + PARENT-2-PROJECT_LOC/powerctrl.h + + + ports/renesas-ra/powerctrlboot.c + 1 + PARENT-2-PROJECT_LOC/powerctrlboot.c + + + ports/renesas-ra/pybthread.c + 1 + PARENT-2-PROJECT_LOC/pybthread.c + + + ports/renesas-ra/pybthread.h + 1 + PARENT-2-PROJECT_LOC/pybthread.h + + + ports/renesas-ra/qstrdefsport.h + 1 + PARENT-2-PROJECT_LOC/qstrdefsport.h + + + ports/renesas-ra/ra + 2 + virtual:/virtual + + + ports/renesas-ra/ra_it.c + 1 + PARENT-2-PROJECT_LOC/ra_it.c + + + ports/renesas-ra/ra_it.h + 1 + PARENT-2-PROJECT_LOC/ra_it.h + + + ports/renesas-ra/rtc.h + 1 + PARENT-2-PROJECT_LOC/rtc.h + + + ports/renesas-ra/spi.h + 1 + PARENT-2-PROJECT_LOC/spi.h + + + ports/renesas-ra/storage.c + 1 + PARENT-2-PROJECT_LOC/storage.c + + + ports/renesas-ra/storage.h + 1 + PARENT-2-PROJECT_LOC/storage.h + + + ports/renesas-ra/systick.c + 1 + PARENT-2-PROJECT_LOC/systick.c + + + ports/renesas-ra/systick.h + 1 + PARENT-2-PROJECT_LOC/systick.h + + + ports/renesas-ra/timer.c + 1 + PARENT-2-PROJECT_LOC/timer.c + + + ports/renesas-ra/timer.h + 1 + PARENT-2-PROJECT_LOC/timer.h + + + ports/renesas-ra/uart.c + 1 + PARENT-2-PROJECT_LOC/uart.c + + + ports/renesas-ra/uart.h + 1 + PARENT-2-PROJECT_LOC/uart.h + + + ports/renesas-ra/usrsw.c + 1 + PARENT-2-PROJECT_LOC/usrsw.c + + + ports/renesas-ra/usrsw.h + 1 + PARENT-2-PROJECT_LOC/usrsw.h + + + ports/renesas-ra/boards/.gitignore + 1 + PARENT-1-PROJECT_LOC/.gitignore + + + ports/renesas-ra/boards/deploy.md + 1 + PARENT-1-PROJECT_LOC/deploy.md + + + ports/renesas-ra/boards/make-pins.py + 1 + PARENT-1-PROJECT_LOC/make-pins.py + + + ports/renesas-ra/boards/manifest.py + 1 + PARENT-1-PROJECT_LOC/manifest.py + + + ports/renesas-ra/boards/ra4w1_af.csv + 1 + PARENT-1-PROJECT_LOC/ra4w1_af.csv + + + ports/renesas-ra/boards/ra_pin_prefix.c + 1 + PARENT-1-PROJECT_LOC/ra_pin_prefix.c + + + ports/renesas-ra/build-VK_RA4W1/frozen_content.c + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/frozen_content.c + + + ports/renesas-ra/build-VK_RA4W1/genhdr + 2 + virtual:/virtual + + + ports/renesas-ra/build-VK_RA4W1/pins_VK_RA4W1.c + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/pins_VK_RA4W1.c + + + ports/renesas-ra/build-VK_RA4W1/pins_qstr.h + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/pins_qstr.h + + + ports/renesas-ra/ra/ra_adc.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_adc.c + + + ports/renesas-ra/ra/ra_adc.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_adc.h + + + ports/renesas-ra/ra/ra_config.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_config.h + + + ports/renesas-ra/ra/ra_dac.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_dac.c + + + ports/renesas-ra/ra/ra_dac.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_dac.h + + + ports/renesas-ra/ra/ra_flash.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_flash.c + + + ports/renesas-ra/ra/ra_flash.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_flash.h + + + ports/renesas-ra/ra/ra_gpio.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_gpio.c + + + ports/renesas-ra/ra/ra_gpio.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_gpio.h + + + ports/renesas-ra/ra/ra_gpt.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_gpt.c + + + ports/renesas-ra/ra/ra_gpt.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_gpt.h + + + ports/renesas-ra/ra/ra_i2c.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_i2c.c + + + ports/renesas-ra/ra/ra_i2c.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_i2c.h + + + ports/renesas-ra/ra/ra_icu.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_icu.c + + + ports/renesas-ra/ra/ra_icu.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_icu.h + + + ports/renesas-ra/ra/ra_init.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_init.c + + + ports/renesas-ra/ra/ra_init.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_init.h + + + ports/renesas-ra/ra/ra_int.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_int.c + + + ports/renesas-ra/ra/ra_int.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_int.h + + + ports/renesas-ra/ra/ra_rtc.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_rtc.c + + + ports/renesas-ra/ra/ra_rtc.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_rtc.h + + + ports/renesas-ra/ra/ra_sci.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_sci.c + + + ports/renesas-ra/ra/ra_sci.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_sci.h + + + ports/renesas-ra/ra/ra_spi.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_spi.c + + + ports/renesas-ra/ra/ra_spi.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_spi.h + + + ports/renesas-ra/ra/ra_timer.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_timer.c + + + ports/renesas-ra/ra/ra_timer.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_timer.h + + + ports/renesas-ra/ra/ra_utils.c + 1 + PARENT-2-PROJECT_LOC/ra/ra_utils.c + + + ports/renesas-ra/ra/ra_utils.h + 1 + PARENT-2-PROJECT_LOC/ra/ra_utils.h + + + ports/renesas-ra/build-VK_RA4W1/genhdr/compressed.data.h + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/genhdr/compressed.data.h + + + ports/renesas-ra/build-VK_RA4W1/genhdr/moduledefs.h + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/genhdr/moduledefs.h + + + ports/renesas-ra/build-VK_RA4W1/genhdr/mpversion.h + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/genhdr/mpversion.h + + + ports/renesas-ra/build-VK_RA4W1/genhdr/pins.h + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/genhdr/pins.h + + + ports/renesas-ra/build-VK_RA4W1/genhdr/pins_ad_const.h + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/genhdr/pins_ad_const.h + + + ports/renesas-ra/build-VK_RA4W1/genhdr/qstrdefs.collected.h + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/genhdr/qstrdefs.collected.h + + + ports/renesas-ra/build-VK_RA4W1/genhdr/qstrdefs.generated.h + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/genhdr/qstrdefs.generated.h + + + ports/renesas-ra/build-VK_RA4W1/genhdr/qstrdefs.preprocessed.h + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/genhdr/qstrdefs.preprocessed.h + + + ports/renesas-ra/build-VK_RA4W1/genhdr/root_pointers.h + 1 + PARENT-2-PROJECT_LOC/build-VK_RA4W1/genhdr/root_pointers.h + + + diff --git a/ports/renesas-ra/boards/VK_RA4W1/VK_RA4W1.pincfg b/ports/renesas-ra/boards/VK_RA4W1/VK_RA4W1.pincfg new file mode 100644 index 0000000000000..f85f68910aab8 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/VK_RA4W1.pincfg @@ -0,0 +1,316 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ports/renesas-ra/boards/VK_RA4W1/board.json b/ports/renesas-ra/boards/VK_RA4W1/board.json new file mode 100644 index 0000000000000..e02c2dd81ef98 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/board.json @@ -0,0 +1,23 @@ +{ + "deploy": [ + "../deploy.md" + ], + "docs": "", + "features": [ + "UART", + "SPI", + "I2C", + "ADC", + "DAC", + "PWM" + ], + "id": "VK-RA4W1", + "images": [ + "https://vekatech.com/VK-RA4W1_docs/images/VK-RA4W1.jpg" + ], + "mcu": "RA4W1", + "product": "VK-RA4W1", + "thumbnail": "", + "url": "https://vekatech.com/VK-RA4W1_docs/brochures/VK-RA4W1%20Flyer%20R2.pdf", + "vendor": "Vekatech" +} diff --git a/ports/renesas-ra/boards/VK_RA4W1/configuration.xml b/ports/renesas-ra/boards/VK_RA4W1/configuration.xml new file mode 100644 index 0000000000000..8debb69833e32 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/configuration.xml @@ -0,0 +1,485 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Board Support Package Common Files + Renesas.RA.2.3.0.pack + + + I/O Port + Renesas.RA.2.3.0.pack + + + Arm CMSIS Version 5 - Core (M) + Arm.CMSIS5.5.7.0+fsp.2.3.0.pack + + + Custom Board Support Files + Renesas.RA_board_custom.2.3.0.pack + + + Board support package for R7FA4W1AD2CNG + Renesas.RA_mcu_ra4w1.2.3.0.pack + + + Board support package for RA4W1 + Renesas.RA_mcu_ra4w1.2.3.0.pack + + + Board support package for RA4W1 - FSP Data + Renesas.RA_mcu_ra4w1.2.3.0.pack + + + A/D Converter + Renesas.RA.2.3.0.pack + + + Asynchronous General Purpose Timer + Renesas.RA.2.3.0.pack + + + Data Transfer Controller + Renesas.RA.2.3.0.pack + + + Flash Memory Low Power + Renesas.RA.2.3.0.pack + + + External Interrupt + Renesas.RA.2.3.0.pack + + + I2C Master Interface + Renesas.RA.2.3.0.pack + + + Low Power Modes + Renesas.RA.2.3.0.pack + + + Real Time Clock + Renesas.RA.2.3.0.pack + + + SCI UART + Renesas.RA.2.3.0.pack + + + Serial Peripheral Interface + Renesas.RA.2.3.0.pack + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ports/renesas-ra/boards/VK_RA4W1/makefile.defs b/ports/renesas-ra/boards/VK_RA4W1/makefile.defs new file mode 100644 index 0000000000000..6df83be96426c --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/makefile.defs @@ -0,0 +1,8 @@ +uPy: + @echo "Does uPY $(BRD) build exist?" +ifeq ($(wildcard ../../../build-$(BRD)/.),) + @echo "-> NO ... Generating uPY firmware first ..." + $(MAKE) -C ../../.. BOARD=$(BRD) V=1 +else + @echo "-> YES ... Using some [build-$(BRD)] files ..." +endif diff --git a/ports/renesas-ra/boards/VK_RA4W1/mpconfigboard.h b/ports/renesas-ra/boards/VK_RA4W1/mpconfigboard.h new file mode 100644 index 0000000000000..8f4935a98781f --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/mpconfigboard.h @@ -0,0 +1,70 @@ +// MCU config +#define MICROPY_HW_BOARD_NAME "VK-RA4W1" +#define MICROPY_HW_MCU_NAME "RA4W1" +#define MICROPY_HW_MCU_SYSCLK 48000000 +#define MICROPY_HW_MCU_PCLK 48000000 + +// 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, 1: LOCO (32.768khz) +#define MICROPY_HW_ENABLE_ADC (1) +#define MICROPY_HW_HAS_FLASH (1) +#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1) + +// board config + +// UART +#define MICROPY_HW_UART1_TX (pin_P213) +#define MICROPY_HW_UART1_RX (pin_P212) +// #define MICROPY_HW_UART1_CTS (pin_P101) // Disable (Conflict with PMOD) +#define MICROPY_HW_UART9_TX (pin_P109) +#define MICROPY_HW_UART9_RX (pin_P110) +// #define MICROPY_HW_UART9_CTS (pin_P108) // NC +#define MICROPY_HW_UART_REPL HW_UART_9 +#define MICROPY_HW_UART_REPL_BAUD 115200 + +// I2C +#define MICROPY_HW_I2C1_SCL (pin_P205) // Note that conflict with PMOD IO0 +#define MICROPY_HW_I2C1_SDA (pin_P206) // Note that conflict with PMOD IO1 + +// SPI +#define MICROPY_HW_SPI0_SSL (pin_P104) // D10 +#define MICROPY_HW_SPI0_RSPCK (pin_P102) // D13 +#define MICROPY_HW_SPI0_MISO (pin_P100) // D12 +#define MICROPY_HW_SPI0_MOSI (pin_P101) // D11 + +// PWM +#define MICROPY_HW_PWM_1A (pin_P105) // D3 +#define MICROPY_HW_PWM_8B (pin_P106) // D8 +#define MICROPY_HW_PWM_8A (pin_P107) // D9 +#define MICROPY_HW_PWM_3A (pin_P111) // D2 +#define MICROPY_HW_PWM_4B (pin_P204) // LED2 +#define MICROPY_HW_PWM_3B (pin_P404) // LED1 +#define MICROPY_HW_PWM_5A (pin_P409) // D4 + +// DAC +#define MICROPY_HW_DAC0 (pin_P014) // A3 + +// Switch +#define MICROPY_HW_HAS_SWITCH (1) +#define MICROPY_HW_USRSW_PIN (pin_P414) +#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_P404) +#define MICROPY_HW_LED2 (pin_P204) +#define MICROPY_HW_LED_ON(pin) mp_hal_pin_low(pin) +#define MICROPY_HW_LED_OFF(pin) mp_hal_pin_high(pin) +#define MICROPY_HW_LED_TOGGLE(pin) mp_hal_pin_toggle(pin) diff --git a/ports/renesas-ra/boards/VK_RA4W1/mpconfigboard.mk b/ports/renesas-ra/boards/VK_RA4W1/mpconfigboard.mk new file mode 100644 index 0000000000000..bad88c0b13993 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/mpconfigboard.mk @@ -0,0 +1,6 @@ +CMSIS_MCU = RA4W1 +MCU_SERIES = m4 +LD_FILES = boards/VK_RA4W1/vk_ra4w1.ld + +# MicroPython settings +MICROPY_VFS_FAT = 1 diff --git a/ports/renesas-ra/boards/VK_RA4W1/pins.csv b/ports/renesas-ra/boards/VK_RA4W1/pins.csv new file mode 100644 index 0000000000000..22a9487be08fe --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/pins.csv @@ -0,0 +1,63 @@ +P004,P004 +P010,P010 +P011,P011 +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 +P200,P200 +P201,P201 +P204,P204 +P205,P205 +P206,P206 +P212,P212 +P213,P213 +P214,P214 +P215,P215 +P300,P300 +P402,P402 +P404,P404 +P407,P407 +P409,P409 +P414,P414 +P501,P501 +P914,P914 +P915,P915 +A0,P004 +A1,P010 +A2,P011 +A3,P014 +A4,P015 +A5,P501 +SDA1,P206 +SCL1,P205 +D13,P102 +D12,P100 +D11,P101 +D10,P104 +D9,P107 +D8,P106 +D7,P915 +D6,P914 +D5,P407 +D4,P409 +D3,P105 +D2,P111 +D1,P213 +D0,P212 +SWDIO,P108 +MD,P201 +SWCLK,P300 +SW1,P414 +LED1,P404 +LED2,P204 diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/board_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/board_cfg.h new file mode 100644 index 0000000000000..87cb51e00ba74 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/board_cfg.h @@ -0,0 +1,5 @@ +/* generated configuration header file - do not edit */ +#ifndef BOARD_CFG_H_ +#define BOARD_CFG_H_ +void bsp_init(void *p_args); +#endif /* BOARD_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h new file mode 100644 index 0000000000000..15474f25bf43a --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h @@ -0,0 +1,49 @@ +/* generated configuration header file - do not edit */ +#ifndef BSP_CFG_H_ +#define BSP_CFG_H_ +#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 +#undef RA_NOT_DEFINED +#define BSP_CFG_MCU_VCC_MV (3300) +#define BSP_CFG_STACK_MAIN_BYTES (0x4000) +#define BSP_CFG_HEAP_BYTES (0xf000) +#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_SOFT_RESET_SUPPORTED ((0)) + +#ifndef BSP_CLOCK_CFG_MAIN_OSC_POPULATED +#define BSP_CLOCK_CFG_MAIN_OSC_POPULATED (0) +#endif +#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT +#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) +#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 +#endif /* BSP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h new file mode 100644 index 0000000000000..444d32e5606c8 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/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 (4) +#endif /* BSP_MCU_DEVICE_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h new file mode 100644 index 0000000000000..70984c8ef6ebc --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h @@ -0,0 +1,10 @@ +/* generated configuration header file - do not edit */ +#ifndef BSP_MCU_DEVICE_PN_CFG_H_ +#define BSP_MCU_DEVICE_PN_CFG_H_ +#define BSP_MCU_R7FA4W1AD2CNG +#define BSP_ROM_SIZE_BYTES (524288) +#define BSP_RAM_SIZE_BYTES (98304) +#define BSP_DATA_FLASH_SIZE_BYTES (8192) +#define BSP_PACKAGE_QFN +#define BSP_PACKAGE_PINS (56) +#endif /* BSP_MCU_DEVICE_PN_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h new file mode 100644 index 0000000000000..fd26bb64e0eb5 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h @@ -0,0 +1,74 @@ +/* generated configuration header file - do not edit */ +#ifndef BSP_MCU_FAMILY_CFG_H_ +#define BSP_MCU_FAMILY_CFG_H_ +#include "bsp_mcu_device_pn_cfg.h" +#include "bsp_mcu_device_cfg.h" +#include "../../../ra/fsp/src/bsp/mcu/ra4w1/bsp_mcu_info.h" +#include "bsp_clock_cfg.h" +#define BSP_MCU_GROUP_RA4W1 (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 (24000000) +#elif BSP_CFG_HOCO_FREQUENCY == 2 +#define BSP_HOCO_HZ (32000000) +#elif BSP_CFG_HOCO_FREQUENCY == 4 +#define BSP_HOCO_HZ (48000000) +#elif BSP_CFG_HOCO_FREQUENCY == 5 +#define BSP_HOCO_HZ (64000000) +#else +#error "Invalid HOCO frequency chosen (BSP_CFG_HOCO_FREQUENCY) in bsp_clock_cfg.h" +#endif +#define BSP_CORTEX_VECTOR_TABLE_ENTRIES (16U) +#define BSP_VECTOR_TABLE_MAX_ENTRIES (48U) +#define BSP_MCU_VBATT_SUPPORT (1) + +#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) +#define BSP_CFG_ROM_REG_OFS1 (0xFFFFFEC3 | (1 << 2) | (3 << 3) | (0 << 8)) +#define BSP_CFG_USE_LOW_VOLTAGE_MODE ((0)) +#define BSP_CFG_ROM_REG_MPU_PC0_ENABLE (1) +#define BSP_CFG_ROM_REG_MPU_PC0_START (0x00FFFFFC) +#define BSP_CFG_ROM_REG_MPU_PC0_END (0x00FFFFFF) +#define BSP_CFG_ROM_REG_MPU_PC1_ENABLE (1) +#define BSP_CFG_ROM_REG_MPU_PC1_START (0x00FFFFFC) +#define BSP_CFG_ROM_REG_MPU_PC1_END (0x00FFFFFF) +#define BSP_CFG_ROM_REG_MPU_REGION0_ENABLE (1) +#define BSP_CFG_ROM_REG_MPU_REGION0_START (0x00FFFFFC) +#define BSP_CFG_ROM_REG_MPU_REGION0_END (0x00FFFFFF) +#define BSP_CFG_ROM_REG_MPU_REGION1_ENABLE (1) +#define BSP_CFG_ROM_REG_MPU_REGION1_START (0x200FFFFC) +#define BSP_CFG_ROM_REG_MPU_REGION1_END (0x200FFFFF) +#define BSP_CFG_ROM_REG_MPU_REGION2_ENABLE (1) +#define BSP_CFG_ROM_REG_MPU_REGION2_START (0x407FFFFC) +#define BSP_CFG_ROM_REG_MPU_REGION2_END (0x407FFFFF) +#define BSP_CFG_ROM_REG_MPU_REGION3_ENABLE (1) +#define BSP_CFG_ROM_REG_MPU_REGION3_START (0x400DFFFC) +#define BSP_CFG_ROM_REG_MPU_REGION3_END (0x400DFFFF) + +/* Used to create IELS values for the interrupt initialization table g_interrupt_event_link_select. */ +#define BSP_PRV_IELS_ENUM(vector) (ELC_##vector) + +/* + ID Code + Note: To permanently lock and disable the debug interface define the BSP_ID_CODE_PERMANENTLY_LOCKED in the compiler settings. + WARNING: This will disable debug access to the part and cannot be reversed by a debug probe. + */ +#if defined(BSP_ID_CODE_PERMANENTLY_LOCKED) +#define BSP_CFG_ID_CODE_LONG_1 (0x00000000) +#define BSP_CFG_ID_CODE_LONG_2 (0x00000000) +#define BSP_CFG_ID_CODE_LONG_3 (0x00000000) +#define BSP_CFG_ID_CODE_LONG_4 (0x00000000) +#else +/* ID CODE: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF */ +#define BSP_CFG_ID_CODE_LONG_1 (0xFFFFFFFF) +#define BSP_CFG_ID_CODE_LONG_2 (0xFFFFFFFF) +#define BSP_CFG_ID_CODE_LONG_3 (0xFFFFFFFF) +#define BSP_CFG_ID_CODE_LONG_4 (0xffFFFFFF) +#endif +#endif /* BSP_MCU_FAMILY_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_adc_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_adc_cfg.h new file mode 100644 index 0000000000000..9c59889ca8fee --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_adc_cfg.h @@ -0,0 +1,5 @@ +/* generated configuration header file - do not edit */ +#ifndef R_ADC_CFG_H_ +#define R_ADC_CFG_H_ +#define ADC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#endif /* R_ADC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_agt_cfg.h new file mode 100644 index 0000000000000..d3ab559238cbd --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_agt_cfg.h @@ -0,0 +1,7 @@ +/* generated configuration header file - do not edit */ +#ifndef R_AGT_CFG_H_ +#define R_AGT_CFG_H_ +#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) +#endif /* R_AGT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_dtc_cfg.h new file mode 100644 index 0000000000000..21405f96741e2 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_dtc_cfg.h @@ -0,0 +1,6 @@ +/* generated configuration header file - do not edit */ +#ifndef R_DTC_CFG_H_ +#define R_DTC_CFG_H_ +#define DTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define DTC_CFG_VECTOR_TABLE_SECTION_NAME ".fsp_dtc_vector_table" +#endif /* R_DTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h new file mode 100644 index 0000000000000..26879f9f4e52a --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h @@ -0,0 +1,7 @@ +/* generated configuration header file - do not edit */ +#ifndef R_FLASH_LP_CFG_H_ +#define R_FLASH_LP_CFG_H_ +#define FLASH_LP_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define FLASH_LP_CFG_CODE_FLASH_PROGRAMMING_ENABLE (1) +#define FLASH_LP_CFG_DATA_FLASH_PROGRAMMING_ENABLE (0) +#endif /* R_FLASH_LP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_icu_cfg.h new file mode 100644 index 0000000000000..5e77b6980f4ee --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_icu_cfg.h @@ -0,0 +1,5 @@ +/* generated configuration header file - do not edit */ +#ifndef R_ICU_CFG_H_ +#define R_ICU_CFG_H_ +#define ICU_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#endif /* R_ICU_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_iic_master_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_iic_master_cfg.h new file mode 100644 index 0000000000000..595ea938d13a7 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_iic_master_cfg.h @@ -0,0 +1,7 @@ +/* generated configuration header file - do not edit */ +#ifndef R_IIC_MASTER_CFG_H_ +#define R_IIC_MASTER_CFG_H_ +#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) +#endif /* R_IIC_MASTER_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_ioport_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_ioport_cfg.h new file mode 100644 index 0000000000000..6b4353d238352 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_ioport_cfg.h @@ -0,0 +1,5 @@ +/* generated configuration header file - do not edit */ +#ifndef R_IOPORT_CFG_H_ +#define R_IOPORT_CFG_H_ +#define IOPORT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#endif /* R_IOPORT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_lpm_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_lpm_cfg.h new file mode 100644 index 0000000000000..5f4d5c4a73627 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_lpm_cfg.h @@ -0,0 +1,5 @@ +/* generated configuration header file - do not edit */ +#ifndef R_LPM_CFG_H_ +#define R_LPM_CFG_H_ +#define LPM_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#endif /* R_LPM_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_rtc_cfg.h new file mode 100644 index 0000000000000..484b7ed044c26 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_rtc_cfg.h @@ -0,0 +1,5 @@ +/* generated configuration header file - do not edit */ +#ifndef R_RTC_CFG_H_ +#define R_RTC_CFG_H_ +#define RTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#endif /* R_RTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h new file mode 100644 index 0000000000000..c70c0be344f9d --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h @@ -0,0 +1,8 @@ +/* generated configuration header file - do not edit */ +#ifndef R_SCI_UART_CFG_H_ +#define R_SCI_UART_CFG_H_ +#define SCI_UART_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define SCI_UART_CFG_FIFO_SUPPORT (0) +#define SCI_UART_CFG_DTC_SUPPORTED (0) +#define SCI_UART_CFG_FLOW_CONTROL_SUPPORT (0) +#endif /* R_SCI_UART_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_spi_cfg.h new file mode 100644 index 0000000000000..861fe12194f63 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_cfg/fsp_cfg/r_spi_cfg.h @@ -0,0 +1,7 @@ +/* generated configuration header file - do not edit */ +#ifndef R_SPI_CFG_H_ +#define R_SPI_CFG_H_ +#define SPI_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define SPI_DTC_SUPPORT_ENABLE (1) +#define SPI_TRANSMIT_FROM_RXI_ISR (0) +#endif /* R_SPI_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_gen/VK_RA4W1.csv b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/VK_RA4W1.csv new file mode 100644 index 0000000000000..ec1b39bf490d5 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/VK_RA4W1.csv @@ -0,0 +1,257 @@ +"Name","Pin","Function","Drive Capacity","IRQ","Mode","Output type","Pull up","Port Capabilities" +"ANT","30","RADIO0_ANT","","","","","","" +"AVCC0","35","ANALOG0_AVCC0","","","","","","" +"AVDDRF","39","RADIO0_AVDDRF","","","","","","" +"AVSS0","36","ANALOG0_AVSS0","","","","","","" +"FBIN","45","RADIO0_FBIN","","","","","","" +"LX","41","RADIO0_LX","","","","","","" +"P004","40","ADC0_AN04","","","Analog mode","","None","ADC0: AN04 +ICU0: IRQ03 +OPAMP2: AMPO" +"P010","38","ADC0_AN05","","","Analog mode","","None","ADC0: AN05 +CTSU0: TS30 +ICU0: IRQ14 +OPAMP2: AMP-" +"P011","37","ADC0_AN06","","","Analog mode","","None","ADC0: AN06 +CTSU0: TS31 +ICU0: IRQ15 +OPAMP2: AMP+" +"P014","32","ADC0_AN09","","","Analog mode","","None","ADC0: AN09 +DAC0: DA" +"P015","31","ADC0_AN10","","","Analog mode","","None","ADC0: AN10 +CTSU0: TS28 +ICU0: IRQ07" +"P100","27","SPI0_MISO","Low","None","Peripheral mode","CMOS","None","ACMPLP0: CMPIN +AGT0: AGTIO +BUS_ASYNCH0: D00 +GPT_POEG0: GTETRG +GPT5: GTIOCB +ICU0: IRQ02 +IIC1: SCL +KINT0: KRM0 +SCI0: RXD +SCI0: SCL +SCI1: SCK +SLCDC0: VL1 +SPI0: MISO" +"P101","26","SPI0_MOSI","Low","None","Peripheral mode","CMOS","None","ACMPLP0: CMPREF +AGT0: AGTEE +BUS_ASYNCH0: D01 +GPT_POEG1: GTETRG +GPT5: GTIOCA +ICU0: IRQ01 +IIC1: SDA +KINT0: KRM1 +SCI0: SDA +SCI0: TXD +SCI1: CTS +SLCDC0: VL2 +SPI0: MOSI" +"P102","25","SPI0_RSPCK","Low","","Peripheral mode","CMOS","None","ACMPLP1: CMPIN +ADC0: ADTRG +ADC0: AN20 +AGT0: AGTO +BUS_ASYNCH0: D02 +CAN0: CRX +GPT_OPS0: GTOWLO +GPT2: GTIOCB +KINT0: KRM2 +SCI0: SCK +SLCDC0: VL3 +SPI0: RSPCK" +"P103","24","CAN0_CTX","Low","","Peripheral mode","CMOS","None","ACMPLP1: CMPREF +ADC0: AN19 +BUS_ASYNCH0: D03 +CAN0: CTX +GPT_OPS0: GTOWUP +GPT2: GTIOCA +KINT0: KRM3 +SCI0: CTS +SLCDC0: VL4 +SPI0: SSL0" +"P104","23","SPI0_SSL1","Low","None","Peripheral mode","CMOS","None","BUS_ASYNCH0: D04 +CTSU0: TS13 +GPT_POEG1: GTETRG +GPT1: GTIOCB +ICU0: IRQ01 +KINT0: KRM4 +SCI0: RXD +SCI0: SCL +SLCDC0: COM0 +SPI0: SSL1" +"P105","22","","","","Disabled","","","BUS_ASYNCH0: D05 +CTSU0: TS34 +GPT_POEG0: GTETRG +GPT1: GTIOCA +ICU0: IRQ00 +KINT0: KRM5 +SLCDC0: COM1 +SPI0: SSL2" +"P106","21","","","","Disabled","","","BUS_ASYNCH0: D06 +GPT8: GTIOCB +KINT0: KRM6 +SLCDC0: COM2 +SPI0: SSL3" +"P107","20","","","","Disabled","","","BUS_ASYNCH0: D07 +GPT8: GTIOCA +KINT0: KRM7 +SLCDC0: COM3" +"P108","14","DEBUG0_SWDIO","Low","","Peripheral mode","CMOS","None","DEBUG0: SWDIO +DEBUG0: TMS +GPT_OPS0: GTOULO +GPT0: GTIOCB +SCI9: CTS +SPI1: SSL0" +"P109","15","SCI9_TXD","Low","","Peripheral mode","CMOS","None","CAN0: CTX +CGC0: CLKOUT +CTSU0: TS10 +DEBUG0: TDO +DEBUG0: TRACESWO +GPT_OPS0: GTOVUP +GPT1: GTIOCA +SCI1: SCK +SCI9: SDA +SCI9: TXD +SLCDC0: SEG52 +SPI1: MOSI" +"P110","16","SCI9_RXD","Low","None","Peripheral mode","CMOS","None","ACMP(0-1): VCOUT +CAN0: CRX +DEBUG0: TDI +GPT_OPS0: GTOVLO +GPT1: GTIOCB +ICU0: IRQ03 +SCI9: RXD +SCI9: SCL +SLCDC0: SEG53 +SPI1: MISO" +"P111","17","","","","Disabled","","","BUS_ASYNCH0: A05 +CTSU0: TS12 +GPT3: GTIOCA +ICU0: IRQ04 +SCI9: SCK +SLCDC0: CAPH +SPI1: RSPCK" +"P200","12","","","","Disabled","","","ICU0: NMI" +"P201","11","SYSTEM0_MD","","","Peripheral mode","","","SYSTEM0: MD +SYSTEM0: VCC +SYSTEM0: VCC +SYSTEM0: VCC +SYSTEM0: VCC +SYSTEM0: VCC +SYSTEM0: VCC +SYSTEM0: VCC" +"P204","9","GPIO","Low","","Output mode (Initial Low)","CMOS","","AGT1: AGTIO +BUS_ASYNCH0: A18 +CAC0: CACREF +CTSU0: TS00 +GPT_OPS0: GTIW +GPT4: GTIOCB +IIC0: SCL +SCI4: SCK +SCI9: SCK +SDHI0: DAT4 +SLCDC0: SEG23 +SPI1: RSPCK +USB_FS0: OVRCURB" +"P205","8","IIC1_SCL","Medium","None","Peripheral mode","CMOS","None","AGT1: AGTO +BUS_ASYNCH0: A16 +CGC0: CLKOUT +CTSU0: TSCAP +GPT_OPS0: GTIV +GPT4: GTIOCA +ICU0: IRQ01 +IIC1: SCL +SCI4: SDA +SCI4: TXD +SCI9: CTS +SDHI0: DAT3 +SLCDC0: SEG20 +SPI1: SSL0 +USB_FS0: OVRCURA" +"P206","7","IIC1_SDA","Medium","None","Peripheral mode","CMOS","None","BUS_ASYNCH0: WAIT +CTSU0: TS01 +GPT_OPS0: GTIU +ICU0: IRQ00 +IIC1: SDA +SCI4: RXD +SCI4: SCL +SDHI0: DAT2 +SLCDC0: SEG12 +SPI1: SSL1 +USB_FS0: VBUSEN" +"P212","53","SCI1_RXD","","None","Peripheral mode","CMOS","None","AGT1: AGTEE +CGC0: EXTAL +GPT_POEG1: GTETRG +GPT0: GTIOCB +ICU0: IRQ03 +SCI1: RXD +SCI1: SCL" +"P213","52","SCI1_TXD","","None","Peripheral mode","CMOS","None","CGC0: XTAL +GPT_POEG0: GTETRG +GPT0: GTIOCA +ICU0: IRQ02 +SCI1: SDA +SCI1: TXD" +"P214","50","CGC0_XCOUT","","","Peripheral mode","","","CGC0: XCOUT" +"P215","49","CGC0_XCIN","","","Peripheral mode","","","CGC0: XCIN" +"P300","13","DEBUG0_SWCLK","Low","","Peripheral mode","CMOS","None","DEBUG0: SWCLK +DEBUG0: TCK +GPT_OPS0: GTOUUP +GPT0: GTIOCA +SPI1: SSL1" +"P305","","","","","Disabled","","","" +"P402","44","CAN0_CRX","Low","None","Peripheral mode","CMOS","None","AGT0: AGTIO +AGT1: AGTIO +CAN0: CRX +CTSU0: TS18 +ICU0: IRQ04 +RTC0: RTCIC0 +SCI1: RXD +SCI1: SCL +SLCDC0: SEG06" +"P404","46","GPIO","Low","","Output mode (Initial Low)","CMOS","","GPT3: GTIOCB +RTC0: RTCIC2 +SSI0: SSIWS" +"P407","1","","","","Disabled","","","ADC0: ADTRG +AGT0: AGTIO +CTSU0: TS03 +IIC0: SDA +RTC0: RTCOUT +SCI4: CTS +SLCDC0: SEG11 +SPI1: SSL3 +USBFS0: VBUS" +"P409","56","","","","Disabled","","","GPT_OPS0: GTOWUP +GPT5: GTIOCA +ICU0: IRQ06 +SLCDC0: SEG09" +"P414","55","IRQ0_IRQ09","","IRQ09","IRQ mode","","None","GPT0: GTIOCB +ICU0: IRQ09 +SDHI0: WP +SPI0: SSL1" +"P501","29","ADC0_AN17","","","Analog mode","","None","ACMPLP1: CMPIN +ADC0: AN17 +AGT0: AGTOB +GPT_OPS0: GTIV +GPT2: GTIOCB +ICU0: IRQ11 +QSPI0: QSSL +SLCDC0: SEG49 +USB_FS0: OVRCURA" +"P914","4","","","","Disabled","","","USB_FS0: DP" +"P915","3","","","","Disabled","","","USB_FS0: DM" +"Q1","34","RADIO0_Q1","","","","","","" +"Q2","33","RADIO0_Q2","","","","","","" +"RES#","10","SYSTEM0_RES","","","","","","" +"TEST0","28","RADIO0_TEST0","","","","","","" +"VBATT","47","SYSTEM0_VBATT","","","","","","" +"VCC","18","SYSTEM0_VCC","","","","","","" +"VCC","54","SYSTEM0_VCC","","","","","","" +"VCCUSB","5","USBFS0_VCC","","","","","","" +"VCCUSBLDO","6","USBFS0_VCCLDO","","","","","","" +"VCL","48","SYSTEM0_VCL","","","","","","" +"VDDDIG","43","RADIO0_VDDDIG","","","","","","" +"VDDRF","42","RADIO0_VDDRF","","","","","","" +"VSS","19","SYSTEM0_VSS","","","","","","" +"VSS","51","SYSTEM0_VSS","","","","","","" +"VSSUSB","2","USBFS0_VSS","","","","","","" diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/bsp_clock_cfg.h new file mode 100644 index 0000000000000..6378da7a2b2fe --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/bsp_clock_cfg.h @@ -0,0 +1,23 @@ +/* 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 (8000000) /* XTAL 8000000Hz */ +#define BSP_CFG_PLL_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_MAIN_OSC) /* PLL Src: XTAL */ +#define BSP_CFG_HOCO_FREQUENCY (4) /* HOCO 48MHz */ +#define BSP_CFG_PLL_DIV (BSP_CLOCKS_PLL_DIV_2) /* PLL Div /2 */ +#define BSP_CFG_PLL_MUL (BSP_CLOCKS_PLL_MUL_12_0) /* PLL Mul x12 */ +#define BSP_CFG_CLOCK_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_HOCO) /* Clock Src: HOCO */ +#define BSP_CFG_ICLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* ICLK Div /1 */ +#define BSP_CFG_PCLKA_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* PCLKA Div /1 */ +#define BSP_CFG_PCLKB_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* PCLKB Div /2 */ +#define BSP_CFG_PCLKC_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* PCLKC Div /1 */ +#define BSP_CFG_PCLKD_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* PCLKD Div /1 */ +#define BSP_CFG_BCLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* BCLK Div /2 */ +#define BSP_CFG_BCLK_OUTPUT (0) /* No output */ +#define BSP_CFG_FCLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* FCLK Div /2 */ +#define BSP_CFG_CLKOUT_SOURCE (BSP_CLOCKS_CLOCK_DISABLED) /* CLKOUT Disabled */ +#define BSP_CFG_CLKOUT_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* CLKOUT Div /1 */ +#define BSP_CFG_UCK_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_HOCO) /* UCLK Src: HOCO */ +#endif /* BSP_CLOCK_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_gen/bsp_pin_cfg.h b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/bsp_pin_cfg.h new file mode 100644 index 0000000000000..cc9f8583a46df --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/bsp_pin_cfg.h @@ -0,0 +1,7 @@ +/* generated configuration header file - do not edit */ +#ifndef BSP_PIN_CFG_H_ +#define BSP_PIN_CFG_H_ +#include "bsp_api.h" +#include "r_ioport_api.h" +extern const ioport_cfg_t g_bsp_pin_cfg; /* VK_RA4W1.pincfg */ +#endif /* BSP_PIN_CFG_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_gen/common_data.c b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/common_data.c new file mode 100644 index 0000000000000..1f573c1e10b43 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/common_data.c @@ -0,0 +1,8 @@ +/* generated common source file - do not edit */ +#include "common_data.h" +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_RA4W1/ra_gen/common_data.h b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/common_data.h new file mode 100644 index 0000000000000..e2eb70836ba79 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/common_data.h @@ -0,0 +1,16 @@ +/* generated common header file - do not edit */ +#ifndef COMMON_DATA_H_ +#define COMMON_DATA_H_ +#include +#include "bsp_api.h" +#include "r_ioport.h" +#include "bsp_pin_cfg.h" +FSP_HEADER +/* 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_RA4W1/ra_gen/hal_data.c b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/hal_data.c new file mode 100644 index 0000000000000..f0d9c4b436644 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/hal_data.c @@ -0,0 +1,440 @@ +/* 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 +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, }; +const adc_cfg_t g_adc0_cfg = { .unit = 0, .mode = ADC_MODE_SINGLE_SCAN, + .resolution = ADC_RESOLUTION_14_BIT, .alignment = + (adc_alignment_t)ADC_ALIGNMENT_RIGHT, .trigger = + ADC_TRIGGER_SOFTWARE, .p_callback = NULL, .p_context = NULL, + .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), }; +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, }; +/* 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 }; +iic_master_instance_ctrl_t g_i2c_master1_ctrl; +const iic_master_extended_cfg_t g_i2c_master1_extend = +{ .timeout_mode = IIC_MASTER_TIMEOUT_MODE_SHORT, + /* Actual calculated bitrate: 99272. Actual calculated duty cycle: 49%. */ .clock_settings.brl_value = + 27, .clock_settings.brh_value = 26, + .clock_settings.cks_value = 2, }; +const i2c_master_cfg_t g_i2c_master1_cfg = { .channel = 1, .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_IIC1_RXI) + .rxi_irq = VECTOR_NUMBER_IIC1_RXI, + #else + .rxi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_IIC1_TXI) + .txi_irq = VECTOR_NUMBER_IIC1_TXI, + #else + .txi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_IIC1_TEI) + .tei_irq = VECTOR_NUMBER_IIC1_TEI, + #else + .tei_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_IIC1_ERI) + .eri_irq = VECTOR_NUMBER_IIC1_ERI, + #else + .eri_irq = FSP_INVALID_VECTOR, + #endif + .ipl = (12), .p_extend = &g_i2c_master1_extend, }; +/* Instance structure to use this module. */ +const i2c_master_instance_t g_i2c_master1 = { .p_ctrl = &g_i2c_master1_ctrl, + .p_cfg = &g_i2c_master1_cfg, .p_api = &g_i2c_master_on_iic }; +lpm_instance_ctrl_t g_lpm0_ctrl; + +const lpm_cfg_t g_lpm0_cfg = { .low_power_mode = LPM_MODE_SLEEP, + .snooze_cancel_sources = LPM_SNOOZE_CANCEL_SOURCE_NONE, + .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM + | (lpm_standby_wake_source_t)0, .snooze_request_source = + LPM_SNOOZE_REQUEST_RXD0_FALLING, .snooze_end_sources = + (lpm_snooze_end_t)0, .dtc_state_in_snooze = + LPM_SNOOZE_DTC_DISABLE, + #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 = 0, + .power_supply_state = 0, + .deep_standby_cancel_source = (lpm_deep_standby_cancel_source_t)0, + .deep_standby_cancel_edge = (lpm_deep_standby_cancel_edge_t)0, + #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 = { .dest_addr_mode = + TRANSFER_ADDR_MODE_INCREMENTED, .repeat_area = + TRANSFER_REPEAT_AREA_DESTINATION, .irq = TRANSFER_IRQ_END, .chain_mode = + TRANSFER_CHAIN_MODE_DISABLED, .src_addr_mode = TRANSFER_ADDR_MODE_FIXED, + .size = TRANSFER_SIZE_2_BYTE, .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 = { .dest_addr_mode = TRANSFER_ADDR_MODE_FIXED, + .repeat_area = TRANSFER_REPEAT_AREA_SOURCE, .irq = TRANSFER_IRQ_END, + .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, .src_addr_mode = + TRANSFER_ADDR_MODE_INCREMENTED, .size = TRANSFER_SIZE_2_BYTE, + .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 }; +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: 12000000. */ .spbr = 1, .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 }; +icu_instance_ctrl_t g_external_irq9_ctrl; +const external_irq_cfg_t g_external_irq9_cfg = { .channel = 9, .trigger = + EXTERNAL_IRQ_TRIG_RISING, .filter_enable = false, .pclk_div = + EXTERNAL_IRQ_PCLK_DIV_BY_64, .p_callback = callback_icu, .p_context = + NULL, .p_extend = NULL, .ipl = (12), + #if defined(VECTOR_NUMBER_ICU_IRQ9) + .irq = VECTOR_NUMBER_ICU_IRQ9, + #else + .irq = FSP_INVALID_VECTOR, + #endif +}; +/* Instance structure to use this module. */ +const external_irq_instance_t g_external_irq9 = { .p_ctrl = + &g_external_irq9_ctrl, .p_cfg = &g_external_irq9_cfg, .p_api = + &g_external_irq_on_icu }; +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, + .agtoa = AGT_PIN_CFG_DISABLED, .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.002730666666666667 seconds. Actual duty: 50%. */ .period_counts = + 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, + .agtoa = AGT_PIN_CFG_DISABLED, .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.002730666666666667 seconds. Actual duty: 50%. */ .period_counts = + 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_lp_instance_ctrl_t g_flash0_ctrl; +const flash_cfg_t g_flash0_cfg = { .data_flash_bgo = false, .p_callback = NULL, + .p_context = NULL, .ipl = (BSP_IRQ_DISABLED), + #if defined(VECTOR_NUMBER_FCU_FRDYI) + .irq = VECTOR_NUMBER_FCU_FRDYI, + #else + .irq = FSP_INVALID_VECTOR, + #endif +}; +/* 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_lp }; +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.160% error. */ .abcse = 0, .abcs = 0, .bgdm = 1, + .cks = 0, .brr = 25, .mddr = (uint8_t)256, .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, .uart_mode = UART_MODE_RS232, + .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, + #if 0 + .flow_control_pin = BSP_IO_PORT_00_PIN_00, + #else + .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), + #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_uart1_ctrl; + +baud_setting_t g_uart1_baud_setting = { +/* Baud rate calculated with 0.160% error. */ .abcse = 0, .abcs = 0, .bgdm = 1, + .cks = 0, .brr = 25, .mddr = (uint8_t)256, .brme = false +}; + +/** UART extended configuration for UARTonSCI HAL driver */ +const sci_uart_extended_cfg_t g_uart1_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_uart1_baud_setting, .uart_mode = UART_MODE_RS232, + .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, + #if 0 + .flow_control_pin = BSP_IO_PORT_00_PIN_00, + #else + .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), + #endif +}; + +/** UART interface configuration */ +const uart_cfg_t g_uart1_cfg = { .channel = 1, .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_uart1_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_SCI1_RXI) + .rxi_irq = VECTOR_NUMBER_SCI1_RXI, + #else + .rxi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI1_TXI) + .txi_irq = VECTOR_NUMBER_SCI1_TXI, + #else + .txi_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI1_TEI) + .tei_irq = VECTOR_NUMBER_SCI1_TEI, + #else + .tei_irq = FSP_INVALID_VECTOR, + #endif + #if defined(VECTOR_NUMBER_SCI1_ERI) + .eri_irq = VECTOR_NUMBER_SCI1_ERI, + #else + .eri_irq = FSP_INVALID_VECTOR, + #endif +}; + +/* Instance structure to use this module. */ +const uart_instance_t g_uart1 = { .p_ctrl = &g_uart1_ctrl, + .p_cfg = &g_uart1_cfg, .p_api = &g_uart_on_sci }; +void g_hal_init(void) { + g_common_init(); +} diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_gen/hal_data.h b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/hal_data.h new file mode 100644 index 0000000000000..9e542dd0b75ea --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/hal_data.h @@ -0,0 +1,165 @@ +/* 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_adc.h" +#include "r_adc_api.h" +#include "r_iic_master.h" +#include "r_i2c_master_api.h" +#include "r_lpm.h" +#include "r_lpm_api.h" +#include "r_dtc.h" +#include "r_transfer_api.h" +#include "r_spi.h" +#include "r_icu.h" +#include "r_external_irq_api.h" +#include "r_agt.h" +#include "r_timer_api.h" +#include "r_flash_lp.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 +/** 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 +/* I2C Master on IIC Instance. */ +extern const i2c_master_instance_t g_i2c_master1; + +/** 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_master1_ctrl; +extern const i2c_master_cfg_t g_i2c_master1_cfg; + +#ifndef callback_iic +void callback_iic(i2c_master_callback_args_t *p_args); +#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 +/** External IRQ on ICU Instance. */ +extern const external_irq_instance_t g_external_irq9; + +/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ +extern icu_instance_ctrl_t g_external_irq9_ctrl; +extern const external_irq_cfg_t g_external_irq9_cfg; + +#ifndef callback_icu +void callback_icu(external_irq_callback_args_t *p_args); +#endif +/** 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 LP Instance. */ +extern const flash_instance_t g_flash0; + +/** Access the Flash LP instance using these structures when calling API functions directly (::p_api is not used). */ +extern flash_lp_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_uart1; + +/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ +extern sci_uart_instance_ctrl_t g_uart1_ctrl; +extern const uart_cfg_t g_uart1_cfg; +extern const sci_uart_extended_cfg_t g_uart1_cfg_extend; + +#ifndef user_uart_callback +void user_uart_callback(uart_callback_args_t *p_args); +#endif +void hal_entry(void); +void g_hal_init(void); +FSP_FOOTER +#endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_gen/main.c b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/main.c new file mode 100644 index 0000000000000..5b9f9805595fa --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/main.c @@ -0,0 +1,6 @@ +/* generated main source file - do not edit */ +#include "hal_data.h" +int main(void) { + hal_entry(); + return 0; +} diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_gen/pin_data.c b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/pin_data.c new file mode 100644 index 0000000000000..fdbbddaf8d875 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/pin_data.c @@ -0,0 +1,101 @@ +/* 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_04, + .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE), + }, + { + .pin = BSP_IO_PORT_00_PIN_10, + .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE), + }, + { + .pin = BSP_IO_PORT_00_PIN_11, + .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE), + }, + { + .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_SPI), + }, + { + .pin = BSP_IO_PORT_01_PIN_01, + .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), + }, + { + .pin = BSP_IO_PORT_01_PIN_02, + .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), + }, + { + .pin = BSP_IO_PORT_01_PIN_03, + .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_CAN), + }, + { + .pin = BSP_IO_PORT_01_PIN_04, + .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), + }, + { + .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_04, + .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), + }, + { + .pin = BSP_IO_PORT_02_PIN_05, + .pin_cfg = ((uint32_t)IOPORT_CFG_DRIVE_MID | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_IIC), + }, + { + .pin = BSP_IO_PORT_02_PIN_06, + .pin_cfg = ((uint32_t)IOPORT_CFG_DRIVE_MID | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_IIC), + }, + { + .pin = BSP_IO_PORT_02_PIN_12, + .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), + }, + { + .pin = BSP_IO_PORT_02_PIN_13, + .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), + }, + { + .pin = BSP_IO_PORT_03_PIN_00, + .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), + }, + { + .pin = BSP_IO_PORT_04_PIN_02, + .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_CAN), + }, + { + .pin = BSP_IO_PORT_04_PIN_04, + .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), + }, + { + .pin = BSP_IO_PORT_04_PIN_14, + .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT), + }, + { + .pin = BSP_IO_PORT_05_PIN_01, + .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE), + }, +}; +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], +}; diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_gen/vector_data.c b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/vector_data.c new file mode 100644 index 0000000000000..ec03bb976fdb3 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/vector_data.c @@ -0,0 +1,55 @@ +/* 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, /* SCI1 RXI (Received data full) */ + [1] = sci_uart_txi_isr, /* SCI1 TXI (Transmit data empty) */ + [2] = sci_uart_tei_isr, /* SCI1 TEI (Transmit end) */ + [3] = sci_uart_eri_isr, /* SCI1 ERI (Receive error) */ + [4] = sci_uart_rxi_isr, /* SCI9 RXI (Received data full) */ + [5] = sci_uart_txi_isr, /* SCI9 TXI (Transmit data empty) */ + [6] = sci_uart_tei_isr, /* SCI9 TEI (Transmit end) */ + [7] = sci_uart_eri_isr, /* SCI9 ERI (Receive error) */ + [8] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ + [9] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ + [10] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ + [11] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ + [12] = agt_int_isr, /* AGT1 INT (AGT interrupt) */ + [13] = r_icu_isr, /* ICU IRQ9 (External pin interrupt 9) */ + [14] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ + [15] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ + [16] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ + [17] = spi_eri_isr, /* SPI0 ERI (Error) */ + [18] = iic_master_rxi_isr, /* IIC1 RXI (Receive data full) */ + [19] = iic_master_txi_isr, /* IIC1 TXI (Transmit data empty) */ + [20] = iic_master_tei_isr, /* IIC1 TEI (Transmit end) */ + [21] = iic_master_eri_isr, /* IIC1 ERI (Transfer error) */ +}; +const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENTRIES] = +{ + [0] = BSP_PRV_IELS_ENUM(EVENT_SCI1_RXI), /* SCI1 RXI (Received data full) */ + [1] = BSP_PRV_IELS_ENUM(EVENT_SCI1_TXI), /* SCI1 TXI (Transmit data empty) */ + [2] = BSP_PRV_IELS_ENUM(EVENT_SCI1_TEI), /* SCI1 TEI (Transmit end) */ + [3] = BSP_PRV_IELS_ENUM(EVENT_SCI1_ERI), /* SCI1 ERI (Receive error) */ + [4] = BSP_PRV_IELS_ENUM(EVENT_SCI9_RXI), /* SCI9 RXI (Received data full) */ + [5] = BSP_PRV_IELS_ENUM(EVENT_SCI9_TXI), /* SCI9 TXI (Transmit data empty) */ + [6] = BSP_PRV_IELS_ENUM(EVENT_SCI9_TEI), /* SCI9 TEI (Transmit end) */ + [7] = BSP_PRV_IELS_ENUM(EVENT_SCI9_ERI), /* SCI9 ERI (Receive error) */ + [8] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ + [9] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ + [10] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ + [11] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ + [12] = BSP_PRV_IELS_ENUM(EVENT_AGT1_INT), /* AGT1 INT (AGT interrupt) */ + [13] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ9), /* ICU IRQ9 (External pin interrupt 9) */ + [14] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ + [15] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ + [16] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ + [17] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ + [18] = BSP_PRV_IELS_ENUM(EVENT_IIC1_RXI), /* IIC1 RXI (Receive data full) */ + [19] = BSP_PRV_IELS_ENUM(EVENT_IIC1_TXI), /* IIC1 TXI (Transmit data empty) */ + [20] = BSP_PRV_IELS_ENUM(EVENT_IIC1_TEI), /* IIC1 TEI (Transmit end) */ + [21] = BSP_PRV_IELS_ENUM(EVENT_IIC1_ERI), /* IIC1 ERI (Transfer error) */ +}; +#endif diff --git a/ports/renesas-ra/boards/VK_RA4W1/ra_gen/vector_data.h b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/vector_data.h new file mode 100644 index 0000000000000..cf41f048c5871 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/ra_gen/vector_data.h @@ -0,0 +1,84 @@ +/* generated vector header file - do not edit */ +#ifndef VECTOR_DATA_H +#define VECTOR_DATA_H +/* Number of interrupts allocated */ +#ifndef VECTOR_DATA_IRQ_COUNT +#define VECTOR_DATA_IRQ_COUNT (22) +#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); + +/* Vector table allocations */ +#define VECTOR_NUMBER_SCI1_RXI ((IRQn_Type)0) /* SCI1 RXI (Received data full) */ +#define VECTOR_NUMBER_SCI1_TXI ((IRQn_Type)1) /* SCI1 TXI (Transmit data empty) */ +#define VECTOR_NUMBER_SCI1_TEI ((IRQn_Type)2) /* SCI1 TEI (Transmit end) */ +#define VECTOR_NUMBER_SCI1_ERI ((IRQn_Type)3) /* SCI1 ERI (Receive error) */ +#define VECTOR_NUMBER_SCI9_RXI ((IRQn_Type)4) /* SCI9 RXI (Received data full) */ +#define VECTOR_NUMBER_SCI9_TXI ((IRQn_Type)5) /* SCI9 TXI (Transmit data empty) */ +#define VECTOR_NUMBER_SCI9_TEI ((IRQn_Type)6) /* SCI9 TEI (Transmit end) */ +#define VECTOR_NUMBER_SCI9_ERI ((IRQn_Type)7) /* SCI9 ERI (Receive error) */ +#define VECTOR_NUMBER_RTC_ALARM ((IRQn_Type)8) /* RTC ALARM (Alarm interrupt) */ +#define VECTOR_NUMBER_RTC_PERIOD ((IRQn_Type)9) /* RTC PERIOD (Periodic interrupt) */ +#define VECTOR_NUMBER_RTC_CARRY ((IRQn_Type)10) /* RTC CARRY (Carry interrupt) */ +#define VECTOR_NUMBER_AGT0_INT ((IRQn_Type)11) /* AGT0 INT (AGT interrupt) */ +#define VECTOR_NUMBER_AGT1_INT ((IRQn_Type)12) /* AGT1 INT (AGT interrupt) */ +#define VECTOR_NUMBER_ICU_IRQ9 ((IRQn_Type)13) /* ICU IRQ9 (External pin interrupt 9) */ +#define VECTOR_NUMBER_SPI0_RXI ((IRQn_Type)14) /* SPI0 RXI (Receive buffer full) */ +#define VECTOR_NUMBER_SPI0_TXI ((IRQn_Type)15) /* SPI0 TXI (Transmit buffer empty) */ +#define VECTOR_NUMBER_SPI0_TEI ((IRQn_Type)16) /* SPI0 TEI (Transmission complete event) */ +#define VECTOR_NUMBER_SPI0_ERI ((IRQn_Type)17) /* SPI0 ERI (Error) */ +#define VECTOR_NUMBER_IIC1_RXI ((IRQn_Type)18) /* IIC1 RXI (Receive data full) */ +#define VECTOR_NUMBER_IIC1_TXI ((IRQn_Type)19) /* IIC1 TXI (Transmit data empty) */ +#define VECTOR_NUMBER_IIC1_TEI ((IRQn_Type)20) /* IIC1 TEI (Transmit end) */ +#define VECTOR_NUMBER_IIC1_ERI ((IRQn_Type)21) /* IIC1 ERI (Transfer error) */ +typedef enum IRQn { + Reset_IRQn = -15, + NonMaskableInt_IRQn = -14, + HardFault_IRQn = -13, + MemoryManagement_IRQn = -12, + BusFault_IRQn = -11, + UsageFault_IRQn = -10, + SecureFault_IRQn = -9, + SVCall_IRQn = -5, + DebugMonitor_IRQn = -4, + PendSV_IRQn = -2, + SysTick_IRQn = -1, + SCI1_RXI_IRQn = 0, /* SCI1 RXI (Received data full) */ + SCI1_TXI_IRQn = 1, /* SCI1 TXI (Transmit data empty) */ + SCI1_TEI_IRQn = 2, /* SCI1 TEI (Transmit end) */ + SCI1_ERI_IRQn = 3, /* SCI1 ERI (Receive error) */ + SCI9_RXI_IRQn = 4, /* SCI9 RXI (Received data full) */ + SCI9_TXI_IRQn = 5, /* SCI9 TXI (Transmit data empty) */ + SCI9_TEI_IRQn = 6, /* SCI9 TEI (Transmit end) */ + SCI9_ERI_IRQn = 7, /* SCI9 ERI (Receive error) */ + RTC_ALARM_IRQn = 8, /* RTC ALARM (Alarm interrupt) */ + RTC_PERIOD_IRQn = 9, /* RTC PERIOD (Periodic interrupt) */ + RTC_CARRY_IRQn = 10, /* RTC CARRY (Carry interrupt) */ + AGT0_INT_IRQn = 11, /* AGT0 INT (AGT interrupt) */ + AGT1_INT_IRQn = 12, /* AGT1 INT (AGT interrupt) */ + ICU_IRQ9_IRQn = 13, /* ICU IRQ9 (External pin interrupt 9) */ + SPI0_RXI_IRQn = 14, /* SPI0 RXI (Receive buffer full) */ + SPI0_TXI_IRQn = 15, /* SPI0 TXI (Transmit buffer empty) */ + SPI0_TEI_IRQn = 16, /* SPI0 TEI (Transmission complete event) */ + SPI0_ERI_IRQn = 17, /* SPI0 ERI (Error) */ + IIC1_RXI_IRQn = 18, /* IIC1 RXI (Receive data full) */ + IIC1_TXI_IRQn = 19, /* IIC1 TXI (Transmit data empty) */ + IIC1_TEI_IRQn = 20, /* IIC1 TEI (Transmit end) */ + IIC1_ERI_IRQn = 21, /* IIC1 ERI (Transfer error) */ +} IRQn_Type; +#endif /* VECTOR_DATA_H */ diff --git a/ports/renesas-ra/boards/VK_RA4W1/script/fsp.ld b/ports/renesas-ra/boards/VK_RA4W1/script/fsp.ld new file mode 100644 index 0000000000000..59fe3168165c0 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/script/fsp.ld @@ -0,0 +1 @@ +INCLUDE ../vk_ra4w1.ld \ No newline at end of file diff --git a/ports/renesas-ra/boards/VK_RA4W1/src/hal_entry.c b/ports/renesas-ra/boards/VK_RA4W1/src/hal_entry.c new file mode 100644 index 0000000000000..3e53787c615e8 --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/src/hal_entry.c @@ -0,0 +1,59 @@ +#include "stdbool.h" +#include "hal_data.h" + +FSP_CPP_HEADER +void R_BSP_WarmStart(bsp_warm_start_event_t event); +FSP_CPP_FOOTER + +void ra_main(uint32_t reset_mode); + +/*******************************************************************************************************************//** + * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function + * is called by main() when no RTOS is used. + **********************************************************************************************************************/ +void hal_entry(void) { + /* TODO: add your own code here */ + + ra_main(1); + + #if BSP_TZ_SECURE_BUILD + /* Enter non-secure code */ + R_BSP_NonSecureEnter(); + #endif +} + +/*******************************************************************************************************************//** + * This function is called at various points during the startup process. This implementation uses the event that is + * called right before main() to set up the pins. + * + * @param[in] event Where at in the start up process the code is currently at + **********************************************************************************************************************/ +void R_BSP_WarmStart(bsp_warm_start_event_t event) { + if (BSP_WARM_START_RESET == event) { + #if BSP_FEATURE_FLASH_LP_VERSION != 0 + + /* Enable reading from data flash. */ + R_FACI_LP->DFLCTL = 1U; + + /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and + * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */ + #endif + } + + if (BSP_WARM_START_POST_C == event) { + /* C runtime environment and system clocks are setup. */ + + /* Configure pins. */ + R_IOPORT_Open(&g_ioport_ctrl, &g_bsp_pin_cfg); + } +} + +#if BSP_TZ_SECURE_BUILD + +BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable(); + +/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */ +BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable() { + +} +#endif diff --git a/ports/renesas-ra/boards/VK_RA4W1/vk_ra4w1.ld b/ports/renesas-ra/boards/VK_RA4W1/vk_ra4w1.ld new file mode 100644 index 0000000000000..1241b5bc2302b --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/vk_ra4w1.ld @@ -0,0 +1,302 @@ +/* + Linker File for RA4W1 MCU +*/ + +/* Linker script to configure memory regions. */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00070000 /* 448KB/512KB */ + FLASH_FS (r) : ORIGIN = 0x00070000, LENGTH = 0x00010000 /* 64KB/512KB */ + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00018000 /* 96KB */ + DATA_FLASH (rx) : ORIGIN = 0x40100000, LENGTH = 0x00002000 /* 8KB */ + ID_CODE (rx) : ORIGIN = 0x01010018, LENGTH = 0x00000020 /* 32bytes */ +} + +/* 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); diff --git a/ports/renesas-ra/boards/VK_RA4W1/vk_ra4w1_conf.h b/ports/renesas-ra/boards/VK_RA4W1/vk_ra4w1_conf.h new file mode 100644 index 0000000000000..692713e8510ae --- /dev/null +++ b/ports/renesas-ra/boards/VK_RA4W1/vk_ra4w1_conf.h @@ -0,0 +1,39 @@ +/* + * 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_RA4M1_CONF_H +#define VK_RA4M1_CONF_H + +#define DEBUG_CH 1 + +#define DBG_TX0 +#define DBG_RX0 + +#define DBG_TX1 P213 +#define DBG_RX1 P212 + +#define DBG_TX9 P109 +#define DBG_RX9 P110 + +#endif /* VK_RA4M1_CONF_H */ diff --git a/ports/renesas-ra/machine_dac.c b/ports/renesas-ra/machine_dac.c new file mode 100644 index 0000000000000..8eba8104e4ffd --- /dev/null +++ b/ports/renesas-ra/machine_dac.c @@ -0,0 +1,187 @@ +/* + * 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 "extmod/machine_dac.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("\033[91mPin(%d) has no DAC Output function\033[0m"), self->dac->pin); + } + } else { + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("\033[91mPin(%d) exist, but is used with other periphery (ALT function)\033[0m"), pin_id->pin); + } + } else { + mp_raise_ValueError(MP_ERROR_TEXT("\033[91mPin missing or does not exist!\033[0m")); + } + + 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("\033[91mValue should be in the DAC range [0 - 4095]\033[0m")); + } 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("\033[91mValue should be in the Power range [0 - 3300] mV\033[0m")); + } 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..3bec4557331d8 --- /dev/null +++ b/ports/renesas-ra/machine_pwm.c @@ -0,0 +1,317 @@ +/* + * 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 +// #include " + +#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 /*, ARG_duty_u16, ARG_duty_ns*/ }; + 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_QSTR_duty_u16, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + // { MP_QSTR_duty_ns, 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("\033[91mfreq should be [0 - 24000000] Hz\033[0m")); + } 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("\033[91mduty should be [0 - 100] %%\033[0m")); + } 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 machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) +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("\033[91mPin(%d) has no timer Output function\033[0m"), self->pwm->pin); + } + } else { + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("\033[91mPin(%d) exist, but is used with other periphery (ALT function)\033[0m"), pin_id->pin); + } + } else { + mp_raise_ValueError(MP_ERROR_TEXT("\033[91mPin missing or does not exist!\033[0m")); + } + + 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("\033[91mcan't set freq, It should be [0 - 24000000] Hz\033[0m")); + } 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("\033[91mduty should be value in [0 - 100] %%\033[0m")); + } 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) + return MP_OBJ_NEW_SMALL_INT(?); +} + +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) +} + +STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { + // give the result in ns + return MP_OBJ_NEW_SMALL_INT(?); +} + +STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { + //assume duty is ns +} +*/ + +#endif // MICROPY_HW_ENABLE_HW_PWM 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 ecb028983c6c4..33d9c7a9931df 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,11 @@ 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 { 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..a26d64f6b29f2 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 @@ -240,5 +241,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 6d40ac8fac48b..f61c103545d6e 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 @@ -121,6 +122,16 @@ #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_INIT (1) +#define MICROPY_PY_MACHINE_PWM_DUTY (1) +// #define MICROPY_PY_MACHINE_PWM_DUTY_U16_NS (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/ra/ra_dac.c b/ports/renesas-ra/ra/ra_dac.c new file mode 100644 index 0000000000000..b4e467c6aa82f --- /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) +#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) + { 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_gpt.c b/ports/renesas-ra/ra/ra_gpt.c new file mode 100644 index 0000000000000..be53ac6f1c6c3 --- /dev/null +++ b/ports/renesas-ra/ra/ra_gpt.c @@ -0,0 +1,537 @@ +/* + * 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) +#define GPT_CH_SIZE 14 +#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) + 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) + R_GPT13, // GPT3213 General PWM Timer 13 (32-bit) + #endif + #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 + #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) + if (ch <= 3) { // 32bit + #elif defined(RA6M1) || defined(RA6M2) + 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]; +} + +/* +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) + if (ch <= 7) { + #else + #error Choose proper clock enable BIT! + #endif + ra_mstpcrd_start(R_MSTP_MSTPCRD_MSTPD5_Msk); + } 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) + if (ch <= 7) { + #else + #error Choose proper clock enable BIT! + #endif + ra_mstpcrd_stop(R_MSTP_MSTPCRD_MSTPD5_Msk); + } 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..fe04d8fc4b31f --- /dev/null +++ b/ports/renesas-ra/ra/ra_gpt.h @@ -0,0 +1,42 @@ +/* + * 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); +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..46b1ed7c30ee4 100644 --- a/ports/renesas-ra/ra/ra_i2c.c +++ b/ports/renesas-ra/ra/ra_i2c.c @@ -305,11 +305,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 @@ -458,7 +463,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 +511,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_spi.c b/ports/renesas-ra/ra/ra_spi.c index 096519ffd6402..b41503d3179c7 100644 --- a/ports/renesas-ra/ra/ra_spi.c +++ b/ports/renesas-ra/ra/ra_spi.c @@ -141,6 +141,102 @@ static const ra_af_pin_t sck_pins[] = { }; #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 */ + + #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 +274,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 +317,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 +334,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 +343,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 +359,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 +373,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 +387,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 +401,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 +415,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 +439,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 +447,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 +465,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 +483,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 +519,50 @@ 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); + + + 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/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 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