STM8S 固件库GPIO设置问题
扫描二维码
随时随地手机看文章
ST对STM8S系列都有提供固件库,而不同的版本自然存在一些不同,版本也一直从V1.0.0升级到目前的V1.1.1。
环境: FWLIB V1.0.1版本,采用STM8SF103
在使用GPIO库时,一个偶然发现stm8s_gpio.h中的宏定义是存在问题的。
代码定义如下:
******************************************************************************
*@filestm8s_gpio.h
*@briefThisfilecontainsallfunctionsprototypeandmacrosfortheGPIOperipheral.
*@authorSTMicroelectronics-MCDApplicationTeam
*@versionV1.0.1
*@date09/22/2008
******************************************************************************
/**
*@briefGPIOmodes
*
*Bitsdefinitions:
*-Bit7:0=INPUTmode
*1=OUTPUTmode
*1=PULL-UP(input)orPUSH-PULL(output)
*-Bit5:0=Noexternalinterrupt(input)orNoslopecontrol(output)
*1=Externalinterrupt(input)orSlowcontrolenabled(output)
*-Bit4:0=Lowlevel(output)
*1=Highlevel(outputpush-pull)orHI-Z(outputopen-drain)
*/
typedefenum
{
GPIO_MODE_IN_FL_NO_IT=(u8)0b00000000,/*! GPIO_MODE_IN_PU_NO_IT=(u8)0b01000000,/*! GPIO_MODE_IN_FL_IT=(u8)0b00100000,/*! GPIO_MODE_IN_PU_IT=(u8)0b01100000,/*! GPIO_MODE_OUT_OD_LOW_FAST=(u8)0b10000000,/*! GPIO_MODE_OUT_PP_LOW_FAST=(u8)0b11000000,/*! GPIO_MODE_OUT_OD_LOW_SLOW=(u8)0b10100000,/*! GPIO_MODE_OUT_PP_LOW_SLOW=(u8)0b11100000,/*! GPIO_MODE_OUT_OD_HIZ_FAST=(u8)0b10010000,/*! GPIO_MODE_OUT_PP_HIGH_FAST=(u8)0b11010000,/*! GPIO_MODE_OUT_OD_HIZ_SLOW=(u8)0b10110000,/*! GPIO_MODE_OUT_PP_HIGH_SLOW=(u8)0b11110000/*! }GPIO_Mode_TypeDef; 我在main.c中是直接这样用的 GPIO_Init(GPIOC,GPIO_PIN_ALL,GPIO_MODE_OUT_PP_HIGH_FAST); //将GPIOC所有IO口设置成推挽输出,10M速度。空闲IO口设置为输出低电平能降低不必要的功耗。 但是调试查看寄存器时发现 CR2寄存器全为0,不应该才对。手册上清晰的表明了为1为设置10M速度。 翻看stm8s_gpio.c中的GPIO_Init函数,有设置CR2寄存器,前提是根据GPIO_MODE掩码来进行判断,判断的根据就是 Bit 5。如下: if((((u8)(GPIO_Mode))&(u8)0x20)!=(u8)0x00)/*InterruptorSlowslope*/ { GPIOx->CR2|=GPIO_Pin; }else/*NoexternalinterruptorNoslopecontrol*/ { GPIOx->CR2&=(u8)(~(GPIO_Pin)); } 继续查看固件库,对于V1.1.1来说不存在这个问题,如: ****************************************************************************** *@filestm8s_gpio.h *@briefThisfilecontainsallfunctionsprototypeandmacrosfortheGPIOperipheral. *@authorSTMicroelectronics-MCDApplicationTeam *@versionV1.1.1 *@date06/05/2009 ****************************************************************************** /** *@briefGPIOmodes * *Bitsdefinitions: *-Bit7:0=INPUTmode *1=OUTPUTmode *1=PULL-UP(input)orPUSH-PULL(output) *-Bit5:0=Noexternalinterrupt(input)orNoslopecontrol(output) *1=Externalinterrupt(input)orSlowcontrolenabled(output) *-Bit4:0=Lowlevel(output) *1=Highlevel(outputpush-pull)orHI-Z(outputopen-drain) */ typedefenum { GPIO_MODE_IN_FL_NO_IT=(u8)0b00000000,/*! GPIO_MODE_IN_PU_NO_IT=(u8)0b01000000,/*! GPIO_MODE_IN_FL_IT=(u8)0b00100000,/*! GPIO_MODE_IN_PU_IT=(u8)0b01100000,/*! GPIO_MODE_OUT_OD_LOW_FAST=(u8)0b10100000,/*! GPIO_MODE_OUT_PP_LOW_FAST=(u8)0b11100000,/*! GPIO_MODE_OUT_OD_LOW_SLOW=(u8)0b10000000,/*! GPIO_MODE_OUT_PP_LOW_SLOW=(u8)0b11000000,/*! GPIO_MODE_OUT_OD_HIZ_FAST=(u8)0b10110000,/*! GPIO_MODE_OUT_PP_HIGH_FAST=(u8)0b11110000,/*! GPIO_MODE_OUT_OD_HIZ_SLOW=(u8)0b10010000,/*! GPIO_MODE_OUT_PP_HIGH_SLOW=(u8)0b11010000/*! }GPIO_Mode_TypeDef; 同样是GPIO_MODE_OUT_PP_HIGH_FAST,前者定义为 0b11010000,而后者则是 0b11110000。 后来从发行日志里也了解到,ST已经更正了这个错误。 V1.1.1 - 06/05/2009
@code
General
-------
+ Project template updated for both STVD and RIDE toolchains
+ Almost peripheral examples reviewed and validated with both Cosmic and Raisonance
compilers
library
-------
+ stm8s.h:
- __CONST definition added for Cosmic and Raisonance compilers
- TINY definition added for Cosmic and Raisonance compilers
- NEAR definition added for Raisonance compilers
- CAN registers declaration updated
- ADC1 registers declaration updated
+ stm8s_adc1.h:
- IS_ADC1_BUFFER_OK macro definition updated
+ stm8s_beep.c:
- BEEP_Init function updated
- BEEP->CSR |= BEEP_CSR_BEEPEN; removed from init function
+ stm8s_can.c/.h:
- Private variables declaration changed to volatile
- CAN_DeInit function updated
- CAN_Receive function updated
- CAN_FilterInit funtion updated
- CAN_Transmit function updated
- CAN_IT_TypeDef enum updated:
- CAN_IT_ERR and CAN_IT_LEC definition updated to avoid ANSI check
error with Cosmic
+ stm8s_clk.h:
- CLK_Peripheral_TypeDef enum updated:
- CLK_PERIPHERAL_UART1 definition updated and conditioned by the
device to use
+ stm8s_gpio.h:
- The GPIO_Mode_TypeDef enum element definition updated:
- GPIO_MODE_OUT_OD_LOW_FAST
- GPIO_MODE_OUT_PP_LOW_FAST
- GPIO_MODE_OUT_OD_LOW_SLOW
- GPIO_MODE_OUT_PP_LOW_SLOW
- GPIO_MODE_OUT_OD_HIZ_FAST
- GPIO_MODE_OUT_PP_HIGH_FAST
- GPIO_MODE_OUT_OD_HIZ_SLOW
- GPIO_MODE_OUT_PP_HIGH_SLOW