2014-03-25 03:52 AM
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
2014-03-25 07:25 AM
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.2014-03-28 07:55 AM
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..... :(2014-03-28 08:19 AM
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