打印

再次偷懒一下,不看资料了,直接问,关于BKP

[复制链接]
2486|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
simon21ic|  楼主 | 2008-8-14 04:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
pi, IO, gp, GPIO, ST
我想增加STM32USBBoot的一个功能,通过BKP寄存器来传递是否需要进入Bootloader模式的参数,代码如下:
void Sys_Init(void)
{
  /* Check Bootloader Condition */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);

  BKP_TamperPinCmd(DISABLE);

  /* Configure Tamper as input pulldown */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  if((GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13) == SET) && (BKP_ReadBackupRegister(0) != FWU_KEY))
  {
    // Realease resources and jump to Application
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,DISABLE);

    __MSR_MSP(*(vu32 *)BL_APP_START);
    APP_ADDR();
  }

  /* Configure the system clocks */
  RCC_Configuration();

  /* Configure the GPIO ports */
  GPIO_Configuration();

  USB_Init();
}
其中,会检测一个按键(目前使用GPIOC_13),还会检测BKP第0号寄存器,如果等于FWU_KEY的话,则运行Bootloader
在应用程序中:
BKP_WriteBackupRegister(0, FWU_KEY);
USB_Reset();
NVIC_GenerateSystemReset();
调用后,系统和USB接口都复位,但复位后没有进入Bootloader,如果复位时,GPIOC_13拉低的话,确实是可以进入Bootloader的。
是否是因为调用了NVIC_GenerateSystemReset后,BKP寄存器的内容也Reset了?
沙发
香水城| | 2008-8-14 10:04 | 只看该作者

哈哈,你偷懒,我帮你把资料抄下来

这是STM32技术参考手册的第5.1节,注意带下划线的部分:

5.1 BKP introduction
The backup registers are forty two 16-bit registers for storing 84 bytes of user application
data. They are implemented in the backup domain that remains powered on by VBAT when
the VDD power is switched off. They are not reset when the device wakes up from Standby
mode or by a system reset or power reset.

In addition, the BKP control registers are used to manage the Tamper detection feature and
RTC calibration.

After reset, access to the Backup registers and RTC is disabled and the Backup domain
(BKP) is protected against possible parasitic write access. To enable access to the Backup
registers and the RTC, proceed as follows:

● enable the power and backup interface clocks by setting the PWREN and BKPEN bits
in the RCC_APB1ENR register
● set the DBP bit the Power Control Register (PWR_CR) to enable access to the Backup
registers and RTC.

使用特权

评论回复
板凳
simon21ic|  楼主 | 2008-8-14 14:05 | 只看该作者

哈哈

以后我再偷懒千万不要理我哈,要被惯坏的。。。。。。
还有一个错误:BKP_ReadBackupRegister的参数应该是BKP_DR1...

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

266

主题

2597

帖子

104

粉丝