背景配置stm32f103使其完成PWM输出的过程中,在配置GPIO口的时候,按照习惯配置GPIO口的speed为50MHZ,突然就意识到,为什么大部分例程习惯配置为50MHZ,而不是其它值,即有了此文章。
正文先说说GPIO口speed的问题,这个一般是用来定义GPIO口上升沿或者下降沿的时间,频率越高,上升沿下降沿时间越短,但是其噪音也就越大,因此,如果没有特别的需求,该值应该不要配置太高。在技术手册里,其给了3个速度选择,库函数的相应表现形式如下:
/** * @brief Output Maximum frequency selection */typedef enum{ GPIO_Speed_10MHz = 1, GPIO_Speed_2MHz, GPIO_Speed_50MHz}GPIOSpeed_TypeDef;50MHZ,意味着GPIO口理论上1s可以翻转50兆次,即1微妙翻转50次,PWM应该不需要如此高的频率,所以,本次PWM的GPIO口速度配置为10MHZ。
再来说说GPIO口其他配置,库函数GPIO口配置的函数为:
/** * @brief Initializes the GPIOx peripheral according to the specified * parameters in the GPIO_InitStruct. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. * @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that * contains the configuration information for the specified GPIO peripheral.&nbs |