Atmel SAM3X 双组切换不起作用 [英] Atmel SAM3X dual bank switching not working

查看:12
本文介绍了Atmel SAM3X 双组切换不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Atmel SAM3X8 ARM 微控制器,该微控制器具有双组 2 x 256KB 闪存.我正在尝试实现固件更新功能,将新固件放入当前未使用的闪存库中,完成后使用闪存重新映射交换库以运行新固件.

I'm currently working with an Atmel SAM3X8 ARM microcontroller that features a dual banked 2 x 256KB flash memory. I'm trying to implement a firmware update feature, that puts the new firmware into the currently unused flash bank, and when done swaps the banks using the flash remapping to run the new firmware.

数据表指出,我需要设置 GPNVM2 位,然后 MCU 将重新映射内存,因此闪存 1 现在位于 0x80000,闪存 0 位于 0xC0000.这也会导致 MCU 执行从 Flash 1 开始的代码.

The datasheet states to do so I need to set the GPNVM2 bit, then the MCU will remap the memory, so Flash 1 is now at 0x80000 and Flash 0 at 0xC0000. This will also lead to the MCU executing code beginning from Flash 1.

引用数据表:

GPNVM2 仅用于交换 Flash 0 和 Flash 1.如果 GPNVM2 为 ENABLE,则 Flash 1 映射到地址 0x0008_0000(Flash 1 和 Flash 0 是连续的).如果 GPNVM2 为 DISABLE,则 Flash 0 映射到地址 0x0008_0000(Flash 0 和 Flash 1 是连续的).

The GPNVM2 is used only to swap the Flash 0 and Flash 1. If GPNVM2 is ENABLE, the Flash 1 is mapped at address 0x0008_0000 (Flash 1 and Flash 0 are continuous). If GPNVM2 is DISABLE, the Flash 0 is mapped at address 0x0008_0000 (Flash 0 and Flash 1 are continuous).

[...]

GPNVM2 可以选择使用 Flash 0 还是 Flash 1 进行引导.设置 GPNVM 位 2 选择从 Flash 1 启动,清除它选择从 Flash 0 启动.

GPNVM2 enables to select if Flash 0 or Flash 1 is used for the boot. Setting GPNVM bit 2 selects the boot from Flash 1, clearing it selects the boot from Flash 0.

但是当我使用 flash_set_gpnvm(2)(ASF SAM Flash Service API)通过 SAM-BA 或我自己的固件设置 GPNVM2 时,它仍然会从 Flash 0 中的程序启动,并且新程序仍将驻留在 Flash 1 的偏移量 0xC0000.GPNVM2的状态已经通过flash_is_gpnvm_set(2)

But when I set GPNVM2, either via SAM-BA or my own firmware using flash_set_gpnvm(2) (ASF SAM Flash Service API), it will still boot from the program in Flash 0, and the new program will still reside at Flash 1's offset 0xC0000. The state of GPNVM2 has been verified by flash_is_gpnvm_set(2)

将固件本身刷入 Flash1 bank 可以完美运行,这已通过使用 SAM-BA 转储整个闪存进行验证.

Flashing the firmware itself to Flash1 bank works flawlessly, that has been verified by dumping the whole flash memory with SAM-BA.

Atmel 有一个关于一个问题的勘误表,即闪存重新映射仅适用于小于 64KB 的部分.我的代码少于那个 (40KB),所以这应该不是问题.

There is an errata from Atmel about an issue, that the flash remapping only works for portions smaller than 64KB. My code is less than that (40KB), so this shouldn't be an issue.

我没有发现任何其他人有这个问题,也没有任何示例如何使用它,所以也许有人可以告诉我我在这里做错了什么,或者还有什么要检查的.

I've not found any other people having this issue, nor any example how to use it, so maybe somebody could tell me if I'm doing something wrong here, or what else to check.

推荐答案

我遇到了同样的问题(请参阅此处:Atmel SAM3X8E 双组切换用于启动不同的行为).

I had the same issue (see here: Atmel SAM3X8E dual bank switching for booting different behaviour).

