本帖最后由 freeelectron 于 2016-3-29 23:43 编辑
写在前面的话,去年在社区领到Nucleo-F030开发板,一直没时间去研究,近来有时间,也觉得该为社区贡献点东西!
1.网上关于103的资料比较多,主要是中文资料比较多,包括库函数,寄存器什么的等等,都有中文,而其他系列貌似资 料就比较少;
2.现在看来用库函数开发是一种趋势,或者说,可以借助别人写的库函数,或者说,自己将寄存器操作封装成库函数,这样就比较简单,也易读。
3.每个系列对应的库函数的定义也不尽相同。
3.刚好前阵看到有人在找库函数,我们都知道,在用官方库函数的时候,会有.c文件和.h文件,那么.c文件里面肯定就是函数原型了,.h文件里面肯定就是对应的函数声明了,那么我们查看库函数的时候,只需打开某个外设对应的.h文件就行了,.h文件里面有很详细的描述,以Nucleo-F030为例说明,其实也就是整个F0系列的库函数。
我们以最常用的外设GPIO为例说明:
当然f0系列,GPIO的库函数定义就是stm32f0XX_gpio.c和stm32f0XX_gpio.h了
- /* Function used to set the GPIO configuration to the default reset state *****/
- void GPIO_DeInit(GPIO_TypeDef* GPIOx);
复制代码 很显然,上面这个函数就是配置GPIO为默认状态;函数原型可以在stm32f0XX_gpio.c里面找到
- /**
- * @brief Deinitializes the GPIOx peripheral registers to their default reset
- * values.
- * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
- * @note GPIOE is available only for STM32F072.
- * @note GPIOD is not available for STM32F031.
- * @retval None
- */
- void GPIO_DeInit(GPIO_TypeDef* GPIOx)
- {
- /* Check the parameters */
- assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
- if(GPIOx == GPIOA)
- {
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE);
- }
- else if(GPIOx == GPIOB)
- {
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, ENABLE);
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE);
- }
- else if(GPIOx == GPIOC)
- {
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, ENABLE);
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE);
- }
- else if(GPIOx == GPIOD)
- {
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, ENABLE);
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, DISABLE);
- }
- else if(GPIOx == GPIOE)
- {
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, ENABLE);
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, DISABLE);
- }
- else
- {
- if(GPIOx == GPIOF)
- {
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, ENABLE);
- RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, DISABLE);
- }
- }
- }
复制代码 关于参数的说明也很详细。
- /* Initialization and Configuration functions *********************************/
- void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
- void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
- void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
- /* GPIO Read and Write functions **********************************************/
- uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
- uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
- uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
- uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
- void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
- void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
- void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
- void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
- /* GPIO Alternate functions configuration functions ***************************/
- void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);
复制代码 上面几个是关于GPIO的其他的库函数,函数原型的查看也是一样的。
其他的外设就不再赘述。
结束语:不管是f0、f1、f2、f4、甚至f7,库函数的使用基本都是这个方法,希望对大家有用。
最后,上传一个库函数点灯,(延时用的官方的systick代码,写得不错)。
觉得有用,请留下脚印,或者赏个金币。
|