Skip to content

Commit 789e478

Browse files
committed
add portenta c33 bsp, add flash by dfu-util
1 parent 1cccbaf commit 789e478

14 files changed

+665
-5
lines changed

examples/rules.mk

+11-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ linkermap: $(BUILD)/$(PROJECT).elf
8888
# Flash Targets
8989
# ---------------------------------------
9090

91-
# Jlink binary
91+
# --------------- Jlink -----------------
9292
ifeq ($(OS),Windows_NT)
9393
JLINKEXE = JLink.exe
9494
else
@@ -110,29 +110,36 @@ $(BUILD)/$(BOARD).jlink: $(BUILD)/$(PROJECT).hex
110110
flash-jlink: $(BUILD)/$(BOARD).jlink
111111
$(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $<
112112

113+
# --------------- stm32 cube programmer -----------------
113114
# Flash STM32 MCU using stlink with STM32 Cube Programmer CLI
114115
flash-stlink: $(BUILD)/$(PROJECT).elf
115116
STM32_Programmer_CLI --connect port=swd --write $< --go
116117

118+
# --------------- xfel -----------------
117119
$(BUILD)/$(PROJECT)-sunxi.bin: $(BUILD)/$(PROJECT).bin
118120
$(PYTHON) $(TOP)/tools/mksunxi.py $< $@
119121

120122
flash-xfel: $(BUILD)/$(PROJECT)-sunxi.bin
121123
xfel spinor write 0 $<
122124
xfel reset
123125

124-
# Flash using pyocd
126+
# --------------- pyocd -----------------
125127
PYOCD_OPTION ?=
126128
flash-pyocd: $(BUILD)/$(PROJECT).hex
127129
pyocd flash -t $(PYOCD_TARGET) $(PYOCD_OPTION) $<
128130
#pyocd reset -t $(PYOCD_TARGET)
129131

130-
# Flash using openocd
132+
# --------------- openocd -----------------
131133
OPENOCD_OPTION ?=
132134
flash-openocd: $(BUILD)/$(PROJECT).elf
133135
openocd $(OPENOCD_OPTION) -c "program $< verify reset exit"
134136

135-
# flash with Black Magic Probe
137+
# --------------- dfu-util -----------------
138+
DFU_UTIL_OPTION ?= -a 0
139+
flash-dfu-util: $(BUILD)/$(PROJECT).bin
140+
dfu-util -R $(DFU_UTIL_OPTION) -D $<
141+
142+
# --------------- Black Magic -----------------
136143
# This symlink is created by https://github.com/blacksphere/blackmagic/blob/master/driver/99-blackmagic.rules
137144
BMP ?= /dev/ttyBmpGdb
138145

hw/bsp/family_support.cmake

+12
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ function(family_flash_nxplink TARGET)
407407
endfunction()
408408

409409

410+
function(family_flash_dfu_util TARGET OPTION)
411+
if (NOT DEFINED DFU_UTIL)
412+
set(DFU_UTIL dfu-util)
413+
endif ()
414+
415+
add_custom_target(${TARGET}-dfu-util
416+
DEPENDS ${TARGET}
417+
COMMAND ${DFU_UTIL} -R -d ${DFU_UTIL_VID_PID} -a 0 -D $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.bin
418+
VERBATIM
419+
)
420+
endfunction()
421+
410422
#----------------------------------
411423
# Family specific
412424
#----------------------------------
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
set(CMAKE_SYSTEM_PROCESSOR cortex-m33 CACHE INTERNAL "System Processor")
2+
set(MCU_VARIANT ra6m5)
3+
4+
set(JLINK_DEVICE R7FA6M5BH)
5+
set(DFU_UTIL_VID_PID 2341:0368)
6+
7+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/${BOARD}.ld)
8+
9+
# Device port default to PORT1 Highspeed
10+
if (NOT DEFINED PORT)
11+
set(PORT 1)
12+
endif()
13+
14+
# Host port will be the other port
15+
set(HOST_PORT $<NOT:${PORT}>)
16+
17+
function(update_board TARGET)
18+
target_compile_definitions(${TARGET} PUBLIC
19+
BOARD_TUD_RHPORT=${PORT}
20+
BOARD_TUH_RHPORT=${HOST_PORT}
21+
# port 0 is fullspeed, port 1 is highspeed
22+
BOARD_TUD_MAX_SPEED=$<IF:${PORT},OPT_MODE_HIGH_SPEED,OPT_MODE_FULL_SPEED>
23+
BOARD_TUH_MAX_SPEED=$<IF:${HOST_PORT},OPT_MODE_HIGH_SPEED,OPT_MODE_FULL_SPEED>
24+
)
25+
endfunction()

