Skip to content

Commit fae96b1

Browse files
mbedNoobNinjadpgeorge
authored andcommitted
renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard.
This commit adds support for a new processor RA6M5. It also adds the following classes to the machine module: PWM, DAC, SDCard. Signed-off-by: mbedNoobNinja <[email protected]>
1 parent 92c7532 commit fae96b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3403
-250
lines changed

ports/renesas-ra/Makefile

+40-38
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,17 @@ endif
1616
# If the build directory is not given, make it reflect the board name.
1717
BUILD ?= build-$(BOARD)
1818

19-
ifeq ($(BOARD),RA4M1_CLICKER)
20-
BOARD_LOW = ra4m1_ek
21-
CMSIS_MCU_LOW = ra4m1
22-
CMSIS_MCU_CAP = RA4M1
23-
USE_FSP_LPM = 0
24-
endif
25-
26-
ifeq ($(BOARD),EK_RA4M1)
27-
BOARD_LOW = ra4m1_ek
28-
CMSIS_MCU_LOW = ra4m1
29-
CMSIS_MCU_CAP = RA4M1
30-
USE_FSP_LPM = 0
31-
endif
32-
33-
ifeq ($(BOARD),EK_RA4W1)
34-
BOARD_LOW = ra4w1_ek
35-
CMSIS_MCU_LOW = ra4w1
36-
CMSIS_MCU_CAP = RA4W1
37-
USE_FSP_LPM = 1
38-
endif
39-
40-
ifeq ($(BOARD),EK_RA6M1)
41-
BOARD_LOW = ra6m1_ek
42-
CMSIS_MCU_LOW = ra6m1
43-
CMSIS_MCU_CAP = RA6M1
44-
USE_FSP_LPM = 1
45-
endif
46-
47-
ifeq ($(BOARD),EK_RA6M2)
48-
BOARD_LOW = ra6m2_ek
49-
CMSIS_MCU_LOW = ra6m2
50-
CMSIS_MCU_CAP = RA6M2
51-
USE_FSP_LPM = 1
52-
endif
53-
5419
# select use wrapper function of FSP library
5520
USE_FSP_FLASH = 1
5621

5722
include ../../py/mkenv.mk
5823
-include mpconfigport.mk
5924
include $(BOARD_DIR)/mpconfigboard.mk
6025

26+
USE_FSP_LPM ?= 1
27+
USE_FSP_QSPI ?= 0
28+
FSP_BOARD_NAME ?= $(shell echo $(BOARD) | tr '[:upper:]' '[:lower:]')
29+
6130
# Files that are generated and needed before the QSTR build.
6231
#QSTR_GENERATED_HEADERS = $(BUILD)/pins_qstr.h $(BUILD)/modstm_qstr.h
6332
QSTR_GENERATED_HEADERS = $(BUILD)/pins_qstr.h
@@ -101,16 +70,18 @@ INC += -I$(TOP)/$(HAL_DIR)/ra/fsp/inc/api
10170
INC += -I$(TOP)/$(HAL_DIR)/ra/fsp/inc/instances
10271
INC += -I$(TOP)/$(HAL_DIR)/ra/fsp/src/bsp/cmsis/Device/RENESAS/Include
10372
#INC += -Ilwip_inc
104-
ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA4M1 RA4W1 RA6M1 RA6M2))
73+
ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA4M1 RA4W1 RA6M1 RA6M2 RA6M5))
10574
INC += -Ira
10675
endif
10776
INC += -I$(BOARD_DIR)/ra_gen
77+
INC += -I$(BOARD_DIR)/ra_cfg/driver
10878
INC += -I$(BOARD_DIR)/ra_cfg/fsp_cfg
10979
INC += -I$(BOARD_DIR)/ra_cfg/fsp_cfg/bsp
11080
INC += -Idebug
11181

11282
CFLAGS += -D$(CMSIS_MCU)
11383
CFLAGS += -DRA_HAL_H='<$(CMSIS_MCU)_hal.h>'
84+
CFLAGS += -DRA_CFG_H='<$(FSP_BOARD_NAME)_conf.h>'
11485

11586
# Basic Cortex-M flags
11687
CFLAGS_CORTEX_M = -mthumb
@@ -123,12 +94,19 @@ CFLAGS_CORTEX_M += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
12394
SUPPORTS_HARDWARE_FP_SINGLE = 1
12495
endif
12596

