Merge branch 'feat-csj' into dev
This commit is contained in:
commit
25cd595d66
|
@ -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
|
||||
#define __SYSCALLS_H
|
||||
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stm32f1xx_hal_uart.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
extern UART_HandleTypeDef huart2;
|
||||
|
||||
/* Variables */
|
||||
extern int __io_putchar(int ch) __attribute__((weak));
|
||||
extern int __io_getchar(void) __attribute__((weak));
|
||||
|
||||
/* Functions */
|
||||
|
||||
__attribute__((weak)) int _read(int file, char *ptr, int len) {
|
||||
(void)file;
|
||||
int DataIdx;
|
||||
|
@ -71,36 +43,8 @@ __attribute__((weak)) int _write(int file, char *ptr, int len) {
|
|||
#define GETCHAR_PROTOTYPE int fgetc(FILE *f)
|
||||
#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
|
||||
* 适用于 Keil、IAR 等IDE;不适用 GCC
|
||||
* @author Suroy
|
||||
* @param ch
|
||||
* @param f
|
||||
|
@ -108,14 +52,13 @@ GETCHAR_PROTOTYPE {
|
|||
*
|
||||
* @usage printf("USART1_Target:\r\n");
|
||||
*/
|
||||
int fputc(int ch, FILE *f) {
|
||||
// 采用轮询方式发送1字节数据,超时时间为无限等待
|
||||
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY); // huart2是串口的句柄
|
||||
PUTCHAR_PROTOTYPE {
|
||||
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY); // 阻塞式无限等待
|
||||
return ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief fgets 重定向
|
||||
* @brief 重定向 c库函数 getchar,scanf到 DEBUG_USARTx
|
||||
* 重定向 C 标准库 scanf 函数到串口 huart2
|
||||
* 注意以 空格 为结束
|
||||
* @param f
|
||||
|
@ -123,14 +66,12 @@ int fputc(int ch, FILE *f) {
|
|||
*
|
||||
* @usage scanf("%c", &RecData);
|
||||
*/
|
||||
int fgetc(FILE *f) {
|
||||
uint8_t ch;
|
||||
HAL_UART_Receive(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY); // huart2是串口的句柄
|
||||
GETCHAR_PROTOTYPE {
|
||||
uint8_t ch = 0;
|
||||
HAL_UART_Receive(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
|
||||
return ch;
|
||||
}
|
||||
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
void delay_us(uint16_t us) {
|
||||
uint32_t delay = (HAL_RCC_GetHCLKFreq() / 4000000 * us);
|
||||
while (delay--);
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
#include "dma.h"
|
||||
#include "gpio.h"
|
||||
#include "i2c.h"
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
@ -71,9 +72,7 @@ void SystemClock_Config(void);
|
|||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
int main(void) {
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
@ -103,16 +102,10 @@ int main(void)
|
|||
MX_TIM4_Init();
|
||||
MX_USART2_UART_Init();
|
||||
MX_USART1_UART_Init();
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
HC_SR04_Init();
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
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 */
|
||||
|
@ -139,8 +132,7 @@ int main(void)
|
|||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
void SystemClock_Config(void) {
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
|
@ -154,22 +146,19 @@ void SystemClock_Config(void)
|
|||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
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();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -182,8 +171,7 @@ void SystemClock_Config(void)
|
|||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
void Error_Handler(void) {
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
|
@ -200,8 +188,7 @@ void Error_Handler(void)
|
|||
* @param line: assert_param error line source number
|
||||
* @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 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) */
|
||||
|
|
Loading…
Reference in New Issue
Block a user