mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
uart working on u5a5
This commit is contained in:
parent
db3ff4b352
commit
6ab7875aab
@ -26,13 +26,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "bsp/board_api.h"
|
#include "bsp/board_api.h"
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
// MACRO CONSTANT TYPEDEF PROTOTYPES
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
|
|
||||||
/* Blink pattern
|
/* Blink pattern
|
||||||
* - 250 ms : button is not pressed
|
* - 250 ms : button is not pressed
|
||||||
* - 1000 ms : button is pressed (and hold)
|
* - 1000 ms : button is pressed (and hold)
|
||||||
@ -44,21 +39,18 @@ enum {
|
|||||||
|
|
||||||
#define HELLO_STR "Hello from TinyUSB\r\n"
|
#define HELLO_STR "Hello from TinyUSB\r\n"
|
||||||
|
|
||||||
int main(void)
|
int main(void) {
|
||||||
{
|
|
||||||
board_init();
|
board_init();
|
||||||
board_led_write(true);
|
board_led_write(true);
|
||||||
|
|
||||||
uint32_t start_ms = 0;
|
uint32_t start_ms = 0;
|
||||||
bool led_state = false;
|
bool led_state = false;
|
||||||
|
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED;
|
uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED;
|
||||||
|
|
||||||
// Blink and print every interval ms
|
// Blink and print every interval ms
|
||||||
if ( !(board_millis() - start_ms < interval_ms) )
|
if (!(board_millis() - start_ms < interval_ms)) {
|
||||||
{
|
|
||||||
board_uart_write(HELLO_STR, strlen(HELLO_STR));
|
board_uart_write(HELLO_STR, strlen(HELLO_STR));
|
||||||
|
|
||||||
start_ms = board_millis();
|
start_ms = board_millis();
|
||||||
@ -69,16 +61,14 @@ int main(void)
|
|||||||
|
|
||||||
// echo
|
// echo
|
||||||
uint8_t ch;
|
uint8_t ch;
|
||||||
if ( board_uart_read(&ch, 1) > 0 )
|
if (board_uart_read(&ch, 1) > 0) {
|
||||||
{
|
|
||||||
board_uart_write(&ch, 1);
|
board_uart_write(&ch, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
|
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
|
||||||
void app_main(void)
|
void app_main(void) {
|
||||||
{
|
|
||||||
main();
|
main();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,12 +43,12 @@ extern "C"
|
|||||||
#define BUTTON_STATE_ACTIVE 1
|
#define BUTTON_STATE_ACTIVE 1
|
||||||
|
|
||||||
// UART Enable for STLink VCOM
|
// UART Enable for STLink VCOM
|
||||||
#define UART_DEV LPUART1
|
#define UART_DEV USART1
|
||||||
#define UART_CLK_EN __HAL_RCC_LPUART1_CLK_ENABLE
|
#define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE
|
||||||
#define UART_GPIO_PORT GPIOG
|
#define UART_GPIO_PORT GPIOA
|
||||||
#define UART_GPIO_AF GPIO_AF8_LPUART1
|
#define UART_GPIO_AF GPIO_AF7_USART1
|
||||||
#define UART_TX_PIN GPIO_PIN_7
|
#define UART_TX_PIN GPIO_PIN_9
|
||||||
#define UART_RX_PIN GPIO_PIN_8
|
#define UART_RX_PIN GPIO_PIN_10
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// RCC Clock
|
// RCC Clock
|
||||||
@ -103,16 +103,24 @@ static void SystemClock_Config(void) {
|
|||||||
// USB Clock
|
// USB Clock
|
||||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||||
|
|
||||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
RCC_PeriphCLKInitTypeDef usb_clk_init = { 0};
|
||||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USBPHY;
|
usb_clk_init.PeriphClockSelection = RCC_PERIPHCLK_USBPHY;
|
||||||
PeriphClkInit.UsbPhyClockSelection = RCC_USBPHYCLKSOURCE_HSE;
|
usb_clk_init.UsbPhyClockSelection = RCC_USBPHYCLKSOURCE_HSE;
|
||||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
|
if (HAL_RCCEx_PeriphCLKConfig(&usb_clk_init) != HAL_OK) {
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set the OTG PHY reference clock selection
|
/** Set the OTG PHY reference clock selection
|
||||||
*/
|
*/
|
||||||
HAL_SYSCFG_SetOTGPHYReferenceClockSelection(SYSCFG_OTG_HS_PHY_CLK_SELECT_1);
|
HAL_SYSCFG_SetOTGPHYReferenceClockSelection(SYSCFG_OTG_HS_PHY_CLK_SELECT_1);
|
||||||
|
|
||||||
|
// USART clock
|
||||||
|
RCC_PeriphCLKInitTypeDef uart_clk_init = { 0};
|
||||||
|
uart_clk_init.PeriphClockSelection = RCC_PERIPHCLK_USART1;
|
||||||
|
uart_clk_init.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
|
||||||
|
if (HAL_RCCEx_PeriphCLKConfig(&uart_clk_init) != HAL_OK) {
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SystemPower_Config(void) {
|
static void SystemPower_Config(void) {
|
||||||
|
@ -106,7 +106,7 @@ void board_init(void) {
|
|||||||
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
|
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||||
GPIO_InitStruct.Alternate = UART_GPIO_AF;
|
GPIO_InitStruct.Alternate = UART_GPIO_AF;
|
||||||
HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);
|
HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);
|
||||||
|
|
||||||
@ -121,7 +121,6 @@ void board_init(void) {
|
|||||||
UartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
UartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||||
UartHandle.Init.ClockPrescaler = UART_PRESCALER_DIV1;
|
UartHandle.Init.ClockPrescaler = UART_PRESCALER_DIV1;
|
||||||
UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||||
|
|
||||||
HAL_UART_Init(&UartHandle);
|
HAL_UART_Init(&UartHandle);
|
||||||
|
|
||||||
/* Configure USB GPIOs */
|
/* Configure USB GPIOs */
|
||||||
@ -196,8 +195,6 @@ void board_init(void) {
|
|||||||
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN;
|
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN;
|
||||||
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALOVAL;
|
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALOVAL;
|
||||||
#endif // USB_OTG_FS
|
#endif // USB_OTG_FS
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
Loading…
x
Reference in New Issue
Block a user