通过应用程序跳转到 STM32 中的引导加载程序,即在引导模式下从用户闪存使用引导 0 和引导 1 引脚 [英] Jump to Bootloader in STM32 through application i.e using Boot 0 and Boot 1 Pins in Boot mode from User flash

查看:33
本文介绍了通过应用程序跳转到 STM32 中的引导加载程序,即在引导模式下从用户闪存使用引导 0 和引导 1 引脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有固件升级的需求.我打算使用 USB DFU 类.但是在我的情况下,固件升级命令将来自 PC 应用程序.所以我需要切换到系统内存中的引导加载程序.最初我正在运行应用程序,因此它是从用户闪存启动的,即我为用户闪存配置了 Boot0 和 Boot 1 引脚.由于系统闪存中存在 DFU 引导加载程序,现在需要更改 Boot0 和 Boot1 引脚设置.有没有办法让 Boot 0 和 Boot 1 设置保持与用户闪存相同,并且在应用程序中我们跳转到系统内存?

I have a requirement for firmware upgrade. I am planning to use USB DFU class. But command for firmware upgrade will come from PC application in my case . so i need to switch to bootloader which is there in System Memory. As initially i am running application so it is getting booted from User flash i.e i have Boot0 and Boot 1 pins configured for User flash. As DFU bootloader is there in System flash ,now for that Boot0 and Boot1 pins settings need to be changed . is there a way like Boot 0 and Boot 1 settings remain same as User Flash memory and in the application we jump to System Memory?

推荐答案

Boot0/1 引脚仅在处理器启动时采样,以检查是否应从内存加载用户代码或是否应加载引导加载程序.之后这些引脚的状态对引导加载程序没有影响.

Boot0/1 pins are sampled only when the processor starts, in order to check if it should load the user code from memory or if it should load the bootloader. The state of these pins has no effect of the bootloader afterwards.

我遇到过类似的请求,并找到了 2 种按需加载引导加载程序的方法.

I've been faced to a similar request, and found 2 ways to load the bootloader on-demand.

首先,您可以从用户代码跳转"到引导加载程序.例如,您可以在按下按钮时跳转到引导加载程序.

First, you can "JUMP" from user-code to the bootloader. For example, you could jump to the bootloader when a button is pressed.

但是...这比简单的 JUMP 指令复杂得多:必须正确重新配置一些寄存器和设备才能与引导加载程序一起使用,您必须确保在 JUMP 期间不会触发 IRQ,...在事实上,您必须重新配置处理器,就像它在重置后刚刚启动一样.您可以找到有关此技术的一些信息:来自 ST 的此视频.

But... this is far more complicated than a simple JUMP instruction : some registers and devices must be reconfigured correctly to work with the bootloader, you have to ensure that no IRQ will be triggered during the JUMP,... In fact, you have to reconfigure the processor as if it was just started after reset. You can find some information about this technic : on this video from ST.

我设法在 STM32F1xx 项目上做这种事情.但是,在基于 STM32F4 的更复杂的项目中,这将变得非常困难......我将不得不停止所有设备(定时器,通信接口,ADC,DAC,......),确保不会触发任何 IRQ,重新配置所有的时钟,...

I managed to do this kind of things on STM32F1xx project. However, on a more complex project based on STM32F4, this would become really difficult... I would have to stop all devices (timers, communication interface, ADC, DAC,...), ensure that no IRQ would be triggered, reconfigure all the clocks,...

相反,我决定实施第二种解决方案:当我想跳转到引导加载程序时,我在其中一个备份寄存器中写入一个字节,然后发出软复位.然后,当处理器重新启动时,在程序的最开始,它会读取这个寄存器.该寄存器包含指示它应该在引导加载程序模式下重新启动的值.然后,如youtube视频所示,跳转到引导加载程序要容易得多.

Instead, I decided to implement this second solution: When I want to jump to the bootloader, I write a byte in one of the backup register and then issue a soft-reset. Then, when the processor will restart, at the very beginning of the program, it will read this register. This register contains the value indicating that it should reboot in bootloader mode. Then, the jump to the bootloader is much easier, as presented in the youtube video.

这篇关于通过应用程序跳转到 STM32 中的引导加载程序,即在引导模式下从用户闪存使用引导 0 和引导 1 引脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