hw/bsp/ra/boards/portenta_c33/board.h

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2023 Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
#ifndef _BOARD_H_
28+
#define _BOARD_H_
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
#define LED1 BSP_IO_PORT_01_PIN_07 // Red LED
35+
#define LED_STATE_ON 1
36+
37+
#define SW1 BSP_IO_PORT_04_PIN_08 // D12
38+
#define BUTTON_STATE_ACTIVE 0
39+
40+
static const ioport_pin_cfg_t board_pin_cfg[] = {
41+
{ .pin = LED1, .pin_cfg = IOPORT_CFG_PORT_DIRECTION_OUTPUT | IOPORT_CFG_PORT_OUTPUT_LOW },
42+
{ .pin = SW1, .pin_cfg = IOPORT_CFG_PORT_DIRECTION_INPUT },
43+
44+
// USB FS
45+
{ .pin = BSP_IO_PORT_04_PIN_07, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_USB_FS | IOPORT_CFG_DRIVE_HIGH },
46+
{ .pin = BSP_IO_PORT_05_PIN_00, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_USB_FS | IOPORT_CFG_DRIVE_HIGH},
47+
{ .pin = BSP_IO_PORT_05_PIN_01, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_USB_FS | IOPORT_CFG_DRIVE_HIGH},
48+
49+
// USB HS
50+
{ .pin = BSP_IO_PORT_07_PIN_07, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_USB_HS },
51+
{ .pin = BSP_IO_PORT_11_PIN_00, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_USB_HS | IOPORT_CFG_DRIVE_HIGH},
52+
{ .pin = BSP_IO_PORT_11_PIN_01, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_USB_HS | IOPORT_CFG_DRIVE_HIGH},
53+
54+
// ETM Trace
55+
#ifdef TRACE_ETM
56+
{ .pin = BSP_IO_PORT_02_PIN_08, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_TRACE | IOPORT_CFG_DRIVE_HS_HIGH },
57+
{ .pin = BSP_IO_PORT_02_PIN_09, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_TRACE | IOPORT_CFG_DRIVE_HS_HIGH },
58+
{ .pin = BSP_IO_PORT_02_PIN_10, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_TRACE | IOPORT_CFG_DRIVE_HS_HIGH },
59+
{ .pin = BSP_IO_PORT_02_PIN_11, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_TRACE | IOPORT_CFG_DRIVE_HS_HIGH },
60+
{ .pin = BSP_IO_PORT_02_PIN_14, .pin_cfg = IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_TRACE | IOPORT_CFG_DRIVE_HS_HIGH },
61+
#endif
62+
};
63+
64+
#ifdef __cplusplus
65+
}
66+
#endif
67+
68+
#endif
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CPU_CORE = cortex-m33
2+
MCU_VARIANT = ra6m5
3+
4+
LD_FILE = ${BOARD_PATH}/${BOARD}.ld
5+
6+
# Port 1 is highspeed
7+
PORT ?= 1
8+
9+
JLINK_DEVICE = R7FA6M5BH
10+
DFU_UTIL_OPTION = -d 2341:0368 -a 0
11+
12+
flash: flash-dfu-util
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* generated configuration header file - do not edit */
2+
#ifndef BSP_CFG_H_
3+
#define BSP_CFG_H_
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include "bsp_clock_cfg.h"
9+
#include "bsp_mcu_family_cfg.h"
10+
#include "board_cfg.h"
11+
12+
#define RA_NOT_DEFINED 0
13+
#ifndef BSP_CFG_RTOS
14+
#if (RA_NOT_DEFINED) != (2)
15+
#define BSP_CFG_RTOS (2)
16+
#elif (RA_NOT_DEFINED) != (RA_NOT_DEFINED)
17+
#define BSP_CFG_RTOS (1)
18+
#else
19+
#define BSP_CFG_RTOS (0)
20+
#endif
21+
#endif
22+
#ifndef BSP_CFG_RTC_USED
23+
#define BSP_CFG_RTC_USED (RA_NOT_DEFINED)
24+
#endif
25+
#undef RA_NOT_DEFINED
26+
#if defined(_RA_BOOT_IMAGE)
27+
#define BSP_CFG_BOOT_IMAGE (1)
28+
#endif
29+
#define BSP_CFG_MCU_VCC_MV (3300)
30+
#define BSP_CFG_STACK_MAIN_BYTES (0x1000)
31+
#define BSP_CFG_HEAP_BYTES (0x1000)
32+
#define BSP_CFG_PARAM_CHECKING_ENABLE (1)
33+
#define BSP_CFG_ASSERT (0)
34+
#define BSP_CFG_ERROR_LOG (0)
35+
36+
#define BSP_CFG_PFS_PROTECT ((1))
37+
38+
#define BSP_CFG_C_RUNTIME_INIT ((1))
39+
#define BSP_CFG_EARLY_INIT ((0))
40+
41+
#define BSP_CFG_STARTUP_CLOCK_REG_NOT_RESET ((0))
42+
43+
#ifndef BSP_CLOCK_CFG_MAIN_OSC_POPULATED
44+
#define BSP_CLOCK_CFG_MAIN_OSC_POPULATED (1)
45+
#endif
46+
47+
#ifndef BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE
48+
#define BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE (0)
49+
#endif
50+
#ifndef BSP_CLOCK_CFG_SUBCLOCK_DRIVE
51+
#define BSP_CLOCK_CFG_SUBCLOCK_DRIVE (0)
52+
#endif
53+
#ifndef BSP_CLOCK_CFG_SUBCLOCK_POPULATED
54+
#define BSP_CLOCK_CFG_SUBCLOCK_POPULATED (1)
55+
#endif
56+
#ifndef BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS
57+
#define BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS 1000
58+
#endif
59+
60+
#ifdef __cplusplus
61+
}
62+
#endif
63+
#endif /* BSP_CFG_H_ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* generated configuration header file - do not edit */
2+
#ifndef BSP_MCU_DEVICE_CFG_H_
3+
#define BSP_MCU_DEVICE_CFG_H_
4+
#define BSP_CFG_MCU_PART_SERIES (6)
5+
#endif /* BSP_MCU_DEVICE_CFG_H_ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* generated configuration header file - do not edit */
2+
#ifndef BSP_MCU_DEVICE_PN_CFG_H_
3+
#define BSP_MCU_DEVICE_PN_CFG_H_
4+
#define BSP_MCU_R7FA6M5BH3CFC
5+
#define BSP_MCU_FEATURE_SET ('B')
6+
#define BSP_ROM_SIZE_BYTES (2097152)
7+
#define BSP_RAM_SIZE_BYTES (524288)
8+
#define BSP_DATA_FLASH_SIZE_BYTES (8192)
9+
#define BSP_PACKAGE_LQFP
10+
#define BSP_PACKAGE_PINS (176)
11+
#endif /* BSP_MCU_DEVICE_PN_CFG_H_ */

0 commit comments

Comments
 (0)