经过更多研究,我找到了一份应用说明(链接:http://ww1.microchip.com/downloads/en/AppNotes/Atmel-42141-SAM-AT02333-Safe-and-Secure-Bootloader-Implementation-for-SAM3-4_Application-Note.pdf) 以更清晰的方式解释了 SAM3X 的启动行为.问题是数据表有点误导(至少我也很困惑).SAM3X 无法重新映射闪存组.启动行为有点不同(参见链接中的图片,它是从应用说明中截取的,第 33/34 页):SAM3X 启动行为

After some more research I found an Application Note (Link: http://ww1.microchip.com/downloads/en/AppNotes/Atmel-42141-SAM-AT02333-Safe-and-Secure-Bootloader-Implementation-for-SAM3-4_Application-Note.pdf) which explains the boot behaviour of the SAM3X in a more clear way. The problem is that the datasheet is a bit misleading (at least I was confused too). The SAM3X has no ability to remap the the Flash banks. The booting behaviour is a bit different (see the picture in the link, it's a snipped from the Application note, page 33/34): Booting behaviour SAM3X

图 3-9 显示了 SAM3X 在启动时的行为.GPNVM 位 1 和 2 仅确定哪个内存部分 (ROM/Flash0/Flash1) 被镜像到引导内存(位于 0x00000000).Flash bank 的映射没有改变.因此 Flash0 仍然映射到 0x00080000,Flash1 映射到 0x000C0000).

Picture 3-9 shows the SAM3X's behaviour at the boot-up. The GPNVM bits 1 and 2 just determine which memory section (ROM/Flash0/Flash1) is mirrored to the boot memory (located at 0x00000000). The mapping of the Flash banks is not changed. Therefore Flash0 still is mapped to 0x00080000 and Flash1 to 0x000C0000).

正如应用说明所述,其他一些 Atmel 微控制器能够真正重新映射闪存组(例如 SAM3SD8 和 SAM4SD32/16).如图 3-10 所示,这些处理器改变了闪存库的位置.

As the Application Note states some other Atmel microcontrollers are able to really remap the Flash banks (e.g. SAM3SD8 and SAM4SD32/16). These processors change the location of the Flash banks as you can see in picture 3-10.

为了能够更新您的固件,因此有必要实施某种引导加载程序.我自己实现了一个,即使根本不使用 GPNVM 位也能够更新我的固件.我还在 Microchip 开了一张支持票,以阐明启动行为.当我收到答复时,我希望能告诉你更多.

To be able to update your firmware it is therefore necessary to implement some kind of bootloader. I implemented one by myself and was able to update my firmware even without using the GPNVM bits at all. I also opend a support ticket at Microchip to clarify the booting behaviour. When I receive an answer I hope to tell you more.

以下是来自 Microchip 支持的答复:

Here's the answer from the Microchip support:

在 SAM3X 中设置 GPNVM2 位只会使 CPU 跳转到"或从闪存组 1 即 0xC0000 启动.不会发生实际的内存地址交换.

Setting the GPNVM2 bit in SAM3X will merely make the CPU 'jump to' or start from flash bank 1 i.e. 0xC0000. No actual swap of memory addresses will take place.

要使用闪存库 1,您需要更改链接器文件 (flash.ld) 以反映闪存起始地址 0xC0000.

To use flash bank 1, you will need to change the linker file (flash.ld) to reflect the flash start address 0xC0000.

对于闪存库 0 应用程序,更改:rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00080000/* Flash, 512K /到:rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00040000/ Flash, 256K */

For flash bank 0 application, change: rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00080000 /* Flash, 512K / to: rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00040000 / Flash, 256K */

对于闪存库 1 应用程序,更改:rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00080000/* Flash, 512K /到:rom (rx) : ORIGIN = 0x000C0000, LENGTH = 0x00040000/ Flash, 256K */

For flash bank 1 application, change: rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00080000 /* Flash, 512K / to: rom (rx) : ORIGIN = 0x000C0000, LENGTH = 0x00040000 / Flash, 256K */

如果不这样做,闪存 1 应用程序中的复位处理程序将指向闪存 0 应用程序中的地址.因此,虽然代码将在 flash 1 中开始执行(如果设置了 GPNVM2),但它会跳回到 flash 0 应用程序.可以忽略说明 64kb 限制的勘误表.

If this is not done, the reset handler in the flash 1 application will point to an address in the flash 0 application. So, although code will start execution in flash 1 (if GPNVM2 is set), it will jump back to the flash 0 application. The errata stating the 64kb limitation can be ignored.

因此应用说明是正确的,并没有对 mmory 映射进行实际更改.

Therefore the Application Note is right and no actual change of the mmory mapping is performed.

干杯卢卡斯

这篇关于Atmel SAM3X 双组切换不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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