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

BLE_APP_UART_PCA10010 change doesn´t work

Hi,

I´m trying to change the "BLE_APP_UART_PCA10010" example, main.c file.

I would like to delete following functions, because I don´t need UART in my project:

void uart_event_handle()

static void uart_init(void)

But when I comment out "uart_init();" in main function and flash this to nRF52833, it doesn´t work. The BLE device can´t be found by nRF connect app. I can´t find any relation between this UART functionality and the BLE stack.

Can you give me more information, whats gonna be wrong?

Thanks in advance

Simon

Parents
  • Hi,

    Might be better off starting with a different example then? I'm just getting into the SDK and found the sdk_config.h is the best way to disable functionality. Have a search in it for UART.

    Unfortunaly there are not many examples for BLE and PCA10010, just three. I think BLE_APP_UART_PCA10010 is the easiest.I would like to delete everything from main.c I don´t need, for more overview...

    Hi Simon,

    There is no problem removing the physical UART usage from the ble_app_uart example. But then you need to remove everything. If you just remove it partially, this means that you will be calling functions that use the UART without it being initialized, and that will not work (for instance calls to app_uart_put() and app_uart_get()).

    I suggest you take care to remove all relevant code. Also, if you make sure to run the debug example (select Debug from the build configuration dropdown if using Segger Embedded Studio) and enable RTT logging, then you will see what causes problems when you run the example and observe the RTT log and can fix the issues one by one.

    Einar

    Can you please help me with that? I just changed the main.c as following:

    1. I delete static void uart_init(void) function. Only reference is in int main(void), so I deleted it from there.

    2. I changed  

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    /**@brief Function for handling app_uart events.
    *
    * @details This function will receive a single character from the app_uart module and append it to
    * a string. The string will be be sent over BLE when the last character received was a
    * 'new line' '\n' (hex 0x0A) or if the string has reached the maximum data length.
    */
    /**@snippet [Handling the data received over UART] */
    void uart_event_handle(app_uart_evt_t * p_event)
    {
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t err_code;
    switch (p_event->evt_type)
    {
    case APP_UART_DATA_READY:
    UNUSED_VARIABLE(app_uart_get(&data_array[index]));
    index++;
    if ((data_array[index - 1] == '\n') ||
    (data_array[index - 1] == '\r') ||
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    to

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    /**@brief Function for handling app_uart events.
    *
    * @details This function will receive a single character from the app_uart module and append it to
    * a string. The string will be be sent over BLE when the last character received was a
    * 'new line' '\n' (hex 0x0A) or if the string has reached the maximum data length.
    */
    /**@snippet [Handling the data received over UART] */
    static void test(void)
    {
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t err_code;
    int new=1;
    switch (new)
    {
    case 1:
    UNUSED_VARIABLE(app_uart_get(&data_array[index]));
    index++;
    if ((data_array[index - 1] == '\n') ||
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    3. I add "test();" function in int main(void)

    The compiling/building process works fine. But nRF connect can´t find the BLE device anymore. I also attached main.c original and main.c customized. Could you please have a look?

    Thanks in advance

    Simon

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    /**
    * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
    *
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without modification,
    * are permitted provided that the following conditions are met:
    *
    * 1. Redistributions of source code must retain the above copyright notice, this
    * list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form, except as embedded into a Nordic
    * Semiconductor ASA integrated circuit in a product or a software update for
    * such product, must reproduce the above copyright notice, this list of
    * conditions and the following disclaimer in the documentation and/or other
    * materials provided with the distribution.
    *
    * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
    * contributors may be used to endorse or promote products derived from this
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    /**
    * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
    *
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without modification,
    * are permitted provided that the following conditions are met:
    *
    * 1. Redistributions of source code must retain the above copyright notice, this
    * list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form, except as embedded into a Nordic
    * Semiconductor ASA integrated circuit in a product or a software update for
    * such product, must reproduce the above copyright notice, this list of
    * conditions and the following disclaimer in the documentation and/or other
    * materials provided with the distribution.
    *
    * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
    * contributors may be used to endorse or promote products derived from this
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi,

    simon1516 said:
    1. I delete static void uart_init(void) function. Only reference is in int main(void), so I deleted it from there.

    Yes, as I mentioned in my initial reply you need to remove other calls to functions that use UART as well, such as app_uart_put() and app_uart_get(). Those are still called by your code.

    simon1516 said:

    3. I add "test();" function in int main(void)

    The compiling/building process works fine. But nRF connect can´t find the BLE device anymore. I also attached main.c original and main.c customized. Could you please have a look?

    Your code will hit error checks, since you are making function calls that rely on UART being enabled (as described above). You need to fix this first. I would like again to strongly recomend that you use RTT logging (just select Debug built configuration if using SES and observe the logs in within SES), as that will typically show you immediately what the problem is.

  • Your code will hit error checks, since you are making function calls that rely on UART being enabled (as described above). You need to fix this first. I would like again to strongly recomend that you use RTT logging (just select Debug built configuration if using SES and observe the logs in within SES), as that will typically show you immediately what the problem is.

    Okay, this is my first time, debugging :-)

    I did the following steps:

    1. enable CMSIS  "log backend rtt enabled" and "log enabled"

    2. Set a breakpoint to "void app_error_handler_bare" as shown in attached screenshot

    3. Press "play" for debugging

    Unfortunaly, in the "call stack" window no error occurs. There only stands the information "running". Do I have to make it in another way?

    Thanks in advance

    Simon

  • Hi,

    Ah, there is one other detail that causes problems with the RTT viewer in SES. You also need to set NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED to 0 in sdk_config.h. In that case, and with the other changes you did, you should see the RTT log in the Debug terminal window in SES. Can you try that?

    Einar

  • Hi,

    the "NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED " was already set to 1 (I comment out the if-instruction additionally now, s. screenshot).

    If I press "debug and build", the pointer stops when it reaches "log_init" function in main.c (s. screenshot attached). But in Debug terminal window nothing happened. Is there something else I can try?

  • Sorry, this was a typo on my part. NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED should be set to 0. (I will update my previous reply as well.) With this, you should see errors logged.

    And regarding the original issue, you must make sure to remove all calls that use the physical UART (as described). You will get errors when you use the physical UART without calling the init function. (For instance, calls to app_uart_put() or app_uart_get() will return an error since you are trying to use a library and driver that hs not been initialized). 

  • hmm, unfortunaly I can´t see anything on debug terminal. I have enabled both options in sdk_config.h with CMSIS configuration wizard as shown in screenshot attached.

    After setting "NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED" to zero, nothing happened. The debug terminal is empty, allthough I press the play button. The result is the same like posted above :-(

Reply
  • hmm, unfortunaly I can´t see anything on debug terminal. I have enabled both options in sdk_config.h with CMSIS configuration wizard as shown in screenshot attached.

    After setting "NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED" to zero, nothing happened. The debug terminal is empty, allthough I press the play button. The result is the same like posted above :-(

Children
  • I also have this issue, I tried all the SDK_CONFIG shorts but couldn't make it work. I then tried a SEGGER_RTT_LOG (can't remember the exact name) call directly and the message appeared, so it does look like there's something up with the macro or whatever translates the NRF_LOG calls over.

    It's not a big deal to me as I prefer breakpoints. :)

  • Hi,

    I see. If you don't need logging, then that is OK. But you need a way to easily check which function failed. Even without logging and just using the debugger you can get good help from the error handling in the SDK. If you use debug builds and break after an error has happened, you can inspect the error handler with a debugger to see the file name, line number and error code of the issue as described here. Also, note that when using a SoftDevice and scanning/advertising/in a connection, you cannot continue after a breakpoint, but need to move the breakpoint and reset, since the SoftDevice will assert if it loses timing.

  • Hi,

    That is odd. It could be that the error causes problems since the example use deferred logging. You could try to disable deferred logging by setting NRF_LOG_DEFERRED to 0 in sdk_config.h and commenting out the call to NRF_LOG_PROCESS() in main.c.

    You could also take advantage of the error handling in the SDK without using logging but inspecting the error handler with a debugger as suggested in this post, but it is more tedious.

  • That is odd. It could be that the error causes problems since the example use deferred logging. You could try to disable deferred logging by setting NRF_LOG_DEFERRED to 0 in sdk_config.h and commenting out the call to NRF_LOG_PROCESS() in main.c.

    Now, after doing this, I got a message to the debug terminal as shown in screenshot attached.

    I did the following steps:

    1. Build and debug button

    2. Go to debug terminal window (no entries)

    3. Press the play button

    I think that is not the result we would like to see. Or where can I see the errors in it?

  • Hi,

    simon1516 said:
    I think that is not the result we would like to see. Or where can I see the errors in it?

    No, there is something odd here. First of all, I would have expected to see an error log message if an error actually occurred. And I would also have expected to see "Debug logging for UART over RTT started." printed. At least with deferred logging, that should be printed, unless the error happens earlier and prevents the log to be output. In that case, you should be able to see something useful by breaking the execution, though. I.e. you should be able to see what state the system is in, what code is being executed (where the program counter points), etc.