About the __io modifier in the STM32 library (volatile modifier, capricious meaning)

Source: Internet
Author: User

The STM32 example code will have a code like this static __io uint32_t timingdelay; Here side of the __io modifier is not good understanding, single from the literal can be seen for IO correlation, check its standard library can know this __io originally was redefined in core_cm3.h, in fact, is volatile, the sentence is as follows

/* IO Definitions (access restrictions to peripheral registers) */#ifdef __cplusplus  #define   __i   &NBSP ; Volatile            /*!< defines ' Read Only ' permissions         &NB Sp       * #else   #define   __i     volatile const      /*!< defines ' r EAD only ' permissions                 * * #endif # define     __o   &NB Sp Volatile            /*!< defines ' write only ' permissions         &N Bsp      */#define     __io    volatile            /*!< D Efines ' read/write ' permissions              */   It's easy to see that these modifiers are used to instruct the compiler how to change the The volume of the operation. The role of volatile is to instruct the compiler not to omit this instruction for optimization, and must read and write its values directly each time. Write a test code as follows   U8 test;   test = 1;  Test = 2;  test = 3; Set optimization levelDo not run after intermediate test will be directly evaluated to 3 only the last statement is compiled with volatile  volatile U8 test;   test = 1;  Test = 2;  test = 3; The sentence will be compiled. Test has been set to 1, 2, 3 it can be seen that this role in IO operations, register operations, special variables, multi-threaded variable read and write are very important.

About the __io modifier in the STM32 library (volatile modifier, capricious meaning)

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.