TI工程师您好:
cc2530,版本2.5.1a,我想用HalFlashWrite来改写secondary MAC。发现调用HalFlashWrite写了,但从打印来看,没写成功。
HalFlashWrite(uint16 addr, uint8 *buf, uint16 cnt)中的addr和cnt均是按除4来处理的,请问还有什么地方需要注意吗?
直接在zmain_ext_addr中增加调试代码如下:
static void zmain_ext_addr(void)
{
uint8 nullAddr[Z_EXTADDR_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8 writeNV = TRUE;
uint8 locbit[HAL_FLASH_LOCK_BITS] = {0};
uint8 testMac[Z_EXTADDR_LEN] = {0};
uint8 testMac2[Z_EXTADDR_LEN] = {0x12,0x34,0x56,0x78,0x9A,0xAB,0xCD,0xEF}; uint8 strTemp[100]={0};
HalUARTWrite(1, "[MAC_01]\r\n", osal_strlen("[MAC_01]\r\n"));
#if defined NON_BANKED
HalUARTWrite(1, "[MAC_02]\r\n", osal_strlen("[MAC_02]\r\n"));
#endif
#if 1 osal_memset(locbit,0,16);
memset(locbit,0,HAL_FLASH_LOCK_BITS);
HalFlashRead(HAL_FLASH_IEEE_PAGE, (HAL_FLASH_IEEE_OSET+HAL_FLASH_IEEE_SIZE), locbit, HAL_FLASH_LOCK_BITS);
osal_memset(strTemp,0,100);
sprintf((char *)strTemp, "\r\n[MAC_00001:%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x]\r\n"
,locbit[0],locbit[1],locbit[2],locbit[3],locbit[4],locbit[5],locbit[6],locbit[7]
,locbit[8],locbit[9],locbit[10],locbit[11],locbit[12],locbit[13],locbit[14],locbit[15]);
HalUARTWrite(1, strTemp, osal_strlen((char *)strTemp));
osal_memset(testMac,0,8);
HalFlashRead(HAL_FLASH_IEEE_PAGE, HAL_FLASH_IEEE_OSET, testMac, Z_EXTADDR_LEN);
osal_memset(strTemp,0,100);
sprintf((char *)strTemp, "\r\n[MAC_00002:%02x %02x %02x %02x %02x %02x %02x %02x]\r\n"
,testMac[0],testMac[1],testMac[2],testMac[3],testMac[4],testMac[5],testMac[6],testMac[7]);
HalUARTWrite(1, strTemp, osal_strlen((char *)strTemp));
HalFlashWrite(0xFFFA, testMac2, 2);
osal_memset(testMac,0,8);
HalFlashRead(HAL_FLASH_IEEE_PAGE, HAL_FLASH_IEEE_OSET, testMac, Z_EXTADDR_LEN);
osal_memset(strTemp,0,100);
sprintf((char *)strTemp, "\r\n[MAC_00003:%02x %02x %02x %02x %02x %02x %02x %02x]\r\n"
,testMac[0],testMac[1],testMac[2],testMac[3],testMac[4],testMac[5],testMac[6],testMac[7]);
HalUARTWrite(1, strTemp, osal_strlen((char *)strTemp));
#endif
// First check whether a non-erased extended address exists in the OSAL NV.
if ((SUCCESS != osal_nv_item_init(ZCD_NV_EXTADDR, Z_EXTADDR_LEN, NULL)) ||
(SUCCESS != osal_nv_read(ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, aExtendedAddress)) ||
(osal_memcmp(aExtendedAddress, nullAddr, Z_EXTADDR_LEN)))
{
// Attempt to read the extended address from the location on the lock bits page
// where the programming tools know to reserve it.
HalFlashRead(HAL_FLASH_IEEE_PAGE, HAL_FLASH_IEEE_OSET, aExtendedAddress, Z_EXTADDR_LEN);
osal_memset(strTemp,0,100);
sprintf((char *)strTemp, "\r\n[MAC_03:page:0x%x,offset:0x%x,%02x %02x %02x %02x %02x %02x %02x %02x]\r\n"
,HAL_FLASH_IEEE_PAGE,HAL_FLASH_IEEE_OSET
,aExtendedAddress[0],aExtendedAddress[1],aExtendedAddress[2],aExtendedAddress[3]
,aExtendedAddress[4],aExtendedAddress[5],aExtendedAddress[6],aExtendedAddress[7]);
HalUARTWrite(1, strTemp, osal_strlen((char *)strTemp));
if (osal_memcmp(aExtendedAddress, nullAddr, Z_EXTADDR_LEN))
{
// Attempt to read the extended address from the designated location in the Info Page.
if (!osal_memcmp((uint8 *)(P_INFOPAGE+HAL_INFOP_IEEE_OSET), nullAddr, Z_EXTADDR_LEN))
{
osal_memcpy(aExtendedAddress, (uint8 *)(P_INFOPAGE+HAL_INFOP_IEEE_OSET), Z_EXTADDR_LEN);
osal_memset(strTemp,0,100);
sprintf((char *)strTemp, "\r\n[MAC_04:%02x %02x %02x %02x %02x %02x %02x %02x]\r\n"
,aExtendedAddress[0],aExtendedAddress[1],aExtendedAddress[2],aExtendedAddress[3]
,aExtendedAddress[4],aExtendedAddress[5],aExtendedAddress[6],aExtendedAddress[7]);
HalUARTWrite(1, strTemp, osal_strlen((char *)strTemp)); }
else // No valid extended address was found.
{
uint8 idx;
#if !defined ( NV_RESTORE )
writeNV = FALSE; // Make this a temporary IEEE address
#endif
/* Attempt to create a sufficiently random extended address for expediency.
* Note: this is only valid/legal in a test environment and
* must never be used for a commercial product.
*/
for (idx = 0; idx < (Z_EXTADDR_LEN – 2);)
{
uint16 randy = osal_rand();
aExtendedAddress[idx++] = LO_UINT16(randy);
aExtendedAddress[idx++] = HI_UINT16(randy);
}
// Next-to-MSB identifies ZigBee devicetype.
#if ZG_BUILD_COORDINATOR_TYPE && !ZG_BUILD_JOINING_TYPE
aExtendedAddress[idx++] = 0x10;
#elif ZG_BUILD_RTRONLY_TYPE
aExtendedAddress[idx++] = 0x20;
#else
aExtendedAddress[idx++] = 0x30;
#endif
// MSB has historical signficance.
aExtendedAddress[idx] = 0xF8;
osal_memset(strTemp,0,100);
sprintf((char *)strTemp, "\r\n[MAC_05:%02x %02x %02x %02x %02x %02x %02x %02x]\r\n"
,aExtendedAddress[0],aExtendedAddress[1],aExtendedAddress[2],aExtendedAddress[3]
,aExtendedAddress[4],aExtendedAddress[5],aExtendedAddress[6],aExtendedAddress[7]);
HalUARTWrite(1, strTemp, osal_strlen((char *)strTemp)); }
}
if (writeNV)
{
(void)osal_nv_write(ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, aExtendedAddress);
HalUARTWrite(1, "\r\n[MAC_06]\r\n", osal_strlen("\r\n[MAC_06]\r\n"));
}
}
// Set the MAC PIB extended address according to results from above.
(void)ZMacSetReq(MAC_EXTENDED_ADDRESS, aExtendedAddress);
osal_memset(strTemp,0,100);
sprintf((char *)strTemp, "\r\n[MAC_07:%02x %02x %02x %02x %02x %02x %02x %02x]\r\n"
,aExtendedAddress[0],aExtendedAddress[1],aExtendedAddress[2],aExtendedAddress[3]
,aExtendedAddress[4],aExtendedAddress[5],aExtendedAddress[6],aExtendedAddress[7]);
HalUARTWrite(1, strTemp, osal_strlen((char *)strTemp));
}
在uart1上打印信息如下:
[MAC_011]
[MAC_00001:FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF]
[MAC_00002:08 34 46 50 00 23 00 01]
[MAC_00003:08 34 46 50 00 23 00 01]
[MAC_07:00 00 00 00 00 00 00 00]
Viki Shi:
1、smartrf flash programmer修改是否成功?
2、HalFlashWrite的使用请参考:
e2echina.ti.com/…/147178
blog.csdn.net/…/95969779
Winkeys Lin:
回复 Viki Shi:
smartrf flash programmer修改可以成功,但直接通过HalFlashWrite不成功。
换了台设备,似乎第1次调用HalFlashWrite可写成功,后续修改参数后再写就不成功了。
请问HalFlashWrite是有这个限制只允许写1次吗?
另smartrf flash programmer写secondary MAC的代码在什么地方?[MAC_01]
[MAC_00001:FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF]
[MAC_00002:12 34 56 78 9A AB CD EF]
[MAC_00003:12 34 56 78 9A AB CD EF]—正确
[MAC_07:CB 3D 62 1A 00 4B 12 00]
[Uart1 init1019]
[MAC_01][MAC_00001:FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF]
[MAC_00002:12 34 56 78 9A AB CD EF]
[MAC_00003:10 20 12 78 9A AB CD EF]—不正确,此时我换成了 11 22 33 78 9A AB CD EF
[MAC_07:CB 3D 62 1A 00 4B 12 00]
[Uart1 init1019]
[MAC_01][MAC_00001:FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF]
[MAC_00002:10 20 12 78 9A AB CD EF]
[MAC_00003:10 20 12 78 9A AB CD EF]
[MAC_07:CB 3D 62 1A 00 4B 12 00]
[Uart1 init1019]
Winkeys Lin:
回复 Viki Shi:
知道原因了。操作前需调用HalFlashErase。
擦除是以1个page(2048字节)为单位的,这个page内还有许多其它信息,如先将page读出到SRAM,在SRAM修改后再整个page写入,可是SRAM才8K(已用了很多,剩余不够2K),请问有什么好的方法推荐?