add uid for some stm32

This commit is contained in:
hathach 2023-08-04 00:20:47 +07:00
parent 041f510f90
commit 9360a3bd51
No known key found for this signature in database
GPG Key ID: F5D50C6D51D17CBA
9 changed files with 281 additions and 261 deletions

View File

@ -25,7 +25,7 @@
</envs> </envs>
</ADDITIONAL_GENERATION_ENVIRONMENT> </ADDITIONAL_GENERATION_ENVIRONMENT>
</configuration> </configuration>
<configuration PROFILE_NAME="rp2040" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberry_pi_pico -DLOG=2 -DLOGGER=RTT" /> <configuration PROFILE_NAME="rp2040" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberry_pi_pico" />
<configuration PROFILE_NAME="metro m7 1011" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=metro_m7_1011 -DLOG=3 -DLOGGER=RTT -DTRACE_ETM=1" /> <configuration PROFILE_NAME="metro m7 1011" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=metro_m7_1011 -DLOG=3 -DLOGGER=RTT -DTRACE_ETM=1" />
<configuration PROFILE_NAME="rt1010 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1010_evk -DLOG=3 -DLOGGER=RTT" /> <configuration PROFILE_NAME="rt1010 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1010_evk -DLOG=3 -DLOGGER=RTT" />
<configuration PROFILE_NAME="rt1015 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1015_evk -DLOG=1" /> <configuration PROFILE_NAME="rt1015 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1015_evk -DLOG=1" />
@ -43,12 +43,14 @@
<configuration PROFILE_NAME="stm32f072disco" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=stm32f072disco" /> <configuration PROFILE_NAME="stm32f072disco" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=stm32f072disco" />
<configuration PROFILE_NAME="stm32f103_mini_2" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=stm32f103_mini_2" /> <configuration PROFILE_NAME="stm32f103_mini_2" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=stm32f103_mini_2" />
<configuration PROFILE_NAME="stm32f769disco" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=stm32f769disco -DLOG=3 -DLOGGER=RTT" /> <configuration PROFILE_NAME="stm32f769disco" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=stm32f769disco -DLOG=3 -DLOGGER=RTT" />
<configuration PROFILE_NAME="stm32l476disco" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=stm32l476disco" /> <configuration PROFILE_NAME="stm32l476disco" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=stm32l476disco -DLOG=3 -DLOGGER=RTT" />
<configuration PROFILE_NAME="ra4m1" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=ra4m1_ek -DLOG=3 -DLOGGER=RTT" /> <configuration PROFILE_NAME="ra4m1" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=ra4m1_ek -DLOG=3 -DLOGGER=RTT" />
<configuration PROFILE_NAME="ra6m1" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=ra6m1_ek -DLOG=3 -DLOGGER=RTT" /> <configuration PROFILE_NAME="ra6m1" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=ra6m1_ek -DLOG=3 -DLOGGER=RTT" />
<configuration PROFILE_NAME="ra6m5" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=ra6m5_ek -DLOG=3 -DLOGGER=RTT -DTRACE_ETM=1" /> <configuration PROFILE_NAME="ra6m5" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=ra6m5_ek -DLOG=3 -DLOGGER=RTT -DTRACE_ETM=1" />
<configuration PROFILE_NAME="rt1050 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1050_evkb -DLOG=1 -DLOGGER=RTT" /> <configuration PROFILE_NAME="rt1050 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1050_evkb -DLOG=1 -DLOGGER=RTT" />
<configuration PROFILE_NAME="ea4088 quickstart" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=ea4088_quickstart -DLOG=3 -DLOGGER=RTT -DTRACE_ETM=1" /> <configuration PROFILE_NAME="ea4088 quickstart" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=ea4088_quickstart -DLOG=3 -DLOGGER=RTT -DTRACE_ETM=1" />
<configuration PROFILE_NAME="ea4357" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=ea4357 -DLOG=3 -DLOGGER=RTT -DTRACE_ETM=1" />
<configuration PROFILE_NAME="feather_rp2040" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=pico_sdk -DPICO_BOARD=adafruit_feather_rp2040" />
</configurations> </configurations>
</component> </component>
</project> </project>

