Hello,
We can read "Config" memory area by DK6Programmer, however I could not find information how to read them from the firmware. Is it mapped to some address?
I want to read the factory MAC address which is located in "Config" memory area. After programming 154_cmac0, vMMAC_GetMacAddress() will refer to 154_cmac0. How do I read factory MAC address?
Note: my program does not use ZigBee3.0 stack, but use MMAC and low level APIs only.
Thanks!
已解决! 转到解答。
Hi @usaygo,
Please look at the next implementation in code.
#define MAC_ADDR_DEFAULT 0x0009fc70
tsExtAddr psMacAddr;
/* Get the factory MAC address from the N-2 page */
psMacAddr.u32L = *(volatile uint32_t *)(MAC_ADDR_DEFAULT);
psMacAddr.u32H = *(volatile uint32_t *)(MAC_ADDR_DEFAULT + 4);
You will read out the mac address.
Regards,
Mario
Hi @usaygo,
You could read it, one method is to use pFLASH read API(psector_ReadData) in your application to read all pFLASH content and then print it.
For the memory map of the pFLASH, you can check structure pflash within in struct psector_page_data_t that defined in rom_psectr.h.
Regards,
Mario
Hello and Thanks for reply,
I already did read the pFlash area, however it does not seem to contain "Config" area.
9e000: 00 80 00 04 e8 01 00 03 : 2d 01 00 03 31 01 00 03
9e010: 35 01 00 03 81 0e 00 03 : 3d 01 00 03 19 e1 09 00
9e020: 14 00 00 cc 00 00 00 00 : 00 00 00 00 85 5e 00 03
...
9ec50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
9ec60: {154_cmac0} ........ : {154_cmac1}
9ec70: {ble_cmac0} : {ble_cmac1}
9ec80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
... // there is same data.
9ee50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
9ee60: {154_cmac0} ........ : {154_cmac1}
9ee70: {ble_cmac0} : {ble_cmac1}
9ee80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...
9eff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
9f <hungs here, cannot read from x9f000>
the "Config" area is
$ DK6Programmer.exe -V 0 -s COM4 -r Config:128
COM4: Connected at 115200
COM4: Detected JN5189 with MAC address 00:15:8D:00:05:B0:EA:86
COM4: Selected memory: Config
COM4: Reading 128 bytes from Config at 00000000
COM4: Config = a41c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ca0100000000000000000000000000d054375254373432423030302e0000000045140080ca000000d83b3401ce870200[86eab005008d1500:Factory MAC]0000000000000000
Any idea to read factory MAC?
Hi @usaygo,
You could type the next command to read out the config data using the DK6Programmer.
DK6Programmer.exe -V5 -s COM18 -r config
Please let m e know if you have any further questions.
Regards,
Mario
Hi @usaygo,
You could read it, one method is to use pFLASH read API(psector_ReadData) in your application to read all pFLASH content and then print it.
For the memory map of the pFLASH, you can check structure pflash within struct psector_page_data_t that is defined in rom_psectr.h
For example:
psector_page_data_t page; /* Stored in the stack temporarily */
psector_page_state_t pg_state;
pg_state=psector_ReadData(PSECTOR_PFLASH_PART,0,0,sizeof(psector_page_data_t),&page);
if (pg_state < PAGE_STATE_DEGRADED)
{
break;
}
// Use the reserved1 for example
page.pFlash.reserved1= 0x1234;
Note: Please take care and do not modify the ISP access level if you don't want to.
Regards,
Mario
Hello,
Unfortunately, this is the way to read the pFlash area, not the Config area.
I apologize for any misunderstanding on this matter. However, if you have an answer for this, please let me know.
Question: What I want is a way to read the following "Config" area from C/C++ firmware code.
$ DK6Programmer.exe -V 0 -s COM4 -r Config:512 <= The Config, not pFlash
COM4: Connected at 115200
COM4: Detected JN5189 with MAC address 00:15:8D:00:05:B0:EA:86
COM4: Selected memory: Config
COM4: Reading 512 bytes from Config at 00000000
COM4: Config = a41c000000000000...snip...2c196c
Just to be sure, I tried the code you gave me, but it still reads pFlash.
const unsigned SIZ = 16;
uint8_t b0[SIZ];
{
Serial << "\r\n[psector_ReadData]";
psector_page_data_t page; /* Stored in the stack temporarily */
psector_page_state_t pg_state;
pg_state = psector_ReadData(PSECTOR_PFLASH_PART,0,0,sizeof(psector_page_data_t),&page);
if (pg_state < PAGE_STATE_DEGRADED)
{
Serial << "error at psector_ReadData()";
}
uint8_t *p = (uint8_t *)&page;
for (unsigned i = 0; i < 512; i += SIZ) {
Serial << crlf << format("%05x:", i);
for(uint8_t j = 0; j < SIZ; j++) {
Serial << format(" %02x", *p);
p++;
}
Serial.flush();
}
}
Serial << "\r\n[Flash Dump]";
for (int i = 0x9ec00; i < 0x9f000; i += SIZ) {
Serial << crlf << format("%05x:", i);
for(uint8_t j = 0; j < SIZ; j++) {
uint8_t *p = (uint8_t*)(i + j);
Serial << format(" %02x", *p);
}
Serial.flush();
}
My code is written in C++ (I think it's not the matter in this case), where Serial is handling output to UART. And the result is...
[psector_ReadData]
00000: 3a e6 2e 62 3d 35 b4 a7 00 00 00 00 08 00 00 00
00010: 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 00
00020: e4 04 00 00 19 e1 09 00 8f cd b5 64 01 00 00 00
00030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00
00040: 00 00 00 00 8a 03 9d b7 00 00 00 00 00 00 00 00
00050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00060: 34 12 38 26 01 c5 1b 00 d1 4a d8 03 00 8d 15 00
00070: 00 00 00 60 37 9f 7a b3 00 00 00 00 00 00 00 00
00080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000c0: 79 2b cf e0 b3 b7 60 d6 38 47 c5 49 28 53 fa 71
000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...
001f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[Flash Dump] Data is stored at both 9ec00 and 9ee00.
9ec00: 3a e6 2e 62 3d 35 b4 a7 00 00 00 00 08 00 00 00
9ec10: 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 00
9ec20: e4 04 00 00 19 e1 09 00 8f cd b5 64 01 00 00 00
9ec30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00
9ec40: 00 00 00 00 8a 03 9d b7 00 00 00 00 00 00 00 00
9ec50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
9ec60: 34 12 38 26 01 c5 1b 00 d1 4a d8 03 00 8d 15 00
...
9edf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
9ee00: 3a e6 2e 62 3d 35 b4 a7 00 00 00 00 08 00 00 00
9ee10: 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 00
...
9eff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Hi @usaygo,
What are the config values that you want to modify?
Is there any specific reason that you want to read out all the config values?
Do you want to modify the trim values?
Regards,
Mario
> What are the config values that you want to modify?
We need to read factory MAC area and no need to write it. After programming 154_cmac0, C/C++ API(e.g. vMMAC_GetMacAddress()) does not report factory MAC but 154_cmac0.
> Is there any specific reason that you want to read out all the config values?
We use factory MAC as a part of encryption (details cannot be disclosed).
> Do you want to modify the trim values?
No. Only reading.
The workaround is to copy factory MAC value to 154_cmac1, however, if possible, it should be avoided for simpler factory process.
Thanks!
Hi @usaygo,
Sorry for the late response.
I was checking the code, you are reading out the pFlash as a first parameter.
PSECTOR_PAGE0_PART, /*!< Page0 partition : termed PSECT by FLashProgramemr tool
* Image related data */
PSECTOR_PFLASH_PART, /*!< PFLASH : Custommer configuration data */
Could you please try to read out page 0?
Regards,
Mario
Thanks Mario, however I can't still get them. Please correct if I am wrong.
The "Config" Area.
C:\>DK6Programmer.exe -V 0 -s COM22 -r Config:512
COM22: Connected at 115200
COM22: Detected K32W061 with MAC address xx:xx...
COM22: Selected memory: Config
COM22: Reading 512 bytes from Config at 00000000
COM22: Config = a42d00000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000da02000000000000
00000000000000d054375254303332413832302e31474e533d7d0080c8000000a6153401
ffc60000d14ad803008d15000000000000000000f1bb1400000000001340040001000000
^^^^^^^^^^^^^^^^ FACTORY MAC ADDR (WHAT I WANT TO READ)
00000000000000000000000000000000000066663900207347003273ca52ce52299a000d
...
The C code (compiled by C++ compiler)
PRINTF("\n[psector read test]\n");
for (unsigned pg = 0; pg < 2; pg++) { // only effective at pg==0.
const unsigned SIZ = 16;
PRINTF("\n[psector_ReadData PAGE0/%d]", pg);
psector_page_data_t page; /* Stored in the stack temporarily */
psector_page_state_t pg_state;
pg_state = psector_ReadData(PSECTOR_PAGE0_PART,pg,0,512,&page);
if (pg_state < PAGE_STATE_DEGRADED)
{
PRINTF("error at psector_ReadData()");
} else {
uint8_t *p = (uint8_t *)&page;
for (unsigned i = 0; i < 512; i += SIZ) {
PRINTF("\n%05x:", i);
for(uint8_t j = 0; j < SIZ; j++) {
PRINTF(" %02x", *p);
p++;
}
CLOCK_uDelay(6000); // small delay for flushing.
}
}
}
The result:
[psector_ReadData PAGE0/0]
0: 56 73 e2 2b a9 8c 1d c5 0 0 0 0 0 0 0 0
10: 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 0
20: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
30: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
...
[psector_ReadData PAGE0/1]error at psector_ReadData()
I tried possible parameter (as below), and got values w/o error from two patterns.
psector_ReadData(0..7, 0..7, 0, 512, &page); // 64 patterns
then the following patterns are okay to get value.
psector_ReadData(0, 0, 0, 512, &page); // ??? (data do not match with Config area)
psector_ReadData(1, 0, 0, 512, &page); // pFlash area
Hi @usaygo,
I am sorry for the late reply. I am still working on your requirement. In this case, you want to read out the factory mac Address, in this case, 00:15:8D:00:03:D7:D5:5E. Am I wrong?
I am assuming, that if you read the 154_cmac0 with the tool, did you see your new address?
Regards,
Mario
Hello Mario and Happy New Year!
I confirmed that the DK6_Programmer and MMAC API behaves the same: if set cmac0, it shows cmac0, otherwise factory mac. My question is how to get factory mac from the firmware C/C++ code when cmac0 is already set via DK6_Programmer.
I just guessed that the easiest way to get it is to read "Config" area, however I only need the factory mac from C/C++ code.
(The workaround is to set an additional copy of factory mac on "pFlash" area. Temporally I implemented in this way, but I would like to avoid it for more efficient/simpler way of factory process.)
//Seigo
Hi @usaygo,
Happy New Year!!!
I am checking the process to read out the factory mac address. I will get back to you as soon as possible.
Note: it is important to mention that you have to request a specific range of addresses with the specific OUI.
Regards,
Mario
Hello,
Thanks, waiting for the reply.
The reason why we need a factory MAC is just to get an unique number assigned to each chip. We don't plan to use factory MAC over RF packets, but to use our own registered addresses.
Regards,
Seigo Okumura
Hi @usaygo,
Please look at the next implementation in code.
#define MAC_ADDR_DEFAULT 0x0009fc70
tsExtAddr psMacAddr;
/* Get the factory MAC address from the N-2 page */
psMacAddr.u32L = *(volatile uint32_t *)(MAC_ADDR_DEFAULT);
psMacAddr.u32H = *(volatile uint32_t *)(MAC_ADDR_DEFAULT + 4);
You will read out the mac address.
Regards,
Mario