YOGYUI

CC2531 USB Dongle - Arduino로 flashing하기 (CCLoader) 본문

Hardware/Home Automation

CC2531 USB Dongle - Arduino로 flashing하기 (CCLoader)

요겨 2021. 1. 12. 22:07
반응형

zigbee 기반 홈 오토메이션 디바이스를 커스터마이즈하기 위해 CC2531 USB Dongle을 하나 구매했다

PP-A485 zigbee CC2531 sniffer USB dongle

Ti에서 만든 CC2531 IC의 Evaluation Kit 일종으로, 기능을 제대로 활용하기 위해서는 펌웨어를 업로드해줘야 한다

(CC2531 Datasheet)

공식적으로 Ti의 CC-Debugger라는 플래시 다운로드 디바이스를 사용해서 헥사 파일(.hex)을 심어줘야 되는데, 디버거 가격이 대략 $10 정도 하다보니 많은 사람들이 라즈베리파이같은 미니 PC나 아두이노같은 오픈소스 하드웨어를 사용해 (시리얼 통신 기반으로) 펌웨어를 다운로드하고 있다

 

라즈베리파이를 이용한 방법은 구글 검색만 해도 수십개가 뜨는지라 본 포스팅에서는 아두이노를 이용한 방법을 기술해보기로 한다 

(zigbee2mqtt 공식 사이트의 가이드를 따라하면 된다)

www.zigbee2mqtt.io/information/alternative_flashing_methods.html

 

Alternative flashing methods

📘 Zigbee2mqtt documentation

www.zigbee2mqtt.io

참고 1) Arduino 방식은 CCLoader를 이용하는 방식과 CCLib를 이용하는 방식이 있는데, 윈도우 OS 환경에서의 CCLoader 방식이 제일 간단하다 (라즈베리파이는 PC 세팅이 좀 오래걸려서...)

 

참고 2) CC2531 USB Dongle에 달려있는 디버깅용 핀헤더는 1.27mm pitch라 일반적으로 우리가 쓰는 2.54mm pitch용 케이블을 체결하기가 꽤나 까다로운데, 케이블 어댑터가 있으면 편하다 (나는 usb dongle이랑 세트로 $15 정도에 구매했는데, 'CC2531 sniffer cable'이라고 검색하니 단독 제품으로 6천원 선에 구매할 수 있는 것 같다)

sniffer cable set

1. 하드웨어 배선

CC2531 dongle 보드의 debug 핀헤더에서 배선해야 할 핀은 총 4

CC Debug Pin # Description
1 GND
3 DC (Debug Clock)
4 DD (Debug Data)
7 RESETn

 

점퍼와이어 4개를 다음과 같이 연결해준다 (아두이노는 서랍에 박혀있던 Arduino MEGA ADK 사용)

아두이노 - CC2531 USB Dongle 배선

 

Schematic

참고) DC +5V로 동작하는 아두이노와 DC +3.3V로 동작하는 CC2531 Dongle 사이에 연결 시 voltage shifter나 저항을 이용한 voltage divider 회로를 꾸미라고 가이드되어있긴 한데, 그냥 다이렉트로 연결해도 별 이상없이 잘 되는 거 같다

2. 아두이노 라이브러리 설치 및 업로드

GitHub에서 CCLibrary를 zip파일로 다운받아 Arduino IDE 라이브러리에 추가한다

github.com/RedBearLab/CCLoader

 

RedBearLab/CCLoader

Burn BLE Mini (CC2540) firmware using Blend Micro board. - RedBearLab/CCLoader

github.com

라이브러리 설치 후 CCLoader.ino 파일을 연다

(메뉴바 - 파일 - 예제 - CCLoader-master-arduino-CCLoader)

CCLoader.ino 파일 열기

코드 86번 라인에 Debug Port Pinout 정의가 되어있다

핀맵을 다르게 구성했다면 이 부분을 수정해주자

// Debug control pins & the indicate LED
int DD = 6;
int DC = 5;
int RESET = 4;
int LED = 13;

(LED는 굳이 신경쓰지 않아도 된다)

 

아두이노 보드에 업로드하면 준비 완료

아두이노 보드 업로드 완료

3. 펌웨어 파일 및 기타 소프트웨어 준비

펌웨어 파일를 GitHub에서 다운로드받는다

github.com/Koenkk/Z-Stack-firmware/tree/master/coordinator/Z-Stack_Home_1.2/bin/default

