This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

如何通过程序修改物理地址

Other Parts Discussed in Thread: Z-STACK, CC2530

请问一下,如何在程序里面修改secondary IEEE address?希望论坛大神指点一二,下面是程序,但是修改过后用flash programmer读到的地址不是修改过后的

static void zmain_ext_addr(void)
{
uint8 nullAddr[Z_EXTADDR_LEN] = {0xFF, 0xFF 0xFF, 0xFF 0xFF, 0xFF, 0xFF, 0xFF};
uint8 writeNV = TRUE;

HalFlashRead(HAL_FLASH_IEEE_PAGE, HAL_FLASH_IEEE_OSET, aExtendedAddress, Z_EXTADDR_LEN);
// 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);

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);
}
else // No valid extended address was found.
{
// uint8 idx=0;

#if !defined ( NV_RESTORE )
writeNV = FALSE; // Make this a temporary IEEE address
#endif
#if defined ZDO_COORDINATOR
aExtendedAddress[0] = 0x10;
#elif defined RTR_NWK
aExtendedAddress[0] = 0x20;
#else
aExtendedAddress[0] = 0x4B;
#endif
// MSB has historical signficance.
aExtendedAddress[1] = 0x54;
aExtendedAddress[2] = 0x44;
aExtendedAddress[3] = 0x5A;
aExtendedAddress[4] = 0x47;
aExtendedAddress[5] = 0xFF;
aExtendedAddress[6] = 0xFF;
aExtendedAddress[7] = 0xFF;
}
}

if ( writeNV )
{
(void)osal_nv_write(ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, aExtendedAddress);
}
}

// Set the MAC PIB extended address according to results from above.
(void)ZMacSetReq(MAC_EXTENDED_ADDRESS, aExtendedAddress);
}

  • 参考C:\Texas Instruments\ZStack-CC2530-2.5.1a\Documents   Z-Stack User's Guide - CC2530DB 可知

    The Secondary IEEE address location is found on the last page of the CC2530 flash memory, at an offset of 0x0018 bytes from the last memory address. For a 256-Kbyte device, the IEEE address can be commissioned at 0x3FFE8-0x3FFEF.

    您可以通过FLASH写入

  • 你好,

    关于协议里面存放IEEE的地址,和使用的逻辑请再搞清楚下。

    1)首先CC2530里面有两个IEEE地址,一个Primary IEEE地址,还有一个Secondary IEEE地址。这个你应该知道的。

    2)Primary IEEE是放在Info Page里面,用户只能读,没办法写。Secondary IEEE是可以读也可以写的

    3)协议栈第一次启动的时候,会去Secondary IEEE和Primary IEEE地址里面挑选一个,作为该设备的MAC 地址,然后写到NV里面。

    所以整个CC2530程序跑起来以后,有三个地方存放了IEEE地址,分别是Primary IEEE 在info page里面。 Secondary IEEE在Flash里面,MAC Address 在NV Flash里面。其中MAC Address是选择Primary和Secondary的某一个。至于怎么选的逻辑上面的程序很清楚了。

    4)协议栈在第一次启动的时候,首先会判断NV里面有没有,如果没有的话就去Primary和Secondary里面挑了,所以你改的代码是没有用的,因为前天通过挑选已经挑选好了,并且放到NV去了,你的代码根本不会执行到。

    所以建议做下面的修改,

    在刚进入的zmain_ext_addr(void)的时候,利用Flash的 Write函数,也就是HalFlashWrite,往HAL_FLASH_IEEE_PAGE, HAL_FLASH_IEEE_OSET地方,写进入8个字节的数据就可以了。

    当然如不你不用代码操作,你也可以用SmartRF Flash Programmer来写也可以的。

  • 谢谢VV的详细讲解!

  • VV解答的很明白,谢谢指导。

    但是官方代码为什么搞那么复杂呢?出发点在哪里?每次上电直接读取Primary IEEE来用不就行了吗?

    如果用户想自定义地址的话,自己写代码直接修改aExtendedAddress不就行了吗?

    以上不解。

  • 没有复杂啊,因为还有个NV。