[Tutorial] STM32F429 of DSP Chapter 6 ARM DSP source code and libraries transplantation (MDK5 of AC5 and AC6)

Download the full version of Guide: http://www.armbbs.cn/forum.php?mod=viewthread&tid=94547

Chapter 6 ARM DSP source code and libraries transplantation (MDK5 of AC5 and AC6)

This issue tutorial teaching the official ARM and DSP source code and transplant some knowledge of the library.

table of Contents

Chapter 6 ARM DSP source code and libraries transplantation (MDK5 of AC5 and AC6)

6.1 Important Beginners

6.2 DSP library for downloading and

Download 6.2.1 DSP Library

Description 6.2.2 DSP Library

The difference between 6.3 DSP library version

Several important predefined macros meaning 6.4 DSP Library

6.5 MDK compiler advantage of AC6

6.6 DSP library on MDK transplant (AC5 source migration path)

6.6.1 Step one: Create MDK project and add DSP Library

6.6.2 Step two: Add the include path

6.6.3 Step 3: Add macro definitions

6.6.4 Step 4: Enable FPU

6.6.5 Step Five: Add the header files arm_math.h

6.7 DSP library on MDK transplant (AC5 library portable way)

6.8 DSP library on MDK transplant (AC6 source migration path)

6.9 DSP library on MDK transplant (AC6 library portable way)

6.10 upgrade to the latest version of the DSP library method

6.11 DSP library functions simple verification

6.12 summary


 

6.1 Important Beginners

  1.   Please use the MDK 5.26 and above, CMSIS packages use version 5.6.0 and above.
  2.   MDK project to create, download and debug method, V6 user manual has detailed instructions: http://www.armbbs.cn/forum.php?mod=viewthread&tid=93255 .
  3.   In view of the MDK AC6 (ARM Compiler 6.X) compiler strong performance on floating-point processing, each case will be a must-do version AC6, compiled and ARM DSP library also began to direct the use of AC6.
  4.   MDK AC6 There are two places in the use of the time to pay attention to:
    •   Remember not to have Chinese project directory path, but not too long, otherwise it will lead to unusable go to def and debugging time is not normal.
    •   Chinese character coding problems MDK AC6 project template, in section 6.8 of this chapter are described in detail.

6.2 DSP library for downloading and

Below we explain in detail to the official transplant DSP library.

Download 6.2.1 DSP Library

CMSIS DSP library is included in the package (Cortex Microcontroller Software Interface Standard) inside, so the download is download CMSIS DSP library package. Here are three places you can download:

  •   Method 1: STM32CubeH7 packages inside.

Each version of the package will carry Cube CMSIS folder, but older versions is not recommended. Even the latest CubeH7

Package, the package contains version CMSIS a bit low.

  •   Second way: MDK installation directory (The following is the path to version 5.6.0).

After you install the new version of MDK, CMSIS package will exist in the path: ARM \ PACK \ ARM \ CMSIS \ 5.6.0 \ CMSIS.

If a newer version, we recommend using the latest version of MDK Package Download: http://www.keil.com/dd2/Pack/ .

  •   Three ways: GitHub.

Available through GitHub is also more convenient, address: https://github.com/ARM-software/CMSIS_5 . Click on the upper right corner you can download CMSIS packages.

Of course, you can also download the official website of ARM, ARM's official website just two years to upgrade so often to find information through the search function is very troublesome. So I do not recommend you to ARM official website to download the data.

Description 6.2.2 DSP Library

Here we have a standard transplant to CMSIS V5.6.0. Open the firmware inside the CMSIS library file, you can see the following files:

DSP folder is where we need:

Examples file folder in the following, mainly to provide some examples:

 

Include folder inside the DSP library header files:

 

Lib folder inside MDK (ARM), IAR and CGG library files:

Projects folder inside the file is as follows, offers three versions of the project templates, each template there is the added come in all source files:

Source Files folder is as follows, this is DSP source code file:

The difference between 6.3 DSP library version

