summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorhathach <[email protected]>2023-06-05 15:41:35 +0700
committerhathach <[email protected]>2023-06-05 15:41:45 +0700
commitf6a45a7aab42264fc9c270150549cd4c4a54292e (patch)
treed6494edada746ceb4ffd541d2aa5f407a86639a9 /hw
parentc7686f8d5e98660137ef176d35bc8a82f63675f3 (diff)
clean up
Diffstat (limited to 'hw')
-rw-r--r--hw/bsp/board.c11
-rw-r--r--hw/bsp/family_support.cmake17
-rw-r--r--hw/bsp/stm32g4/family.c50
3 files changed, 45 insertions, 33 deletions
diff --git a/hw/bsp/board.c b/hw/bsp/board.c
index 66ffcb199..3f62547a0 100644
--- a/hw/bsp/board.c
+++ b/hw/bsp/board.c
@@ -39,7 +39,7 @@
#define sys_read _read
#endif
-#if defined(LOGGER_RTT)
+#if defined(LOGGER_RTT) || defined(LOGGER_rtt)
// Logging with RTT
// If using SES IDE, use the Syscalls/SEGGER_RTT_Syscalls_SES.c instead
@@ -62,7 +62,7 @@ TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
#endif
-#elif defined(LOGGER_SWO)
+#elif defined(LOGGER_SWO) || defined(LOGGER_swo)
// Logging with SWO for ARM Cortex
#include "board_mcu.h"
@@ -71,11 +71,12 @@ TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
{
(void) fhdl;
uint8_t const* buf8 = (uint8_t const*) buf;
- for(size_t i=0; i<count; i++)
- {
+
+ for(size_t i=0; i<count; i++) {
ITM_SendChar(buf8[i]);
}
- return count;
+
+ return (int) count;
}
TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake
index fdcd9a983..2c0ee95d6 100644
--- a/hw/bsp/family_support.cmake
+++ b/hw/bsp/family_support.cmake
@@ -115,6 +115,12 @@ function(family_configure_common TARGET)
"LINKER:-Map=$<TARGET_FILE:${TARGET}>.map"
)
endif()
+
+ # LOGGER
+ if (DEFINED LOGGER)
+ target_compile_definitions(${TARGET} PUBLIC LOGGER_${LOGGER})
+ endif ()
+
endfunction()
@@ -136,12 +142,11 @@ function(family_add_tinyusb TARGET OPT_MCU)
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
add_library(${TARGET}-tinyusb_config INTERFACE)
- target_include_directories(${TARGET}-tinyusb_config INTERFACE
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
- target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
- CFG_TUSB_MCU=${OPT_MCU}
- )
+ target_include_directories(${TARGET}-tinyusb_config INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src)
+ target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_MCU=${OPT_MCU})
+ if (DEFINED LOG)
+ target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_DEBUG=${LOG})
+ endif()
# tinyusb's CMakeList.txt
add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
diff --git a/hw/bsp/stm32g4/family.c b/hw/bsp/stm32g4/family.c
index 3b490e9b3..19ba415bc 100644
--- a/hw/bsp/stm32g4/family.c
+++ b/hw/bsp/stm32g4/family.c
@@ -79,32 +79,35 @@ void board_init(void)
NVIC_SetPriority(USBWakeUp_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
#endif
- GPIO_InitTypeDef GPIO_InitStruct;
+ GPIO_InitTypeDef gpio_init;
// LED
- GPIO_InitStruct.Pin = LED_PIN;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
+ memset(&gpio_init, 0, sizeof(gpio_init));
+ gpio_init.Pin = LED_PIN;
+ gpio_init.Mode = GPIO_MODE_OUTPUT_PP;
+ gpio_init.Pull = GPIO_PULLUP;
+ gpio_init.Speed = GPIO_SPEED_FREQ_HIGH;
+ HAL_GPIO_Init(LED_PORT, &gpio_init);
board_led_write(false);
// Button
- GPIO_InitStruct.Pin = BUTTON_PIN;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN : GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
+ memset(&gpio_init, 0, sizeof(gpio_init));
+ gpio_init.Pin = BUTTON_PIN;
+ gpio_init.Mode = GPIO_MODE_INPUT;
+ gpio_init.Pull = BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN : GPIO_PULLUP;
+ gpio_init.Speed = GPIO_SPEED_FREQ_HIGH;
+ HAL_GPIO_Init(BUTTON_PORT, &gpio_init);
#ifdef UART_DEV
// UART
- GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- GPIO_InitStruct.Alternate = UART_GPIO_AF;
- HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);
+ memset(&gpio_init, 0, sizeof(gpio_init));
+ gpio_init.Pin = UART_TX_PIN | UART_RX_PIN;
+ gpio_init.Mode = GPIO_MODE_AF_PP;
+ gpio_init.Pull = GPIO_PULLUP;
+ gpio_init.Speed = GPIO_SPEED_FREQ_HIGH;
+ gpio_init.Alternate = UART_GPIO_AF;
+ HAL_GPIO_Init(UART_GPIO_PORT, &gpio_init);
UartHandle = (UART_HandleTypeDef){
.Instance = UART_DEV,
@@ -121,15 +124,18 @@ void board_init(void)
// USB Pins TODO double check USB clock and pin setup
// Configure USB DM and DP pins. This is optional, and maintained only for user guidance.
- GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ memset(&gpio_init, 0, sizeof(gpio_init));
+ gpio_init.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
+ gpio_init.Mode = GPIO_MODE_INPUT;
+ gpio_init.Pull = GPIO_NOPULL;
+ gpio_init.Speed = GPIO_SPEED_FREQ_HIGH;
+ HAL_GPIO_Init(GPIOA, &gpio_init);
__HAL_RCC_USB_CLK_ENABLE();
board_vbus_sense_init();
+
+ // USB PD
}
//--------------------------------------------------------------------+