MCU:STM32F103ZET6
IDE: MDK-ARM V5 +STM32CubeMX5.2.1
原子哥f429教程学习
一、打开Cube,建立工程
图片:
点击ACCESS project from MCU
然后选择芯片类型
图片:
二、系统配置
在 Pinout&Configuration—System Core中:
设置时钟RCC的HSE(外部高速时钟)为晶振模式:
Crystal/ceramic Resonator:
设置系统SYS的Debug为Serial Wire(SWD调试):
三、配置串口
在 Pinout&Configuration—Connectivity中:
打开UART1,配置工作模式,在NVIC选项中勾选使能
四、在 Clock Configuration中:
配置时钟为72 Mhz。

五、工程输出配置

Tips:最好把Linker Settings中的Minimum Heap Size设置为0x600。

最后点击GENERATE CODE代码就生成了:

至此,一个工程就创建完了。
六、代码部分处理
printf重定义
在usart.c文件中添加如下代码
/* USER CODE BEGIN 1 */
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
* @brief? Retargets the C library printf function to the USART.
* @param? None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
/* USER CODE END 1 */
以上步骤参考帖https://blog.csdn.net/weixin_42108484/article/details/84578414.
相关函数
串口使能和关闭方法
__HAL_UART_ENABLE(handler); //使能句柄 handler 指定的串口
__HAL_UART_DISABLE(handler); //关闭句柄 handler 指定的串口
串口中断开启和关闭函数
* This parameter can be one of the following values:
* @arg UART_IT_CTS: CTS change interrupt
* @arg UART_IT_LBD: LIN Break detection interrupt
* @arg UART_IT_TXE: Transmit Data Register empty interrupt
* @arg UART_IT_TC: Transmission complete interrupt
* @arg UART_IT_RXNE: Receive Data register not empty interrupt
* @arg UART_IT_IDLE: Idle line detection interrupt
* @arg UART_IT_PE
8000



被折叠的 条评论
为什么被折叠?



