问题描述
我一直在尝试从 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,它应该给出错误或警告消息,然后停止读取。 不要从中国购买假芯片!
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)