97+
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),m33))
98+
CFLAGS_CORTEX_M += -mfpu=fpv5-sp-d16 -mfloat-abi=hard
99+
SUPPORTS_HARDWARE_FP_SINGLE = 1
100+
endif
101+
126102
# Options for particular MCU series
127103
CFLAGS_MCU_RA4M1 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4
128104
CFLAGS_MCU_RA4W1 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4
129105
CFLAGS_MCU_RA6M1 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4
130106
CFLAGS_MCU_RA6M2 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4
107+
CFLAGS_MCU_RA6M5 = $(CFLAGS_CORTEX_M) -mtune=cortex-m33 -mcpu=cortex-m33
131108

109+
ASFLAGS += $(CFLAGS_CORTEX_M) -mcpu=cortex-$(MCU_SERIES)
132110
CFLAGS += $(INC) -Wall -Wpointer-arith -Werror -Wdouble-promotion -Wfloat-conversion -std=gnu99 -nostdlib $(CFLAGS_EXTRA)
133111
#CFLAGS += -D$(CMSIS_MCU)
134112
CFLAGS += $(CFLAGS_MCU_$(CMSIS_MCU))
@@ -315,11 +293,13 @@ SRC_C += \
315293
gccollect.c \
316294
help.c \
317295
machine_adc.c \
296+
machine_dac.c \
318297
machine_i2c.c \
319298
machine_spi.c \
320299
machine_uart.c \
321300
machine_pin.c \
322301
machine_rtc.c \
302+
machine_sdcard.c \
323303
modmachine.c \
324304
extint.c \
325305
usrsw.c \
@@ -365,6 +345,17 @@ HAL_SRC_C += $(addprefix $(HAL_DIR)/ra/fsp/src/,\
365345
CFLAGS_FSP = -Wno-unused-variable -Wno-unused-function
366346
$(BUILD)/lib/fsp/ra/fsp/src/r_sci_uart/r_sci_uart.o: CFLAGS += $(CFLAGS_FSP)
367347

348+
ifeq ($(USE_FSP_QSPI), 1)
349+
CFLAGS += -DUSE_FSP_QSPI
350+
HAL_SRC_C += $(HAL_DIR)/ra/fsp/src/r_qspi/r_qspi.c
351+
endif
352+
353+
ifeq ($(USE_FSP_SDHI), 1)
354+
CFLAGS += -DUSE_FSP_SDHI
355+
HAL_SRC_C += $(HAL_DIR)/ra/fsp/src/r_sdhi/r_sdhi.c \
356+
$(HAL_DIR)/ra/fsp/src/r_dtc/r_dtc.c
357+
endif
358+
368359
ifeq ($(USE_FSP_LPM), 1)
369360
CFLAGS += -DUSE_FSP_LPM
370361
HAL_SRC_C += $(HAL_DIR)/ra/fsp/src/r_lpm/r_lpm.c
@@ -377,16 +368,17 @@ HAL_SRC_C += $(HAL_DIR)/ra/fsp/src/r_flash_lp/r_flash_lp.c
377368
endif
378369
endif
379370

380-
ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA6M1 RA6M2))
371+
ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA6M1 RA6M2 RA6M5))
381372
ifeq ($(USE_FSP_FLASH), 1)
382373
CFLAGS += -DUSE_FSP_FLASH
383374
HAL_SRC_C += $(HAL_DIR)/ra/fsp/src/r_flash_hp/r_flash_hp.c
384375
endif
385376
endif
386377

387-
ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA4M1 RA4W1 RA6M1 RA6M2))
378+
ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA4M1 RA4W1 RA6M1 RA6M2 RA6M5))
388379
HAL_SRC_C += $(addprefix ra/,\
389380
ra_adc.c \
381+
ra_dac.c \
390382
ra_flash.c \
391383
ra_gpio.c \
392384
ra_i2c.c \
@@ -397,6 +389,7 @@ HAL_SRC_C += $(addprefix ra/,\
397389
ra_sci.c \
398390
ra_spi.c \
399391
ra_timer.c \
392+
ra_gpt.c \
400393
ra_utils.c \
401394
)
402395

@@ -413,6 +406,12 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o))
413406
OBJ += $(addprefix $(BUILD)/, $(SRC_O))
414407
OBJ += $(BUILD)/pins_$(BOARD).o
415408