MDK version of the DSP library as follows:

 

  •   arm_cortexM4lf_math.lib

Cortex-M4 core, l indicates little-endian format, f denotes FPU belt unit, M4 Single Precision supports only single precision floating point.

  •   arm_cortexM4l_math.lib

Cortex-M4 core, l indicates little-endian format.

  •   arm_cortexM4bf_math.lib

Cortex-M4 core, b represents big-endian format, f denotes FPU belt unit, M4 Single Precision supports only single precision floating point.

  •   arm_cortexM4b_math.lib

Cortex-M4 core, b represents big-endian format.

 

STM32F4 is M4 core, single-precision floating point, generally use little-endian format, so we chose the library arm_cortexM4lf_math.lib

Several important predefined macros meaning 6.4 DSP Library

According to the requirements of users, these predefined macros can be added to MDK predefined options:


Here these several predefined macros to be introduced:

  •   ARM_MATH_BIG_ENDIAN:

Big-endian format.

  •   ARM_MATH_MATRIX_CHECK:

Input and output size of the detection matrix

  • ARM_MATH_NEON:
  • ARM_MATH_NEON_EXPERIMENTAL:

Both being less than, because M0, M3, M4 and M7 kernel does not support the NEON instruction, need to wait to upgrade to ARMv8.1-M architecture.

  •   ARM_MATH_ROUNDING:

Mainly used in float switch Q32, Q15 and Q7, the process similar to the rounding, is useless to other functions.

 

  •   ARM_MATH_LOOPUNROLL:

4 for the treatment of small quantities of a group, faster execution.

By following the absolute value function, you can easily see the difference:

void arm_abs_f32(
  const float32_t * pSrc,
        float32_t * pDst,
        uint32_t blockSize)
{
        uint32_t blkCnt;                               /* Loop counter */

#if defined(ARM_MATH_NEON)
    float32x4_t vec1;
    float32x4_t res;

    /* Compute 4 outputs at a time */
    blkCnt = blockSize >> 2U;

    while (blkCnt > 0U)
    {
        /* C = |A| */

            /* Calculate absolute values and then store the results in the destination buffer. */
        vec1 = vld1q_f32(pSrc);
        res = vabsq_f32(vec1);
        vst1q_f32(pDst, res);

        /* Increment pointers */
        pSrc += 4;
        pDst += 4;
        
        /* Decrement the loop counter */
        blkCnt--;
    }

    /* Tail */
    blkCnt = blockSize & 0x3;

#else
#if defined (ARM_MATH_LOOPUNROLL)

  /* Loop unrolling: Compute 4 outputs at a time */
  blkCnt = blockSize >> 2U;

  while (blkCnt > 0U)
  {
    /* C = |A| */

    /* Calculate absolute and store result in destination buffer. */
    *pDst++ = fabsf(*pSrc++);

    *pDst++ = fabsf(*pSrc++);

    *pDst++ = fabsf(*pSrc++);

    *pDst++ = fabsf(*pSrc++);

    /* Decrement loop counter */
    blkCnt--;
  }

  /* Loop unrolling: Compute remaining outputs */
  blkCnt = blockSize % 0x4U;

#else

  /* Initialize blkCnt with number of samples */
  blkCnt = blockSize;

#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
#endif /* #if defined(ARM_MATH_NEON) */

  while (blkCnt > 0U)
  {
    /* C = |A| */

    /* Calculate absolute and store result in destination buffer. */
    *pDst++ = fabsf(*pSrc++);

    /* Decrement loop counter */
    blkCnt--;
  }

}

6.5 MDK compiler advantage of AC6

More related to knowledge, to dedicate it to the finishing accessory section E.

6.6 DSP library on MDK transplant (AC5 source migration path)

Here we explain how to transplant the next DSP library source code MDK above, DSP library is relatively easy to transplant.

6.6.1 Step one: Create MDK project and add DSP Library

