Skip to main content
jbl_raw
Associate III
May 9, 2013
Question

simple stm32 c question ?

  • May 9, 2013
  • 9 replies
  • 2471 views
Posted on May 10, 2013 at 00:34

what is this 1ul and 2ul and 3ul

examble

 RCC->AHB1ENR  |= ((1UL <<  0) );              /* Enable GPIOA clock         *

  GPIOA->MODER    &= ~((3UL << 2*0)  );         /* PA.0 is input              */

what is the new value for   RCC->AHB1ENR and  GPIOA->MODER

#c-basics #off-topic
    This topic has been closed for replies.

    9 replies

    Tesla DeLorean
    Guru
    May 9, 2013
    Posted on May 10, 2013 at 00:40

    UL means the number is handled as an Unsigned Long,

    RCC->AHB1ENR  |= 0x00000001;

    GPIOA->MODER  &= 0xFFFFFFFC; // mask off low two bits ie ~0x00000003

    The final state will depend on the initial state of the registers.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    jbl_raw
    jbl_rawAuthor
    Associate III
    May 10, 2013
    Posted on May 10, 2013 at 15:28

    RCC->AHB1ENR  |= 0x00000001;

    GPIOA->MODER  &= 0xFFFFFFFC; // mask off low two bits ie ~0x00000003

    thank you very much

    but how you convert this (3UL << 2*0)   and this (1UL <<  0) to number !

    Tesla DeLorean
    Guru
    May 10, 2013
    Posted on May 10, 2013 at 15:53

    but how you convert this (3UL << 2*0)   and this (1UL <<  0) to number !

     

    I'm not sure I understand the question. The compiler parses suffixes which imply type information which it uses to do the computation, which can be different from the type it is later stored in, or other variables used in the computation. (Like using L to specify a long, on a compiler that would normally hold the value in 16-bit, or F to specify a float rather than a double)

    (3UL << 2*0)

    3 << 0

    3

    ~3 is equivalent to 3 ^ 0xFFFFFFFF, ie the inverse or logical NOT

    A quick Google

    http://www.parashift.com/c++-faq/numeric-literal-suffixes.html

    http://hackipedia.org/Platform/3D0/html%2c%203DO%20SDK%20Documentation/Type%20A/tktfldr/arrfldr/1arrg.html

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Andrew Neil
    Super User
    May 10, 2013
    Posted on May 11, 2013 at 00:25

    Note that none of this has anything to do with the STM32 - it is all just normal, standard 'C' syntax.

    Time to dust-off that 'C' textbook...

    http://blog.antronics.co.uk/2010/12/12/things-you-shouldve-learned-in-c-class-0-introduction/

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Tesla DeLorean
    Guru
    May 11, 2013
    Posted on May 11, 2013 at 14:33

    Note that none of this has anything to do with the STM32

    The code is an example out there for the chip, it's not an unreasonable question, we want to cultivate this as a safe place to ask question, or seek clarifications.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Andrew Neil
    Super User
    May 12, 2013
    Posted on May 12, 2013 at 19:00

    Yes;  but it's important to understand that this is just standard'C' syntax - not something that's in any way specific to the STM32 itself.

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    lakhi48
    Visitor II
    June 18, 2014
    Posted on June 18, 2014 at 15:21

    Hello all

    I am new with ST micro controller,I have been designing a circuit bases on STM32F302VBT,

    Can anybody guide me from where i can get the demo code or start up code or example code 

    bd_india
    Visitor II
    June 18, 2014
    Posted on June 18, 2014 at 16:59

    Hello Lakhwinder Ji,

    Go to below link & download the example codes configured 4 different IDE's.

    http://www.st.com/web/en/catalog/tools/PF258154

    For more help/assistance please send me an email on monu.yadav@yosun.com.sg

    Tesla DeLorean
    Guru
    June 18, 2014
    Posted on June 18, 2014 at 17:13

    How to start a new thread

    0690X00000605VxQAI.png
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..