2021.01.12 기준으로 CC2531_DEFAULT_20190608.zip이 최신파일이다

다운로드받은 뒤 압축을 풀어서 CC2531ZNP-Prod.hex 파일만 따로 작업폴더로 옮겨주자

 

objcopy를 이용해서 hex 파일을 bin 파일로 변환해줘야 한다 (zip파일 내의 bin 파일은 사용하지 않는다)

다음 사이트에서 MinGW (Minimalist GNU for Windows)를 설치한다 (Download 후 mingw-get-setup.exe 파일 실행)

sourceforge.net/projects/mingw/

 

설치 경로를 변경하지 않았다면 objcopy.exe 파일은 다음 경로에서 찾을 수 있다

C:\MinGW\mingw64\bin

objcopy.exe를 CC2531ZNP-Prod.hex 파일이 있는 디렉터리로 옮긴 후 명령 프롬프트(cmd.exe)로 다음 명령을 실행

objcopy.exe --gap-fill 0xFF --pad-to 0x040000 -I ihex CC2531ZNP-Prod.hex -O binary CC2531ZNP-Prod.bin

262,144바이트 크기의 CC2531ZNP-Prod.bin 파일이 생성된다

objcopy로 생성한 bin 파일

4. 펌웨어 업로드

아두이노 라이브러리 CCLoader 설치경로에서 CCLoader_x86_64.exe 파일을 작업경로로 복사한다

Arduino\libraries\CCLoader-master\Windows\CCLoader_x86_64.exe

명령 프롬프트에서 다음 명령 수행

CCLoader_x86_64.exe [Number of the COM port] CC2531ZNP-Prod.bin 0

Arduino MEGA ADK의 시리얼 포트가 현재 COM6으로 잡혀있기 때문에 다음과 같이 명령을 주고 펌웨어 업로드 완료된 것을 확인! (5분내로 끝난다)

C:\Users\Yogyui\Desktop\CCLoaderPath> CCLoader_x86_64.exe 6 CC2531ZNP-Prod.bin 0
Copyright (c) 2013 RedBearLab.com
CCLoader_x86_64.exe version 0.5
Comport : COM6
Bin file: CC2531ZNP-Prod.bin
Device  : Default (e.g. UNO)

Comport open!
<Baud:115200> <data:8> <parity:none> <stopbit:1> <DTR:off> <RTS:off>

File open!
Block total: 512

Enable transmission...
Request sent already!
/********************************************************************/
* If there is no respond last for 3s, please press "Ctrl+C" to exit!
* And pay attention to :
*   1. The connection between computer and Arduino;
*   2. The connection between Arduino and CC2540;
*   3. Whether the device you using is Leonardo or not;
*   4. Other unexpected errors.
/********************************************************************/

Waiting for respond from Arduino...

Uploading firmware...

1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  
21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  
39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  
57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  
75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  
93  94  95  96  97  98  99  100  101  102  103  104  105  106  107  108  
109  110  111  112  113  114  115  116  117  118  119  120  121  122  123  
124  125  126  127  128  129  130  131  132  133  134  135  136  137  138  
139  140  141  142  143  144  145  146  147  148  149  150  151  152  153  
154  155  156  157  158  159  160  161  162  163  164  165  166  167  168  
169  170  171  172  173  174  175  176  177  178  179  180  181  182  183  
184  185  186  187  188  189  190  191  192  193  194  195  196  197  198 
199  200  201  202  203  204  205  206  207  208  209  210  211  212  213  
214  215  216  217  218  219  220  221  222  223  224  225  226  227  228  
229  230  231  232  233  234  235  236  237  238  239  240  241  242  243  
244  245  246  247  248  249  250  251  252  253  254  255  256  257  258  
259  260  261  262  263  264  265  266  267  268  269  270  271  272  273  
274  275  276  277  278  279  280  281  282  283  284  285  286  287  288  
289  290  291  292  293  294  295  296  297  298  299  300  301  302  303  
304  305  306  307  308  309  310  311  312  313  314  315  316  317  318  
319  320  321  322  323  324  325  326  327  328  329  330  331  332  333  
334  335  336  337  338  339  340  341  342  343  344  345  346  347  348  
349  350  351  352  353  354  355  356  357  358  359  360  361  362  363  
364  365  366  367  368  369  370  371  372  373  374  375  376  377  378  
379  380  381  382  383  384  385  386  387  388  389  390  391  392  393  
394  395  396  397  398  399  400  401  402  403  404  405  406  407  408  
409  410  411  412  413  414  415  416  417  418  419  420  421  422  423  
424  425  426  427  428  429  430  431  432  433  434  435  436  437  438  
439  440  441  442  443  444  445  446  447  448  449  450  451  452  453  
454  455  456  457  458  459  460  461  462  463  464  465  466  467  468  
469  470  471  472  473  474  475  476  477  478  479  480  481  482  483  
484  485  486  487  488  489  490  491  492  493  494  495  496  497  498  
499  500  501  502  503  504  505  506  507  508  509  510  511  512  
Upload successfully!
File closed!
Comport closed!

 

