【发布时间】:2021-05-01 05:20:58
【问题描述】:
我一直在尝试从 Atmel SAM3U MCU 读取唯一标识符 (UID),但事实证明它比实现它所需的难度更大。有没有人有任何例子或可以建议如何正确阅读它?每当我这样做时,我都会在 do while 循环(如文档状态)中等待 EEFC(闪存 ROM)状态寄存器更改状态,但它从来没有这样做,因此 MCU 会陷入循环。
这是我正在使用的代码
// must run this from SRAM
__attribute__((section(".ARM.__at_0x20080000"))) void Get_Unique_ID(unsigned int *pdwUniqueID)
{
Efc *p_efc;
unsigned int status;
// clear the array
pdwUniqueID[0] = 0;
pdwUniqueID[1] = 0;
pdwUniqueID[2] = 0;
pdwUniqueID[3] = 0;
// send the Start Read Unique Identifier command (STUI) by writing the Flash Command Register with the STUI command
p_efc->EEFC_FCR = EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_STUI;
// wait for the Flash Programming Status Register (EEFC_FSR) to fall
do { status = p_efc->EEFC_FSR; }
while ((status & EEFC_FSR_FRDY) == EEFC_FSR_FRDY);
// the Unique Identifier is located in the first 128 bits of the Flash memory mapping
pdwUniqueID[0] = *(unsigned int *)IFLASH0_ADDR;
pdwUniqueID[1] = *(unsigned int *)(IFLASH0_ADDR + 4);
pdwUniqueID[2] = *(unsigned int *)(IFLASH0_ADDR + 8);
pdwUniqueID[3] = *(unsigned int *)(IFLASH0_ADDR + 12);
// to stop the Unique Identifier mode, the user needs to send the Stop Read unique Identifier
// command (SPUI) by writing the Flash Command Register with the SPUI command
p_efc->EEFC_FCR = EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_SPUI;
// when the Stop Read Unique Unique Identifier command (SPUI) has been performed
// the FRDY bit in the Flash Programming Status Register (EEFC_FSR) rises
do { status = p_efc->EEFC_FSR; }
while ((status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY);
}
请注意,__attribute__((section(".ARM.__at_0x20080000"))) 不是通过链接器将此函数动态分配给 SRAM 的最佳方法,如果有任何关于如何使其更具动态性的建议,我们将不胜感激。
已解决问题是我的芯片是假的,所以 SAM-BA 会返回它指定的 SRAM 缓冲区地址中的任何内容。这是 SAM-BA 中的一个错误,因为如果它收到 0x00000000,它应该给出错误或警告消息,然后停止读取。 不要从中国购买假芯片!
谢谢。
【问题讨论】:
-
有什么理由不写循环,例如
while((p_efc->EEFC_FSR & EEFC_FSR_FRDY)==0){}? -
我问的原因是因为 SAM 部件在一些寄存器中往往具有神秘的未记录副作用。有时您必须在不屏蔽位域的情况下读取整个寄存器,否则会出现未记录的硅奥秘。
-
循环代码不是我认为的问题。问题是 MCU 没有触发那些 Flash ROM (EEFC) 寄存器位,因此它实际上卡在了那个循环中。
-
在调用函数之前是否禁用了所有中断(“IRQ 禁用”)?
-
是的,中断被禁用。
标签: arm embedded microcontroller keil atmel