본문으로 바로가기

[NCS-V2.4.0] peripheral_hids_keyboard 분석-1

category 미분류 항목 2023. 6. 7. 12:07

  : peripheral_hids_keyboard  프로젝트는 GATT HID Service 를  사용하는 키보드 데모 예제로서 

   NFC를 사용한 OOB (Out-of-Band) 페어링도  지원합니다.

 

목차

     

      nRF Connect SDK  document 링크

    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/bluetooth/peripheral_hids_keyboard/README.html#bluetooth-peripheral-hids-keyboard

     

    Bluetooth: Peripheral HIDS keyboard — nRF Connect SDK 2.4.99 documentation

    When built for an _ns build target, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure

    developer.nordicsemi.com

     

    ▶  사용가능 보드 리스트

      : nRF5340 DK , nRF52 DK , nRF52840 DK

     

    ▶  프로젝트 Template 위치

       : <install-Dir>\nrf\smaples\bluetooth\peripheral_hids_keyboard 

     

     

    1>  Visual Studio Code 를 이용한 프로젝트 생성/빌드/ 플래시

     ▶ nRF Connect --> Create a new application 선택

     

    ▶  New Application 설정하기 

       : 아래의 붉은색 박스부분을 수정해 줍니다. 

         application template 에 peripheral_hids_keyboard 를 선택합니다.

     

    ▶  nRF Connect --> APPLICATIONS 탭의 "No build configurations" 항목 선택

     

    ▶ Add Build Configuration 설정

       : Board 및 기타 내용를 선택해 주고  "Build Configuration" 을 눌러줍니다.

         자동으로 빌드가 진행이 됩니다.

     

     

    ▶ 빌드성공시의 빌드로그  일부 발췌

    [244/254] Linking C executable zephyr\zephyr_pre0.elf
    
    [245/254] Generating dev_handles.c
    [246/254] Building C object zephyr/CMakeFiles/zephyr_pre1.dir/misc/empty_file.c.obj
    [247/254] Building C object zephyr/CMakeFiles/zephyr_pre1.dir/dev_handles.c.obj
    [248/254] Linking C executable zephyr\zephyr_pre1.elf
    [249/254] Generating linker.cmd
    [250/254] Generating isr_tables.c, isrList.bin
    [251/254] Building C object zephyr/CMakeFiles/zephyr_final.dir/misc/empty_file.c.obj
    [252/254] Building C object zephyr/CMakeFiles/zephyr_final.dir/dev_handles.c.obj
    [253/254] Building C object zephyr/CMakeFiles/zephyr_final.dir/isr_tables.c.obj
    [254/254] Linking C executable zephyr\zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:      203180 B       512 KB     38.75%
                 RAM:         35 KB        64 KB     54.69%
            IDT_LIST:          0 GB         2 KB      0.00%
     *  Terminal will be reused by tasks, press any key to close it.

     

    ▶ 이미지 플래시 

      : nRF Connect -->   ACTIONS 탭의 Flash 버튼을 선택해 이미지를 보드에 라이트해 줍니다.

        Erase and Flash to board

     출력 로그

     *  Executing task: nRF Connect: Flash: peripheral_hids_keyboard/build (active) 
    
    Flashing build to 1050365745
    C:\WINDOWS\system32\cmd.exe /d /s /c "west flash -d c:\Project\nordic\myApps\peripheral_hids_keyboard\build --skip-rebuild --dev-id 1050365745 --erase"
    
    -- west flash: using runner nrfjprog
    -- runners.nrfjprog: mass erase requested
    -- runners.nrfjprog: Flashing file: c:\Project\nordic\myApps\peripheral_hids_keyboard\build\zephyr\zephyr.hex
    [ ######               ]   0.000s | Erase file - Check image                [ #################### ]   0.153s | Erase file - Done erasing                                                          
    [ ######               ]   0.000s | Program file - Checking image           [ ####                 ]   0.000s | Check image validity - Initialize device[ ########             ]   0.000s | Check image validity - Check region 0 se[ ############         ]   0.000s | Check image validity - block 1 of 3     [ #################### ]   0.006s | Check image validity - Finished         [ #############        ]   0.000s | Program file - Programming              [ ######               ]   0.000s | Programming image - block 1 of 2        [ #################### ]   0.000s | Programming image - Write successful    [ #################### ]   3.661s | Program file - Done programming                                                    
    [ ######               ]   0.000s | Verify file - Check image               [ ####                 ]   0.000s | Check image validity - Initialize device[ ########             ]   0.000s | Check image validity - Check region 0 se[ ############         ]   2.555s | Check image validity - block 1 of 3     [ #################### ]   0.000s | Check image validity - Finished         [ #############        ]   0.000s | Verify file - Verifying                 [ ######               ]   0.000s | Verifying image - block 1 of 2          [ #################### ]   0.000s | Verifying image - Verify successful     [ #################### ]   1.385s | Verify file - Done verifying                                                       
    Enabling pin reset.
    Applying pin reset.
    -- runners.nrfjprog: Board with serial number 1050365745 flashed successfully.
     *  Terminal will be reused by tasks, press any key to close it.

     

    ▶ 부팅로그

    *** Booting Zephyr OS build v3.3.99-ncs1 ***
    Starting Bluetooth Peripheral HIDS keyboard example
    I: 6 Sectors of 4096 bytes
    I: alloc wra: 0, fd0
    I: data wra: 0, 1c
    I: SoftDevice Controller build revision: 
    I: e0 7e 2e c1 5e 05 85 23 |.~..^..#
    I: 46 15 dc fa 8e 29 7d 70 |F....)}p
    I: 10 93 a5 fc             |....    
    I: HW Platform: Nordic Semiconductor (0x0002)
    I: HW Variant: nRF52x (0x0002)
    I: Firmware: Standard Bluetooth controller (0x00) Version 224.11902 Build 2231721665
    I: No ID address. App must call settings_load()
    Bluetooth initialized
    I: Identity: DB:22:99:7F:59:EB (random)
    I: HCI: version 5.4 (0x0d) revision 0x1077, manufacturer 0x0059
    I: LMP: version 5.4 (0x0d) subver 0x1077
    NFC configuration start
    NFC configuration done

     

    2> nRF Connect 앱을 이용한 디바이스 페어링

     ▶ Advertising 시작하기 (DK 보드의 Button 4 푸시)

    Advertising successfully started
    Advertising continued

     

    ▶ nRF Connect 앱의 Scanner 탭에  "Nordic_HIDS_Keyboard"  검색 확인

    ▶  RAW 버튼 클릭시 화면

     

    ▶  MORE 버튼 클릭시 화면

     

    ▶ 디바이스 연결상태에서의 Service 리스트

     

      --> 아래처럼 DK 보드에 연결 메시지가 출력됩니다.

    Connected 62:C6:58:79:3E:1A (random)

     

      서비스 항목 (5개)

      ↓ Generic Attribute

       Generic Access

       Battery Service

       Device Information

       Human Interface Device

     

      각 서비스별 Charateristics

      ↓ Generic Attribute

       Generic Access

       Battery Service

       Device Information

       Human Interface Device

     

     

      Bond 버튼을 이용한 페어링

      ↓   연결탭 선택후 nRF Connect 앱의 위 상단의 설정 버튼 클릭

     

       Bond 메뉴 선택

     

       DK 보드의 시리얼에  수락할려면 Button1을 누르라는 메시지 출력됨.

       ==> Button 1 푸시

    Passkey for 5A:63:07:DA:5D:D0 (random): 435310
    Press Button 1 to confirm, Button 2 to reject.

     

      스마트폰 화면에  "블루투스 연결요청" 창이 뜨고 "등록" 버튼을 눌러줍니다.

     

      다음처럼  페어링 완료 메시지가 출력됩니다.

    Numeric Match, conn 0x20001b40
    Security changed: 78:26:30:FD:E6:47 (random) level 4
    Pairing completed: 74:9E:F5:13:83:AE (public), bonded: 1

     

      스마트폰 등록된 기기 항목에 Nordic_HIDS_keyboard" 항목이 있는지 확인합니다.

     

     

      동작테스트 

     : Button1 키를 누를때 마다 hello 단어의 한글자씩 보내지고 마지막에 Enter키가 전송됩니다.

     

     

    <기타>

      NFC OOB 페어링

    ↓ DK 보드 리셋후  스마트폰의 NFC 파트와  DK 의 NFC 안테나를 가까이 가져갑니다.

     

     

      스마트폰 화면에 블루투스 디바이스 등록화면이 나오면 "" 를 눌러줍니다.

     

      블루투스 연결 요청  화면이 나오고 "등록" 버튼을 눌러줍니다.

     

      

    ↓  DK 보드에서도 Button 1 을 눌러 Confirm 해 줍니다.

    Connected 4A:26:EF:FE:2D:E7 (random)
    Passkey for 4A:26:EF:FE:2D:E7 (random): 746345
    Press Button 1 to confirm, Button 2 to reject.
    Numeric Match, conn 0x20001b40
    Security changed: 4A:26:EF:FE:2D:E7 (random) level 4
    Pairing completed: 74:9E:F5:13:83:AE (public), bonded: 1

     

    세부항목은 다음 글 참고하세요.

     

    그럼 수고하세요.

    반응형