5. 장치 확인

펌웨어 업로드 후 디버그 케이블 뽑은 뒤 USB 동글을 뽑았다 다시 끼우면 시리얼 포트가 추가된 것을 확인할 수 있다

시리얼 포트가 추가되었다

(윈도우에 node가 설치되어 있다고 가정하고 진행)

 

다음 repository를 Git clone해주자

github.com/Koenkk/zigbee2mqtt.git

 

clone 작업경로에서 npm dependencies를 설치해준다

C:\Users\Yogyui\Desktop\CCLoaderPath\zigbee2mqtt-master> npm ci

zigbee2mqtt-master\data\configuration.yaml 에서 시리얼포트 설정 변경 후 저장

# Home Assistant integration (MQTT discovery)
homeassistant: false

# allow new devices to join
permit_join: true

# MQTT settings
mqtt:
  # MQTT base topic for zigbee2mqtt MQTT messages
  base_topic: zigbee2mqtt
  # MQTT server URL
  server: 'mqtt://localhost'
  # MQTT server authentication, uncomment if required:
  # user: my_user
  # password: my_password

# Serial settings
serial:
  # Location of CC2531 USB sniffer
  # port: /dev/ttyACM0
  port: COM7  # 수정

이제 커맨드라인에서 npm start를 입력하면 다음과 같이 Zigbee2MQTT 어플리케이션이 시작된다

C:\Users\Yogyui\Desktop\CCLoaderPath\zigbee2mqtt-master> npm start

> zigbee2mqtt@1.17.0 start C:\Users\Yogyui\Desktop\CCLoaderPath\zigbee2mqtt-master
> node index.js

Zigbee2MQTT:info  2021-01-12 23:03:41: Logging to console and directory: 'C:\Users\Yogyui\Desktop\CCLoaderPath\zigbee2mqtt-master\data\log\2021-01-12.23-03-41' filename: log.txt
Zigbee2MQTT:info  2021-01-12 23:03:42: Starting Zigbee2MQTT version 1.17.0 (commit #unknown)
Zigbee2MQTT:info  2021-01-12 23:03:42: Starting zigbee-herdsman (0.13.46)
Zigbee2MQTT:info  2021-01-12 23:03:48: zigbee-herdsman started
Zigbee2MQTT:info  2021-01-12 23:03:48: Coordinator firmware version: '{"meta":{"maintrel":3,"majorrel":2,"minorrel":6,"product":0,"revision":20190608,"transportrev":2},"type":"zStack12"}'
Zigbee2MQTT:info  2021-01-12 23:03:48: Currently 0 devices are joined:
Zigbee2MQTT:warn  2021-01-12 23:03:48: `permit_join` set to  `true` in configuration.yaml.
Zigbee2MQTT:warn  2021-01-12 23:03:48: Allowing new devices to join.
Zigbee2MQTT:warn  2021-01-12 23:03:48: Set `permit_join` to `false` once you joined all devices.
Zigbee2MQTT:info  2021-01-12 23:03:48: Zigbee: allowing new devices to join.
Zigbee2MQTT:info  2021-01-12 23:03:48: Connecting to MQTT server at mqtt://localhost
Zigbee2MQTT:error 2021-01-12 23:03:58: Not connected to MQTT server!
Zigbee2MQTT:error 2021-01-12 23:04:08: Not connected to MQTT server!

Coordicator firmware version 항목이 보이면 USB Dongle과 정상적으로 통신이 이루어지고 있다는 의미

mqtt 서버를 따로 실행하지 않았다면 Not Connected to MQTT server! 메시지가 반복적으로 로깅된다

 

끝!

반응형

'Hardware > Home Automation' 카테고리의 다른 글

nRF52840 USB Dongle - RCP 펌웨어 올리기 (for OTBR)  (0) 2023.01.15
Comments