For your convenience, we are no longer here to establish a special project of MDK, V6 direct to the development board example: V6-001_ Marquee routines can be added as a template (note example we are using the version HAL). Examples of open and add this packet CMSIS / DSP on the left:


We do not need to add here each C source file, simply add the summary file contains the C files, C files such as BasicMathFunctions.c file contains is:

#include "arm_abs_f32.c"
#include "arm_abs_q15.c"
#include "arm_abs_q31.c"
#include "arm_abs_q7.c"
#include "arm_add_f32.c"
#include "arm_add_q15.c"
#include "arm_add_q31.c"
#include "arm_add_q7.c"
#include "arm_dot_prod_f32.c"
#include "arm_dot_prod_q15.c"
#include "arm_dot_prod_q31.c"
#include "arm_dot_prod_q7.c"
#include "arm_mult_f32.c"
#include "arm_mult_q15.c"
#include "arm_mult_q31.c"
#include "arm_mult_q7.c"
#include "arm_negate_f32.c"
#include "arm_negate_q15.c"
#include "arm_negate_q31.c"
#include "arm_negate_q7.c"
#include "arm_offset_f32.c"
#include "arm_offset_q15.c"
#include "arm_offset_q31.c"
#include "arm_offset_q7.c"
#include "arm_scale_f32.c"
#include "arm_scale_q15.c"
#include "arm_scale_q31.c"
#include "arm_scale_q7.c"
#include "arm_shift_q15.c"
#include "arm_shift_q31.c"
#include "arm_shift_q7.c"
#include "arm_sub_f32.c"
#include "arm_sub_q15.c"
#include "arm_sub_q31.c"
#include "arm_sub_q7.c"

As a result, the MDK compiler automatically associates, view source code is very easy:

6.6.2 Step two: Add the include path

Add the include path required for DSP, this header file path is already added in good template project, but stressed that with you here:

Here we must note that, why directly add the path Libraries \ CMSIS \ Include inside the header will, without adding Libraries \ CMSIS \ DSP \ Include, this is because the path Libraries \ CMSIS \ Include DSP library which already contains the header files .

6.6.3 Step 3: Add macro definitions

Here we can only make a macro definition ARM_MATH_LOOPUNROLL:

6.6.4 Step 4: Enable FPU

Customers need to open the FPU by MDK, due STM32F4 single precision floating point support, here to open the Single Precision.

 

6.6.5 Step Five: Add the header files arm_math.h

File uses DSP library functions have to add #include "arm_math.h" you can call the API DSP library. This completes the migration DSP library.

6.7 DSP library on MDK transplant (AC5 library portable way)

Migration method is the same, only the first step section different chapter 6.5, add, modify the source code for the library was added:

6.8 DSP library on MDK transplant (AC6 source migration path)

AC6 DSP source of transplantation and inside sections of this chapter 6.5 AC5 transplantation identical, there is no difference. But there are differences on the three AC5 and AC6 engineering, highlighted here under:

  •   At first, the compiler uses AC6

  •   At the second, select the type of alert AC5-lik

  •   At first 3, MDK AC6 engineering of error code if the file is active GBK encoding, and the use of Chinese characters, the MDK compile time, requires the use of Chinese characters with Notepad source file, save as UTF-8. For example, a serial printer function printf main.c file uses Chinese characters, then you need to make the following changes 

And then recompile the error will not. Meanwhile, when serial printing, serial Assistant to support the use of UTF-8, recommended SecureCRT, Download: http://www.armbbs.cn/forum.php?mod=viewthread&tid=91718 .

Set as follows:

6.9 DSP library on MDK transplant (AC6 library portable way)

AC6 DSP library transplant with section 6.6 of this chapter AC5 transplant inside exactly the same, no difference. But pay attention to the problem as explained in section 6.8 can be.

6.10 upgrade to the latest version of the DSP library method

Since CMSIS packages are updated in real time, this provides a simple way to an up, download the latest version CMSIS packages as described in Section 6.1 of this chapter, and then direct coverage inside CMSIS DSP project folder.

6.11 DSP library functions simple verification

