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

combining 2 examples

Hi 

i am using the nrf52832 dk.

I am trying to combine the ble_app_uart code along with the fds code using ses.

what are the changes i have to make in the config file of ble_app_uart.

Please suggest the most ideal method to combine the 2 projects.

The only flash function i require is the write function.

  • Hi,

    First of all: Do you need a filesystem (like FDS) or do you just want to write directly to flash? If you just need to write directly to flash, you can use fstorage instead.

    If you want FDS in the NUS example you can use this approach:

    1. Start with the NUS example (which use SoftDevice and is generally more complex) and add things from the FDS example as needed.
    2. Add the FDS files and include path to your project. 
    3. Add required includes and code to your main.c file.
    4. Modify the sdk_config.h file to enable FDS and add related configurations. Refer to the FDS example or other examples that use FDS.
    5. Compile the application
      1. If there are errors or warnings, go back to pint 2 and resolve the errors before you build again. This will probably happen several times.
    6. Test application.

    Note that most other BLE examples include the FDS, as it is used by the Peer manager for storing bonding information, so they can be used as a reference.

  • Thanks for the reply.

    Yes I only need to write to the flash.

  • Modify the sdk_config.h file to enable FDS and add related configurations. Refer to the FDS example or other examples that use FDS

    For viewing & modifying the sdk_config.h file, you can use the free Keil:

    I find this superior to the Java utility:

    https://devzone.nordicsemi.com/f/nordic-q-a/47937/mesh-compilation-error/190186#190186

    You can run 2 (or more) instances of uVision to view 2 (or more) sdk_config.h files side-by-side.

    The attached ZIP file contains a uVision Project for viewing & editing the sdk_config.h file and nothing else.

    Simply extract the sdk_config.uvoptx and sdk_config.uvprojx files into the same folder as the sdk_config.h file.

    uvision_sdk_config.zip

    EDIT

    Added screenshot

    EDIT 2

    The above uVision Project assumes nRF52832; you will get warning messages  if you don't have its Device Pack installed. This is entirely benign, and it is completely safe to just ignore the messages - as you are not going to build any code. But it is a bit annoying.

    The project below assumes a generic Cortex-M0,  which doesn't require any Device Pack - so won't give any messages:

    uvision_sdk_config-m0.zip

  • Hi,

    I made the following changes to the nus_data_handler function.

    the i am able to run the code, but when i send data from my phone(central) to the dk no data is sent and the devise gets disconnected and starts advertising again.

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
        char wagon[20];//string i added 
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint32_t err_code;
    
            NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
            NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
            strcpy(wagon,p_evt->params.rx_data.p_data);//string copy
            for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
            {
                do
                {
                    err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
                    if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                    {
                        NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                        APP_ERROR_CHECK(err_code);
                    }
                } while (err_code == NRF_ERROR_BUSY);
            }
            if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
            {
                while (app_uart_put('\n') == NRF_ERROR_BUSY);
            }
        }
        //changes i made 
        ret_code_t rc;
        nrf_fstorage_api_t * p_fs_api;
        p_fs_api = &nrf_fstorage_sd;
        rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
        APP_ERROR_CHECK(rc);
        rc = nrf_fstorage_write(&fstorage, 0x3e000, wagon, strlen(wagon), NULL);
        APP_ERROR_CHECK(rc);
    
    }

    i used the function from the flash storage example

  • Hi,

    Dcrossd said:
    the devise gets disconnected and starts advertising again.

    This is typically the behavior when an APP_ERROR_CHECK has been hit, and DEBUG is not defined. I recommend you define DEBUG for your project (Just select the Debug build configuration if using SES) and enable logging. Then you should see the error code and location printed in the log. See An introduction to error handling in nRF5 projects for more details.

Related