int main(void)
{
gpio_pin_remap_config(GPIO_USART1_REMAP,ENABLE);
/* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOD);
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART1);
/* connect port to USARTx_Tx */
gpio_init(GPIOD, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_5);
/* connect port to USARTx_Rx */
gpio_init(GPIOD, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
/* USART configure */
usart_deinit(USART1);
usart_baudrate_set(USART1, 115200U);
usart_word_length_set(USART1, USART_WL_8BIT);
usart_stop_bit_set(USART1, USART_STB_1BIT);
usart_parity_config(USART1, USART_PM_NONE);
usart_hardware_flow_rts_config(USART1, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(USART1, USART_CTS_DISABLE);
usart_receive_config(USART1, USART_RECEIVE_ENABLE);
usart_transmit_config(USART1, USART_TRANSMIT_ENABLE);
usart_enable(USART1);
//usart_data_transmit(USART1, 0x55);
//while(RESET == usart_flag_get(USART1, USART_FLAG_TBE));
//
printf("a usart transmit test example!");
while(1);
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(USART1, (uint8_t)ch);
while(RESET == usart_flag_get(USART1, USART_FLAG_TBE));
return ch;
} |