Skip to content
1 change: 0 additions & 1 deletion examples/device/audio_4_channel_mic_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mcu:MKL25ZXX
mcu:MSP430x5xx
mcu:RP2040
mcu:SAMD11
mcu:SAMX7X
mcu:VALENTYUSB_EPTRI
mcu:RAXXX
mcu:STM32L0
Expand Down
1 change: 0 additions & 1 deletion examples/device/audio_test_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mcu:MKL25ZXX
mcu:MSP430x5xx
mcu:RP2040
mcu:SAMD11
mcu:SAMX7X
mcu:VALENTYUSB_EPTRI
mcu:RAXXX
family:broadcom_32bit
Expand Down
1 change: 0 additions & 1 deletion examples/device/cdc_msc_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mcu:MKL25ZXX
mcu:MSP430x5xx
mcu:RP2040
mcu:SAMD11
mcu:SAMX7X
mcu:VALENTYUSB_EPTRI
mcu:RAXXX
mcu:STM32L0
Expand Down
1 change: 0 additions & 1 deletion examples/device/hid_composite_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mcu:MKL25ZXX
mcu:MSP430x5xx
mcu:RP2040
mcu:SAMD11
mcu:SAMX7X
mcu:VALENTYUSB_EPTRI
mcu:RAXXX
family:broadcom_32bit
Expand Down
1 change: 0 additions & 1 deletion examples/device/midi_test_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mcu:MKL25ZXX
mcu:MSP430x5xx
mcu:RP2040
mcu:SAMD11
mcu:SAMX7X
mcu:VALENTYUSB_EPTRI
mcu:RAXXX
family:broadcom_32bit
Expand Down
7 changes: 5 additions & 2 deletions hw/bsp/same7x/boards/same70_qmtech/board.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
set(JLINK_DEVICE SAME70N19B)
set(LD_FILE_GNU ${TOP}/hw/mcu/microchip/same70/same70b/gcc/gcc/same70q21b_flash.ld)
set(JLINK_DEVICE ATSAME70N19B)
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/same70n19b_flash.ld)

# N19B and Q21B share the same vector table / startup code
set(STARTUP_FILE_GNU ${TOP}/hw/mcu/microchip/same70/same70b/gcc/gcc/startup_same70q21b.c)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
Expand Down
5 changes: 4 additions & 1 deletion hw/bsp/same7x/boards/same70_qmtech/board.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
CFLAGS += -D__SAME70N19B__

JLINK_DEVICE = SAME70N19B
LD_FILE = $(BOARD_PATH)/same70n19b_flash.ld
STARTUP_FILE = $(SDK_DIR)/same70b/gcc/gcc/startup_same70q21b.c

JLINK_DEVICE = ATSAME70N19B
6 changes: 5 additions & 1 deletion hw/bsp/same7x/boards/same70_xplained/board.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
set(JLINK_DEVICE SAME70Q21B)
set(JLINK_DEVICE ATSAME70Q21B)
set(LD_FILE_GNU ${TOP}/hw/mcu/microchip/same70/same70b/gcc/gcc/same70q21b_flash.ld)
set(LD_FILE_IAR ${TOP}/hw/mcu/microchip/same70/same70b/iar/config/linker/Microchip/atsame70q21b/flash.icf)

set(STARTUP_FILE_GNU ${TOP}/hw/mcu/microchip/same70/same70b/gcc/gcc/startup_same70q21b.c)
set(STARTUP_FILE_IAR ${TOP}/hw/mcu/microchip/same70/same70b/iar/iar/startup_same70q21b.c)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
Expand Down
5 changes: 4 additions & 1 deletion hw/bsp/same7x/boards/same70_xplained/board.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
CFLAGS += -D__SAME70Q21B__

JLINK_DEVICE = SAME70Q21B
LD_FILE = $(SDK_DIR)/same70b/gcc/gcc/same70q21b_flash.ld
STARTUP_FILE = $(SDK_DIR)/same70b/gcc/gcc/startup_same70q21b.c

