different errors with different compiler optimization settings

Hello,

I'm having a very strange issue where changing the compiler optimization level will generate different errors in the ble_ess_init() function (sometimes even in sd_enable() )

in particular:

optimization set to None = everything works fine

optimization set to Level 2 for size= NRF_ERROR_DATA_SIZE

optimization set to Level 2 for speed = NRF_ERROR_INVALID_ADDR

 

how do I fix this issue?

Regards,

Rocco

  • Hi,

    in attachment my project. I have commented out all code specific to our custom hardware, you should be able to run it on a nrF52 DK. probably there are some include paths that need to be modified. the way I can see the error is the follow:

    • enable log over uart (you might need to change the TX pin in sdk_config.h
    • compile Release build with different optimization settings
    • connect the serial terminal and run the code
    • you will see different errors generated at startup according to the optimisation level

    tPCB_Temp_mod.zip

  • Hi 

    Which SDK did you build it for? 

    I tried to make it run in my local Thingy52 SDK installation, but the library folders don't quite match up. 

    Best regards
    Torbjørn

  • As I said, you can run it on a nrF52 Development Kit. I use the nRF5_SDK v17.1.0

  • Hi 

    Thanks, now I can find most of the library files, but it seems the source code for the ble_cus module is missing?

    I also get some build errors in the ble_dtm.c module, but I can probably patch this out somehow. What are you using the ble_dtm module for in the project?

    When you said "no modifications at all" earlier did you mean to say that the unmodified Thingy project will also show this error? 

    The project you sent me is obviously changed a lot from the Thingy project. 

    Best regards
    Torbjørn 

  • Hi,

    here you are the missing file.

    #include "sdk_common.h"
    #include "ble_cus.h"
    
    
    static void on_write(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt)
    {
        ble_gatts_evt_write_t const * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
    
        if (   (p_evt_write->handle == p_cus->cus_char_handles.value_handle)
            && (p_evt_write->len == 2)
            && (p_cus->cus_write_handler != NULL))
        {
            
            p_cus->cus_data = (uint16_t)(((uint16_t)p_evt_write->data[0] << 8) | (uint16_t)p_evt_write->data[1])  ; // Update the cus data in the server instance
            p_cus->write_event = CUS_CHAR_WRITTEN; // Set LED4 Characteristic was written in the server instance
            p_cus->cus_write_handler(p_ble_evt->evt.gap_evt.conn_handle, p_cus); //Forward the event to the user handler.
        } 
    }
    
    
    
    void ble_cus_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
    {
        ble_cus_t * p_cus = (ble_cus_t *)p_context;//Cast the context as a service instance
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GATTS_EVT_WRITE:
                on_write(p_cus, p_ble_evt);
                break;
    
            default:
                // No implementation needed.
                break;
        }
    }
    
    
    uint32_t ble_cus_init(ble_cus_t * p_cus, const ble_cus_init_t * p_cus_init)
    {
        uint32_t              err_code; // Return value for the initialization function
        ble_uuid128_t         base_uuid = {BLE_CC_UUID_BASE}; //Base UUID
        ble_uuid_t            service_uuid; //Service UUID
        ble_add_char_params_t add_char_params;  //Add characteristic parameters needed by characteristic_add()
        uint8_t               cus_initial_state = 0 ; //A variable to hold the initial value for the LED4 Blinking Frequency characteristic
    	
        /* Copy all members from the initialization structure to the service instance. We only have one member to set.*/
        p_cus->cus_write_handler = p_cus_init->cus_write_handler;
        
        /* Add our base UUID to the BLE stack's table*/
        err_code = sd_ble_uuid_vs_add(&base_uuid, &p_cus->uuid_type);
        VERIFY_SUCCESS(err_code);
    
        /* Initialize the service UUID and its type. */
        service_uuid.uuid = BLE_UUID_CC_SERVICE;
        service_uuid.type = p_cus->uuid_type;
    
    
        /* Add the service to the GATT server*/
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service_uuid, &p_cus->service_handle);
        VERIFY_SUCCESS(err_code);
    
    
        /* Initialize all members of the add_char_params variable to zero.*/
        memset(&add_char_params, 0, sizeof(add_char_params));
    
        /* Set the UUID ,UUID type , initial size, max size , and the initial value for the characteristic.*/
        add_char_params.uuid             = BLE_UUID_CC_CUS_CHAR; //Set the UUID for the characteristic
        add_char_params.uuid_type        = p_cus->uuid_type; //Set the type of UUID for the characteristic
        add_char_params.init_len         = 2*sizeof(uint8_t); //Set the inital size for the characteristic
        add_char_params.max_len          = 2*sizeof(uint8_t); //Set the max size for the characteristic
        add_char_params.p_init_value     = &cus_initial_state; //Set the initial value for the characteristic
    
    
        /* Specify the standard properties supported by the characteristic.*/
        add_char_params.char_props.read  = 1;
        add_char_params.char_props.write = 1;
        add_char_params.char_props.notify = 0; 
       
    
        /* Specify the security level for reading, writing, CCCD writing (if applicable) of that characteristic.*/
        add_char_params.read_access  = SEC_OPEN;
        add_char_params.write_access = SEC_OPEN;
    
       /* Call the characteristic_add()to add the csalibration characteristic*/
        err_code =  characteristic_add(p_cus->service_handle, &add_char_params, &p_cus->cus_char_handles);
    	
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        } 
    
        return err_code;
    
    }
    
    

    I'm using the dtm module to increase the transmission power to +4dBm

    I have inherited the project from another the person, so I don't know the exact source of the ble_ess module, I assumed it was from Nordic , whether nrF52 or Thingy, but I'm pretty sure that the original code hasn't been modified

    do you know where I can find the source code of  ble_ess module for Thingy project?

Related