[Debugging Record 1] Improve MC3172's floating point operation ability, and the course of obtaining and importing IQmath library
Background:
TI introduced IQmath library for fixed-point DSP without floating-point arithmetic unit. It is very convenient to analyze and process data in Q format, and the code becomes more concise.
In RISC-V architecture, some people also implement or conform to the IQmath library. The purpose of this paper is to obtain the IQmath library of RISC architecture, and import and use it on the MC3172 MCU chip.
MC3172 chip is a single core and multi-threaded MC3172 chip newly launched by Sension Technology Co., Ltd. Click to enter the official website link
Preparation of engineering formwork
Open the official website and go to the following link:
Download at Gitee[ Project template file ]And unzip the project template to obtain the following files:
install MounRiver Studio
All the way to Next.
Acquisition of IQmath library
Open project file:
After export, unzip to get two files: a and. h files
Import of IQmath library
Here, create two new folders, including the. h file and the. a file in the lib. Drag them directly as follows and select the copy method.
To configure the. a file:
After configuration, it is as follows:
Use in project
Open the main.c import header file:
Open the header file, you can see many Chinese comments, and introduce the functions, as follows:
Use and Testing of IQmath Library
For detailed introduction, see the information document provided at the end of the document.
Here, the performance speed is compared by calculating trigonometric functions sin and cos. By calculating trigonometric functions of the same number of times and inverting the IO level, the floating point calculation speed of library functions can be compared with the Q format calculation speed by using an LED lamp or directly measuring the frequency of IO output.
IO control realization:
led.c file
Insert code slice here#include "../include/led.h" void Led_Init(u32 gpio_sel,u32 gpio_pin) { INTDEV_SET_CLK_RST(gpio_sel,(INTDEV_RUN|INTDEV_IS_GROUP0|INTDEV_CLK_IS_CORECLK_DIV2)); GPIO_SET_OUTPUT_EN_VALUE(gpio_sel,(gpio_pin),GPIO_SET_ENABLE); LED_OFF(gpio_sel,(gpio_pin)); }
/* * led.h * * Created on: 2022 July 31 * Author: Four dimensions */ #ifndef USER_CODE_LED_H_ #define USER_CODE_LED_H_ #include "../MC3172/MC3172.h" #define LED_ON(gpio_sel,gpio_pin) GPIO_SET_OUTPUT_PIN_TO_0(gpio_sel,gpio_pin); #define LED_OFF(gpio_sel,gpio_pin) GPIO_SET_OUTPUT_PIN_TO_1(gpio_sel,gpio_pin); void Led_Init(u32 gpio_sel,u32 gpio_pin); #define LED0_ADDR GPIOA_BASE_ADDR #define LED0_Pin GPIO_PIN6 #define LED0_Init() Led_Init(LED0_ADDR,LED0_Pin) #define LED0_ON LED_ON(LED0_ADDR,LED0_Pin) #define LED0_OFF LED_OFF(LED0_ADDR,LED0_Pin) #endif /* USER_CODE_LED_H_ */
The document road reinforcement is as follows:
Add a header file in main and prepare to call:
Test IQmath first:
void thread0_main(void) { u32 i,j,k; _iq s,c; LED0_Init(); while(1){ LED0_ON for (i = 0; i < 2000; ++i){ for (j = 0; j < 2000; ++j){ for (k = 0; k < 2000; ++k){ c=_IQcosPU(_IQ(3.1415926)); s=_IQsinPU(_IQ(3.1415926)); } } } LED0_OFF for (i = 0; i < 2000; ++i){ for (j = 0; j < 2000; ++j){ for (k = 0; k < 2000; ++k){ c=_IQcosPU(_IQ(3.1415926)); s=_IQsinPU(_IQ(3.1415926)); } } } } thread_end(); }
Then test the math library function:
void thread0_main(void) { u32 i,j,k; float s,c; LED0_Init(); while(1){ LED0_ON for (i = 0; i < 2000; ++i){ for (j = 0; j < 2000; ++j){ for (k = 0; k < 2000; ++k){ c=cos(_IQ(3.1415926)); s=sin(_IQ(3.1415926)); } } } LED0_OFF for (i = 0; i < 2000; ++i){ for (j = 0; j < 2000; ++j){ for (k = 0; k < 2000; ++k){{ c=cos(_IQ(3.1415926)); s=sin(_IQ(3.1415926)); } } } } } thread_end(); }
The two test programs are downloaded to the development board, and the comparison can be observed by connecting the LED or oscilloscope through the IO port PA6:
This is the end of this article. Download the test process file and IQmath manual at the end. Thank you for watching.
https://gitee.com/Jim-Chenming/mc3172/tree/master/
Click Jump