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).
..\..\..\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.