By the punctual atomic engineering way of programming, after transplantation, the simulation environment, one step operation, running at full speed, application no problem, print is no problem,
But the development board (wildfires development board) to electricity run separately, the program card to death,
But check the Use MicroLIB, programs run right,
Behind the printf function, without the need to select the use MicroLIB processing form (is usart. This part c). \ Objects \ LEDApp axf: Error: L6200E: Symbol __stdout multiply defined by stdio_streams. O and usart. (o).
Under this error, check the Use MicroLIB, normal program,,,,,,,,,
Directly on the code below the great god, please help me analysis the:
# include "myusart. H"
Void usart_init (void)
{
//GPIO Settings
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1, ENABLE);//can make USART1, GPIOA clock
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA, ENABLE);//can make USART1, GPIOA clock
//USART1_TX GPIOA. 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);//initialize the PA. 9
//USART1_RX GPIOA. 10
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_10; 10
//PA.GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IN_FLOATING;//floated input
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);//initialize the PA. 10
//USART initialization setting
USART_InitStructure. USART_BaudRate=115200;//serial port baud rate
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 1
USART_Cmd (USART1, ENABLE);//can make a serial port 1
}
/* * * * * * * * * * * * * * * * * * * * send one character at a time * * * * * * * * * * * * * * * * * * * * * * */
Void Usart_SendByte (USART_TypeDef * pUSARTx uint8_t ch)
{
USART_SendData (pUSARTx, ch);//send a byte data to the USART
While (USART_GetFlagStatus (pUSARTx USART_FLAG_TXE)==RESET);//wait for sending data register is empty
}
/* * * * * * * * * * * * * * * * * * * * send string * * * * * * * * * * * * * * * * * * * * * * * * * */
Void Usart_SendString (USART_TypeDef * pUSARTx, char * STR)
{
Unsigned int k=0;
Do {
Usart_SendByte (pUSARTx, * (STR + k));
K++;
} while (* (STR + k)!='\ 0');
While (USART_GetFlagStatus (pUSARTx USART_FLAG_TC)==RESET)//waiting to send complete
{
}
}
/* * * * * * * * * * * * * * * * * send a 16 digit * * * * * * * * * * * * * * * * * * * * * * */
Void Usart_SendHalfWord (USART_TypeDef * pUSARTx uint16_t ch)
{
Uint8_t temp_h temp_l;
Temp_h=(ch& 0 xff00) & gt;> 8;//remove the high eight
Temp_l=ch& 0 XFF.//remove the low eight
USART_SendData (pUSARTx temp_h);//send high eight
While (USART_GetFlagStatus (pUSARTx USART_FLAG_TXE)==RESET);
USART_SendData (pUSARTx temp_l);//send low eight
While (USART_GetFlagStatus (pUSARTx USART_FLAG_TXE)==RESET);
}
/* * * * * * * * * * * * redirect C library printf () function to the serial port, after the redirection can use print f * * */
Int fputc (int ch, FILE * F)
{
USART_SendData (USART1, (uint8_t) ch);//send a byte data to the serial port
While (USART_GetFlagStatus (USART1, USART_FLAG_TXE)==RESET);//waiting to send complete
Return (ch);
}
/* * * * to redirect the scanf c library function to the serial port, rewrite the backward can use the scanf, getchar function such as * * * * * */
Int fgetc (FILE * f)
{
While (USART_GetFlagStatus (USART1, USART_FLAG_RXNE)==RESET);//wait for serial input data
Return (int), USART_ReceiveData (USART1);
}
# # ifndef __MYUSART_H
# define __MYUSART_H
# include "stm32f10x. H"
#include
Void usart_init (void);
Void Usart_SendByte (USART_TypeDef * pUSARTx uint8_t ch);
Void Usart_SendString (USART_TypeDef * pUSARTx, char * STR);
Void Usart_SendHalfWord (USART_TypeDef * pUSARTx uint16_t ch);
# endif
# include "sys. H"
# include "usart. H"
//////////////////////////////////////////////////////////////////////////////////
//if you use the ucos, include the header file for the below.
# if SYSTEM_SUPPORT_OS
# 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;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * add the following function * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//__use_no_semihosting was requested, but _ttywrch was
_ttywrch int (ch)
{
ch=ch;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * to increase the function above * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# endif
# # ifndef __USART_H
# define __USART_H
# include "stdio.h"
# include "sys. H"
# endif
# include "led. H"
# include "myusart. H"
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull