🐞 fix: 修复syscall.h编译错误
This commit is contained in:
parent
feab37ed42
commit
1d0343d349
|
@ -1,46 +1,18 @@
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file syscalls.c
|
|
||||||
* @author Suroy Wrote with Auto-generated by STM32CubeIDE
|
|
||||||
* @url https://suroy.cn
|
|
||||||
* @brief STM32CubeIDE Minimal System calls file
|
|
||||||
*
|
|
||||||
* For more information about which c-functions
|
|
||||||
* need which of these lowlevel functions
|
|
||||||
* please consult the Newlib libc-manual
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020-2022 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Includes */
|
|
||||||
#ifndef __SYSCALLS_H
|
#ifndef __SYSCALLS_H
|
||||||
#define __SYSCALLS_H
|
#define __SYSCALLS_H
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stm32f1xx_hal_uart.h>
|
#include <stm32f1xx_hal_uart.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
extern UART_HandleTypeDef huart2;
|
extern UART_HandleTypeDef huart2;
|
||||||
|
|
||||||
/* Variables */
|
|
||||||
extern int __io_putchar(int ch) __attribute__((weak));
|
extern int __io_putchar(int ch) __attribute__((weak));
|
||||||
extern int __io_getchar(void) __attribute__((weak));
|
extern int __io_getchar(void) __attribute__((weak));
|
||||||
|
|
||||||
/* Functions */
|
|
||||||
|
|
||||||
__attribute__((weak)) int _read(int file, char *ptr, int len) {
|
__attribute__((weak)) int _read(int file, char *ptr, int len) {
|
||||||
(void)file;
|
(void)file;
|
||||||
int DataIdx;
|
int DataIdx;
|
||||||
|
@ -71,36 +43,8 @@ __attribute__((weak)) int _write(int file, char *ptr, int len) {
|
||||||
#define GETCHAR_PROTOTYPE int fgetc(FILE *f)
|
#define GETCHAR_PROTOTYPE int fgetc(FILE *f)
|
||||||
#endif /* __GNUC__ */
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
/**
|
|
||||||
* 函数功能: 重定向 c库函数 printf到 DEBUG_USARTx
|
|
||||||
* 输入参数: 无
|
|
||||||
* 返 回 值: 无
|
|
||||||
* 说 明:无
|
|
||||||
*/
|
|
||||||
PUTCHAR_PROTOTYPE {
|
|
||||||
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF); // 阻塞式无限等待
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 函数功能: 重定向 c库函数 getchar,scanf到 DEBUG_USARTx
|
|
||||||
* 输入参数: 无
|
|
||||||
* 返 回 值: 无
|
|
||||||
* 说 明:无
|
|
||||||
*/
|
|
||||||
GETCHAR_PROTOTYPE {
|
|
||||||
uint8_t ch = 0;
|
|
||||||
HAL_UART_Receive(&huart2, &ch, 1, 0xFFFF);
|
|
||||||
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 非GCC模式才允许编译使用即 Keil、IAR 等 */
|
|
||||||
#ifndef __GNUC__
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 重定向 C 标准库 printf 函数到串口 huart2
|
* @brief 重定向 C 标准库 printf 函数到串口 huart2
|
||||||
* 适用于 Keil、IAR 等IDE;不适用 GCC
|
|
||||||
* @author Suroy
|
* @author Suroy
|
||||||
* @param ch
|
* @param ch
|
||||||
* @param f
|
* @param f
|
||||||
|
@ -108,14 +52,13 @@ GETCHAR_PROTOTYPE {
|
||||||
*
|
*
|
||||||
* @usage printf("USART1_Target:\r\n");
|
* @usage printf("USART1_Target:\r\n");
|
||||||
*/
|
*/
|
||||||
int fputc(int ch, FILE *f) {
|
PUTCHAR_PROTOTYPE {
|
||||||
// 采用轮询方式发送1字节数据,超时时间为无限等待
|
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY); // 阻塞式无限等待
|
||||||
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY); // huart2是串口的句柄
|
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief fgets 重定向
|
* @brief 重定向 c库函数 getchar,scanf到 DEBUG_USARTx
|
||||||
* 重定向 C 标准库 scanf 函数到串口 huart2
|
* 重定向 C 标准库 scanf 函数到串口 huart2
|
||||||
* 注意以 空格 为结束
|
* 注意以 空格 为结束
|
||||||
* @param f
|
* @param f
|
||||||
|
@ -123,14 +66,12 @@ int fputc(int ch, FILE *f) {
|
||||||
*
|
*
|
||||||
* @usage scanf("%c", &RecData);
|
* @usage scanf("%c", &RecData);
|
||||||
*/
|
*/
|
||||||
int fgetc(FILE *f) {
|
GETCHAR_PROTOTYPE {
|
||||||
uint8_t ch;
|
uint8_t ch = 0;
|
||||||
HAL_UART_Receive(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY); // huart2是串口的句柄
|
HAL_UART_Receive(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __GNUC__ */
|
|
||||||
|
|
||||||
void delay_us(uint16_t us) {
|
void delay_us(uint16_t us) {
|
||||||
uint32_t delay = (HAL_RCC_GetHCLKFreq() / 4000000 * us);
|
uint32_t delay = (HAL_RCC_GetHCLKFreq() / 4000000 * us);
|
||||||
while (delay--);
|
while (delay--);
|
||||||
|
|
171
Core/Src/main.c
171
Core/Src/main.c
|
@ -18,11 +18,12 @@
|
||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
#include "dma.h"
|
#include "dma.h"
|
||||||
|
#include "gpio.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "tim.h"
|
#include "tim.h"
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
#include "gpio.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
@ -68,57 +69,49 @@ void SystemClock_Config(void);
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The application entry point.
|
* @brief The application entry point.
|
||||||
* @retval int
|
* @retval int
|
||||||
*/
|
*/
|
||||||
int main(void)
|
int main(void) {
|
||||||
{
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
/* USER CODE BEGIN Init */
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
/* USER CODE END Init */
|
||||||
|
|
||||||
/* USER CODE END Init */
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
/* Configure the system clock */
|
/* USER CODE BEGIN SysInit */
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_DMA_Init();
|
||||||
|
MX_I2C2_Init();
|
||||||
|
MX_TIM2_Init();
|
||||||
|
MX_TIM3_Init();
|
||||||
|
MX_TIM4_Init();
|
||||||
|
MX_USART2_UART_Init();
|
||||||
|
MX_USART1_UART_Init();
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
/* USER CODE BEGIN 2 */
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_DMA_Init();
|
|
||||||
MX_I2C2_Init();
|
|
||||||
MX_TIM2_Init();
|
|
||||||
MX_TIM3_Init();
|
|
||||||
MX_TIM4_Init();
|
|
||||||
MX_USART2_UART_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
HC_SR04_Init();
|
HC_SR04_Init();
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
/* USER CODE BEGIN 2 */
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_I2C2_Init();
|
|
||||||
MX_TIM2_Init();
|
|
||||||
MX_TIM3_Init();
|
|
||||||
MX_TIM4_Init();
|
|
||||||
MX_USART2_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("test\n");
|
printf("test\n");
|
||||||
|
|
||||||
|
@ -128,50 +121,46 @@ int main(void)
|
||||||
|
|
||||||
HAL_Delay(300); // 延时300毫秒
|
HAL_Delay(300); // 延时300毫秒
|
||||||
|
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
}
|
}
|
||||||
/* USER CODE END 3 */
|
/* USER CODE END 3 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief System Clock Configuration
|
* @brief System Clock Configuration
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void SystemClock_Config(void)
|
void SystemClock_Config(void) {
|
||||||
{
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
* in the RCC_OscInitTypeDef structure.
|
* in the RCC_OscInitTypeDef structure.
|
||||||
*/
|
*/
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||||
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
||||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||||
{
|
Error_Handler();
|
||||||
Error_Handler();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
*/
|
*/
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
|
||||||
{
|
Error_Handler();
|
||||||
Error_Handler();
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
/* USER CODE BEGIN 4 */
|
||||||
|
@ -179,32 +168,30 @@ void SystemClock_Config(void)
|
||||||
/* USER CODE END 4 */
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is executed in case of error occurrence.
|
* @brief This function is executed in case of error occurrence.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void Error_Handler(void)
|
void Error_Handler(void) {
|
||||||
{
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
while (1) {
|
while (1) {
|
||||||
}
|
}
|
||||||
/* USER CODE END Error_Handler_Debug */
|
/* USER CODE END Error_Handler_Debug */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_FULL_ASSERT
|
#ifdef USE_FULL_ASSERT
|
||||||
/**
|
/**
|
||||||
* @brief Reports the name of the source file and the source line number
|
* @brief Reports the name of the source file and the source line number
|
||||||
* where the assert_param error has occurred.
|
* where the assert_param error has occurred.
|
||||||
* @param file: pointer to the source file name
|
* @param file: pointer to the source file name
|
||||||
* @param line: assert_param error line source number
|
* @param line: assert_param error line source number
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
void assert_failed(uint8_t *file, uint32_t line) {
|
||||||
{
|
/* USER CODE BEGIN 6 */
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
/* User can add his own implementation to report the file name and line number,
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
/* USER CODE END 6 */
|
/* USER CODE END 6 */
|
||||||
}
|
}
|
||||||
#endif /* USE_FULL_ASSERT */
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user