This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Printf() in NRF51

Hi!,

UART works fine with nrf-ble-tutorial-characteristic-CompletedCode in my nRF51-DK but I'm trying to implement in my application but not works.

These are my includes:

#include <app_error.h>
#include <app_timer.h>
#include <app_uart.h>
#include <app_util.h>
#include <app_util_platform.h>
#include <ble.h>
#include <ble_advdata.h>
#include <ble_advertising.h>
#include <ble_conn_params.h>
#include <ble_gap.h>
#include <ble_gatt.h>
#include <ble_hci.h>
#include <ble_stack_handler_types.h>
#include <ble_types.h>
#include <boards.h>
#include <bsp.h>
#include <bsp_btn_ble.h>
#include <device_manager.h>
#include <nrf_error.h>
#include <nrf_sdm.h>
#include <nrf_soc.h>
#include <nrf52_bitfields.h>
#include <pca10040.h>
#include <pstorage.h>
#include <pstorage_platform.h>
#include <sdk_errors.h>
#include <softdevice_handler.h>
#include <stdbool.h>
#include <string.h>
#include <sys/_stdint.h>
#include "custom_service.h"


static void uart_events_handler(app_uart_evt_t * p_event)
{
    switch (p_event->evt_type)
    {
        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_code);
            break;

        default:
            break;
    }
}


/**
 * @brief Inicialización UART.
 *
 */
static void uart_config(void)
{
    uint32_t                     err_code;
    const app_uart_comm_params_t comm_params =
    {
        RX_PIN_NUMBER,
        TX_PIN_NUMBER,
        RTS_PIN_NUMBER,
        CTS_PIN_NUMBER,
        APP_UART_FLOW_CONTROL_DISABLED,
        false,
        UART_BAUDRATE_BAUDRATE_Baud38400
    };

    APP_UART_FIFO_INIT(&comm_params,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       uart_events_handler,
                       APP_IRQ_PRIORITY_LOW,
                       err_code);

    APP_ERROR_CHECK(err_code);
}

And my main thread:

int main(void)
{   
    uint32_t err_code;
    bool erase_bonds;

    uart_config();
    printf("\033[2J\033[;HTest UART on NRF51\r\n");

    // Inicializa.
    timers_init();
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    device_manager_init(erase_bonds);
    gap_params_init();
    servicios_init();
    advertising_init();
    conn_params_init();

    // Inicia ejecución.
    application_timers_start();
    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);

    // Entra en el loop principal.
    for (;;)
    {
        power_manage();
    }
}

Baud rate of minicom is 38400.

Can you say me where is the error? Thanks.

