본문으로 바로가기

[nRF52] radio_test 프로젝트에 button 기능 넣기

category Nordic_nRF52 2023. 4. 12. 15:07

: radio_test 프로젝트에 bsp 프로젝트안에 있는 button 관련 기능을 추가해 넣어 테스트 해봤습니다.

목차

     

    1> 진행순서를 정리해 봤습니다.

     ▶ bsp 프로젝트안의 다음코드 복사해 옵니다.

    void bsp_evt_handler(bsp_event_t evt)
    {
       ~~ 중략 ~~
    }
    
    void bsp_configuration()
    {
        uint32_t err_code;
        err_code = bsp_init(BSP_INIT_BUTTONS, bsp_evt_handler);
        APP_ERROR_CHECK(err_code);
    }

     

     ▶ radio_test 프로젝트의 sdk_config.h 파일을 열고 다음을 추가해 줍니다.

    // <h> app_button - buttons handling module
    
    //==========================================================
    // <q> BUTTON_ENABLED  - Enables Button module
     
    
    #ifndef BUTTON_ENABLED
    #define BUTTON_ENABLED 1
    #endif
    
    // <q> BUTTON_HIGH_ACCURACY_ENABLED  - Enables GPIOTE high accuracy for buttons
     
    
    #ifndef BUTTON_HIGH_ACCURACY_ENABLED
    #define BUTTON_HIGH_ACCURACY_ENABLED 0
    #endif
    
    // </h>

     

     ▶  radio_test 에  bsp 프로젝트에서  복사한 코드 및  main()함수에 아래내용 추가후 빌드 진행합니다.

    int main(void)
    {
        ~~ 중략 ~~
    	bsp_configuration();
        ~~ 중략 ~~
    }

     

     ▶ 빌드에러 발생 (bsp_init 에러)

    Building ‘radio_test_pca10040’ from solution ‘radio_test_pca10040’ in configuration ‘Debug’
    5> Compiling ‘main.c’
    1> Linking radio_test_pca10040.elf
    1> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 5.42a/gcc/arm-none-eabi/bin/ld: Output/Debug/Obj/radio_test_pca10040/main.o: in function `bsp_configuration':
    1> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\examples\peripheral\radio_test/main.c:158: undefined reference to `bsp_init'
    Build failed

        → 프로젝트 파일(.emProject)을 연후 아래 내용 추가해 줍니다.

     

     ▶ 빌드에러 발생 (app_button.h 에러)

    Building ‘radio_test_pca10040’ from solution ‘radio_test_pca10040’ in configuration ‘Debug’
    5> Compiling ‘bsp.c’
    5> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\bsp\bsp.c:52:10: fatal error: app_button.h: No such file or directory
    5> compilation terminated.
    Build failed

        → 프로젝트 파일에서 nRF_Libraries  아래에 app_button.c 를 추가해 줍니다.

        프로젝트 파일에서  c_user_include_directories 에 다음내용 추가

          c_user_include_directories= ~~ 중략~~ ;../../../../../../components/libraries/button;

     

     

     ▶ APP_BUTTON_* 에러 발생

    6> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\bsp\bsp.c:165:18: error: 'BSP_BUTTON_ACTION_LONG_PUSH' undeclared (first use in this function)
    6> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\bsp\bsp.c:165:18: note: each undeclared identifier is reported only once for each function it appears in
    6> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\bsp\bsp.c:182:53: error: 'BSP_BUTTON_ACTION_LONG_PUSH' undeclared (first use in this function)
    6> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\bsp\bsp.c:499:63: error: 'BSP_BUTTON_ACTION_PUSH' undeclared (first use in this function); did you mean 'APP_BUTTON_ACTIVE_HIGH'?
    6> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\bsp\bsp.c:563:32: error: 'BSP_BUTTON_ACTION_PUSH' undeclared (first use in this function); did you mean 'APP_BUTTON_ACTIVE_HIGH'?
    6> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\bsp\bsp.c:570:18: error: 'BSP_BUTTON_ACTION_LONG_PUSH' undeclared (first use in this function)
    6> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\bsp\bsp.c:573:18: error: 'BSP_BUTTON_ACTION_RELEASE' undeclared (first use in this function); did you mean 'APP_BUTTON_RELEASE'?
    Build failed

      → 프로젝트 파일의 c_preprocessor_definitions=  안에서 다음 내용 제거 

      BSP_DEFINES_ONLY; 제거

     

     

     ▶ 빌드에러 발생 ( nrfx_gpiote_in_is_set  에러)

    1> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 5.42a/gcc/arm-none-eabi/bin/ld: Output/Debug/Obj/radio_test_pca10040/app_button.o: in function `detection_delay_timeout_handler':
    1> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\button/app_button.c:229: undefined reference to `nrfx_gpiote_in_is_set'
    1> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 5.42a/gcc/arm-none-eabi/bin/ld: Output/Debug/Obj/radio_test_pca10040/app_button.o: in function `gpiote_event_handler':
    1> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\button/app_button.c:248: undefined reference to `nrfx_gpiote_in_is_set'
    1> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 5.42a/gcc/arm-none-eabi/bin/ld: Output/Debug/Obj/radio_test_pca10040/app_button.o: in function `app_button_init':
    1> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\button/app_button.c:272: undefined reference to `nrfx_gpiote_is_init'
    1> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 5.42a/gcc/arm-none-eabi/bin/ld: D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\button/app_button.c:274: undefined reference to `nrfx_gpiote_init'
    1> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 5.42a/gcc/arm-none-eabi/bin/ld: D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\button/app_button.c:297: undefined reference to `nrfx_gpiote_in_init'
    1> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 5.42a/gcc/arm-none-eabi/bin/ld: Output/Debug/Obj/radio_test_pca10040/app_button.o: in function `app_button_enable':
    1> D:\Project\SES\nRF5SDK_1702\nRF5_SDK\components\libraries\button/app_button.c:314: undefined reference to `nrfx_gpiote_in_event_enable'
    Build failed

          → 프로젝트 파일에 다음추가

      <folder Name="nRF_Drivers">
          ~~ 중략~~
          <file file_name="../../../../../../modules/nrfx/drivers/src/nrfx_gpiote.c" />
      </folder>

     

       →  sdk_config.h 파일에 다음추가

    //==========================================================
    // <e> GPIOTE_ENABLED - nrf_drv_gpiote - GPIOTE peripheral driver - legacy layer
    //==========================================================
    #ifndef GPIOTE_ENABLED
    #define GPIOTE_ENABLED 1
    #endif
    // <o> GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS - Number of lower power input pins 
    #ifndef GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS
    #define GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 4
    #endif
    
    // <o> GPIOTE_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    
    // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef GPIOTE_CONFIG_IRQ_PRIORITY
    #define GPIOTE_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // </e>
    
    // <e> NRFX_GPIOTE_ENABLED - nrfx_gpiote - GPIOTE peripheral driver
    //==========================================================
    #ifndef NRFX_GPIOTE_ENABLED
    #define NRFX_GPIOTE_ENABLED 1
    #endif
    // <o> NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS - Number of lower power input pins 
    #ifndef NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS
    #define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1
    #endif
    
    // <o> NRFX_GPIOTE_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_GPIOTE_CONFIG_IRQ_PRIORITY
    #define NRFX_GPIOTE_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // <e> NRFX_GPIOTE_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_GPIOTE_CONFIG_LOG_ENABLED
    #define NRFX_GPIOTE_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_GPIOTE_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_GPIOTE_CONFIG_LOG_LEVEL
    #define NRFX_GPIOTE_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_GPIOTE_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_GPIOTE_CONFIG_INFO_COLOR
    #define NRFX_GPIOTE_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_GPIOTE_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_GPIOTE_CONFIG_DEBUG_COLOR
    #define NRFX_GPIOTE_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    // </e>

     

     ▶  빌드 성공

     

     ▶  radio_test 실행후 Button1, Button2 누르면 Serial 로그에 다음처럼 나오면 OK 입니다.

         →  bsp_evt_handler () 코드는 아래 내용 참고하세요.

    void bsp_evt_handler(bsp_event_t evt)
    {
        switch (evt)
        {
            case BSP_EVENT_KEY_0:
                NRF_LOG_INFO("BSP_EVENT_KEY_0");
                break;
    
            case BSP_EVENT_KEY_1:
                NRF_LOG_INFO("BSP_EVENT_KEY_1");
                break;
    
            default:
                return; // no implementation needed
        }
    }

     

     

    간단히 radio_test 프로젝트에 button 기능을 추가해 봤습니다.

     

     

    그럼 수고하세요.

     

     

     

    반응형