409+
ifeq ($(CMSIS_MCU),RA6M5)
410+
$(BUILD)/shared/runtime/gchelper_thumb2.o: $(TOP)/shared/runtime/gchelper_thumb2.s
411+
$(ECHO) "AS $<"
412+
$(Q)$(AS) $(ASFLAGS) -o $@ $<
413+
endif
414+
416415
# This file contains performance critical functions so turn up the optimisation
417416
# level. It doesn't add much to the code size and improves performance a bit.
418417
# Don't use -O3 with this file because gcc tries to optimise memset in terms of itself.
@@ -486,6 +485,9 @@ endif
486485
ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA6M2))
487486
AF_FILE = boards/ra6m2_af.csv
488487
endif
488+
ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),RA6M5))
489+
AF_FILE = boards/ra6m5_af.csv
490+
endif
489491
GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
490492
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
491493
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h

ports/renesas-ra/RA4M1_hal.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
// #include "hal_data.h"
3232
#include "bsp_api.h"
3333
#include "common_data.h"
34+
#if defined(USE_DBG_PRINT)
35+
#include RA_CFG_H
36+
#endif
3437

35-
#define SCI_CH 0
38+
#define SCI_CH DEFAULT_DBG_CH
3639
#define SCI_BAUD 115200
3740
#define UART_CH SCI_CH
3841
#define UART_TxStr sci_tx_str
@@ -56,8 +59,10 @@
5659

5760
#include "ra_config.h"
5861
#include "ra_adc.h"
62+
#include "ra_dac.h"
5963
#include "ra_flash.h"
6064
#include "ra_gpio.h"
65+
#include "ra_gpt.h"
6166
#include "ra_i2c.h"
6267
#include "ra_icu.h"
6368
#include "ra_init.h"

ports/renesas-ra/RA4W1_hal.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
// #include "hal_data.h"
3232
#include "bsp_api.h"
3333
#include "common_data.h"
34+
#if defined(USE_DBG_PRINT)
35+
#include RA_CFG_H
36+
#endif
3437

35-
#define SCI_CH 0
38+
#define SCI_CH DEFAULT_DBG_CH
3639
#define SCI_BAUD 115200
3740
#define UART_CH SCI_CH
3841
#define UART_TxStr sci_tx_str
@@ -56,8 +59,10 @@
5659

5760
#include "ra_config.h"
5861
#include "ra_adc.h"
62+
#include "ra_dac.h"
5963
#include "ra_flash.h"
6064
#include "ra_gpio.h"
65+
#include "ra_gpt.h"
6166
#include "ra_i2c.h"
6267
#include "ra_icu.h"
6368
#include "ra_init.h"

ports/renesas-ra/RA6M1_hal.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
// #include "hal_data.h"
3232
#include "bsp_api.h"
3333
#include "common_data.h"
34+
#if defined(USE_DBG_PRINT)
35+
#include RA_CFG_H
36+
#endif
3437

35-
#define SCI_CH 0
38+
#define SCI_CH DEFAULT_DBG_CH
3639
#define SCI_BAUD 115200
3740
#define UART_CH SCI_CH
3841
#define UART_TxStr sci_tx_str
@@ -56,8 +59,10 @@
5659

5760
#include "ra_config.h"
5861
#include "ra_adc.h"
62+
#include "ra_dac.h"
5963
#include "ra_flash.h"
6064
#include "ra_gpio.h"
65+
#include "ra_gpt.h"
6166
#include "ra_i2c.h"
6267
#include "ra_icu.h"
6368
#include "ra_init.h"

ports/renesas-ra/RA6M2_hal.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
// #include "hal_data.h"
3232
#include "bsp_api.h"
3333
#include "common_data.h"
34+
#if defined(USE_DBG_PRINT)
35+
#include RA_CFG_H
36+
#endif
3437

35-
#define SCI_CH 0
38+
#define SCI_CH DEFAULT_DBG_CH
3639
#define SCI_BAUD 115200
3740
#define UART_CH SCI_CH
3841
#define UART_TxStr sci_tx_str
@@ -56,8 +59,10 @@
5659

5760
#include "ra_config.h"
5861
#include "ra_adc.h"
62+
#include "ra_dac.h"
5963
#include "ra_flash.h"
6064
#include "ra_gpio.h"
65+
#include "ra_gpt.h"
6166
#include "ra_i2c.h"
6267
#include "ra_icu.h"
6368
#include "ra_init.h"

