Use of Assert_param in STM32

Source: Internet
Author: User

The use of Assert_param () can be seen everywhere in the STM32 firmware library and the provided routines. If you open a stm32f10x_conf.h file in any routine, you can see that the Assert_param is actually a macro definition;
In the firmware library, its purpose is to detect whether the arguments passed to the function are valid parameters.
The so-called valid parameter refers to the parameter that satisfies the specified range, for example, the value range of a parameter can only be a positive integer less than 3, if the given parameter is greater than 3,
This assert_param () can report errors when a running program calls to this function, allowing programmers to find errors in time without having to wait for the error of the program to run the result.

This is a common software technology that can help programmers quickly troubleshoot obvious errors during the debugging phase.

It does sacrifice efficiency on the run of the program (but only in the debug phase), but it helps you improve efficiency in project development.

When your project has been successfully developed, compiled with release mode, or commented out the macro definition of Use_full_assert in the Stm32f10x_conf.h file, all Assert_param () tests have disappeared without affecting the efficiency of the final program.

#define ASSERT_PARAM (expr) (expr)? (void) 0:assert_failed ((U8 *) __file__, __line__))
。。。

Assert_param (Is_adc_all_periph (ADCX));
。。。

When performing a assert_param () test, if a parameter is found to be faulted, it calls the function assert_failed () to report the error to the programmer, and in any one of the routines there is a template for the function in Main.c, as follows:

void assert_failed (uint8_t* file, uint32_t line)
{


while (1)
{}
}

You can follow your own environment requirements, add appropriate statements to output incorrect information hints, or modify this function to make appropriate error handling.

1. STM32F10xD.LIB is the library file of debug mode.
2. STM32F10xR.LIB is the library file of release mode.
3, to choose Debug and Release mode, you need to modify the content of stm32f10x_conf.h.
#define DEBUG indicates the debug mode and the statement is commented out, it is the release mode.
4, to choose Debug and Release mode, you can also fill in the Options,c/c++,define debug predefined.
This way, you do not need to modify the contents of the stm32f10x_conf.h.
5, if the library to join the project, you do not need to add the library source files to the project, more convenient.
However, the selection of the library corresponds to the debug pre-defined.

(turn) use of Assert_param in STM32

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.