makerdiary / nrf52840-mdk

An Open-Source, Micro Development Kit for IoT Applications using the nRF52840 SoC
https://wiki.makerdiary.com/nrf52840-mdk/
169 stars 42 forks source link

how to import sdk example? #15

Closed stefanosky closed 4 years ago

stefanosky commented 5 years ago

please can you explain how to use the others sdk examples, from Nordic. like other example about nfc and ble. in particular the import section and the board specification

thanks

caizelin commented 5 years ago

Hi, You can see these examples. They are imported from nRF5 SDK. You can follow these steps to import a new one by yourself:

  1. Copy an example from the nRF5 SDK to your workspace
  2. Adapt the directories like this:
    .
    ├── armgcc
    │   ├── Makefile
    │   ├── _build
    │   └── ble_app_blinky_gcc_nrf52.ld
    ├── config
    │   └── sdk_config.h
    ├── hex
    │   └── ble_app_blinky_nrf52840_mdk_s140.hex
    └── main.c
  3. Adapt the SDK base path in Makefile:
    MDK_ROOT := ../../../..
    SDK_ROOT := $(MDK_ROOT)/nrf_sdks/nRF5_SDK_15.2.0_9412b96
    PROJ_DIR := ..
  4. Specify the board flag in Makefile. Remember to add the include path for nrf52840_mdk.h and custom_board.h
    CFLAGS += -DBOARD_CUSTOM
    CFLAGS += -DNRF52840_MDK
    ... 
    ASMFLAGS += -DBOARD_CUSTOM
    ASMFLAGS += -DNRF52840_MDK
  5. Set the pyocd command in Makefile:
    
    .PHONY: flash flash_softdevice flash_all erase release

Flash the program

flash: default @echo Flashing: $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex pyocd-flashtool -t nrf52 -se $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex

Flash softdevice

flash_softdevice: @echo Flashing: s140_nrf52_6.1.0_softdevice.hex pyocd-flashtool -t nrf52 -se $(SDK_ROOT)/components/softdevice/s140/hex/s140_nrf52_6.1.0_softdevice.hex

Merge application and softdevice, then flash

flash_all: default mergehex -m $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex $(SDK_ROOT)/components/softdevice/s140/hex/s140_nrf52_6.1.0_softdevice.hex -o $(OUTPUT_DIRECTORY)/nrf52840_xxaa_s140.hex @echo Flashing: $(OUTPUT_DIRECTORY)/nrf52840_xxaa_s140.hex pyocd-flashtool -t nrf52 -se $(OUTPUT_DIRECTORY)/nrf52840_xxaa_s140.hex

Erase chip

erase: pyocd-flashtool -t nrf52 -ce

Generate hex file

release: @echo Generating hex file... mergehex -m $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex $(SDK_ROOT)/components/softdevice/s140/hex/s140_nrf52_6.1.0_softdevice.hex -o $(PROJ_DIR)/hex/$(PROJECT_NAME).hex


6. If Log UART backend is used, remember to set `NRF_LOG_BACKEND_UART_TX_PIN` to `20` in `sdk_config.h`

That's it!
stefanosky commented 5 years ago

thank you very much for this usefull tut :) i will do it ok, i'had problem with logging, i tried to insert logging in blink example, with no success. so for logging it's only to put NRF_LOG_BACKEND_UART_TX_PIN 20 ? therarent other flags to activate?

caizelin commented 5 years ago

thank you very much for this usefull tut :) i will do it ok, i'had problem with logging, i tried to insert logging in blink example, with no success. so for logging it's only to put NRF_LOG_BACKEND_UART_TX_PIN 20 ? therarent other flags to activate?

Just for the examples with logging module enabled. Also seeing this example and comparing with the blinky example, you will know how to enable a UART logging module.

stefanosky commented 5 years ago

yess!! thanks for the patience, you still help me very much, and i hope other people starting prototyping with your module.

stefanosky commented 5 years ago

here a blink with log that i wrote :)

`

include

include

include

include "nrf_delay.h"

include "boards.h"

include "nrf_log.h"

include "nrf_log_ctrl.h"

include "nrf_log_default_backends.h"

define BOARD_NAME "nRF52840-MDK"

define STRING_EOL "\r\n"

define STRING_HEADER "-- Power Profiling example 2 --"STRING_EOL \

"-- "BOARD_NAME " --"STRING_EOL \
"-- Compiled: "__DATE__ " "__TIME__ " --"STRING_EOL

define STRING_HEADER2 "-- kiki --"

static void log_init(void) { ret_code_t err_code = NRF_LOG_INIT(NULL); APP_ERROR_CHECK(err_code); NRF_LOG_DEFAULT_BACKENDS_INIT(); nrf_delay_ms(100); }

int main(void) { uint32_t conteggio=0;

log_init();
bsp_board_init(BSP_INIT_LEDS);

    nrf_delay_ms(100);

NRF_LOG_INFO(STRING_HEADER);

NRF_LOG_INFO("blink startedddd");
nrf_delay_ms(100);
NRF_LOG_FLUSH();

/* Toggle LEDs. */
// Enter main loop. 

while (true)
{

    conteggio++;
    NRF_LOG_INFO("c %d", conteggio);
    NRF_LOG_FLUSH();
    nrf_delay_ms(100);

        for (int i = 0; i < LEDS_NUMBER; i++)
        {
            NRF_LOG_INFO("blink al led %d .", i );
            NRF_LOG_FLUSH();
            nrf_delay_ms(100);
            bsp_board_led_invert(i);
            nrf_delay_ms(1000);
        }
}

} `

caizelin commented 4 years ago

I’m closing this issue because it has been inactive for a long time. Please reopen if you still encounter this issue. Thank you!