zoukankan      html  css  js  c++  java
  • 基于IAR移植sdk12.2.0建立nrf52832的工程———GPIO

    工程伊始,需要在sdk包中拷贝三个重要的文件,blinky_iar_nRF5x.icf,iar_startup_nrf52.s,system_nrf52.c。

    工程目录建立:

    1、建立bsp文件,包括了开发板相关的头文件,开发板用PCA10040,

    2、把sdk中的components目录中的drivers_nrf、libraries、device、toolchain,以及sdk_validation.h文件拷贝到自己建立的目录中,

    3、建立project目录,用于放iar的工程文件,其中,RTE文件存放一些底层的文件,具体可以参考下面的罗列出来的详细的目录树。

    文件夹 PATH 列表
    卷序列号为 523663A7 7005:0F54
    D:.
    │  dir.txt
    │  
    └─LED
        ├─bsp
        │      boards.h
        │      bsp.c
        │      bsp.h
        │      bsp_btn_ble.c
        │      bsp_btn_ble.h
        │      n5_starterkit.h
        │      pca10028.h
        │      pca10031.h
        │      pca10040.h
        │      
        ├─components
        │  │  sdk_validation.h
        │  │  
        │  ├─device
        │  │      compiler_abstraction.h
        │  │      nrf.h
        │  │      nrf51.h
        │  │      nrf51422_peripherals.h
        │  │      nrf51802_peripherals.h
        │  │      nrf51822_peripherals.h
        │  │      nrf51_bitfields.h
        │  │      nrf51_deprecated.h
        │  │      nrf51_to_nrf52.h
        │  │      nrf51_to_nrf52840.h
        │  │      nrf52.h
        │  │      nrf52832_peripherals.h
        │  │      nrf52840.h
        │  │      nrf52840_bitfields.h
        │  │      nrf52840_peripherals.h
        │  │      nrf52_bitfields.h
        │  │      nrf52_name_change.h
        │  │      nrf52_to_nrf52840.h
        │  │      
        │  ├─drivers_nrf
        │  │  ├─adc
        │  │  │      nrf_drv_adc.c
        │  │  │      nrf_drv_adc.h
        │  │  │      
        │  │  ├─ble_flash
        │  │  │      ble_flash.c
        │  │  │      ble_flash.h
        │  │  │      
        │  │  ├─clock
        │  │  │      nrf_drv_clock.c
        │  │  │      nrf_drv_clock.h
        │  │  │      
        │  │  ├─common
        │  │  │      nrf_drv_common.c
        │  │  │      nrf_drv_common.h
        │  │  │      
        │  │  ├─comp
        │  │  │      nrf_drv_comp.c
        │  │  │      nrf_drv_comp.h
        │  │  │      
        │  │  ├─config
        │  │  │      nrf_drv_config.h
        │  │  │      nrf_drv_config_validation.h
        │  │  │      
        │  │  ├─delay
        │  │  │      nrf_delay.c
        │  │  │      nrf_delay.h
        │  │  │      
        │  │  ├─gpiote
        │  │  │      nrf_drv_gpiote.c
        │  │  │      nrf_drv_gpiote.h
        │  │  │      
        │  │  ├─hal
        │  │  │      nrf_adc.c
        │  │  │      nrf_adc.h
        │  │  │      nrf_clock.h
        │  │  │      nrf_comp.h
        │  │  │      nrf_ecb.c
        │  │  │      nrf_ecb.h
        │  │  │      nrf_egu.h
        │  │  │      nrf_gpio.h
        │  │  │      nrf_gpiote.h
        │  │  │      nrf_i2s.h
        │  │  │      nrf_lpcomp.h
        │  │  │      nrf_nvmc.c
        │  │  │      nrf_nvmc.h
        │  │  │      nrf_pdm.h
        │  │  │      nrf_ppi.h
        │  │  │      nrf_pwm.h
        │  │  │      nrf_qdec.h
        │  │  │      nrf_rng.h
        │  │  │      nrf_rtc.h
        │  │  │      nrf_saadc.c
        │  │  │      nrf_saadc.h
        │  │  │      nrf_spi.h
        │  │  │      nrf_spim.h
        │  │  │      nrf_spis.h
        │  │  │      nrf_temp.h
        │  │  │      nrf_timer.h
        │  │  │      nrf_twi.h
        │  │  │      nrf_twim.h
        │  │  │      nrf_twis.h
        │  │  │      nrf_uart.h
        │  │  │      nrf_uarte.h
        │  │  │      nrf_wdt.h
        │  │  │      
        │  │  ├─i2s
        │  │  │      nrf_drv_i2s.c
        │  │  │      nrf_drv_i2s.h
        │  │  │      
        │  │  ├─lpcomp
        │  │  │      nrf_drv_lpcomp.c
        │  │  │      nrf_drv_lpcomp.h
        │  │  │      
        │  │  ├─nrf_soc_nosd
        │  │  │      nrf_error.h
        │  │  │      nrf_nvic.c
        │  │  │      nrf_nvic.h
        │  │  │      nrf_soc.c
        │  │  │      nrf_soc.h
        │  │  │      
        │  │  ├─pdm
        │  │  │      nrf_drv_pdm.c
        │  │  │      nrf_drv_pdm.h
        │  │  │      
        │  │  ├─ppi
        │  │  │      nrf_drv_ppi.c
        │  │  │      nrf_drv_ppi.h
        │  │  │      
        │  │  ├─pstorage
        │  │  │  │  pstorage.c
        │  │  │  │  pstorage.h
        │  │  │  │  pstorage_nosd.c
        │  │  │  │  pstorage_raw.c
        │  │  │  │  
        │  │  │  └─config
        │  │  │          pstorage_platform.h
        │  │  │          
        │  │  ├─pwm
        │  │  │      nrf_drv_pwm.c
        │  │  │      nrf_drv_pwm.h
        │  │  │      
        │  │  ├─qdec
        │  │  │      nrf_drv_qdec.c
        │  │  │      nrf_drv_qdec.h
        │  │  │      
        │  │  ├─radio_config
        │  │  │      radio_config.c
        │  │  │      radio_config.h
        │  │  │      
        │  │  ├─rng
        │  │  │      nrf_drv_rng.c
        │  │  │      nrf_drv_rng.h
        │  │  │      
        │  │  ├─rtc
        │  │  │      nrf_drv_rtc.c
        │  │  │      nrf_drv_rtc.h
        │  │  │      
        │  │  ├─saadc
        │  │  │      nrf_drv_saadc.c
        │  │  │      nrf_drv_saadc.h
        │  │  │      
        │  │  ├─sdio
        │  │  │  │  sdio.c
        │  │  │  │  sdio.h
        │  │  │  │  
        │  │  │  └─config
        │  │  │          sdio_config.h
        │  │  │          
        │  │  ├─spi_master
        │  │  │      nrf_drv_spi.c
        │  │  │      nrf_drv_spi.h
        │  │  │      spi_5W_master.c
        │  │  │      spi_5W_master.h
        │  │  │      
        │  │  ├─spi_slave
        │  │  │      nrf_drv_spis.c
        │  │  │      nrf_drv_spis.h
        │  │  │      
        │  │  ├─swi
        │  │  │      nrf_drv_swi.c
        │  │  │      nrf_drv_swi.h
        │  │  │      
        │  │  ├─timer
        │  │  │      nrf_drv_timer.c
        │  │  │      nrf_drv_timer.h
        │  │  │      
        │  │  ├─twis_slave
        │  │  │      nrf_drv_twis.c
        │  │  │      nrf_drv_twis.h
        │  │  │      nrf_drv_twis_inst.def
        │  │  │      
        │  │  ├─twi_master
        │  │  │  │  nrf_drv_twi.c
        │  │  │  │  nrf_drv_twi.h
        │  │  │  │  
        │  │  │  └─deprecated
        │  │  │      │  twi_hw_master.c
        │  │  │      │  twi_master.h
        │  │  │      │  twi_sw_master.c
        │  │  │      │  
        │  │  │      └─config
        │  │  │              twi_master_config.h
        │  │  │              
        │  │  ├─uart
        │  │  │      nrf_drv_uart.c
        │  │  │      nrf_drv_uart.h
        │  │  │      
        │  │  └─wdt
        │  │          nrf_drv_wdt.c
        │  │          nrf_drv_wdt.h
        │  │          
        │  ├─libraries
        │  │  ├─bootloader_dfu
        │  │  │  │  bootloader.c
        │  │  │  │  bootloader.h
        │  │  │  │  bootloader_settings.c
        │  │  │  │  bootloader_settings.h
        │  │  │  │  bootloader_types.h
        │  │  │  │  bootloader_util.c
        │  │  │  │  bootloader_util.h
        │  │  │  │  dfu.h
        │  │  │  │  dfu_app_handler.c
        │  │  │  │  dfu_app_handler.h
        │  │  │  │  dfu_bank_internal.h
        │  │  │  │  dfu_ble_svc.h
        │  │  │  │  dfu_ble_svc_internal.h
        │  │  │  │  dfu_dual_bank.c
        │  │  │  │  dfu_init.h
        │  │  │  │  dfu_init_template.c
        │  │  │  │  dfu_single_bank.c
        │  │  │  │  dfu_transport.h
        │  │  │  │  dfu_transport_ble.c
        │  │  │  │  dfu_transport_serial.c
        │  │  │  │  dfu_types.h
        │  │  │  │  
        │  │  │  ├─ble_transport
        │  │  │  │      hci_mem_pool_internal.h
        │  │  │  │      
        │  │  │  ├─experimental
        │  │  │  │      dfu_init_template_signing.c
        │  │  │  │      nrf_sec.h
        │  │  │  │      
        │  │  │  └─hci_transport
        │  │  │          hci_mem_pool_internal.h
        │  │  │          hci_transport_config.h
        │  │  │          
        │  │  ├─button
        │  │  │      app_button.c
        │  │  │      app_button.h
        │  │  │      
        │  │  ├─crc16
        │  │  │      crc16.c
        │  │  │      crc16.h
        │  │  │      
        │  │  ├─crc32
        │  │  │      crc32.c
        │  │  │      crc32.h
        │  │  │      
        │  │  ├─ecc
        │  │  │      ecc.c
        │  │  │      ecc.h
        │  │  │      
        │  │  ├─experimental_section_vars
        │  │  │      section_vars.h
        │  │  │      
        │  │  ├─fds
        │  │  │  │  fds.c
        │  │  │  │  fds.h
        │  │  │  │  fds_internal_defs.h
        │  │  │  │  
        │  │  │  └─config
        │  │  │          fds_config.h
        │  │  │          
        │  │  ├─fifo
        │  │  │      app_fifo.c
        │  │  │      app_fifo.h
        │  │  │      
        │  │  ├─fstorage
        │  │  │  │  fstorage.c
        │  │  │  │  fstorage.h
        │  │  │  │  fstorage_internal_defs.h
        │  │  │  │  fstorage_nosd.c
        │  │  │  │  
        │  │  │  └─config
        │  │  │          fstorage_config.h
        │  │  │          
        │  │  ├─gpiote
        │  │  │      app_gpiote.c
        │  │  │      app_gpiote.h
        │  │  │      app_gpiote_fast_detect.c
        │  │  │      
        │  │  ├─hardfault
        │  │  │  │  hardfault.h
        │  │  │  │  hardfault_implementation.c
        │  │  │  │  
        │  │  │  ├─nrf51
        │  │  │  │  └─handler
        │  │  │  │          hardfault_handler_gcc.c
        │  │  │  │          hardfault_handler_iar.c
        │  │  │  │          hardfault_handler_keil.c
        │  │  │  │          
        │  │  │  └─nrf52
        │  │  │      └─handler
        │  │  │              hardfault_handler_gcc.c
        │  │  │              hardfault_handler_iar.c
        │  │  │              hardfault_handler_keil.c
        │  │  │              
        │  │  ├─hci
        │  │  │  │  hci_mem_pool.c
        │  │  │  │  hci_mem_pool.h
        │  │  │  │  hci_slip.c
        │  │  │  │  hci_slip.h
        │  │  │  │  hci_transport.c
        │  │  │  │  hci_transport.h
        │  │  │  │  
        │  │  │  └─config
        │  │  │          hci_mem_pool_internal.h
        │  │  │          hci_transport_config.h
        │  │  │          
        │  │  ├─ic_info
        │  │  │      nrf_ic_info.c
        │  │  │      nrf_ic_info.h
        │  │  │      
        │  │  ├─led_softblink
        │  │  │      led_softblink.c
        │  │  │      led_softblink.h
        │  │  │      
        │  │  ├─low_power_pwm
        │  │  │      low_power_pwm.c
        │  │  │      low_power_pwm.h
        │  │  │      
        │  │  ├─mailbox
        │  │  │      app_mailbox.c
        │  │  │      app_mailbox.h
        │  │  │      app_mailbox_local.h
        │  │  │      
        │  │  ├─mem_manager
        │  │  │      mem_manager.c
        │  │  │      mem_manager.h
        │  │  │      
        │  │  ├─pwm
        │  │  │      app_pwm.c
        │  │  │      app_pwm.h
        │  │  │      
        │  │  ├─scheduler
        │  │  │      app_scheduler.c
        │  │  │      app_scheduler.h
        │  │  │      app_scheduler_serconn.c
        │  │  │      
        │  │  ├─sensorsim
        │  │  │      sensorsim.c
        │  │  │      sensorsim.h
        │  │  │      
        │  │  ├─sha256
        │  │  │      sha256.c
        │  │  │      sha256.h
        │  │  │      
        │  │  ├─simple_timer
        │  │  │      app_simple_timer.c
        │  │  │      app_simple_timer.h
        │  │  │      
        │  │  ├─slip
        │  │  │      slip.c
        │  │  │      slip.h
        │  │  │      
        │  │  ├─timer
        │  │  │      app_timer.c
        │  │  │      app_timer.h
        │  │  │      app_timer_appsh.c
        │  │  │      app_timer_appsh.h
        │  │  │      app_timer_ble_gzll.c
        │  │  │      app_timer_freertos.c
        │  │  │      app_timer_rtx.c
        │  │  │      
        │  │  ├─trace
        │  │  │      app_trace.c
        │  │  │      app_trace.h
        │  │  │      
        │  │  ├─twi
        │  │  │      app_twi.c
        │  │  │      app_twi.h
        │  │  │      
        │  │  ├─uart
        │  │  │      app_uart.c
        │  │  │      app_uart.h
        │  │  │      app_uart_fifo.c
        │  │  │      retarget.c
        │  │  │      
        │  │  └─util
        │  │          app_error.c
        │  │          app_error.h
        │  │          app_error_weak.c
        │  │          app_error_weak.h
        │  │          app_util.h
        │  │          app_util_bds.h
        │  │          app_util_platform.c
        │  │          app_util_platform.h
        │  │          common.h
        │  │          nordic_common.h
        │  │          nrf_assert.c
        │  │          nrf_assert.h
        │  │          nrf_log.c
        │  │          nrf_log.h
        │  │          sdk_common.h
        │  │          sdk_errors.h
        │  │          sdk_macros.h
        │  │          sdk_mapped_flags.c
        │  │          sdk_mapped_flags.h
        │  │          sdk_os.h
        │  │          sdk_resources.h
        │  │          
        │  └─toolchain
        │      │  system_nrf51.c
        │      │  system_nrf51.h
        │      │  system_nrf51422.c
        │      │  system_nrf52.c
        │      │  system_nrf52.h
        │      │  system_nrf52840.c
        │      │  system_nrf52840.h
        │      │  
        │      ├─arm
        │      │      arm_startup_nrf51.s
        │      │      arm_startup_nrf52.s
        │      │      arm_startup_nrf52840.s
        │      │      uicr_config.h
        │      │      
        │      ├─cmsis
        │      │  ├─dsp
        │      │  │  │  license.txt
        │      │  │  │  
        │      │  │  ├─ARM
        │      │  │  │      arm_cortexM4lf_math.lib
        │      │  │  │      arm_cortexM4l_math.lib
        │      │  │  │      
        │      │  │  └─GCC
        │      │  │          libarm_cortexM4lf_math.a
        │      │  │          libarm_cortexM4l_math.a
        │      │  │          
        │      │  └─include
        │      │          arm_common_tables.h
        │      │          arm_const_structs.h
        │      │          arm_math.h
        │      │          cmsis_armcc.h
        │      │          cmsis_armcc_V6.h
        │      │          cmsis_gcc.h
        │      │          core_cm0.h
        │      │          core_cm0plus.h
        │      │          core_cm3.h
        │      │          core_cm4.h
        │      │          core_cm7.h
        │      │          core_cmFunc.h
        │      │          core_cmInstr.h
        │      │          core_cmSimd.h
        │      │          core_sc000.h
        │      │          core_sc300.h
        │      │          
        │      ├─gcc
        │      │      file_list.mk
        │      │      gcc_nrf51_common.ld
        │      │      gcc_startup_nrf51.S
        │      │      gcc_startup_nrf52.S
        │      │      gcc_startup_nrf52840.S
        │      │      Makefile.common
        │      │      Makefile.posix
        │      │      Makefile.windows
        │      │      nrf51_common.ld
        │      │      nrf51_xxaa.ld
        │      │      nrf51_xxab.ld
        │      │      nrf51_xxac.ld
        │      │      nrf52840_xxaa.ld
        │      │      nrf52_common.ld
        │      │      nrf52_xxaa.ld
        │      │      nrf5x_common.ld
        │      │      
        │      └─iar
        │              iar_nrf51_blank_xxaa.icf
        │              iar_nrf51_blank_xxac.icf
        │              iar_startup_nrf51.s
        │              iar_startup_nrf52.s
        │              iar_startup_nrf52840.s
        │              
        └─project
            │  JLinkLog.txt
            │  JLinkSettings.ini
            │  led.dep
            │  LED.emProject
            │  LED.emSession
            │  led.ewd
            │  led.ewp
            │  led.ewt
            │  LED.eww
            │  LED.uvguix.liming
            │  LED.uvoptx
            │  LED.uvprojx
            │  main.c
            │  
            ├─Debug
            │  ├─Exe
            │  │      led.hex
            │  │      led.out
            │  │      led.sim
            │  │      
            │  ├─List
            │  │      led.map
            │  │      
            │  └─Obj
            │          iar_startup_nrf52.o
            │          led.pbd
            │          led.pbd.browse
            │          led.pbd.linf
            │          main.o
            │          main.pbi
            │          main.pbi.xcl
            │          nrf_delay.o
            │          nrf_delay.pbi
            │          nrf_delay.pbi.xcl
            │          system_nrf52.o
            │          system_nrf52.pbi
            │          system_nrf52.pbi.xcl
            │          
            ├─Listings
            │      arm_startup_nrf52.lst
            │      led.map
            │      
            ├─Objects
            │      arm_startup_nrf52.d
            │      arm_startup_nrf52.o
            │      ExtDll.iex
            │      led.axf
            │      led.build_log.htm
            │      led.hex
            │      led.htm
            │      led.lnp
            │      led.sct
            │      LED_nrf52832_xxaa.dep
            │      main.crf
            │      main.d
            │      main.o
            │      nrf_delay.crf
            │      nrf_delay.d
            │      nrf_delay.o
            │      system_nrf52.crf
            │      system_nrf52.d
            │      system_nrf52.o
            │      
            ├─Output
            │  └─LED nrf52832_xxaa
            │      └─Obj
            ├─RTE
            │  │  RTE_Components.h
            │  │  system_nrf52.h
            │  │  
            │  └─Device
            │      └─nRF52832_xxAA
            │              arm_startup_nrf52.s
            │              blinky_iar_nRF5x.icf
            │              iar_startup_nrf52.s
            │              ses_nrf51_startup.s
            │              ses_nrf52_startup.s
            │              system_nrf52.c
            │              
            └─settings
                    led.crun
                    led.Debug.cspy.bat
                    led.Debug.cspy.ps1
                    led.Debug.driver.xcl
                    led.Debug.general.xcl
                    led.dnx
                    LED.wsdt
                    led_Debug.jlink
                    
    

      

    首先,需要blinky_iar_nRF5x.icf文件,这个名称可以修改的,sdk里面根据不同的工程起了不同的文件名,但是内容是一样的。我的目录放在$PROJ_DIR$RTEDevice RF52832_xxAAlinky_iar_nRF5x.icf,在linker选项中就填上面的路径,如下图所示:

    其次,需要iar_startup_nrf52.s,和icf文件同一个目录,是汇编启动文件,和stm32的启动文件和类似的。


    再次需要system_nrf52.c,里面实现了始终初始化的函数。即iar_startup_nrf52.s先执行,后执行system_nrf52.c,该文件在toolchain目录中,最后执行main函数。


    建立Wordspace,建立project,各目录如下所示:


    最后,需要对工程进行配置,右键options


    头文件路径如下:


    $PROJ_DIR$RTEDevice RF52832_xxAA
    $PROJ_DIR$RTE
    $PROJ_DIR$..sp
    $PROJ_DIR$..componentsdrivers_nrfdelay
    $PROJ_DIR$..componentsdrivers_nrfhal
    $PROJ_DIR$..componentsdrivers_nrfcommon
    $PROJ_DIR$..componentsdrivers_nrfuart
    $PROJ_DIR$..componentsdrivers_nrfconfig
    $PROJ_DIR$..componentsdrivers_nrf rf_soc_nosd
    $PROJ_DIR$..componentslibrariesuart
    $PROJ_DIR$..componentslibrariesutil
    $PROJ_DIR$..componentslibrariesfifo
    $PROJ_DIR$..componentsdevice
    $PROJ_DIR$..components
    $PROJ_DIR$..components oolchain
    $PROJ_DIR$..components oolchaincmsisinclude
    宏定义如下
    BSP_DEFINES_ONLY
    BOARD_PCA10040
    NRF52
    每个定义如下所示:

    最后编译,下载工程hex文件,ok了。此文,参考了艾克姆科技的文档,再此表示感谢。

  • 相关阅读:
    Move Zeroes
    Intersection of Two Arrays II
    Intersection of Two Arrays
    Create Maximum Number
    Leetcode version 2
    JDBC学习笔记
    九章算法基础班
    九章算法强化班
    LeetCode
    Amazon High Frequent 9 problems
  • 原文地址:https://www.cnblogs.com/CodeWorkerLiMing/p/10495778.html
Copyright © 2011-2022 走看看