From 9e45f4e6ec29e9b021beaf16444487358383bdc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 17 Dec 2017 01:18:05 +0100 Subject: [PATCH] fix 303, now works with usb --- USB/usb_device.c | 35 ++++++++++++++++++----------------- USB/usbd_conf.c | 2 ++ platform/debug_uart.c | 5 ++++- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/USB/usb_device.c b/USB/usb_device.c index 8a37c7e..b04f13b 100644 --- a/USB/usb_device.c +++ b/USB/usb_device.c @@ -86,32 +86,33 @@ void MX_USB_DEVICE_Init(void) } /* USER CODE BEGIN USB_IRQ */ + /** -* @brief This function handles USB low priority or CAN RX0 interrupts. -*/ + * Common USB handler + */ +static void __attribute__((used)) BASE_USB_IRQHandler(void) +{ + HAL_PCD_IRQHandler(&hpcd_USB_FS); +} + // Function from F103 -void USB_LP_CAN1_RX0_IRQHandler(void) __attribute__((alias("USB_IRQHandler"))); +/** +* @brief This function handles USB low priority or CAN RX0 interrupts. +*/ +void USB_LP_CAN1_RX0_IRQHandler(void) __attribute__((alias("BASE_USB_IRQHandler"))); // Function for F303 -void USB_LP_CAN_RX0_IRQHandler(void) __attribute__((alias("USB_IRQHandler"))); +/** +* @brief This function handles USB low priority or CAN_RX0 interrupts. +*/ +void USB_LP_CAN_RX0_IRQHandler(void) __attribute__((alias("BASE_USB_IRQHandler"))); +// Function for F072 /** * @brief This function handles USB global interrupt / USB wake-up interrupt through EXTI line 18. */ - -// Function from F072 -void USB_IRQHandler(void) -{ - /* USER CODE BEGIN USB_IRQn 0 */ - - /* USER CODE END USB_IRQn 0 */ - HAL_PCD_IRQHandler(&hpcd_USB_FS); - /* USER CODE BEGIN USB_IRQn 1 */ - - /* USER CODE END USB_IRQn 1 */ -} - +void USB_IRQHandler(void) __attribute__((alias("BASE_USB_IRQHandler"))); /** * @} diff --git a/USB/usbd_conf.c b/USB/usbd_conf.c index b65aa62..e0d1703 100644 --- a/USB/usbd_conf.c +++ b/USB/usbd_conf.c @@ -96,6 +96,8 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) PA12 ------> USB_DP */ __HAL_RCC_GPIOA_CLK_ENABLE(); + LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_11, LL_GPIO_MODE_ALTERNATE); + LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_12, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_11, LL_GPIO_AF_14); LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_12, LL_GPIO_AF_14); HAL_NVIC_SetPriority(USB_LP_CAN_RX0_IRQn, 5, 0); diff --git a/platform/debug_uart.c b/platform/debug_uart.c index 444d715..0a3d5b6 100644 --- a/platform/debug_uart.c +++ b/platform/debug_uart.c @@ -43,7 +43,10 @@ void DebugUart_PreInit(void) #elif GEX_PLAT_F103_BLUEPILL LL_USART_SetBaudRate(USART2, SystemCoreClock/2, 115200); // This is not great, let's hope it's like this on all platforms... #elif GEX_PLAT_F303_DISCOVERY - LL_USART_SetBaudRate(USART2, SystemCoreClock/2, LL_USART_OVERSAMPLING_16, 115200); // FIXME better way to determine frequency? + LL_USART_SetBaudRate(USART2, + LL_RCC_GetUSARTClockFreq(LL_RCC_USART2_CLKSOURCE), + LL_USART_OVERSAMPLING_16, + 115200); LL_GPIO_SetAFPin_0_7(GPIOA, LL_GPIO_PIN_2, LL_GPIO_AF_7); // uart2 is AF7 here #else #error "BAD PLATFORM!"