View File

@ -112,32 +112,33 @@ static inline void board_led_off(void) {
// Get USB Serial number string from unique ID if available. Return number of character. // Get USB Serial number string from unique ID if available. Return number of character.
// Input is string descriptor from index 1 (index 0 is type + len) // Input is string descriptor from index 1 (index 0 is type + len)
static inline size_t board_usb_get_serial(uint16_t desc_str1[], size_t max_chars) { static inline size_t board_usb_get_serial(uint16_t desc_str1[], size_t max_chars) {
uint8_t serial_id[16] TU_ATTR_ALIGNED(4); uint8_t uid[16] TU_ATTR_ALIGNED(4);
size_t serial_len; size_t uid_len;
if ( board_get_unique_id ) { if ( board_get_unique_id ) {
serial_len = board_get_unique_id(serial_id, sizeof(serial_id)); uid_len = board_get_unique_id(uid, sizeof(uid));
}else { }else {
// fixed serial string is 01234567889ABCDEF // fixed serial string is 01234567889ABCDEF
*((uint32_t*)(uintptr_t) serial_id) = 0x67452301; uint32_t* uid32 = (uint32_t*) (uintptr_t) uid;
*((uint32_t*)(uintptr_t) (serial_id+4)) = 0xEFCDAB89; uid32[0] = 0x67452301;
serial_len = 8; uid32[1] = 0xEFCDAB89;
uid_len = 8;
} }
if ( serial_len > max_chars / 2 ) serial_len = max_chars / 2; if ( uid_len > max_chars / 2 ) uid_len = max_chars / 2;
for ( size_t i = 0; i < serial_len; i++ ) { for ( size_t i = 0; i < uid_len; i++ ) {
for ( size_t j = 0; j < 2; j++ ) { for ( size_t j = 0; j < 2; j++ ) {
const char nibble_to_hex[16] = { const char nibble_to_hex[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
}; };
uint8_t const nibble = (serial_id[i] >> (j * 4)) & 0xf; uint8_t const nibble = (uid[i] >> (j * 4)) & 0xf;
desc_str1[i * 2 + (1 - j)] = nibble_to_hex[nibble]; // UTF-16-LE desc_str1[i * 2 + (1 - j)] = nibble_to_hex[nibble]; // UTF-16-LE
} }
} }
return 2*serial_len; return 2 * uid_len;
} }
// TODO remove // TODO remove

View File

@ -31,8 +31,7 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler // Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void USB_IRQHandler(void) void USB_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
@ -41,8 +40,7 @@ void USB_IRQHandler(void)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
UART_HandleTypeDef UartHandle; UART_HandleTypeDef UartHandle;
void board_init(void) void board_init(void) {
{
board_stm32f0_clock_init(); board_stm32f0_clock_init();
// Enable All GPIOs clocks // Enable All GPIOs clocks
@ -116,56 +114,59 @@ void board_init(void)
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_led_write(bool state) void board_led_write(bool state) {
{ GPIO_PinState pin_state = (GPIO_PinState)(state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1-LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state); HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
} }
uint32_t board_button_read(void) uint32_t board_button_read(void) {
{
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN); return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
} }
int board_uart_read(uint8_t* buf, int len) size_t board_get_unique_id(uint8_t id[], size_t max_len) {
{ (void) max_len;
(void) buf; (void) len; volatile uint32_t * stm32_uuid = (volatile uint32_t *) UID_BASE;
uint32_t* id32 = (uint32_t*) (uintptr_t) id;
uint8_t const len = 12;
id32[0] = stm32_uuid[0];
id32[1] = stm32_uuid[1];
id32[2] = stm32_uuid[2];
return len;
}
int board_uart_read(uint8_t *buf, int len) {
(void) buf;
(void) len;
return 0; return 0;
} }
int board_uart_write(void const * buf, int len) int board_uart_write(void const *buf, int len) {
{ HAL_UART_Transmit(&UartHandle, (uint8_t * )(uintptr_t)
HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff); buf, len, 0xffff);
return len; return len;
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler (void)
{ void SysTick_Handler(void) {
HAL_IncTick(); HAL_IncTick();
system_ticks++; system_ticks++;
} }
uint32_t board_millis(void) uint32_t board_millis(void) {
{
return system_ticks; return system_ticks;
} }
#endif #endif
void HardFault_Handler (void) void HardFault_Handler(void) {
{
__asm("BKPT #0\n"); __asm("BKPT #0\n");
} }
#ifdef USE_FULL_ASSERT #ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(const char* file, uint32_t line) void assert_failed(const char* file, uint32_t line)
{ {
(void) file; (void) line; (void) file; (void) line;
@ -178,7 +179,5 @@ void assert_failed(const char* file, uint32_t line)
// Required by __libc_init_array in startup code if we are compiling using // Required by __libc_init_array in startup code if we are compiling using
// -nostdlib/-nostartfiles. // -nostdlib/-nostartfiles.
void _init(void) void _init(void) {
{
} }

View File

@ -31,18 +31,15 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler // Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void USB_HP_IRQHandler(void) void USB_HP_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
void USB_LP_IRQHandler(void) void USB_LP_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
void USBWakeUp_IRQHandler(void) void USBWakeUp_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
@ -50,8 +47,7 @@ void USBWakeUp_IRQHandler(void)
// MACRO TYPEDEF CONSTANT ENUM // MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_init(void) void board_init(void) {
{
board_stm32f1_clock_init(); board_stm32f1_clock_init();
// Enable All GPIOs clocks // Enable All GPIOs clocks
@ -102,56 +98,59 @@ void board_init(void)
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_led_write(bool state) void board_led_write(bool state) {
{ GPIO_PinState pin_state = (GPIO_PinState)(state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1-LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state); HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
} }
uint32_t board_button_read(void) uint32_t board_button_read(void) {
{
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN); return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
} }
int board_uart_read(uint8_t* buf, int len) size_t board_get_unique_id(uint8_t id[], size_t max_len) {
{ (void) max_len;
(void) buf; (void) len; volatile uint32_t * stm32_uuid = (volatile uint32_t *) UID_BASE;
uint32_t* id32 = (uint32_t*) (uintptr_t) id;
uint8_t const len = 12;
id32[0] = stm32_uuid[0];
id32[1] = stm32_uuid[1];
id32[2] = stm32_uuid[2];
return len;
}
int board_uart_read(uint8_t *buf, int len) {
(void) buf;
(void) len;
return 0; return 0;
} }
int board_uart_write(void const * buf, int len) int board_uart_write(void const *buf, int len) {
{ (void) buf;
(void) buf; (void) len; (void) len;
return 0; return 0;
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler (void)
{ void SysTick_Handler(void) {
HAL_IncTick(); HAL_IncTick();
system_ticks++; system_ticks++;
} }
uint32_t board_millis(void) uint32_t board_millis(void) {
{
return system_ticks; return system_ticks;
} }
#endif #endif
void HardFault_Handler (void) void HardFault_Handler(void) {
{
__asm("BKPT #0\n"); __asm("BKPT #0\n");
} }
#ifdef USE_FULL_ASSERT #ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(const char *file, uint32_t line) void assert_failed(const char *file, uint32_t line)
{ {
/* USER CODE BEGIN 6 */ /* USER CODE BEGIN 6 */
@ -163,7 +162,5 @@ void assert_failed(const char *file, uint32_t line)
// Required by __libc_init_array in startup code if we are compiling using // Required by __libc_init_array in startup code if we are compiling using
// -nostdlib/-nostartfiles. // -nostdlib/-nostartfiles.
void _init(void) void _init(void) {
{
} }

View File

@ -33,15 +33,13 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler // Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void) void OTG_FS_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
// Despite being call USB2_OTG // Despite being call USB2_OTG
// OTG_HS is marked as RHPort1 by TinyUSB to be consistent across stm32 port // OTG_HS is marked as RHPort1 by TinyUSB to be consistent across stm32 port
void OTG_HS_IRQHandler(void) void OTG_HS_IRQHandler(void) {
{
tud_int_handler(1); tud_int_handler(1);
} }
@ -51,8 +49,7 @@ void OTG_HS_IRQHandler(void)
UART_HandleTypeDef UartHandle; UART_HandleTypeDef UartHandle;
void board_init(void) void board_init(void) {
{
board_clock_init(); board_clock_init();
// Enable All GPIOs clocks // Enable All GPIOs clocks
@ -276,51 +273,58 @@ void board_init(void)
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_led_write(bool state) void board_led_write(bool state) {
{ GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1-LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state); HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
} }
uint32_t board_button_read(void) uint32_t board_button_read(void) {
{
return HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN); return HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
} }
int board_uart_read(uint8_t* buf, int len) size_t board_get_unique_id(uint8_t id[], size_t max_len) {
{ (void) max_len;
(void) buf; (void) len; volatile uint32_t * stm32_uuid = (volatile uint32_t *) UID_BASE;
uint32_t* id32 = (uint32_t*) (uintptr_t) id;
uint8_t const len = 12;
id32[0] = stm32_uuid[0];
id32[1] = stm32_uuid[1];
id32[2] = stm32_uuid[2];
return len;
}
int board_uart_read(uint8_t *buf, int len) {
(void) buf;
(void) len;
return 0; return 0;
} }
int board_uart_write(void const * buf, int len) int board_uart_write(void const *buf, int len) {
{ HAL_UART_Transmit(&UartHandle, (uint8_t *) (uintptr_t) buf, len, 0xffff);
HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff);
return len; return len;
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler (void)
{ void SysTick_Handler(void) {
HAL_IncTick(); HAL_IncTick();
system_ticks++; system_ticks++;
} }
uint32_t board_millis(void) uint32_t board_millis(void) {
{
return system_ticks; return system_ticks;
} }
#endif #endif
void HardFault_Handler (void) void HardFault_Handler(void) {
{
__asm("BKPT #0\n"); __asm("BKPT #0\n");
} }
// Required by __libc_init_array in startup code if we are compiling using // Required by __libc_init_array in startup code if we are compiling using
// -nostdlib/-nostartfiles. // -nostdlib/-nostartfiles.
void _init(void) void _init(void) {
{
} }

View File

@ -32,8 +32,7 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler // Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void USB_UCPD1_2_IRQHandler(void) void USB_UCPD1_2_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
@ -42,8 +41,7 @@ void USB_UCPD1_2_IRQHandler(void)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
UART_HandleTypeDef UartHandle; UART_HandleTypeDef UartHandle;
void board_init(void) void board_init(void) {
{
HAL_Init(); // required for HAL_RCC_Osc TODO check with freeRTOS HAL_Init(); // required for HAL_RCC_Osc TODO check with freeRTOS
board_clock_init(); board_clock_init();
@ -130,56 +128,66 @@ void board_init(void)
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_led_write(bool state) void board_led_write(bool state) {
{ GPIO_PinState pin_state = (GPIO_PinState)(state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1-LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state); HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
} }
uint32_t board_button_read(void) uint32_t board_button_read(void) {
{
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN); return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
} }
int board_uart_read(uint8_t* buf, int len) size_t board_get_unique_id(uint8_t id[], size_t max_len) {
{ (void) max_len;
(void) buf; (void) len; volatile uint32_t * stm32_uuid = (volatile uint32_t *) UID_BASE;
uint32_t* id32 = (uint32_t*) (uintptr_t) id;
uint8_t const len = 12;
id32[0] = stm32_uuid[0];
id32[1] = stm32_uuid[1];
id32[2] = stm32_uuid[2];
return len;
}
int board_uart_read(uint8_t *buf, int len) {
(void) buf;
(void) len;
return 0; return 0;
} }
int board_uart_write(void const * buf, int len) int board_uart_write(void const *buf, int len) {
{
#ifdef UART_DEV #ifdef UART_DEV
HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff); HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff);
return len; return len;
#else #else
(void) buf; (void) len; (void) UartHandle; (void) buf;
(void) len;
(void) UartHandle;
return 0; return 0;
#endif #endif
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler (void)
{ void SysTick_Handler(void) {
system_ticks++; system_ticks++;
HAL_IncTick(); HAL_IncTick();
} }
uint32_t board_millis(void) uint32_t board_millis(void) {
{
return system_ticks; return system_ticks;
} }
#endif #endif
void HardFault_Handler (void) void HardFault_Handler(void) {
{
__asm("BKPT #0\n"); __asm("BKPT #0\n");
} }
// Required by __libc_init_array in startup code if we are compiling using // Required by __libc_init_array in startup code if we are compiling using
// -nostdlib/-nostartfiles. // -nostdlib/-nostartfiles.
void _init(void) void _init(void) {
{
} }

View File

@ -33,18 +33,15 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler // Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void USB_HP_IRQHandler(void) void USB_HP_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
void USB_LP_IRQHandler(void) void USB_LP_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
void USBWakeUp_IRQHandler(void) void USBWakeUp_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
@ -58,8 +55,7 @@ void UCPD1_IRQHandler(void) {
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
UART_HandleTypeDef UartHandle; UART_HandleTypeDef UartHandle;
void board_init(void) void board_init(void) {
{
HAL_Init(); HAL_Init();
board_clock_init(); board_clock_init();
@ -162,56 +158,65 @@ void board_init(void)
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_led_write(bool state) void board_led_write(bool state) {
{ GPIO_PinState pin_state = (GPIO_PinState)(state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1-LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state); HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
} }
uint32_t board_button_read(void) uint32_t board_button_read(void) {
{
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN); return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
} }
int board_uart_read(uint8_t* buf, int len) size_t board_get_unique_id(uint8_t id[], size_t max_len) {
{ (void) max_len;
(void) buf; (void) len; volatile uint32_t * stm32_uuid = (volatile uint32_t *) UID_BASE;
uint32_t* id32 = (uint32_t*) (uintptr_t) id;
uint8_t const len = 12;
id32[0] = stm32_uuid[0];
id32[1] = stm32_uuid[1];
id32[2] = stm32_uuid[2];
return len;
}
int board_uart_read(uint8_t *buf, int len) {
(void) buf;
(void) len;
return 0; return 0;
} }
int board_uart_write(void const * buf, int len) int board_uart_write(void const *buf, int len) {
{
#ifdef UART_DEV #ifdef UART_DEV
HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff); HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff);
return len; return len;
#else #else
(void) buf; (void) len; (void) UartHandle; (void) buf;
(void) len;
(void) UartHandle;
return 0; return 0;
#endif #endif
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler (void)
{ void SysTick_Handler(void) {
HAL_IncTick(); HAL_IncTick();
system_ticks++; system_ticks++;
} }
uint32_t board_millis(void) uint32_t board_millis(void) {
{
return system_ticks; return system_ticks;
} }
#endif #endif
void HardFault_Handler (void) void HardFault_Handler(void) {
{
__asm("BKPT #0\n"); __asm("BKPT #0\n");
} }
// Required by __libc_init_array in startup code if we are compiling using // Required by __libc_init_array in startup code if we are compiling using
// -nostdlib/-nostartfiles. // -nostdlib/-nostartfiles.
void _init(void) void _init(void) {
{
} }

View File

@ -37,15 +37,13 @@
// Despite being call USB2_OTG // Despite being call USB2_OTG
// OTG_FS is marked as RHPort0 by TinyUSB to be consistent across stm32 port // OTG_FS is marked as RHPort0 by TinyUSB to be consistent across stm32 port
void OTG_FS_IRQHandler(void) void OTG_FS_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
// Despite being call USB2_OTG // Despite being call USB2_OTG
// OTG_HS is marked as RHPort1 by TinyUSB to be consistent across stm32 port // OTG_HS is marked as RHPort1 by TinyUSB to be consistent across stm32 port
void OTG_HS_IRQHandler(void) void OTG_HS_IRQHandler(void) {
{
tud_int_handler(1); tud_int_handler(1);
} }
@ -80,8 +78,7 @@ void trace_etm_init(void) {
#define trace_etm_init() #define trace_etm_init()
#endif #endif
void board_init(void) void board_init(void) {
{
board_stm32h7_clock_init(); board_stm32h7_clock_init();
// Enable All GPIOs clocks // Enable All GPIOs clocks
@ -249,52 +246,60 @@ void board_init(void)
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_led_write(bool state) void board_led_write(bool state) {
{ GPIO_PinState pin_state = (GPIO_PinState)(state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1-LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state); HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
} }
uint32_t board_button_read(void) uint32_t board_button_read(void) {
{
return (BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) ? 1 : 0; return (BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) ? 1 : 0;
} }
int board_uart_read(uint8_t* buf, int len) size_t board_get_unique_id(uint8_t id[], size_t max_len) {
{ (void) max_len;
(void) buf; (void) len; volatile uint32_t * stm32_uuid = (volatile uint32_t *) UID_BASE;
uint32_t* id32 = (uint32_t*) (uintptr_t) id;
uint8_t const len = 12;
id32[0] = stm32_uuid[0];
id32[1] = stm32_uuid[1];
id32[2] = stm32_uuid[2];
return len;
}
int board_uart_read(uint8_t *buf, int len) {
(void) buf;
(void) len;
return 0; return 0;
} }
int board_uart_write(void const * buf, int len) int board_uart_write(void const *buf, int len) {
{ HAL_UART_Transmit(&UartHandle, (uint8_t * )(uintptr_t)
HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff); buf, len, 0xffff);
return len; return len;
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler(void)
{ void SysTick_Handler(void) {
HAL_IncTick(); HAL_IncTick();
system_ticks++; system_ticks++;
} }
uint32_t board_millis(void) uint32_t board_millis(void) {
{
return system_ticks; return system_ticks;
} }
#endif #endif
void HardFault_Handler(void) void HardFault_Handler(void) {
{
__asm("BKPT #0\n"); __asm("BKPT #0\n");
} }
// Required by __libc_init_array in startup code if we are compiling using // Required by __libc_init_array in startup code if we are compiling using
// -nostdlib/-nostartfiles. // -nostdlib/-nostartfiles.
void _init(void) void _init(void) {
{
} }

View File

@ -188,9 +188,8 @@ uint32_t board_button_read(void) {
size_t board_get_unique_id(uint8_t id[], size_t max_len) { size_t board_get_unique_id(uint8_t id[], size_t max_len) {
(void) max_len; (void) max_len;
volatile uint32_t * stm32_uuid = (volatile uint32_t *) UID_BASE; volatile uint32_t * stm32_uuid = (volatile uint32_t *) UID_BASE;
uint8_t const len = 12;
uint32_t* id32 = (uint32_t*) (uintptr_t) id; uint32_t* id32 = (uint32_t*) (uintptr_t) id;
uint8_t const len = 12;
id32[0] = stm32_uuid[0]; id32[0] = stm32_uuid[0];
id32[1] = stm32_uuid[1]; id32[1] = stm32_uuid[1];