请选择 进入手机版 | 继续访问电脑版
搜索
查看: 1143|回复: 2

[分享] STM32CubeMX5.01+F1 1.7.0初始化默认端口为高电平时要注意

[复制链接]

该用户从未签到

15

主题

151

帖子

16

蝴蝶豆

金牌会员

最后登录
2022-2-25
发表于 2019-1-18 15:28:02 | 显示全部楼层 |阅读模式
发现初始化时在图形界面设置输出为置位(就是高电平),不能成功,必须在后面重新置位才行,使用时需要当心。
详细看下文
static void MX_GPIO_Init(void)
{
  LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC);
  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOD);
  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);

  /**/
  LL_GPIO_SetOutputPin(Pow_Con_GPIO_Port, Pow_Con_Pin);

  /**/
  LL_GPIO_SetOutputPin(SPI2_NSS_GPIO_Port, SPI2_NSS_Pin);

  /**/
  LL_GPIO_ResetOutputPin(GPIOB, Dis_Led0_Pin|Dis_Led1_Pin|Dis_Led2_Pin|Dis_Led3_Pin);

  /**/
  LL_GPIO_ResetOutputPin(GPIOA, Dis_Led5_Pin|Dis_Led6_Pin|Dis_Led7_Pin);

  /**/
  GPIO_InitStruct.Pin = Pow_Con_Pin;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  LL_GPIO_Init(Pow_Con_GPIO_Port, &GPIO_InitStruct);

  /**/
  GPIO_InitStruct.Pin = LL_GPIO_PIN_14|LL_GPIO_PIN_15;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  LL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /**/
  GPIO_InitStruct.Pin = Dis_Led0_Pin|Dis_Led1_Pin|Dis_Led2_Pin|Dis_Led3_Pin;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_MEDIUM;
  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  LL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /**/
  GPIO_InitStruct.Pin = SPI2_NSS_Pin;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  LL_GPIO_Init(SPI2_NSS_GPIO_Port, &GPIO_InitStruct);

  /**/
  GPIO_InitStruct.Pin = Dis_Led5_Pin|Dis_Led6_Pin|Dis_Led7_Pin;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_MEDIUM;
  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /**/
  GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /**/
  GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6
                          |LL_GPIO_PIN_7|LL_GPIO_PIN_8;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  LL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /**/
  GPIO_InitStruct.Pin = Pow_Key_Pin;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  LL_GPIO_Init(Pow_Key_GPIO_Port, &GPIO_InitStruct);

//必须添加下列代码,否则口初始化默认置位不成功
  /**/
  LL_GPIO_SetOutputPin(Pow_Con_GPIO_Port, Pow_Con_Pin);

  /**/
  LL_GPIO_SetOutputPin(SPI2_NSS_GPIO_Port, SPI2_NSS_Pin);

}

回复

使用道具 举报

该用户从未签到

2

主题

6

帖子

0

蝴蝶豆

新手上路

最后登录
2019-1-18
发表于 2019-1-18 15:31:11 | 显示全部楼层
回复

使用道具 举报

该用户从未签到

76

主题

759

帖子

17

蝴蝶豆

论坛元老

最后登录
2022-5-20
发表于 2019-2-27 15:26:31 | 显示全部楼层
不知道HAL库有没有这个问题。
回复 支持 反对

使用道具 举报

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

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|论坛-意法半导体STM32/STM8技术社区

GMT+8, 2024-3-29 16:39 , Processed in 1.148832 second(s), 31 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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