cancel
Showing results for 
Search instead for 
Did you mean: 

simple stm32 c question ?

jbl_raw
Associate II
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
9 REPLIES 9
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
Up vote any posts that you find helpful, it shows what's working..
jbl_raw
Associate II
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 !

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
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist III
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/

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
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist III
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.

lakhi48
Associate
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
Associate
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

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
Up vote any posts that you find helpful, it shows what's working..