ports/renesas-ra/RA6M5_hal.h

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2021 Renesas Electronics Corporation
5+
* Copyright (c) 2023 Vekatech Ltd.
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
#ifndef PORTS_RA_RA6M5_HAL_H_
27+
#define PORTS_RA_RA6M5_HAL_H_
28+
29+
#include <stdio.h>
30+
#include <stdint.h>
31+
#include <stdbool.h>
32+
// #include "hal_data.h"
33+
#include "bsp_api.h"
34+
#include "common_data.h"
35+
#if defined(USE_DBG_PRINT)
36+
#include RA_CFG_H
37+
#endif
38+
39+
#define SCI_CH DEFAULT_DBG_CH
40+
#define SCI_BAUD 115200
41+
#define UART_CH SCI_CH
42+
#define UART_TxStr sci_tx_str
43+
#define PCLK 100000000
44+
45+
#define RA_PRI_SYSTICK (0)
46+
#define RA_PRI_UART (1)
47+
#define RA_PRI_SDIO (4)
48+
#define RA_PRI_DMA (5)
49+
#define RA_PRI_FLASH (6)
50+
#define RA_PRI_OTG_FS (6)
51+
#define RA_PRI_OTG_HS (6)
52+
#define RA_PRI_TIM5 (6)
53+
#define RA_PRI_CAN (7)
54+
#define RA_PRI_SPI (8)
55+
#define RA_PRI_I2C (8)
56+
#define RA_PRI_TIMX (13)
57+
#define RA_PRI_EXTINT (14)
58+
#define RA_PRI_PENDSV (15)
59+
#define RA_PRI_RTC_WKUP (15)
60+
61+
#include "ra_config.h"
62+
#include "ra_adc.h"
63+
#include "ra_dac.h"
64+
#include "ra_flash.h"
65+
#include "ra_gpio.h"
66+
#include "ra_gpt.h"
67+
#include "ra_i2c.h"
68+
#include "ra_icu.h"
69+
#include "ra_init.h"
70+
#include "ra_int.h"
71+
#include "ra_rtc.h"
72+
#include "ra_sci.h"
73+
#include "ra_spi.h"
74+
#include "ra_timer.h"
75+
#include "ra_utils.h"
76+
77+
typedef enum {
78+
HAL_OK = 0x00,
79+
HAL_ERROR = 0x01,
80+
HAL_BUSY = 0x02,
81+
HAL_TIMEOUT = 0x03
82+
} HAL_StatusTypeDef;
83+
84+
#define __IO volatile
85+
86+
#if defined(USE_DBG_PRINT)
87+
#if !defined(DEBUG_CH)
88+
#define DEBUG_CH SCI_CH
89+
#endif
90+
#if (DEBUG_CH == 6)
91+
#define DEBUG_TX_PIN P506
92+
#define DEBUG_RX_PIN P505
93+
#endif
94+
#if (DEBUG_CH == 7)
95+
#define DEBUG_TX_PIN P613
96+
#define DEBUG_RX_PIN P614
97+
#endif
98+
#if (DEBUG_CH == 9)
99+
#define DEBUG_TX_PIN P109
100+
#define DEBUG_RX_PIN P110
101+
#endif
102+
#define DEBUG_TXSTR(s) ra_sci_tx_str(DEBUG_CH, (unsigned char *)s)
103+
#define DEBUG_TXCH(c) ra_sci_tx_ch(DEBUG_CH, c)
104+
#else
105+
#define DEBUG_TXSTR(s)
106+
#define DEBUG_TXCH(c)
107+
#endif
108+
109+
#endif /* PORTS_RA_RA6M5_HAL_H_ */

ports/renesas-ra/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Currently supported features are:
66
- Filesystem on the internal flash using FatFs.
77
- `time` module with sleep, time, and ticks functions.
88
- `os` module with VFS support.
9-
- `machine` module with the following classes: `Pin`, `ADC`, `I2C`, `SPI`,
10-
`SoftI2C`, `SoftSPI`, `UART`, `RTC`
11-
- sdcard driver if frozen driver is installed.
9+
- `machine` module with the following classes: `Pin`, `ADC`, `PWM`, `DAC`, `I2C`,
10+
`SPI`, `SoftI2C`, `SoftSPI`, `UART`, `RTC`, `SDCard`.
11+
- `sdcard` module for MCUs without native `machine.SDCard` support.
1212

1313
Currently supported board product names are:
1414

0 commit comments

Comments
 (0)