野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14812|回复: 2

为什么GPIO复用的代码出现了HardFault?

[复制链接]
发表于 2018-4-29 09:06:56 | 显示全部楼层 |阅读模式
10火花
本帖最后由 如花 于 2018-4-29 09:09 编辑

我用GPIO复用FMC的代码如下:
  1. GPIO_InitTypeDef GPIO_InitStruct;
  2.         
  3.         RCC_AHB3PeriphResetCmd(RCC_AHB3Periph_FMC, ENABLE);
  4.         
  5.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC
  6.                                                                                                 |RCC_AHB1Periph_GPIOD
  7.                                                                                                 |RCC_AHB1Periph_GPIOE
  8.                                                                                                 |RCC_AHB1Periph_GPIOF
  9.                                                                                                 |RCC_AHB1Periph_GPIOG
  10.                                                                                                 |RCC_AHB1Periph_GPIOH, ENABLE);
  11.         
  12.         
  13.         GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
  14.         GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  15.         GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  16.         GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  17.         
  18.         /*A0-A11*/
  19.         GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0
  20.                                                                                                          | GPIO_Pin_1
  21.                                                                                                          | GPIO_Pin_2
  22.                                                                                                          | GPIO_Pin_3
  23.                                                                                                          | GPIO_Pin_4
  24.                                                                                                          | GPIO_Pin_5
  25.                                                                                                          | GPIO_Pin_12
  26.                                                                                                          | GPIO_Pin_13
  27.                                                                                                          | GPIO_Pin_14
  28.                                                                                                          | GPIO_Pin_15;
  29.         GPIO_Init(GPIOF, &GPIO_InitStruct);
  30.         
  31.         GPIO_PinAFConfig(GPIOF, GPIO_Pin_0, GPIO_AF_FMC);
  32.         GPIO_PinAFConfig(GPIOF, GPIO_Pin_1, GPIO_AF_FMC);
  33.         GPIO_PinAFConfig(GPIOF, GPIO_Pin_2, GPIO_AF_FMC);
  34.         GPIO_PinAFConfig(GPIOF, GPIO_Pin_3, GPIO_AF_FMC);
  35.         GPIO_PinAFConfig(GPIOF, GPIO_Pin_4, GPIO_AF_FMC);
  36.         GPIO_PinAFConfig(GPIOF, GPIO_Pin_5, GPIO_AF_FMC);
  37.         GPIO_PinAFConfig(GPIOF, GPIO_Pin_12, GPIO_AF_FMC);
  38.         GPIO_PinAFConfig(GPIOF, GPIO_Pin_13, GPIO_AF_FMC);
  39.         GPIO_PinAFConfig(GPIOF, GPIO_Pin_14, GPIO_AF_FMC);
  40.         GPIO_PinAFConfig(GPIOF, GPIO_Pin_15, GPIO_AF_FMC);
复制代码
但不知道为什么程序在执行了几条GPIO_PinAFConfig的代码之后,就跑不动了。进入调试模式,发现停在了HardFault_Handler那里,然后选择Show Caller Code,发现是ADD  r5,r0,#0x20这段汇编出了问题。
但是我看不懂是什么意思,哪位大神可以帮忙解释一下?
1.png

2.png

3.png

最佳答案

查看完整内容

我来采纳。。。
回复

使用道具 举报

发表于 2018-4-29 09:06:57 | 显示全部楼层
我来采纳。。。
回复

使用道具 举报

 楼主| 发表于 2018-4-29 09:44:25 | 显示全部楼层
发现问题的根源了,GPIO_PinAFConfig函数写错,
GPIO_PinAFConfig(GPIOF, GPIO_Pin_0, GPIO_AF_FMC)是错误的,
GPIO_PinAFConfig(GPIOF, GPIO_PinSource0, GPIO_AF_FMC)是正确的。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-5-4 11:18 , Processed in 0.032851 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表