We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello guys!
I'm just starting to use the LPC17xx MCU, using the Keil uVision4 as the design tool. I want to build a new project, using the outstanding CMSIS library, because this is a complete driver library for the MCU peripherals.
After studying the CMSIS included examples, I tried to create a new project, adding all the necessary header and source files of the drivers. (And the Cortex-M driver files too).
I created a simple "main.c" program just for testing the project.
The compiler results of some drivers source files (lpc17xx_gpio.c, lpc17xx_dac.c, etc) show me lots of warnings, but no errors.
And the CMSIS examples, with the same files and structure, compiles without any error.
I just don't know what to do!!!! I think that the problem is in the "lpc17xx_libcfg_default.h" ou the "lpc17xx_libcfg.h" file.
Please, help me.
Regards from Brazil.
---------------------------------------------------------------------------------- Here is the Build Output text result (using just the gpio.c file)
assembling startup_LPC17xx.s... compiling core_cm3.c... compiling system_LPC17xx.c... compiling lpc17xx_gpio.c... ..\..\..\Drivers\source\lpc17xx_gpio.c(293): warning: #188-D: enumerated type mixed with another type ..\..\..\Drivers\source\lpc17xx_gpio.c: return (((LPC_GPIOINT->IO0IntStatR)>>pinNum)& 0x1); ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c(295): warning: #188-D: enumerated type mixed with another type ..\..\..\Drivers\source\lpc17xx_gpio.c: return (((LPC_GPIOINT->IO2IntStatR)>>pinNum)& 0x1); ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c(297): warning: #188-D: enumerated type mixed with another type ..\..\..\Drivers\source\lpc17xx_gpio.c: return (((LPC_GPIOINT->IO0IntStatF)>>pinNum)& 0x1); ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c(299): warning: #188-D: enumerated type mixed with another type ..\..\..\Drivers\source\lpc17xx_gpio.c: return (((LPC_GPIOINT->IO2IntStatF)>>pinNum)& 0x1); ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c(617): warning: #186-D: pointless comparison of unsigned integer with zero ..\..\..\Drivers\source\lpc17xx_gpio.c: if ((byteNum >= 0) && (byteNum <= 3)) { ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c(623): warning: #186-D: pointless comparison of unsigned integer with zero ..\..\..\Drivers\source\lpc17xx_gpio.c: if ((byteNum >= 0) && (byteNum <= 3)) { ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c(655): warning: #186-D: pointless comparison of unsigned integer with zero ..\..\..\Drivers\source\lpc17xx_gpio.c: if ((byteNum >= 0) && (byteNum <= 3)) { ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c(661): warning: #186-D: pointless comparison of unsigned integer with zero ..\..\..\Drivers\source\lpc17xx_gpio.c: if ((byteNum >= 0) && (byteNum <= 3)) { ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c(687): warning: #186-D: pointless comparison of unsigned integer with zero ..\..\..\Drivers\source\lpc17xx_gpio.c: if ((byteNum >= 0) && (byteNum <= 3)){ ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c(712): warning: #186-D: pointless comparison of unsigned integer with zero ..\..\..\Drivers\source\lpc17xx_gpio.c: if ((byteNum >= 0) && (byteNum <= 3)){ ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c(732): warning: #186-D: pointless comparison of unsigned integer with zero ..\..\..\Drivers\source\lpc17xx_gpio.c: if ((byteNum >= 0) && (byteNum <= 3)){ ..\..\..\Drivers\source\lpc17xx_gpio.c: ^ ..\..\..\Drivers\source\lpc17xx_gpio.c: ..\..\..\Drivers\source\lpc17xx_gpio.c: 11 warnings, 0 errors compiling main.c... linking... Program Size: Code=124 RO-data=644 RW-data=0 ZI-data=512 "projeto1.axf" - 0 Error(s), 11 Warning(s).
Wow!! I forgot the "No Warnings" option!! So innocent!
Thank you a lot, guys!
Except that no code should require such a flag. On the contrary - code should be written with the aim that it can be compiled with very high warning levels and still give a clean build.
Yes, some compilers do produce a couple of warnings where the compiler developer should either be shot or at least have to buy a cup of coffee but the majority of warnings tend to be meaningful in one way or another.
Talking about stupid warnings - I'm not too happy about warnings about some null operations. An example:
if (var >> 0 & 1) { ... }
Maybe the code looks like:
enum { INPUT_SENSOR_1 = 0, INPUT_SENSOR_2 = 1, INPUT_BUTTON_ENTER = 2, INPUT_BUTTON_ESC = 3, INPUT_BUTTON_NEXT = 4, INPUT_BUTTON_PREV = 5, }; if ((port_value >> INPUT_SENSOR_1) & 1) sensor_1_trigged(); if ((port_value >> INPUT_SENSOR_2) & 1) sensor_2_trigged(); ... if ((port_value >> INPUT_BUTTON_PREV) & 1) button_prev_pressed();
It isn't so nice if the above code gives a warning - or not - depending on the allocation of the port bits. The meaning with the use of constants is to reduce the number of source code lines that gets affected by global changes.
In the sample code, it may be a bit hard to generate a warning for the test of an unsigned >= 0. It would be preferable if the same code works well if the variable is signed or unsigned. It should be trivial for the compiler to just optimize away the test when the data type is unsigned.
We want the code to run efficiently on the target hardware. Not the same as being optimally writted for the compiler to process.
The OP mentioned: compiling lpc17xx_gpio.c... ..\..\..\Drivers\source\lpc17xx_gpio.c(293): warning: #188-D: enumerated type mixed with another type
The [..\..\..\Drivers\source\lpc17xx_gpio.c] is part of the NXP LPC17xx CMSIS Driver Library. The below line in red is the line 293 of lpc17xx_gpio.c.
/*********************************************************************//** * @brief Get GPIO Interrupt Status (just used for P0.0-P0.30, P2.0-P2.13) * @param[in] portNum Port number to read value, should be: 0 or 2 * @param[in] pinNum Pin number, should be: 0..30(with port 0) and 0..13 * (with port 2) * @param[in] edgeState state of edge, should be: * - 0: Rising edge * - 1: Falling edge * @return Bool could be: * - ENABLE: Interrupt has been generated due to a rising * edge on P0.0 * - DISABLE: A rising edge has not been detected on P0.0 **********************************************************************/ FunctionalState GPIO_GetIntStatus(uint8_t portNum, uint32_t pinNum, uint8_t edgeState) { if((portNum == 0) && (edgeState == 0))//Rising Edge return (((LPC_GPIOINT->IO0IntStatR)>>pinNum)& 0x1); else if ((portNum == 2) && (edgeState == 0)) return (((LPC_GPIOINT->IO2IntStatR)>>pinNum)& 0x1); else if ((portNum == 0) && (edgeState == 1))//Falling Edge return (((LPC_GPIOINT->IO0IntStatF)>>pinNum)& 0x1); else if ((portNum == 2) && (edgeState == 1)) return (((LPC_GPIOINT->IO2IntStatF)>>pinNum)& 0x1); else //Error while(1); }
The line 293 as below triggers a warning.
return (((LPC_GPIOINT->IO0IntStatR)>>pinNum)& 0x1);
If I change line 293 to the below, no warning.
return ((FunctionalState)(((LPC_GPIOINT->IO0IntStatR)>>pinNum)& 0x1));
Related Definitions:
/** * @brief Functional State Definition */ typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
#define LPC_GPIOINT ((LPC_GPIOINT_TypeDef *) LPC_GPIOINT_BASE )
/** @brief General Purpose Input/Output interrupt (GPIOINT) register structure definition */ typedef struct { __I uint32_t IntStatus; __I uint32_t IO0IntStatR; __I uint32_t IO0IntStatF; __O uint32_t IO0IntClr; __IO uint32_t IO0IntEnR; __IO uint32_t IO0IntEnF; uint32_t RESERVED0[3]; __I uint32_t IO2IntStatR; __I uint32_t IO2IntStatF; __O uint32_t IO2IntClr; __IO uint32_t IO2IntEnR; __IO uint32_t IO2IntEnF; } LPC_GPIOINT_TypeDef;
Would like to know more about the NXP LPC17xx CMSIS Driver Library and the C Programming.
..\..\..\Drivers\source\lpc17xx_gpio.c(617): warning: #186-D: pointless comparison of unsigned integer with zero
The below line in red is the line 617 of lpc17xx_gpio.c.
/*********************************************************************//** * @brief Set direction for FIO port in byte accessible style * @param[in] portNum Port number, in range from 0 to 4 * @param[in] byteNum Byte part number, should be in range from 0 to 3 * @param[in] bitValue Value that contains all bits in to set direction, * in range from 0 to 0xFF. * @param[in] dir Direction value, should be: * - 0: Input. * - 1: Output. * @return None * * Note: All remaining bits that are not activated in bitValue (value '0') * will not be effected by this function. **********************************************************************/ void FIO_ByteSetDir(uint8_t portNum, uint8_t byteNum, uint8_t bitValue, uint8_t dir) { GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum); if(pFIO != NULL) { // Output direction if (dir) { if ((byteNum >= 0) && (byteNum <= 3)) { pFIO->FIODIR[byteNum] |= bitValue; } } // Input direction else { if ((byteNum >= 0) && (byteNum <= 3)) { pFIO->FIODIR[byteNum] &= ~bitValue; } } } }
..\..\..\..\Drivers\source\lpc17xx_timer.c(108): warning: #68-D: integer conversion resulted in a change of sign
The below line in red is the line 108 of lpc17xx_timer.c.
/*********************************************************************//** * @brief Convert a timer register pointer to a timer number * @param[in] TIMx Pointer to LPC_TIM_TypeDef, should be: * - LPC_TIM0: TIMER0 peripheral * - LPC_TIM1: TIMER1 peripheral * - LPC_TIM2: TIMER2 peripheral * - LPC_TIM3: TIMER3 peripheral * @return The timer number (0 to 3) or -1 if register pointer is bad **********************************************************************/ uint32_t converPtrToTimeNum (LPC_TIM_TypeDef *TIMx) { uint32_t tnum = -1; if (TIMx == LPC_TIM0) { tnum = 0; } else if (TIMx == LPC_TIM1) { tnum = 1; } else if (TIMx == LPC_TIM2) { tnum = 2; } else if (TIMx == LPC_TIM3) { tnum = 3; } return tnum; }
Why set it to -1?
The "header" comment at the start of the function tells you that:
/*********************************************************************//** * @brief Convert a timer register pointer to a timer number * @param[in] TIMx Pointer to LPC_TIM_TypeDef, should be: * - LPC_TIM0: TIMER0 peripheral * - LPC_TIM1: TIMER1 peripheral * - LPC_TIM2: TIMER2 peripheral * - LPC_TIM3: TIMER3 peripheral * @return The timer number (0 to 3) or -1 if register pointer is bad **********************************************************************/
So this is clearly a coding error - the function cannot possibly ever return a negative value, as its return type is defined as unsigned!!
This is a perfect example of why ignoring warnings is a Bad Thing!
As I said earlier, whoever allowed this to be releaed should be shot!
should be "released", of course!
Well, not the first package of bad ARM code from NXP. I did look at the source code packages for LPC21xx and LPC23xx and decided to ignore them completely and just make use of the chip manual and write my own code.