This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Properly initializing an nRF51822-DK board

I have an nRF51822-DK board and so far I could not properly grab from the examples a simple thing: is there any specific initialization needed when coding?

For example I currently run APP_TIMER_INIT, APP_UART_FIFO_INIT, etc. but should I call some bsp-like init procedure first? should I be coding it instead? Or calling the UART/timer app_foo_init function is just enough to set up the proper GPIOS/internal stuff?

Note: yes, for the UART case I'm defining which are the pins that should be used, parity, baudare, etc by using definitions in nrf_drv_config.h. But maybe I'm missing something else.

  • Hi,

    Initialization of HW is done through board definition header file. The "hook" prepared in the SDK is following:

    • All is managed by boards.h file (located in \examples\bsp\ for nRF5 SDK up to V12.1.0 or \components\boards\ for V12.2.0 and newer).
    • If you are using one of supported HW boards (or you beard matches some of these) then simply define particular constant in your project (e.g. by -DBOARD_PCAxxxxx in GCC Makefile) and include boards.h in all custom source code files you write (where needed).
    • If you are using custom HW then use one of these pre-defined header files as example, copy it to your project, rename it to custom_board.h and edit wherever needed (typically remapped GPIO pins and LF clock source). Then simply remove any BOARD_xxxxx from your project defines and add BOARD_CUSTOM.

    This is enough to adopt all basic libraries and SDK modules to your HW. There is another part of "customization" and that's SDK configuration through sdk_config.h file. You should take \config\sdk_config.h as example and either copy it to your project and edit manually or use some interactive generator with GUI wizard if that's supported in your IDE (I assume there is something like that but I was not looking for it). That will set all modules like app_uart, app_fifo, app_timer, segger_rtt, nrf_twi etc.as you need so then everything should compile without clashes (if you write the file correctly and have all modules in compiler/linker paths of course;).

    Two recommendations:

    • I usually define two custom HW filew in my project: one is custom_board.h and then some real definitions of my HW (like boardxyz_revA.h). I leave custom_board.h with structure very close to actual boards.h from SDK (just switch between all known HW definitions based on some project constants defined globally) and all is managed in the end by two global defines BOARD_CUSTOM and BOARDXYZ_REVA.
    • There is even more "complete" sdk_config.h template available in one Q&S on this forum, the one in SDK v13.0.0 has some exotic items missing. However I find it more educative for co-workers on the project to keep sdk_config.h default from SDK and use project-specific defines (typically smaller number of 5-50 items) in app_config.h file which gets included if you define USE_APP_CONFIG globally in your project.

    Cheers Jan

  • Thanks a lot Jan! Looking at the code you pointed out I already have the pieces together, but it's at least reassuring I could grasp the small details correctly.

    Thanks again!

Related