stm32cubemx配置
复制全部的库,里面含有DSP库等
的keil配置
开启硬件浮点单元
stm32cubemx新建完成的STM32F4系列的工程,在莱凯勒这里配置应该的英文自动默认开启的
然后可见这里为灰色使能硬件FPU未开启,
查看定义
可以发现这两个没有进行定义
然后加入宏定义
__CC_ARM,__硬件TARGET_FPU_VFP
点ok,重新编译
再看变亮了发现有fpu
加入头
文件,以便
在文件里面需要我直接加在main中使用。 h里
再加入一个宏定义
ARM_MATH_CM4
加入他的路径
最后加入优化库
drive–>cmsis–>
lib– >arm
2021.8.30
tim2配置10ms
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM2_Init 1 */
/* USER CODE END TIM2_Init 1 */
htim2.Instance = TIM2;
htim2.Init.Prescaler = 8399;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 99;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
测试代码部分
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
*
© Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "fatfs.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint64_t sum=0;
uint64_t end=0;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance==TIM2)
{ end=0;
end=sum;
sum=0;
//printf("次数为%lld",sum);
}
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
float a=5.4698f;
float b=3.246f;
float c =2.35469f;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_TIM1_Init();
MX_TIM2_Init();
MX_USART1_UART_Init();
MX_FATFS_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim2);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
a=arm_sin_f32(a);
b=arm_sin_f32(b);
c=arm_sin_f32(c);
/* a=sin(a);
b=sin(b);
c=sin(c);*/
sum++;
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
未用fpu的sin()函数
使用fpu 的 arm_sin_f32() 函数
经测试 arm_sqrt_f32() 等更容易使用的数学方法比未优化的 sqrt() 可以简单地快上接近 100 倍。
但使用优化库 arm_add_f32 , arm_sub_f32等,反而会更慢。