|
|
@@ -24,8 +24,9 @@
|
|
|
* This file is part of the TinyUSB stack.
|
|
|
*/
|
|
|
|
|
|
-#include "../board.h"
|
|
|
#include "stm32f1xx_hal.h"
|
|
|
+#include "bsp/board.h"
|
|
|
+#include "board.h"
|
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
// Forward USB interrupt events to TinyUSB IRQ Handler
|
|
|
@@ -48,72 +49,29 @@ void USBWakeUp_IRQHandler(void)
|
|
|
//--------------------------------------------------------------------+
|
|
|
// MACRO TYPEDEF CONSTANT ENUM
|
|
|
//--------------------------------------------------------------------+
|
|
|
-#define LED_PORT GPIOC
|
|
|
-#define LED_PIN GPIO_PIN_13
|
|
|
-#define LED_STATE_ON 0
|
|
|
-
|
|
|
-#define BUTTON_PORT GPIOA
|
|
|
-#define BUTTON_PIN GPIO_PIN_0
|
|
|
-#define BUTTON_STATE_ACTIVE 1
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- * @brief System Clock Configuration
|
|
|
- * The system Clock is configured as follow :
|
|
|
- * System Clock source = PLL (HSE)
|
|
|
- * SYSCLK(Hz) = 72000000
|
|
|
- * HCLK(Hz) = 72000000
|
|
|
- * AHB Prescaler = 1
|
|
|
- * APB1 Prescaler = 2
|
|
|
- * APB2 Prescaler = 1
|
|
|
- * HSE Frequency(Hz) = 8000000
|
|
|
- * HSE PREDIV1 = 1
|
|
|
- * PLLMUL = 9
|
|
|
- * Flash Latency(WS) = 2
|
|
|
- * @param None
|
|
|
- * @retval None
|
|
|
- */
|
|
|
-void SystemClock_Config(void)
|
|
|
-{
|
|
|
- RCC_ClkInitTypeDef clkinitstruct = {0};
|
|
|
- RCC_OscInitTypeDef oscinitstruct = {0};
|
|
|
- RCC_PeriphCLKInitTypeDef rccperiphclkinit = {0};
|
|
|
-
|
|
|
- /* Enable HSE Oscillator and activate PLL with HSE as source */
|
|
|
- oscinitstruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
|
- oscinitstruct.HSEState = RCC_HSE_ON;
|
|
|
- oscinitstruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
|
|
- oscinitstruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
|
|
- oscinitstruct.PLL.PLLState = RCC_PLL_ON;
|
|
|
- oscinitstruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
|
- HAL_RCC_OscConfig(&oscinitstruct);
|
|
|
-
|
|
|
- /* USB clock selection */
|
|
|
- rccperiphclkinit.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
|
|
- rccperiphclkinit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
|
|
|
- HAL_RCCEx_PeriphCLKConfig(&rccperiphclkinit);
|
|
|
-
|
|
|
- /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
|
|
|
- clkinitstruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
|
|
- clkinitstruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
|
- clkinitstruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
|
- clkinitstruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
|
- clkinitstruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
|
- HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2);
|
|
|
-}
|
|
|
|
|
|
void board_init(void)
|
|
|
{
|
|
|
-
|
|
|
- SystemClock_Config();
|
|
|
+ board_stm32f1_clock_init();
|
|
|
|
|
|
- #if CFG_TUSB_OS == OPT_OS_NONE
|
|
|
+ // Enable All GPIOs clocks
|
|
|
+ __HAL_RCC_GPIOA_CLK_ENABLE();
|
|
|
+ __HAL_RCC_GPIOB_CLK_ENABLE();
|
|
|
+ __HAL_RCC_GPIOC_CLK_ENABLE();
|
|
|
+ __HAL_RCC_GPIOD_CLK_ENABLE();
|
|
|
+
|
|
|
+#if CFG_TUSB_OS == OPT_OS_NONE
|
|
|
// 1ms tick timer
|
|
|
SysTick_Config(SystemCoreClock / 1000);
|
|
|
- #endif
|
|
|
+
|
|
|
+#elif CFG_TUSB_OS == OPT_OS_FREERTOS
|
|
|
+ // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
|
|
|
+ NVIC_SetPriority(USB_HP_CAN1_TX_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
|
|
|
+ NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
|
|
|
+ NVIC_SetPriority(USBWakeUp_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
|
|
|
+#endif
|
|
|
|
|
|
// LED
|
|
|
- __HAL_RCC_GPIOC_CLK_ENABLE();
|
|
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|
|
GPIO_InitStruct.Pin = LED_PIN;
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
@@ -122,7 +80,6 @@ void board_init(void)
|
|
|
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
|
|
|
|
|
|
// Button
|
|
|
- __HAL_RCC_GPIOA_CLK_ENABLE();
|
|
|
GPIO_InitStruct.Pin = BUTTON_PIN;
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
|
|
@@ -131,7 +88,6 @@ void board_init(void)
|
|
|
|
|
|
// USB Pins
|
|
|
// Configure USB DM and DP pins.
|
|
|
- __HAL_RCC_GPIOA_CLK_ENABLE();
|
|
|
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|