Home > other >  The use of STM32 printf
The use of STM32 printf

Time:09-17


For help, to press the button, level and it can receive the printf serial debugging output, but the printf is not received,

CodePudding user response:

Baud rate is not set to? The way inconsistent check? Digits set right?

CodePudding user response:

A serial port communication timer is not started?

CodePudding user response:

Baud rate confirm it first

CodePudding user response:

The serial port first send/recive debugging using the printf

CodePudding user response:

Choose to confirm in USART can communication, is using the printf

CodePudding user response:

Baud rate is not set right

CodePudding user response:

First turn a serial port communication, print something on serial assistants, such routines that many online, then can realize the function of you,,, implementation level after reverse print information,,

CodePudding user response:

Take a look at your serial port set up yet

CodePudding user response:

//if you use the ucos, include the header file for the below.
# if SYSTEM_SUPPORT_UCOS
# include "includes. H"//ucos use
# endif

//add the following code, support the printf function, without the need to select the use MicroLIB
If # 1
# pragma import (__use_no_semihosting)
//the standard library needs the support of function
Struct __FILE
{
int handle;

};

FILE __stdout;
//define _sys_exit () to avoid using half a host mode
_sys_exit (int x)
{
x=x;
}
//redefine fputc function
Int fputc (int ch, FILE * f)
{
While ((USART1 - & gt; SR& 0 x40)==0);//cycle to send, until completion of the send
USART1 - & gt; DR=(u8) ch;
return ch;
}
# endif


Void uart_init (u32 bound) {
//set the GPIO port
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);//can make USART1, GPIOA clock
//USART1_TX PA. 9
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9; 9
//PA.GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//multiplexing push-pull output
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

//USART1_RX PA. 10
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;//floated input
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

//Usart1 NVIC configuration
NVIC_InitStructure. NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=3;//take priority 3
NVIC_InitStructure. NVIC_IRQChannelSubPriority=3;//child priority 3
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//IRQ channel can make
NVIC_Init (& amp; NVIC_InitStructure);//based on the specified parameters initialization VIC register

//USART initialization setting
USART_InitStructure. USART_BaudRate=bound;//general set to 9600;
USART_InitStructure.USART_WordLength=USART_WordLength_8b;//word length of 8 bits of data format
USART_InitStructure.USART_StopBits=USART_StopBits_1;//a stop bit
USART_InitStructure.USART_Parity=USART_Parity_No;//and white parity bit
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;//no hardware flow control
USART_InitStructure.USART_Mode=USART_Mode_Rx | USART_Mode_Tx;//transceiver model

USART_Init (USART1, & amp; USART_InitStructure);//initialize serial port
USART_ITConfig (USART1, USART_IT_RXNE, ENABLE);//open interrupt
USART_Cmd (USART1, ENABLE);//can make a serial port

}

Initialize serial port, put this code in a, then the PRINTF, serial port can output a thing, absolutely

CodePudding user response:

USART does not define which special register with flags to set

CodePudding user response:

Thanks for sharing!
Did you put that piece of graphic my heart for a long time: printf always cannot understand how monitoring:
HAL_UART_Transmit (& amp; Huart1, CH. 1, 30);
The status of the original can not monitor,

CodePudding user response:

Detect where the mouse click, to confirm, and then when your lift, or cancel the operation.

CodePudding user response:

No printf () output, is often associated with a serial port Settings, open the serial clock, set the baud rate, etc
  • Related