创建STM32 HAL库程序编译时出现的错误解决办法

1、当出现下列错误时:

..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(1): error: A1167E: Invalid line start 
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(2): error: A1137E: Unexpected characters at end of line
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(3): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(4): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(5): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(6): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(7): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(8): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(9): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(10): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(11): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(12): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(13): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(14): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(15): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(16): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(17): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(18): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(19): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(20): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(21): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(22): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(23): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(24): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(25): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(26): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(27): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(28): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(29): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(30): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(31): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(32): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(33): error: A1137E: Unexpected characters at end of line
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(34): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(35): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(36): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(37): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(38): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(39): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(40): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(41): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(42): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(43): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(44): error: A1137E: Unexpected characters at end of line
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(45): error: A1137E: Unexpected characters at end of line
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(47): error: A1167E: Invalid line start 
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(48): error: A1159E: Label missing from line start
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(49): error: A1137E: Unexpected characters at end of line
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(51): error: A1167E: Invalid line start 
..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c(52): error: A1159E: Label missing from line start

一共50个错误的时候,我们点击每一项错误的时候,会发现其跳到“system_stm32f1xx.c”该文件中,基本点击哪个错误就显示错误就在哪一行,那也就是说该文件的开头就已经是错误了。而且该C程序并没有链接到其他文件:

仔细观察该文件:

会发现该文件第一行开始用的是C语言的注释,那就给了我们一个提示:软件应该是把该文件当成其他的文件了,并不是将其看成C程序去解释,所以我们右击该文件,得到下图:

 点击Option for File 'system_stm32xx.c',得到如下图:

 我们看到“File Type”文件类型为“Assembly language file”(汇编语言文件),显然系统把它当成汇编语言理解,所以我们需要把文件类型改成C语言类型,点击该倒三角,选择“C Source file”:

编译后就不会出现该问题了,“system_stm32f1xx.c”文件也被链接上了:

下面是一个使用HAL库生成的F103 LIN通讯实例代码,该代码使用USART1作为LIN总线的物理层,使用HAL库函数进行初始化和数据传输: ```c #include "main.h" #include "stm32f1xx_hal.h" #define LIN_BAUDRATE 9600 UART_HandleTypeDef huart1; void LIN_Configuration(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; huart1.Instance = USART1; huart1.Init.BaudRate = LIN_BAUDRATE; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_EVEN; huart1.Init.Mode = UART_MODE_TX_RX; huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart1.Init.OverSampling = UART_OVERSAMPLING_16; huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart1) != HAL_OK) { Error_Handler(); } HAL_UARTEx_EnableLIN(&huart1); } void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if (huart->Instance == USART1) { // 处理接收到的数据 uint8_t rx_data; HAL_UART_Receive(&huart1, &rx_data, 1, 100); // TODO: 根据接收到的数据进行处理 } } void LIN_SendByte(uint8_t data) { HAL_UART_Transmit(&huart1, &data, 1, 100); } int main(void) { HAL_Init(); LIN_Configuration(); while (1) { // 发送数据 LIN_SendByte(0x55); HAL_Delay(1000); } } ``` 该代码在主函数中循环发送数据,通过LIN_SendByte函数将一个字节的数据发送到LIN总线上。在HAL_UART_RxCpltCallback回调函数中,处理接收到的数据。需要注意的是,HAL_UART_Receive函数在接收到一个字节的数据后会自动触发回调函数,因此不需要单独调用HAL_UART_Receive_IT函数进行中断接收。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值