attempt uart printf
This commit is contained in:
parent
63bef1cd68
commit
84d00d8178
1 changed files with 19 additions and 9 deletions
|
|
@ -1,25 +1,34 @@
|
||||||
// Tx/Rx: PA09[PA11]/PA10[PA12]
|
// Tx/Rx: PA09[PA11]/PA10[PA12]
|
||||||
|
|
||||||
//#include <string.h>
|
//#include <string.h>
|
||||||
|
//#include <stdio.h>
|
||||||
#include "stm32g0xx_hal_msp.h"
|
#include "stm32g0xx_hal_msp.h"
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
UART_HandleTypeDef huart1;
|
||||||
|
|
||||||
char buffer[] = "Hello World\r\n";
|
char buffer[] = "Hello World\r\n";
|
||||||
#define TXBUFFERSIZE 14 //strlen(buffer)
|
#define TXBUFFERSIZE 14 //strlen(buffer)
|
||||||
#define TIMEOUT 1000 //right val?
|
#define TIMEOUT 0xFFFF
|
||||||
|
/*
|
||||||
|
int __io_putchar(int ch)
|
||||||
|
{
|
||||||
|
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, TIMEOUT);
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
setvbuf(stout, NULL, _IOLBF, 0);
|
||||||
|
|
||||||
|
int _write (int file, const void * ptr, size_t len)
|
||||||
|
{
|
||||||
|
HAL_UART_Transmit(&huart1, ptr, len, TIMEOUT);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
*/
|
||||||
static void uart_init(void)
|
static void uart_init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 0 */
|
huart1.Instance = USART1; // Defined in CMSIS header as peripheral address
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
|
||||||
huart1.Instance = USART1;
|
|
||||||
huart1.Init.BaudRate = 115200;
|
huart1.Init.BaudRate = 115200;
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
huart1.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
|
@ -44,6 +53,7 @@ int main(void)
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
HAL_UART_Transmit(&huart1, (uint8_t *)buffer, TXBUFFERSIZE, TIMEOUT);
|
HAL_UART_Transmit(&huart1, (uint8_t *)buffer, TXBUFFERSIZE, TIMEOUT);
|
||||||
|
//printf("Hello World\r\n");
|
||||||
HAL_Delay(100);
|
HAL_Delay(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue