Skip to content

Commit d65964e

Browse files
authored
Merge pull request #3519 from hathach/samx7x_update
refresh dcd_samx7x
2 parents 5f69034 + 1c53009 commit d65964e

File tree

16 files changed

+406
-510
lines changed

16 files changed

+406
-510
lines changed

examples/device/audio_4_channel_mic_freertos/skip.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ mcu:MKL25ZXX
99
mcu:MSP430x5xx
1010
mcu:RP2040
1111
mcu:SAMD11
12-
mcu:SAMX7X
1312
mcu:VALENTYUSB_EPTRI
1413
mcu:RAXXX
1514
mcu:STM32L0

examples/device/audio_test_freertos/skip.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ mcu:MKL25ZXX
99
mcu:MSP430x5xx
1010
mcu:RP2040
1111
mcu:SAMD11
12-
mcu:SAMX7X
1312
mcu:VALENTYUSB_EPTRI
1413
mcu:RAXXX
1514
family:broadcom_32bit

examples/device/cdc_msc_freertos/skip.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ mcu:MKL25ZXX
99
mcu:MSP430x5xx
1010
mcu:RP2040
1111
mcu:SAMD11
12-
mcu:SAMX7X
1312
mcu:VALENTYUSB_EPTRI
1413
mcu:RAXXX
1514
mcu:STM32L0

examples/device/hid_composite_freertos/skip.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ mcu:MKL25ZXX
99
mcu:MSP430x5xx
1010
mcu:RP2040
1111
mcu:SAMD11
12-
mcu:SAMX7X
1312
mcu:VALENTYUSB_EPTRI
1413
mcu:RAXXX
1514
family:broadcom_32bit

examples/device/midi_test_freertos/skip.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ mcu:MKL25ZXX
99
mcu:MSP430x5xx
1010
mcu:RP2040
1111
mcu:SAMD11
12-
mcu:SAMX7X
1312
mcu:VALENTYUSB_EPTRI
1413
mcu:RAXXX
1514
family:broadcom_32bit

hw/bsp/same7x/boards/same70_qmtech/board.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
set(JLINK_DEVICE SAME70N19B)
2-
set(LD_FILE_GNU ${TOP}/hw/mcu/microchip/same70/same70b/gcc/gcc/same70q21b_flash.ld)
1+
set(JLINK_DEVICE ATSAME70N19B)
2+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/same70n19b_flash.ld)
3+
4+
# N19B and Q21B share the same vector table / startup code
5+
set(STARTUP_FILE_GNU ${TOP}/hw/mcu/microchip/same70/same70b/gcc/gcc/startup_same70q21b.c)
36

