How to get started quickly using the STM32 library function

Source: Internet
Author: User

First , the background as described earlier, the advantage of using standard library functions is that it can be developed quickly, without going to the data sheet, with a cautious configuration of one
Complicated registers, because these work stmicroelectronics has found some top engineers to help you, and masterpieces are both library functions. Of course, some code
The library function cannot be used, given the low power consumption or the need for a very small ROM, which is usually said,
"highly customizable", sacrificing development time to get more
High code efficiency, this needs to weigh itself. This paper takes the DMA library function of STM32 as an example, that is, how to quickly use the STM32 library function to make a brief and record. Second, the text first go to the official website or the forum to download STM32, extract out, will find the inside is a variety of
". C"". h", file, all files are not required
A single brain of the full collection, only need to copy some of their own needs,
1, create a new project (nonsense:-D), and then set the library function's". C"". h"files are added to their own projects and made to be compiled through; the most basic engineering required library function files are:"Startup_stm32f10x_hd.s"-startup file;"system_stm32f10x.c"-used to set the initialization clock, the "systeminit ()" Function inside the startup file is called;"MISC.C"-cotex-M3 Kernel Common configuration files, such as containing NVIC configuration library functions and so on;"STM32F10X_RCC.C"-clock configuration related files, which contains the clock configuration library functions, in the case of DMA functions,"STM32F10X_DMA.C","stm32f10x_dma.h"File into the specified folder, and then add an existing
Project, in the main function, try to call the simplest library function, and compile the library function by passing, and then removing the test call from the main function.
2, do not hurry to see the library function what the specific library functions, not to go with the library function code, first to see STM32 technical manual about DMA
The content, figure out what the DMA is a structure, the register probably need to configure which, to understand the register does not need to drill down every bit, only need
Understand which functions each register controls.
3, after reading the STM32 manual on the introduction of DMA, you can parse the library function code. The parameters of the general library function code are an address, a struct-body parameter that contains configuration information, such as a DMA initialization library function:/** * @brief initializes the Dmay Channelx according to the specified * parameters in the DMA _initstruct. * @param dmay_channelx:where y can be 1 or 2 to select the DMA and * x can is 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel. * @param dma_initstruct:pointer to a DMA_INITTYPEDEF structure that * contains the configuration inform ation for the specified DMA Channel. * @retval None*/ voidDma_init (dma_channel_typedef* Dmay_channelx, dma_inittypedef*dma_initstruct); Each library function is preceded by a description of what the function of the library is, what the incoming parameters are worth, and what parameters are passed to be considered valid
parameters, return values, and so on. For incoming parameters, some will be more complex, often not the beginning of a few words can be described in full, at this time you need to drill down the library function code,
See
It takes this parameter to do exactly what. As an example of this function, the first parameter structure is as follows:
typedefstruct{__io uint32_t CCR;          __io uint32_t CNDTR;          __io uint32_t Cpar;        __io uint32_t Cmar;        } dma_channel_typedef;        It is clear at this point that each DMA channel will have a separate register, and the first parameter contains the addresses of these separate registers. The registers that are common to all DMA channels are not in this parameter and do not need to be within that parameter. So it does the following in the parameter description:/** @param dmay_channelx:where y can 1 or 2 to select the DMA and * x can is 1 to 7 for DMA1 an         D 1 to 5 for DMA2 to select the DMA Channel. */then the second parameter structure is analyzed, and the structure contains all the parameter information of configuration DMA, as follows: TypeDefstruct{uint32_t dma_peripheralbaseaddr;                uint32_t dma_memorybaseaddr;                           uint32_t Dma_dir;                    uint32_t dma_buffersize;                 uint32_t Dma_peripheralinc;                     uint32_t Dma_memoryinc;            uint32_t dma_peripheraldatasize;                uint32_t dma_memorydatasize;                          uint32_t Dma_mode;                      uint32_t dma_priority;                       uint32_t dma_m2m;        }dma_inittypedef; This one-eyed, really is two eyes crazy, or according to the routine (23333), enter the library function to see what each parameter does. Tmpreg|= Dma_initstruct->dma_dir | Dma_initstruct->dma_mode |dma_initstruct->dma_peripheralinc |
Dma_initstruct->dma_memoryinc |dma_initstruct->dma_peripheraldatasize |
Dma_initstruct->dma_memorydatasize |dma_initstruct->dma_priority | Dma_initstruct->dma_m2m; /*Write to Dmay channelx CCR*/Dmay_channelx->CCR =Tmpreg; See here, so many parameters here, all set to a register called CCR, and then we find out what this CCR register is set: DMA Channel x Configuration Register (DMA_CCRX), navigate to this register, plus each parameter 32 bits in the number of bits to determine the structure
What each member represents, and so are the other parameters.
After determining the function of all parameters, it is possible to pass the correct parameters to the corresponding configuration according to your own requirements. Here I would like to insert a sentence, and some of the newly-STM32 friends, I have been a, I think that using library functions instead of configuring each register, will feel
The heart is not steadfast, can not learn the real STM32 technology, and just do a series of actions to see, in fact, is misunderstood, using library functions, with
You also have to go deep into STM32 's technical manuals, so there is no way to learn the actual technology.
Technology has been updated, the old technology has been precipitated stable, we just stand on the shoulders of giants, you can see higher and farther, why also need
Waste time and energy to do what others have done. :
-D4, after parsing all the functions, you can use the library function to implement your own functional logic. At this point, the record is complete. Record time: November 11, 2016 record location: Shenzhen wz

How to get started quickly using the STM32 library function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.