JLINK_DEVICE = ATSAME70Q21B
85 changes: 37 additions & 48 deletions hw/bsp/same7x/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,56 +42,15 @@ static inline void board_vbus_set(uint8_t rhport, bool state);
void _init(void);
#include "board.h"

#ifndef LED_STATE_ON
#define LED_STATE_ON 1
#endif

#ifndef LED_PORT_CLOCK
#define LED_PORT_CLOCK ID_PIOA
#endif

#ifndef BUTTON_PORT_CLOCK
#define BUTTON_PORT_CLOCK ID_PIOA
#endif

#ifndef UART_PORT_CLOCK
#define UART_PORT_CLOCK ID_USART1
#endif

#ifndef BOARD_USART
#define BOARD_USART USART1
#endif

#ifndef BOARD_UART_DESCRIPTOR
#define BOARD_UART_DESCRIPTOR edbg_com
#endif

#ifndef BOARD_UART_BUFFER
#define BOARD_UART_BUFFER edbg_com_buffer
#endif

#ifndef BUTTON_STATE_ACTIVE
#define BUTTON_STATE_ACTIVE 0
#endif

#ifndef UART_TX_FUNCTION
#define UART_TX_FUNCTION MUX_PB4D_USART1_TXD1
#endif

#ifndef UART_RX_FUNCTION
#define UART_RX_FUNCTION MUX_PA21A_USART1_RXD1
#endif

#ifndef UART_BUFFER_SIZE
#define UART_BUFFER_SIZE 64
#endif

#define LED_STATE_OFF (1 - LED_STATE_ON)

static struct usart_async_descriptor BOARD_UART_DESCRIPTOR;
static uint8_t BOARD_UART_BUFFER[UART_BUFFER_SIZE];
static struct usart_async_descriptor edbg_com;
static uint8_t edbg_com_buffer[UART_BUFFER_SIZE];
static volatile bool uart_busy = false;

