你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【freeelectron】库函数那些事

[复制链接]
freeelectron 发布时间:2016-3-29 23:41
本帖最后由 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了
  1. /* Function used to set the GPIO configuration to the default reset state *****/
  2. void GPIO_DeInit(GPIO_TypeDef* GPIOx);
复制代码
很显然,上面这个函数就是配置GPIO为默认状态;函数原型可以在stm32f0XX_gpio.c里面找到
  1. /**
  2.   * @brief  Deinitializes the GPIOx peripheral registers to their default reset
  3.   *         values.
  4.   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
  5.   * @note   GPIOE is available only for STM32F072.
  6.   * @note   GPIOD is not available for STM32F031.   
  7.   * @retval None
  8.   */
  9. void GPIO_DeInit(GPIO_TypeDef* GPIOx)
  10. {
  11.   /* Check the parameters */
  12.   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));

  13.   if(GPIOx == GPIOA)
  14.   {
  15.     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  16.     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE);
  17.   }
  18.   else if(GPIOx == GPIOB)
  19.   {
  20.     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, ENABLE);
  21.     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE);
  22.   }
  23.   else if(GPIOx == GPIOC)
  24.   {
  25.     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, ENABLE);
  26.     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE);
  27.   }
  28.   else if(GPIOx == GPIOD)
  29.   {
  30.     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, ENABLE);
  31.     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, DISABLE);
  32.   }
  33.   else if(GPIOx == GPIOE)
  34.   {
  35.     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, ENABLE);
  36.     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, DISABLE);
  37.   }
  38.   else
  39.   {
  40.     if(GPIOx == GPIOF)
  41.     {
  42.       RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, ENABLE);
  43.       RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, DISABLE);
  44.     }
  45.   }
  46. }
复制代码
关于参数的说明也很详细。
  1. /* Initialization and Configuration functions *********************************/
  2. void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
  3. void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
  4. void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

  5. /* GPIO Read and Write functions **********************************************/
  6. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  7. uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
  8. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  9. uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
  10. void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  11. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  12. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
  13. void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);

  14. /* GPIO Alternate functions configuration functions ***************************/
  15. void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);
复制代码
上面几个是关于GPIO的其他的库函数,函数原型的查看也是一样的。
其他的外设就不再赘述。
结束语:不管是f0、f1、f2、f4、甚至f7,库函数的使用基本都是这个方法,希望对大家有用。
最后,上传一个库函数点灯,(延时用的官方的systick代码,写得不错)。

觉得有用,请留下脚印,或者赏个金币。





IMG_20160327_230420.jpg
IMG_20160327_230439.jpg

LED.rar

下载

3.08 MB, 下载次数: 0

评分

参与人数 1 ST金币 +30 收起 理由
沐紫 + 30

查看全部评分

收藏 1 评论6 发布时间:2016-3-29 23:41

举报

6个回答
沐紫 回答时间:2016-3-30 09:14:59
很好,谢谢!
党国特派员 回答时间:2016-3-30 09:16:55
很科普。。。。。 0.png 1.png 2.png 3.png 4.png
freeelectron 回答时间:2016-3-30 09:47:37
freeelectron 回答时间:2016-3-30 12:40:22

还是管理识货
lisingch 回答时间:2016-3-30 14:17:43
不错!收藏学习。
caoren123 回答时间:2016-3-31 14:39:41
看看!!!!写的不错!!!

所属标签

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版