STM8S 固件庫GPIO設(shè)置問題
ST對(duì)STM8S系列都有提供固件庫,而不同的版本自然存在一些不同,版本也一直從V1.0.0升級(jí)到目前的V1.1.1。
環(huán)境: FWLIB V1.0.1版本,采用STM8SF103
在使用GPIO庫時(shí),一個(gè)偶然發(fā)現(xiàn)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口設(shè)置成推挽輸出,10M速度。空閑IO口設(shè)置為輸出低電平能降低不必要的功耗。 但是調(diào)試查看寄存器時(shí)發(fā)現(xiàn) CR2寄存器全為0,不應(yīng)該才對(duì)。手冊(cè)上清晰的表明了為1為設(shè)置10M速度。 翻看stm8s_gpio.c中的GPIO_Init函數(shù),有設(shè)置CR2寄存器,前提是根據(jù)GPIO_MODE掩碼來進(jìn)行判斷,判斷的根據(jù)就是 Bit 5。如下: if((((u8)(GPIO_Mode))&(u8)0x20)!=(u8)0x00)/*InterruptorSlowslope*/ { GPIOx->CR2|=GPIO_Pin; }else/*NoexternalinterruptorNoslopecontrol*/ { GPIOx->CR2&=(u8)(~(GPIO_Pin)); } 繼續(xù)查看固件庫,對(duì)于V1.1.1來說不存在這個(gè)問題,如: ****************************************************************************** *@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。 后來從發(fā)行日志里也了解到,ST已經(jīng)更正了這個(gè)錯(cuò)誤。 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