关于STM32F107移植到GD32F307后,固件不断重启的一个解决方式

近期有一个STM32F107的项目需要移植到GD32F307。遇到一个问题发现其他移植教程中都没有提到。

目录

1.首先是按照网上的教程:

1)修改启动时间宏定义

2)修改内部flash

3)flash访问时间

2.这个是其他教程中没有提到的

1)floating point hardware设置

 总结:




1.首先是按照网上的教程:

1)修改启动时间宏定义

#define HSE_STARTUP_TIMEOUT ((uint16_t)0x0500)

修改为:

#define HSE_STARTUP_TIMEOUT ((uint16_t)0xFFFF)

2)修改内部flash

在写完KEY 序列以后,需要读该位,确认key 已生效。

需要插入:while((FLASH->CR&CR_OPTWRE_Set)!=CR_OPTWRE_Set ){}

                  #define CR_OPTWRE_Set ((uint32_t)0x00000200)

在ST库中,有以下四个函数中需要修改:

FLASH_Status FLASH_EraseOptionBytes(void)

FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data)

FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages)

FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState)

示例:

FLASH_Status FLASH_EraseOptionBytes(void)
{
  uint16_t rdptmp = RDP_Key;

  FLASH_Status status = FLASH_COMPLETE;

  /* Get the actual read protection Option Byte value */ 
  if(FLASH_GetReadOutProtectionStatus() != RESET)
  {
    rdptmp = 0x00;  
  }

  /* Wait for last operation to be completed */
  status = FLASH_WaitForLastOperation(EraseTimeout);
  if(status == FLASH_COMPLETE)
  {
    /* Authorize the small information block programming */
    FLASH->OPTKEYR = FLASH_KEY1;
    FLASH->OPTKEYR = FLASH_KEY2;

	/********看这里看这里看这里看这里看这里看这里**********/	
	while((FLASH->CR&CR_OPTWRE_Set)!=CR_OPTWRE_Set )
	{}
    /****************************************************/	

    /* if the previous operation is completed, proceed to erase the option bytes */
    FLASH->CR |= CR_OPTER_Set;
    FLASH->CR |= CR_STRT_Set;
    /* Wait for last operation to be completed */
    status = FLASH_WaitForLastOperation(EraseTimeout);
    
    if(status == FLASH_COMPLETE)
    {
      /* if the erase operation is completed, disable the OPTER Bit */
      FLASH->CR &= CR_OPTER_Reset;
       
      /* Enable the Option Bytes Programming operation */
      FLASH->CR |= CR_OPTPG_Set;
      /* Restore the last read protection Option Byte value */
      OB->RDP = (uint16_t)rdptmp; 
      /* Wait for last operation to be completed */
      status = FLASH_WaitForLastOperation(ProgramTimeout);
 
      if(status != FLASH_TIMEOUT)
      {
        /* if the program operation is completed, disable the OPTPG Bit */
        FLASH->CR &= CR_OPTPG_Reset;
      }
    }
    else
    {
      if (status != FLASH_TIMEOUT)
      {
        /* Disable the OPTPG Bit */
        FLASH->CR &= CR_OPTPG_Reset;
      }
    }  
  }
  /* Return the erase status */
  return status;
}

3)flash访问时间

GD32 由于自有flash 的0 访问时序,同STM32 在Flash 的Erase 和Program 上存在差别,GD32 的Erase 和Program 时间比STM32 的稍微长些,建议对Erase 和Program 时间进行修改。

解决方法:将宏定义

#define EraseTimeout ((uint32_t)0x000B0000)

#define ProgramTimeout ((uint32_t)0x00002000)

修改为:

#define EraseTimeout ((uint32_t)0x000FFFFF)

#define ProgramTimeout ((uint32_t)0x0000FFFF)

2.这个是其他教程中没有提到的

1)floating point hardware设置

一般来说,完成以上三个步骤移植就算完成了,但是我的固件烧录在固件中后,程序会不断重启。折腾了大半天,发现把下面这个配置关掉就好了。

点击“魔术棒”-“Code Generation”中的“Floating Point Hardware”,选择“Not Used”。

 总结:

这个选项在STM32中貌似是没有的,把工程中的芯片包换成GD32F30x之后,就会冒出这个选项。暂不清楚有什么作用,有知道的大佬也可以在评论区解惑,谢谢啦!

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CSDNITK

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值