Regards

  • Thanks Jørgen but I already have that line in my Makefile.

    Source common to all targets

    C_SOURCE_FILES += \
    
    $(abspath ../../../../../../components/libraries/uart/app_uart.c) \
    $(abspath ../../../../../../components/libraries/uart/retarget.c) \
    $(abspath ../../../../../../components/drivers_nrf/uart/nrf_drv_uart.c) \
    $(abspath ../../../../../../components/ble/ble_services/ble_nus/ble_nus.c) \
    
  • I see that you are using the macro APP_UART_FIFO_INIT to init your UART. Can you change your source file include from app_uart.c to app_uart_fifo.c?

  • Of course,

    Makefile in my_app_sdk11:

    #source common to all targets
    $(abspath ../../../../../../components/libraries/uart/app_uart_fifo.c) \
    
    #includes common to all targets
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/uart)
    

    javi@PC:~/Development/Nordic/NRF-SDK/nRF5_SDK_11.0.0_89a8197/components/libraries/uart$ tree .
        .
        ├── app_uart.c
        ├── app_uart_fifo.c
        ├── app_uart.h
        └── retarget.c
        
        0 directories, 4 files
    

    Compiling file: app_uart_fifo.c
    /home/javi/Development/Nordic/NRF-SDK/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/app_uart_fifo.c:14:22: fatal error: app_fifo.h: No such file or directory
    Makefile:222: fallo en las instrucciones para el objetivo '_build/app_uart_fifo.o'
     #include "app_fifo.h"
                          ^
    compilation terminated.
    make: *** [_build/app_uart_fifo.o] Error 1
    

    However, yesterday, I started to migrate from SDK11 to SDK12 and I used ble_app_uart as template.

    I put it in another post.

  • You also need to include the path to app_fifo.h in your include paths:

    INC_PATHS += -I$(abspath ../../../../../../components/libraries/fifo)
    

    And add app_fifo.c to your source files:

    C_SOURCE_FILES += $(abspath ../../../../../../components/libraries/fifo/app_fifo.c)
    
  • Thanks!

    I have it done but not works to me:

    PROJECT_NAME := ble_app_template_s132_pca10040
    
    export OUTPUT_FILENAME
    #MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
    MAKEFILE_NAME := $(MAKEFILE_LIST)
    MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
    
    TEMPLATE_PATH = ../../../../../../components/toolchain/gcc
    ifeq ($(OS),Windows_NT)
    include $(TEMPLATE_PATH)/Makefile.windows
    else
    include $(TEMPLATE_PATH)/Makefile.posix
    endif
    
    MK := mkdir
    RM := rm -rf
    
    #echo suspend
    ifeq ("$(VERBOSE)","1")
    NO_ECHO :=
    else
    NO_ECHO := @
    endif
    
    # Toolchain commands
    CC              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc'
    AS              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as'
    AR              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar' -r
    LD              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld'
    NM              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm'
    OBJDUMP         := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump'
    OBJCOPY         := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy'
    SIZE            := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size'
    
    #function for removing duplicates in a list
    remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
    
    #source common to all targets
    C_SOURCE_FILES += \
    $(abspath ../../../../../../components/libraries/button/app_button.c) \
    $(abspath ../../../../../../components/libraries/util/app_error.c) \
    $(abspath ../../../../../../components/libraries/util/app_error_weak.c) \
    $(abspath ../../../../../../components/libraries/timer/app_timer.c) \
    $(abspath ../../../../../../components/libraries/trace/app_trace.c) \
    $(abspath ../../../../../../components/libraries/util/app_util_platform.c) \
    $(abspath ../../../../../../components/libraries/fstorage/fstorage.c) \
    $(abspath ../../../../../../components/libraries/util/nrf_assert.c) \
    $(abspath ../../../../../../components/libraries/util/nrf_log.c) \
    $(abspath ../../../../../../components/libraries/uart/retarget.c) \
    $(abspath ../../../../../../components/libraries/uart/app_uart.c) \
    $(abspath ../../../../../../components/libraries/fifo/app_fifo.c) \
    $(abspath ../../../../../../components/libraries/sensorsim/sensorsim.c) \
    $(abspath ../../../../../../external/segger_rtt/RTT_Syscalls_GCC.c) \
    $(abspath ../../../../../../external/segger_rtt/SEGGER_RTT.c) \
    $(abspath ../../../../../../external/segger_rtt/SEGGER_RTT_printf.c) \
    $(abspath ../../../../../../components/drivers_nrf/delay/nrf_delay.c) \
    $(abspath ../../../../../../components/drivers_nrf/common/nrf_drv_common.c) \
    $(abspath ../../../../../../components/drivers_nrf/gpiote/nrf_drv_gpiote.c) \
    $(abspath ../../../../../../components/drivers_nrf/uart/nrf_drv_uart.c) \
    $(abspath ../../../../../../components/drivers_nrf/pstorage/pstorage.c) \
    $(abspath ../../../../../bsp/bsp.c) \
    $(abspath ../../../../../bsp/bsp_btn_ble.c) \
    $(abspath ../../../main.c) \
    $(abspath ../../../my_custom_service.c) \
    $(abspath ../../../../../../components/ble/common/ble_advdata.c) \
    $(abspath ../../../../../../components/ble/ble_advertising/ble_advertising.c) \
    $(abspath ../../../../../../components/ble/common/ble_conn_params.c) \
    $(abspath ../../../../../../components/ble/common/ble_srv_common.c) \
    $(abspath ../../../../../../components/ble/device_manager/device_manager_peripheral.c) \
    $(abspath ../../../../../../components/toolchain/system_nrf52.c) \
    $(abspath ../../../../../../components/softdevice/common/softdevice_handler/softdevice_handler.c) \
    
    #assembly files common to all targets
    ASM_SOURCE_FILES  = $(abspath ../../../../../../components/toolchain/gcc/gcc_startup_nrf52.s)
    
    #includes common to all targets
    INC_PATHS  = -I$(abspath ../../../config/ble_app_template_s132_pca10040)
    INC_PATHS += -I$(abspath ../../../config)
    INC_PATHS += -I$(abspath ../../../../../../components/drivers_nrf/config)
    INC_PATHS += -I$(abspath ../../../../../../components/drivers_nrf/delay)
    INC_PATHS += -I$(abspath ../../../../../../components/drivers_nrf/uart)
    INC_PATHS += -I$(abspath ../../../../../../components/drivers_nrf/pstorage)
    INC_PATHS += -I$(abspath ../../../../../../components/drivers_nrf/gpiote)
    INC_PATHS += -I$(abspath ../../../../../../components/drivers_nrf/hal)
    INC_PATHS += -I$(abspath ../../../../../../components/drivers_nrf/common)
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/timer)
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/fstorage/config)
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/sensorsim)
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/uart)
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/fifo)
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/util)
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/button)
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/fstorage)
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/experimental_section_vars)
    INC_PATHS += -I$(abspath ../../../../../../components/libraries/trace)
    INC_PATHS += -I$(abspath ../../../../../../components/softdevice/s132/headers/nrf52)
    INC_PATHS += -I$(abspath ../../../../../../components/softdevice/s132/headers)
    INC_PATHS += -I$(abspath ../../../../../../components/softdevice/common/softdevice_handler)
    INC_PATHS += -I$(abspath ../../../../../../components/ble/ble_advertising)
    INC_PATHS += -I$(abspath ../../../../../../components/ble/device_manager)
    INC_PATHS += -I$(abspath ../../../../../../components/ble/common)
    INC_PATHS += -I$(abspath ../../../../../../components/device)
    INC_PATHS += -I$(abspath ../../../../../../external/segger_rtt)
    INC_PATHS += -I$(abspath ../../../../../bsp)
    INC_PATHS += -I$(abspath ../../../../../../components/toolchain/CMSIS/Include)
    INC_PATHS += -I$(abspath ../../../../../../components/toolchain/gcc)
    INC_PATHS += -I$(abspath ../../../../../../components/toolchain)
    
    
    OBJECT_DIRECTORY = _build
    LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
    OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY)
    
    # Sorting removes duplicates
    BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
    
    #flags common to all targets
    CFLAGS  = -DNRF52
    CFLAGS += -DSOFTDEVICE_PRESENT
    CFLAGS += -DBOARD_PCA10040
    CFLAGS += -DNRF52_PAN_12
    CFLAGS += -DNRF52_PAN_15
    CFLAGS += -DNRF52_PAN_58
    CFLAGS += -DNRF52_PAN_55
    CFLAGS += -DNRF52_PAN_54
    CFLAGS += -DNRF52_PAN_31
    CFLAGS += -DNRF52_PAN_30
    CFLAGS += -DNRF52_PAN_51
    CFLAGS += -DNRF52_PAN_36
    CFLAGS += -DNRF52_PAN_53
    CFLAGS += -DNRF_LOG_USES_UART=1
    CFLAGS += -DS132
    CFLAGS += -DCONFIG_GPIO_AS_PINRESET
    CFLAGS += -DBLE_STACK_SUPPORT_REQD
    CFLAGS += -DSWI_DISABLE0
    CFLAGS += -DNRF52_PAN_20
    CFLAGS += -DNRF52_PAN_64
    CFLAGS += -DNRF52_PAN_62
    CFLAGS += -DNRF52_PAN_63
    CFLAGS += -mcpu=cortex-m4
    CFLAGS += -mthumb -mabi=aapcs --std=gnu99
    CFLAGS += -Wall -O3 -g3
    CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    # keep every function in separate section. This will allow linker to dump unused functions
    CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
    CFLAGS += -fno-builtin --short-enums
    # keep every function in separate section. This will allow linker to dump unused functions
    LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
    LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
    LDFLAGS += -mcpu=cortex-m4
    LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    # let linker to dump unused sections
    LDFLAGS += -Wl,--gc-sections
    # use newlib in nano version
    LDFLAGS += --specs=nano.specs -lc -lnosys
    
    # Assembler flags
    ASMFLAGS += -x assembler-with-cpp
    ASMFLAGS += -DNRF52
    ASMFLAGS += -DSOFTDEVICE_PRESENT
    ASMFLAGS += -DBOARD_PCA10040
    ASMFLAGS += -DNRF52_PAN_12
    ASMFLAGS += -DNRF52_PAN_15
    ASMFLAGS += -DNRF52_PAN_58
    ASMFLAGS += -DNRF52_PAN_55
    ASMFLAGS += -DNRF52_PAN_54
    ASMFLAGS += -DNRF52_PAN_31
    ASMFLAGS += -DNRF52_PAN_30
    ASMFLAGS += -DNRF52_PAN_51
    ASMFLAGS += -DNRF52_PAN_36
    ASMFLAGS += -DNRF52_PAN_53
    ASMFLAGS += -DNRF_LOG_USES_UART=1
    ASMFLAGS += -DS132
    ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
    ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
    ASMFLAGS += -DSWI_DISABLE0
    ASMFLAGS += -DNRF52_PAN_20
    ASMFLAGS += -DNRF52_PAN_64
    ASMFLAGS += -DNRF52_PAN_62
    ASMFLAGS += -DNRF52_PAN_63
    
    #default target - first one defined
    default: clean nrf52832_xxaa_s132
    
    #building all targets
    all: clean
    	$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
    	$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf52832_xxaa_s132
    
    #target for printing all targets
    help:
    	@echo following targets are available:
    	@echo 	nrf52832_xxaa_s132
    	@echo 	flash_softdevice
    
    C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
    C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
    C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
    
    ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
    ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
    ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )
    
    vpath %.c $(C_PATHS)
    vpath %.s $(ASM_PATHS)
    
    OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
    
    nrf52832_xxaa_s132: OUTPUT_FILENAME := nrf52832_xxaa_s132
    nrf52832_xxaa_s132: LINKER_SCRIPT=ble_app_template_gcc_nrf52.ld
    
    nrf52832_xxaa_s132: $(BUILD_DIRECTORIES) $(OBJECTS)
    	@echo Linking target: $(OUTPUT_FILENAME).out
    	$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    	$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
    
    ## Create build directories
    $(BUILD_DIRECTORIES):
    	echo $(MAKEFILE_NAME)
    	$(MK) $@
    
    # Create objects from C SRC files
    $(OBJECT_DIRECTORY)/%.o: %.c
    	@echo Compiling file: $(notdir $<)
    	$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
    
    # Assemble files
    $(OBJECT_DIRECTORY)/%.o: %.s
    	@echo Assembly file: $(notdir $<)
    	$(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<
    # Link
    $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
    	@echo Linking target: $(OUTPUT_FILENAME).out
    	$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    ## Create binary .bin file from the .out file
    $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    	@echo Preparing: $(OUTPUT_FILENAME).bin
    	$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
    
    ## Create binary .hex file from the .out file
    $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    	@echo Preparing: $(OUTPUT_FILENAME).hex
    	$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
    
    finalize: genbin genhex echosize
    
    genbin:
    	@echo Preparing: $(OUTPUT_FILENAME).bin
    	$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
    
    ## Create binary .hex file from the .out file
    genhex:
    	@echo Preparing: $(OUTPUT_FILENAME).hex
    	$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
    echosize:
    	-@echo ''
    	$(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    	-@echo ''
    
    clean:
    	$(RM) $(BUILD_DIRECTORIES)
    
    cleanobj:
    	$(RM) $(BUILD_DIRECTORIES)/*.o
    flash: nrf52832_xxaa_s132
    	@echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
    	nrfjprog --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex -f nrf52  --sectorerase
    	nrfjprog --reset -f nrf52
    
    ## Flash softdevice
    flash_softdevice:
    	@echo Flashing: s132_nrf52_2.0.0_softdevice.hex
    	nrfjprog --program ../../../../../../components/softdevice/s132/hex/s132_nrf52_2.0.0_softdevice.hex -f nrf52 --chiperase
    	nrfjprog --reset -f nrf52
    

    #include <app_error.h>
    #include <app_timer.h>
    #include <app_uart.h>
    #include <app_util.h>
    #include <app_util_platform.h>
    #include <ble.h>
    #include <ble_advdata.h>
    #include <ble_advertising.h>
    #include <ble_conn_params.h>
    #include <ble_gap.h>
    #include <ble_gatt.h>
    #include <ble_hci.h>
    #include <ble_stack_handler_types.h>
    #include <ble_types.h>
    #include <boards.h>
    #include <bsp.h>
    #include <bsp_btn_ble.h>
    #include <device_manager.h>
    #include <nrf_error.h>
    #include <nrf_sdm.h>
    #include <nrf_soc.h>
    #include <nrf52_bitfields.h>
    #include <pca10040.h>
    #include <pstorage.h>
    #include <pstorage_platform.h>
    #include <sdk_errors.h>
    #include <softdevice_handler.h>
    #include <stdbool.h>
    #include <string.h>
    #include <sys/_stdint.h>
    #include "my_custom_service.h"
    
Related