cancel
Showing results for 
Search instead for 
Did you mean: 

SM32L1xx Standard Peripherals Library Drivers, IS_RCC_APB1_PERIPH(PERIPH)

daniele
Associate II
Posted on March 25, 2014 at 11:52

Hi,

I saw on the latest version of STM32L1xx Standard Peripherals Library Drivers,V1.2.0 something that I do not like.

Look at those macros:

&sharpdefine IS_RCC_APB1_PERIPH(PERIPH)

 

&sharpdefine IS_RCC_APB2_PERIPH(PERIPH)

 

 

In case of RCC_APB2Periph_USART1, both will return TRUE.

 

 

///                  100000000000000   ,

 

 

///  1001111000000010011010111000000   , &sharpdefine IS_RCC_APB1_PERIPH(PERIPH) ((((PERIPH) & 0x4F0135C0) == 0x00) && ((PERIPH) != 0x00))

 

 

/// 11111111111111111010010111100010   , &sharpdefine IS_RCC_APB2_PERIPH(PERIPH) ((((PERIPH) & 0xFFFFA5E2) == 0x00) && ((PERIPH) != 0x00))

 

 

 

And look where those are used:

 

''void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)

 

{

 

  /* Check the parameters */

 

  assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));

 

 

 

''

 

and

 

 

''void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)

 

{

 

  /* Check the parameters */

 

  assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));

 

''

 

 

If you analyze a but more you will see that SPI2 and UART1 have the same value.

Now the questions are coming:

1) am I right that this is a mistake?

2) due to the same value of SPI2 and UART1 it is not really possible to make the check using the approach of those macros (therefore not so easy to solve)

3) Does somebody have an idea if this is an exeption or are there other cases?, shall I really ''trust'' those asserts ?

#stm32-standard-peripheral-librar
3 REPLIES 3
Posted on March 25, 2014 at 15:25

The assert's aren't idiot proof.

There are only 32-bits in the vectors, and nothing other than the name ties the peripheral enable to APB1 or APB2.

People will mix up the Reset and Clock functions, and mix up AHB, APB1 and APB2, be more attentive, the compiler isn't going to catch them. In another world people might use enum instead of defines.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
daniele
Associate II
Posted on March 28, 2014 at 15:55

Maybe my low level of English does not help tp really understand what you mean.

Assert is on my opinion a very important mechanism, this is why I wonder that I found one case where it will not do the expected job.

And no reaction from ST is not a good sign for me..... :(

Posted on March 28, 2014 at 16:19

And no reaction from ST is not a good sign for me..... :(

ST has a low level of participation here, it's a user driven forum.

The compiler is not going to be able to determine which of TWO definitions of ''4'' a user might be using in some specific context, the assert() provide some degree of sanity checking, but embedded generally can't sustain the level of real-time parameter checking a PC based system might. The use of enum would provide context specific checking.

http://en.wikipedia.org/wiki/Enumerated_type#C

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..