static void tx_complete_cb(const struct usart_async_descriptor *const io_descr) {
(void) io_descr;
uart_busy = false;
Expand Down Expand Up @@ -121,10 +80,10 @@ void board_init(void) {
gpio_set_pin_function(UART_RX_PIN, UART_RX_FUNCTION);
gpio_set_pin_function(UART_TX_PIN, UART_TX_FUNCTION);

usart_async_init(&BOARD_UART_DESCRIPTOR, BOARD_USART, BOARD_UART_BUFFER, sizeof(BOARD_UART_BUFFER), _usart_get_usart_async());
usart_async_set_baud_rate(&BOARD_UART_DESCRIPTOR, CFG_BOARD_UART_BAUDRATE);
usart_async_register_callback(&BOARD_UART_DESCRIPTOR, USART_ASYNC_TXC_CB, tx_complete_cb);
usart_async_enable(&BOARD_UART_DESCRIPTOR);
usart_async_init(&edbg_com, BOARD_USART, edbg_com_buffer, sizeof(edbg_com_buffer), _usart_get_usart_async());
usart_async_set_baud_rate(&edbg_com, CFG_BOARD_UART_BAUDRATE);
usart_async_register_callback(&edbg_com, USART_ASYNC_TXC_CB, tx_complete_cb);
usart_async_enable(&edbg_com);

#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer (SystemCoreClock may not be correct after init)
Expand Down Expand Up @@ -181,10 +140,40 @@ int board_uart_write(void const *buf, int len) {
while (uart_busy) {}
uart_busy = true;

io_write(&BOARD_UART_DESCRIPTOR.io, buf, len);
io_write(&edbg_com.io, buf, len);
return len;
}

// Read 128-bit unique ID via EFC STUI/SPUI commands
// Must run from RAM since STUI remaps flash to the unique ID
__attribute__((noinline)) TU_ATTR_SECTION(.ramfunc) static void read_unique_id(uint32_t uid[4]) {
// Wait for flash to be ready
while (!(EFC->EEFC_FSR & EEFC_FSR_FRDY)) {}

// Issue Start Read Unique Identifier command
EFC->EEFC_FCR = EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_STUI;
while (EFC->EEFC_FSR & EEFC_FSR_FRDY) {}

// Read 128-bit unique ID from flash base address
const volatile uint32_t *flash = (const volatile uint32_t *) IFLASH_ADDR;
for (int i = 0; i < 4; i++) {
uid[i] = flash[i];
}

// Issue Stop Read Unique Identifier command
EFC->EEFC_FCR = EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_SPUI;
while (!(EFC->EEFC_FSR & EEFC_FSR_FRDY)) {}
}

size_t board_get_unique_id(uint8_t id[], size_t max_len) {
const size_t uid_len = 16;
if (max_len < uid_len) {
return 0;
}
read_unique_id((uint32_t *)(uintptr_t) id);
return uid_len;
}

#if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0;

Expand Down
20 changes: 10 additions & 10 deletions hw/bsp/same7x/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ set(FAMILY_MCUS SAMX7X CACHE INTERNAL "")
#------------------------------------
# Startup & Linker script
#------------------------------------
set(STARTUP_FILE_GNU ${SDK_DIR}/same70b/gcc/gcc/startup_same70q21b.c)
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
set(LD_FILE_Clang ${LD_FILE_GNU})

Expand Down Expand Up @@ -47,12 +46,9 @@ function(family_add_board BOARD_TARGET)

update_board(${BOARD_TARGET})

target_compile_options(${BOARD_TARGET} PUBLIC
-Wno-error=unused-parameter
-Wno-error=cast-align
-Wno-error=redundant-decls
-Wno-error=cast-qual
)
if (TOOLCHAIN STREQUAL "gcc" OR TOOLCHAIN STREQUAL "clang")
set_target_properties(${BOARD_TARGET} PROPERTIES COMPILE_FLAGS -Wno-error=cast-qual)
endif ()
endfunction()

#------------------------------------
Expand Down Expand Up @@ -89,9 +85,13 @@ function(family_configure_example TARGET RTOS)
"LINKER:--config=${LD_FILE_IAR}"
)
endif ()
set_source_files_properties(${STARTUP_FILE_${CMAKE_C_COMPILER_ID}} PROPERTIES
SKIP_LINTING ON
COMPILE_OPTIONS -w)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
# ignore hal error
set_source_files_properties(${STARTUP_FILE_${CMAKE_C_COMPILER_ID}} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
PROPERTIES
SKIP_LINTING ON
COMPILE_OPTIONS -w)
endif()

family_add_bin_hex(${TARGET})
family_flash_jlink(${TARGET})
Expand Down
7 changes: 1 addition & 6 deletions hw/bsp/same7x/family.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ CFLAGS_SKIP += -Wcast-qual
LDFLAGS_GCC += -specs=nosys.specs -specs=nano.specs

# All source paths should be relative to the top level.
LD_FILE = $(SDK_DIR)/same70b/gcc/gcc/same70q21b_flash.ld

SRC_C += \
src/portable/microchip/samx7x/dcd_samx7x.c \
$(SDK_DIR)/same70b/gcc/gcc/startup_same70q21b.c \
$(STARTUP_FILE) \
$(SDK_DIR)/same70b/gcc/system_same70q21b.c \
$(SDK_DIR)/hpl/core/hpl_init.c \
$(SDK_DIR)/hpl/usart/hpl_usart.c \
Expand All @@ -48,9 +46,6 @@ INC += \
$(TOP)/$(SDK_DIR)/hri \
$(TOP)/$(SDK_DIR)/CMSIS/Core/Include

# For freeRTOS port source
FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM7

# For flash-jlink target
flash: $(BUILD)/$(PROJECT).bin
edbg --verbose -t same70 -pv -f $<
4 changes: 4 additions & 0 deletions src/common/tusb_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@
#define TUP_RHPORT_HIGHSPEED 1
#define TUD_ENDPOINT_ONE_DIRECTION_ONLY

// Enable dcache if DMA is enabled
#define CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT CFG_TUD_SAMX7X_DMA_ENABLE
#define CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT 32

#elif TU_CHECK_MCU(OPT_MCU_PIC32MZ)
#define TUP_DCD_ENDPOINT_MAX 8
#define TUD_ENDPOINT_ONE_DIRECTION_ONLY
Expand Down
Loading
Loading