Here we run arm_abs_f32, arm_abs_q31, arm_abs_q15 these three functions, in order to validate our portable DSP library is correct.

Supporting examples:

This chapter supporting the following two examples:

  •   V6-200_DSP program template (source mode)
  •   V6-201_DSP program template (library mode)

Each example supporting the MDK of AC5 and AC6 two versions of the project.

Purpose:

1. Learn transplantation official DSP library

Experiment:

1. Press the key K1, the serial printer output function arm_abs_f32

2. Press key K2, the serial printer output function arm_abs_q31

3. Press key K3, the serial printer output function arm_abs_q15

Experimental phenomena:

       Look through the serial port PC software SecureCRT print information phenomenon as follows (respectively several times K1, K2, K3). If the compiler is the MDK AC6 engineering, with particular attention to section 6.7 of this chapter mentioned problems.

programming:

The design process is relatively simple, by pressing different keys so that different printing functions DSP Library execution result, the main program as follows:

#include "bsp.h" / * the underlying hardware driver * / 
#include "arm_math.h" 



/ * definition of routine routine name and release date * / 
#define EXAMPLE_NAME "V7 ARM's DSP-transplant template (source mode)" 
# EXAMPLE_DATE DEFINE "2019-07-31" 
#define DEMO_VER "1.0" 

static void PrintfLogo (void); 
static void PrintfHelp (void); 

/ * 
******************* ************************************************** ************************************ 
* function name: main 
* function: c program entry 
*-shaped parameters: None 
* return value: error code (without treatment) 
************************************* ************************************************** ************************************************** 
* / 
int main (void) 
{ 
    uint8_t ucKeyCode;/ * Key code * /
    pSrc float32_t; 
    float32_t pDst; 
    q31_t PSRC1; 
    q31_t pDst1; 
    q15_t pSrc2; 
    q15_t pDst2; 

    
    bsp_Init (); / * hardware initialization * / 
    
    PrintfLogo (); / * print routine name and version, etc. * / 
    PrintfHelp (); / * Tip printing operation * / 

    bsp_StartAutoTimer (0, 100); / * start an auto-reload timer of 100ms * / 
    
    / * main routine of a cycle * / 
    the while (. 1) 
    { 
        / * function is performed when the CPU is idle, the * bsp.c / 
        bsp_Idle ();         
        
        / * Analyzing timer timeout time * / 
        IF (bsp_CheckTimer (0))     
        { 
            / * * once every 100ms incoming / 
            / * LED2 inverted state * / 
            bsp_LedToggle (2);     
        }

        / * Process the event * / 
        ucKeyCode bsp_GetKey = (); 
        IF (ucKeyCode> 0) 
        { 
            / * key is pressed * / 
            Switch (ucKeyCode) 
            { 
                Case KEY_DOWN_K1: / * key is pressed Kl * / 
                    pSrc - = 1.23f; 
                    arm_abs_f32 (& pSrc, & pDst,. 1); 
                    the printf ( "pDst =% F \ R & lt \ n-", pDst); 
                    BREAK; 
                    
                Case KEY_DOWN_K2: / * K2 key depression * / 
                    PSRC1 - =. 1; 
                    arm_abs_q31 (& PSRC1, & pDst1,. 1 ); 
                    the printf ( "% D pDst1 = \ R & lt \ n-", pDst1); 
                    BREAK;

                case KEY_DOWN_K3:              /* K3键按下 */
                    pSrc2 -= 1;
                    arm_abs_q15(&pSrc2, &pDst2, 1);
                    printf("pDst2 = %d\r\n", pDst2);
                    break;
                
                default:
                    break;
            }
        }
    }
}

6.12 summary

The main issue with the tutorial to introduce the official DSP library transplant, transplantation is relatively simple, relatively speaking, it is recommended beginner students follow this step migration again.

 

He published 189 original articles · 87 won praise · views 60000 +

Guess you like

Origin blog.csdn.net/Simon223/article/details/105311321