# TI-Z-Stack-firmware-patch **Repository Path**: zrainx/Z-Stack-firmware ## Basic Information - **Project Name**: TI-Z-Stack-firmware-patch - **Description**: ti z stack firmware - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2020-04-22 - **Last Updated**: 2023-07-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Compiling the firmware ## Setup development environment Download and install [Z-STACK-HOME 1.2.2a And IAR Embedded Workbench for 8051](https://pan.baidu.com/s/1actAYRsCcLH-7YH78Wamnw ). password: 0z28 ## Compiling 1. Copy `firmware.patch` to `Z-Stack Home 1.2.2a.44539` 2. Open Git Bash, go to `Z-Stack Home 1.2.2a.44539` and apply the patch using `git apply firmware.patch --ignore-space-change`. 3. Open `Z-Stack Home 1.2.2a.44539\Projects\zstack\ZNP\CC253x\znp.eww` with IAR Embedded workbench for 8051. 4. You will get a warning: *The project file 'CC253(0/1).ewp' is in an old format. Would you like to convert it for use with this version?*. Press **yes** for both. 5. Select the correct target: - For CC2531 select *CC2531 - X* - For CC2530, CC2530_CC2591, CC2530_CC2592 select *CC2530 - X* - Depending if you want to compile the `.hex` or SBL firmware select *- ProdHex* or *- ProdSBL* 6. Right-click on your target and press options. Go to C/C++ compiler -> preprocessor. **Remove** all *Defined symbols* : FEATURE_SYSTEM_STATS ASSERT_RESET POWER_SAVING FAKE_CRC_SHDW xTC_LINKKEY_JOIN Depending on what you want to compile, add the following symbols to *Defined symbols*: - Device type: `FIRMWARE_CC2530`, `FIRMWARE_CC2530_CC2591`, `FIRMWARE_CC2531` or `FIRMWARE_CC2530_CC2592` - If you chose for *- ProdSBL* add `FIRMWARE_SBL`. - In case you want to compile the source routing firmware, also add `SOURCE_ROUTING`. 7. Press OK. 8. Right-click on your target and click *Rebuild all*. 9. Once finished, you can find the `CC253(0|1)ZNP-Prod.(hex|bin)` file in `Z-Stack Home 1.2.2a.44539\Projects\zstack\ZNP\CC253x\dev`. ## FAQ 1. IAR 编译不过performing Post-Build Action的问题 如果不在默认c盘安装 Z-Stack,会遇到 IAR 编译不过performing Post-Build Action的问题,需要修改znp.bat。(相对路径在 `Z-Stack Home 1.2.2a.44539\Projects\zstack\ZNP\CC253x\tools`) 修改znp.bat第43~46行 ```bat :Launch chdir %1 start znp.js %2 exit /b ``` 改为: ```bat :Launch %~d1 chdir %1 start znp.js %2 exit /b ``` http://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/314089 # Flashing the firmware https://www.zigbee2mqtt.io/getting_started/flashing_the_cc2531.html # Change PA from 2591 to 2401 ## 修改使能脚 由于 PA 使能脚定义不同。2591 转换到 2401 需要转换使能脚。 Z-Stack Home 1.2.2a.44539\Components\mac\low_level\srf04\single_chip\mac_radio_defs.c 代码做如下改动 ```c MAC_INTERNAL_API void macRadioTurnOnPower(void) { ... else { /* P1_1 -> PAEN */ RFC_OBS_CTRL0 = RFC_OBS_CTRL_PA_PD_INV; OBSSEL1 = OBSSEL_OBS_CTRL0; /* P1_4 -> EN (LNA control) */ RFC_OBS_CTRL1 = RFC_OBS_CTRL_LNAMIX_PD_INV; OBSSEL4 = OBSSEL_OBS_CTRL1; } /* For any RX, change CCA settings for CC2591 compression workaround. * This will override LNA control if CC2591_COMPRESSION_WORKAROUND * flag is defined. */ } ... } ``` 改为: ```c MAC_INTERNAL_API void macRadioTurnOnPower(void) { ... else { /* P1_1 -> PAEN */ /* P1_1 -> P1_2 *///////////////////////////////////// RFC_OBS_CTRL0 = RFC_OBS_CTRL_PA_PD_INV; OBSSEL2 = OBSSEL_OBS_CTRL0; /* P1_4 -> EN (LNA control) */ RFC_OBS_CTRL1 = RFC_OBS_CTRL_LNAMIX_PD_INV; OBSSEL4 = OBSSEL_OBS_CTRL1; } /* For any RX, change CCA settings for CC2591 compression workaround. * This will override LNA control if CC2591_COMPRESSION_WORKAROUND * flag is defined. */ } ``` Z-Stack Home 1.2.2a.44539\Components\mac\low_level\srf05\single_chip\mac_radio_defs.c 如下改动: ```c MAC_INTERNAL_API void macRadioTurnOnPower(void){ ... /* PC3 -> PAEN */ RFC_OBS_CTRL0 = RFC_OBS_CTRL_PA_PD_INV; OBSSEL3 = OBSSEL_OBS_CTRL0; /* PC2 -> EN (LNA control) */ RFC_OBS_CTRL1 = RFC_OBS_CTRL_LNAMIX_PD_INV; OBSSEL2 = OBSSEL_OBS_CTRL1; } ``` 改成: ```c MAC_INTERNAL_API void macRadioTurnOnPower(void) { ... /* P1_1 -> PAEN */ /* P1_1 -> P1_2 *///////////////////////////////////// RFC_OBS_CTRL0 = RFC_OBS_CTRL_PA_PD_INV; OBSSEL2 = OBSSEL_OBS_CTRL0; /* P1_4 -> EN (LNA control) */ RFC_OBS_CTRL1 = RFC_OBS_CTRL_LNAMIX_PD_INV; OBSSEL4 = OBSSEL_OBS_CTRL1; } ``` 2401 比 2591 少用一个脚,所以 P0_7 可以去掉:mac_radio_defs.h 中 Z-Stack Home 1.2.2a.44539\Components\mac\low_level\srf04\single_chip\mac_radio_defs.h ```c /* ----------- PA/LNA control ---------- */ /* For Skyworks parts only CPS maps closely to the HGM line */ #define HAL_PA_LNA_RX_HGM() st( P0_7 = 1; ) #define HAL_PA_LNA_RX_LGM() st( P0_7 = 0; ) ``` 改成 ```c /* ----------- PA/LNA control ---------- */ /* For Skyworks parts only CPS maps closely to the HGM line */ #define HAL_PA_LNA_RX_HGM() st( ; ) /* P0_7 = 1 */ #define HAL_PA_LNA_RX_LGM() st( ; ) /* P0_7 = 0 */ ``` Z-Stack Home 1.2.2a.44539\Components\mac\low_level\srf05\single_chip\mac_radio_defs.h ```c /* ----------- PA/LNA control ---------- */ #define HAL_PA_LNA_RX_HGM() st( GPIOPinWrite(HGM_BASE, HGM_PIN, HGM_PIN); ) #define HAL_PA_LNA_RX_LGM() st( GPIOPinWrite(HGM_BASE, HGM_PIN, 0); ) ``` 改成 ```c /* ----------- PA/LNA control ---------- */ #define HAL_PA_LNA_RX_HGM() st( ; ) /* GPIOPinWrite(HGM_BASE, HGM_PIN, HGM_PIN) */ #define HAL_PA_LNA_RX_LGM() st( ; ) /* GPIOPinWrite(HGM_BASE, HGM_PIN, 0) */ ``` ## 修改输出功率表 CC2530 芯片的输出功率不能超过 2401 的输入最大值,一般设置 CC2530 芯片的输出功率为 0x5a。 Z-Stack Home 1.2.2a.44539\Components\mac\low_level\srf04\single_chip\mac_radio_defs.c ```c #if defined HAL_PA_LNA || defined MAC_RUNTIME_CC2591 const uint8 CODE macRadioDefsTxPwrCC2591[] = { 20, /* tramsmit power level of the first entry */ (uint8)(int8)10, /* transmit power level of the last entry */ /* 20 dBm */ 0xE5, /* characterized as 20 dBm in datasheet */ /* 19 dBm */ 0xD5, /* characterized as 19 dBm in datasheet */ /* 18 dBm */ 0xC5, /* characterized as 18 dBm in datasheet */ /* 17 dBm */ 0xB5, /* characterized as 17 dBm in datasheet */ /* 16 dBm */ 0xA5, /* characterized as 16 dBm in datasheet */ /* 15 dBm */ 0xA5, /* 14 dBm */ 0x95, /* characterized as 14.5 dBm in datasheet */ /* 13 dBm */ 0x85, /* characterized as 13 dBm in datasheet */ /* 12 dBm */ 0x85, /* 11 dBm */ 0x75, /* characterized as 11.5 dBm in datasheet */ /* 10 dBm */ 0x65 /* characterized as 10 dBm in datasheet */ }; #endif ``` 改成 ```c #if defined HAL_PA_LNA || defined MAC_RUNTIME_CC2591 const uint8 CODE macRadioDefsTxPwrCC2591[] = { 20, /* tramsmit power level of the first entry */ (uint8)(int8)10, /* transmit power level of the last entry */ /* 20 dBm */ 0xA5, /* characterized as 20 dBm in datasheet */ /* 19 dBm */ 0xA5, /* characterized as 19 dBm in datasheet */ /* 18 dBm */ 0xA5, /* characterized as 18 dBm in datasheet */ /* 17 dBm */ 0xA5, /* characterized as 17 dBm in datasheet */ /* 16 dBm */ 0xA5, /* characterized as 16 dBm in datasheet */ /* 15 dBm */ 0xA5, /* 14 dBm */ 0x95, /* characterized as 14.5 dBm in datasheet */ /* 13 dBm */ 0x85, /* characterized as 13 dBm in datasheet */ /* 12 dBm */ 0x85, /* 11 dBm */ 0x75, /* characterized as 11.5 dBm in datasheet */ /* 10 dBm */ 0x65 /* characterized as 10 dBm in datasheet */ }; #endif ``` Z-Stack Home 1.2.2a.44539\Components\mac\low_level\srf05\single_chip\mac_radio_defs.c ```c #if defined HAL_PA_LNA || defined MAC_RUNTIME_CC2591 const uint8 CODE macRadioDefsTxPwrCC2591[] = { 20, /* tramsmit power level of the first entry */ (uint8)(int8)8, /* transmit power level of the last entry */ /* 20 dBm */ 0xE5, /* characterized as 19.5 dBm in datasheet */ /* 19 dBm */ 0xE5, /* 18 dBm */ 0xD0, /* characterized as 18 dBm in datasheet */ /* 17 dBm */ 0xD0, /* 16 dBm */ 0xBC, /* characterized as 16 dBm in datasheet */ /* 15 dBm */ 0xBC, /* 14 dBm */ 0xA6, /* characterized as 14 dBm in datasheet */ /* 13 dBm */ 0xA6, /* 12 dBm */ 0x9C, /* characterized as 12 dBm in datasheet */ /* 11 dBm */ 0x9C, /* 10 dBm */ 0x87, /* characterized as 10 dBm in datasheet */ /* 9 dBm */ 0x87, /* 8 dBm */ 0x80, /* characterized as 8 dBm in datasheet */ }; #endif ``` 改成 ```c #if defined HAL_PA_LNA || defined MAC_RUNTIME_CC2591 const uint8 CODE macRadioDefsTxPwrCC2591[] = { 20, /* tramsmit power level of the first entry */ (uint8)(int8)8, /* transmit power level of the last entry */ /* 20 dBm */ 0xA5, /* characterized as 19.5 dBm in datasheet */ /* 19 dBm */ 0xA5, /* 18 dBm */ 0xA5, /* characterized as 18 dBm in datasheet */ /* 17 dBm */ 0xA5, /* 16 dBm */ 0xA5, /* characterized as 16 dBm in datasheet */ /* 15 dBm */ 0xA5, /* 14 dBm */ 0xA5, /* characterized as 14 dBm in datasheet */ /* 13 dBm */ 0xA5, /* 12 dBm */ 0x9C, /* characterized as 12 dBm in datasheet */ /* 11 dBm */ 0x9C, /* 10 dBm */ 0x87, /* characterized as 10 dBm in datasheet */ /* 9 dBm */ 0x87, /* 8 dBm */ 0x80, /* characterized as 8 dBm in datasheet */ }; #endif ``` ## 编译宏 FIRMWARE_CC2530_CC2591 在IAR C/C++ compiler -> preprocessor 中输入 ## 资料 目录 docs of change PA from 2591 to 2401/