47
function(update_board TARGET)
58
target_compile_definitions(${TARGET} PUBLIC
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
CFLAGS += -D__SAME70N19B__
22

3-
JLINK_DEVICE = SAME70N19B
3+
LD_FILE = $(BOARD_PATH)/same70n19b_flash.ld
4+
STARTUP_FILE = $(SDK_DIR)/same70b/gcc/gcc/startup_same70q21b.c
5+
6+
JLINK_DEVICE = ATSAME70N19B

hw/bsp/same7x/boards/same70_xplained/board.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
set(JLINK_DEVICE SAME70Q21B)
1+
set(JLINK_DEVICE ATSAME70Q21B)
22
set(LD_FILE_GNU ${TOP}/hw/mcu/microchip/same70/same70b/gcc/gcc/same70q21b_flash.ld)
3+
set(LD_FILE_IAR ${TOP}/hw/mcu/microchip/same70/same70b/iar/config/linker/Microchip/atsame70q21b/flash.icf)
4+
5+
set(STARTUP_FILE_GNU ${TOP}/hw/mcu/microchip/same70/same70b/gcc/gcc/startup_same70q21b.c)
6+
set(STARTUP_FILE_IAR ${TOP}/hw/mcu/microchip/same70/same70b/iar/iar/startup_same70q21b.c)
37

48
function(update_board TARGET)
59
target_compile_definitions(${TARGET} PUBLIC
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
CFLAGS += -D__SAME70Q21B__
22

3-
JLINK_DEVICE = SAME70Q21B
3+
LD_FILE = $(SDK_DIR)/same70b/gcc/gcc/same70q21b_flash.ld
4+
STARTUP_FILE = $(SDK_DIR)/same70b/gcc/gcc/startup_same70q21b.c
5+
6+
JLINK_DEVICE = ATSAME70Q21B

hw/bsp/same7x/family.c

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -42,56 +42,15 @@ static inline void board_vbus_set(uint8_t rhport, bool state);
4242
void _init(void);
4343
#include "board.h"
4444

45-
#ifndef LED_STATE_ON
46-
#define LED_STATE_ON 1
47-
#endif
48-
49-
#ifndef LED_PORT_CLOCK
50-
#define LED_PORT_CLOCK ID_PIOA
51-
#endif
52-
53-
#ifndef BUTTON_PORT_CLOCK
54-
#define BUTTON_PORT_CLOCK ID_PIOA
55-
#endif
56-
57-
#ifndef UART_PORT_CLOCK
58-
#define UART_PORT_CLOCK ID_USART1
59-
#endif
60-
61-
#ifndef BOARD_USART
62-
#define BOARD_USART USART1
63-
#endif
64-
65-
#ifndef BOARD_UART_DESCRIPTOR
66-
#define BOARD_UART_DESCRIPTOR edbg_com
67-
#endif
68-
69-
#ifndef BOARD_UART_BUFFER
70-
#define BOARD_UART_BUFFER edbg_com_buffer
71-
#endif
72-
73-
#ifndef BUTTON_STATE_ACTIVE
74-
#define BUTTON_STATE_ACTIVE 0
75-
#endif
76-
77-
#ifndef UART_TX_FUNCTION
78-
#define UART_TX_FUNCTION MUX_PB4D_USART1_TXD1
79-
#endif
80-
81-
#ifndef UART_RX_FUNCTION
82-
#define UART_RX_FUNCTION MUX_PA21A_USART1_RXD1
83-
#endif
84-
8545
#ifndef UART_BUFFER_SIZE
8646
#define UART_BUFFER_SIZE 64
8747
#endif
8848

8949
#define LED_STATE_OFF (1 - LED_STATE_ON)
9050

91-
static struct usart_async_descriptor BOARD_UART_DESCRIPTOR;
92-
static uint8_t BOARD_UART_BUFFER[UART_BUFFER_SIZE];
51+
static struct usart_async_descriptor edbg_com;
52+
static uint8_t edbg_com_buffer[UART_BUFFER_SIZE];
9353
static volatile bool uart_busy = false;
94-
9554
static void tx_complete_cb(const struct usart_async_descriptor *const io_descr) {
9655
(void) io_descr;
9756
uart_busy = false;
@@ -121,10 +80,10 @@ void board_init(void) {
12180
gpio_set_pin_function(UART_RX_PIN, UART_RX_FUNCTION);
12281
gpio_set_pin_function(UART_TX_PIN, UART_TX_FUNCTION);
12382

124-
usart_async_init(&BOARD_UART_DESCRIPTOR, BOARD_USART, BOARD_UART_BUFFER, sizeof(BOARD_UART_BUFFER), _usart_get_usart_async());
125-
usart_async_set_baud_rate(&BOARD_UART_DESCRIPTOR, CFG_BOARD_UART_BAUDRATE);
126-
usart_async_register_callback(&BOARD_UART_DESCRIPTOR, USART_ASYNC_TXC_CB, tx_complete_cb);
127-
usart_async_enable(&BOARD_UART_DESCRIPTOR);
83+
usart_async_init(&edbg_com, BOARD_USART, edbg_com_buffer, sizeof(edbg_com_buffer), _usart_get_usart_async());
84+
usart_async_set_baud_rate(&edbg_com, CFG_BOARD_UART_BAUDRATE);
85+
usart_async_register_callback(&edbg_com, USART_ASYNC_TXC_CB, tx_complete_cb);
86+
usart_async_enable(&edbg_com);
12887

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

184-
io_write(&BOARD_UART_DESCRIPTOR.io, buf, len);
143+
io_write(&edbg_com.io, buf, len);
185144
return len;
186145
}
187146

147+
// Read 128-bit unique ID via EFC STUI/SPUI commands
148+
// Must run from RAM since STUI remaps flash to the unique ID
149+
__attribute__((noinline)) TU_ATTR_SECTION(.ramfunc) static void read_unique_id(uint32_t uid[4]) {
150+
// Wait for flash to be ready
151+
while (!(EFC->EEFC_FSR & EEFC_FSR_FRDY)) {}
152+
153+
// Issue Start Read Unique Identifier command
154+
EFC->EEFC_FCR = EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_STUI;
155+
while (EFC->EEFC_FSR & EEFC_FSR_FRDY) {}
156+
157+
// Read 128-bit unique ID from flash base address
158+
const volatile uint32_t *flash = (const volatile uint32_t *) IFLASH_ADDR;
159+
for (int i = 0; i < 4; i++) {
160+
uid[i] = flash[i];
161+
}
162+
163+
// Issue Stop Read Unique Identifier command
164+
EFC->EEFC_FCR = EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_SPUI;
165+
while (!(EFC->EEFC_FSR & EEFC_FSR_FRDY)) {}
166+
}
167+
168+
size_t board_get_unique_id(uint8_t id[], size_t max_len) {
169+
const size_t uid_len = 16;
170+
if (max_len < uid_len) {
171+
return 0;
172+
}
173+
read_unique_id((uint32_t *)(uintptr_t) id);
174+
return uid_len;
175+
}
176+
188177
#if CFG_TUSB_OS == OPT_OS_NONE
189178
volatile uint32_t system_ticks = 0;
190179

0 commit comments

Comments
 (0)