Use UART driver
This commit is contained in:
parent
f94f7f0d68
commit
cca848eec0
44
Core/main.cc
44
Core/main.cc
@ -6,25 +6,20 @@
|
||||
#include "main.h"
|
||||
|
||||
#include "platform/stm32g0xx/Gpio.h"
|
||||
#include "platform/stm32g0xx/Uart.h"
|
||||
|
||||
IWDG_HandleTypeDef hiwdg;
|
||||
UART_HandleTypeDef huart2;
|
||||
|
||||
static void SystemClock_Config(void);
|
||||
static void MX_USART2_UART_Init(void);
|
||||
// static void MX_IWDG_Init(void);
|
||||
|
||||
#define SYS_TICK_PRIO 0
|
||||
|
||||
class My
|
||||
{
|
||||
public:
|
||||
My() {printf("Constructor\r\n");};
|
||||
~My() {printf("Destructor\r\n");};
|
||||
};
|
||||
|
||||
using namespace perinet::platform::stm32g0xx;
|
||||
|
||||
Gpio green_led(Gpio::Port::PORT_A, 5, Gpio::Mode::MODE_OUTPUT_PP);
|
||||
Uart uart(Uart::UartDevice::UART_2, 115200);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned int i = 1, j = 40;
|
||||
@ -45,15 +40,10 @@ int main(void)
|
||||
MODIFY_REG(SYSCFG->CFGR1, (SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE), SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE);
|
||||
|
||||
SystemClock_Config();
|
||||
MX_USART2_UART_Init();
|
||||
|
||||
My* my = new My();
|
||||
|
||||
delete(my);
|
||||
|
||||
Gpio green_led(Gpio::Port::PORT_A, 5, Gpio::Mode::MODE_OUTPUT_PP);
|
||||
|
||||
// MX_IWDG_Init();
|
||||
|
||||
char tx_buf[80];
|
||||
while (1) {
|
||||
if (j < 100) {
|
||||
j += 10;
|
||||
@ -67,7 +57,8 @@ int main(void)
|
||||
if (j > 800) {
|
||||
j = 800;
|
||||
}
|
||||
printf("%u: Hello World\r\n", i++);
|
||||
sprintf(tx_buf, "%u: Hello World\r\n", i++);
|
||||
uart.sync_send((const uint8_t *)tx_buf, strlen(tx_buf));
|
||||
green_led.toggle();
|
||||
HAL_Delay(j);
|
||||
// HAL_IWDG_Refresh(&hiwdg);
|
||||
@ -152,25 +143,6 @@ void SystemClock_Config(void)
|
||||
// }
|
||||
// }
|
||||
|
||||
static void MX_USART2_UART_Init(void)
|
||||
{
|
||||
huart2.Instance = USART2;
|
||||
huart2.Init.BaudRate = 115200;
|
||||
huart2.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart2.Init.StopBits = UART_STOPBITS_1;
|
||||
huart2.Init.Parity = UART_PARITY_NONE;
|
||||
huart2.Init.Mode = UART_MODE_TX_RX;
|
||||
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||
huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
|
||||
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||
if (HAL_UART_Init(&huart2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Error_Handler(void)
|
||||
{
|
||||
__disable_irq();
|
||||
|
Loading…
x
Reference in New Issue
Block a user