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

`.nrf_queue' will not fit in region `UNPLACED_SECTIONS' on NRF52810

I started from the blinky example for pca10040e (NRF52810) on SDK15.3, added some files and code to get TWI_MNGR working but i get an error which i can't solve

`.nrf_queue' will not fit in region `UNPLACED_SECTIONS'
region `UNPLACED_SECTIONS' overflowed by 20 bytes

  • Hi,

    You need to add the .nrf_queue section to your flash_placement.xml (placed adjacent to the SES project file) to use the Queue module:

    <Root name="Flash Section Placement">
      <MemorySegment name="FLASH" start="$(FLASH_PH_START)" size="$(FLASH_PH_SIZE)">
        <ProgramSection alignment="0x100" load="Yes" name=".vectors" start="$(FLASH_START)" />
        <ProgramSection alignment="4" load="Yes" name=".init" />
        <ProgramSection alignment="4" load="Yes" name=".init_rodata" />
        <ProgramSection alignment="4" load="Yes" name=".text" />
        <ProgramSection alignment="4" keep="Yes" load="Yes" name=".pwr_mgmt_data" inputsections="*(SORT(.pwr_mgmt_data*))" address_symbol="__start_pwr_mgmt_data" end_symbol="__stop_pwr_mgmt_data" />
        <ProgramSection alignment="4" keep="Yes" load="Yes" name=".nrf_queue" inputsections="*(.nrf_queue*)" address_symbol="__start_nrf_queue" end_symbol="__stop_nrf_queue" />
        ...

  • Hi,

    Apart from your problem we found a serious bug in nrf_queue library, in function nrf_queue_write.

    In file nrf_queue.c please replace function "static void queue_write(nrf_queue_t const * p_queue, void const * p_data, uint32_t element_count)"

    with following code:

    __STATIC_INLINE size_t circullar_buffer_size_get(nrf_queue_t const * p_queue)                                            
    {                                                                                                                        
        static const uint8_t full_queue_indicator = 1;                                                                       
                                                                                                                             
        /* When a queue is implemented as a cyclic buffer, it is not possible to                                             
         * distinguish a full queue from an empty queue. In order to solve this                                              
         * problem, the cyclic buffer has been implemented one element larger than                                           
         * the queue size.                                                                                                   
         */                                                                                                                  
        return p_queue->size + full_queue_indicator;                                                                         
    }     
    
    /* Purpose of this function is to provide number of continous bytes in the queue's                                       
     * array before circullar buffer needs to wrapp.                                                                         
     */                                                                                                                      
    static size_t continous_items_get(nrf_queue_t const * p_queue, bool write)                                               
    {                                                                                                                        
        size_t front    = p_queue->p_cb->front;                                                                              
        size_t back     = p_queue->p_cb->back;                                                                               
                                                                                                                             
        /* Number of continous items for queue write operation */                                                            
        if (write)                                                                                                           
        {                                                                                                                    
            return (back >= front) ? circullar_buffer_size_get(p_queue) - back : front - back;                               
        }                                                                                                                    
        else                                                                                                                 
        {                                                                                                                    
            return (back >= front) ? back - front : circullar_buffer_size_get(p_queue) - front;                              
        }                                                                                                                    
    }                                                                                                                        
                                                                                                                             
    /**@brief Write elements to the queue. This function assumes that there is enough room in the queue                      
     *        to write the requested number of elements and that this process will not be interrupted.                       
     *                                                                                                                       
     * @param[in]   p_queue             Pointer to the nrf_queue_t instance.                                                 
     * @param[in]   p_data              Pointer to the buffer with elements to write.                                        
     * @param[in]   element_count       Number of elements to write.                                                         
     */                                                                                                                      
    static void queue_write(nrf_queue_t const * p_queue, void const * p_data, uint32_t element_count)                        
    {                                                                                                                        
        size_t prev_available = nrf_queue_available_get(p_queue);                                                            
        size_t continuous     = continous_items_get(p_queue, true);                                                          
        void * p_write_ptr    = (void *)((size_t)p_queue->p_buffer                                                           
                              + p_queue->p_cb->back * p_queue->element_size);                                                
                                                                                                                             
        if (element_count <= continuous)                                                                                     
        {                                                                                                                    
            memcpy(p_write_ptr,                                                                                              
                   p_data,                                                                                                   
                   element_count * p_queue->element_size);                                                                   
                                                                                                                             
            p_queue->p_cb->back = ((p_queue->p_cb->back + element_count) <= p_queue->size)                                   
                                ? (p_queue->p_cb->back + element_count)                                                      
                                : 0;                                                                                         
        }                                                                                                                    
        else                                                                                                                 
        {                                                                                                                    
            size_t first_write_length = continuous * p_queue->element_size;                                                  
            memcpy(p_write_ptr,                                                                                              
                   p_data,                                                                                                   
                   first_write_length);                                                                                      
                                                                                                                             
            size_t elements_left = element_count - continuous;                                                               
            memcpy(p_queue->p_buffer,                                                                                        
                   (void const *)((size_t)p_data + first_write_length),                                                      
                   elements_left * p_queue->element_size);                                                                   
                                                                                                                             
            p_queue->p_cb->back = elements_left;                                                                             
            if (prev_available < element_count)                                                                              
            {                                                                                                                
                // Overwrite the oldest elements.
                p_queue->p_cb->front = nrf_queue_next_idx(p_queue, p_queue->p_cb->back);                                     
            }                                                                                                                
        }                                                                                                                    
                

Related