Reading file nrf_fprintf(line) ?

Dear Members,

We tried reading file with nrf_fprintf()....

Code :

 NRF_LOG_RAW_INFO("Entries count _sd: %u\r\n", entries_count);
	  //printf("UART text \r\n");
		NRF_LOG_INFO("Reading file \r \n");
		f_open(&fil, "HRM.TXT", FA_READ);
									
								/* Read all lines and display it */
								while (f_gets(line, sizeof line, &fil))
							  
								 nrf_fprintf(line);
								 
										/* Close the file */
						
								NRF_LOG_INFO("Finished reading file.. \n \r\n");

								f_close(&fil);
}

Output in UART :

0:00:00.000,000] <info> app: USBD MSC example started.
                       

0:00:00.000,000] <info> app: Initializing disk 0 (SDC)...
                    

0:00:00.000,000] <info> app: 
                                                

sting directory _sd: /
                                                       

 <DIR>   SYSTEM~1
                                                            

   6716  NORDIC.TXT
                                                          

  29900  RIXTRO.TXT
                                                          

 305208  HRM.TXT
                                                             

 210693  SPD.TXT
                                                             

 120038  SPD_MPS.TXT
                                                         

  75344  POW.TXT
                                                             

 150265  DIS.TXT
                                                             

 102699  CAD.TXT
                                                             

 147407  TOR.TXT
                                                             

1246035  GPS.TXT
                                                             

tries count _sd: 12
                                                          
[00:00:00.000,000] <info> app: Reading file 
                                   
 

                                                                            

                                                                              
[00:00:00.000,000] <error> app: ASSERTION FAILED at ..\..\..\..\..\..\external\f

intf\nrf_fprintf.c:67

Does anyone know on how to rectify it ?

Kind regards..

Parents Reply Children
  • Hi Vidar,

    Thanks for the reply,

    We can see :

    Line 67 is

     ASSERT(p_ctx->fwrite != NULL);

    SDK =

    D:\nRF5_SDK_17.0.2_d674dde\external\fprintf\nrf_fprintf.c,

    What do we miss here ?

    We want to display all the content of text file to UART.

    Best regards,

  •  BYTE line[1024];

    Related with variable above ?

    D:\nRF5_SDK_17.0.2_d674dde\components\libraries\util\nrf_assert.h

    Line 103

    #define ASSERT(expr)                                                          \
    if (NRF_ASSERT_PRESENT)                                                       \
    {                                                                             \
        if (expr)                                                                 \
        {                                                                         \
        }                                                                         \
        else                                                                      \
        {                                                                         \
            assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__);         \
        }                                                                         \
    }

    #endif

    uint16_t and BYTE ?

    Kind regards,

  • I'm not sure how you were able to build the code in the first place as you are only passing 1 argument to your nrf_fprintf() call. I checked the function declaration, and it seems to require at least 2:

    You can use the NRF_LOG_RAW_INFO() macro if you want to print strings without the logger prefix.

  • Hi Vidar,

    Thanks for the reply,

    We tried :

    f_open(&fil, "HRM.TXT", FA_READ);
                                    uint32_t bytes_written;    
                                    /* Read all lines and display it */
                                    while (f_gets( line, sizeof  line,   &fil))
                                    NRF_LOG_INFO("data: %s",line);
                                            /* Close the file */
                            
                                    NRF_LOG_INFO("Finished reading file.. \n \r\n");

                                    f_close(&fil);

    Output : 

     <DIR>   SYSTEM~1
                                                                
    
       6716  NORDIC.TXT
                                                              
    
      31700  RIXTRO.TXT
                                                              
    
     340020  HRM.TXT
                                                                 
    
     234612  SPD.TXT
                                                                 
    
     134173  SPD_MPS.TXT
                                                             
    
      84336  POW.TXT
                                                                 
    
     166711  DIS.TXT
                                                                 
    
     114309  CAD.TXT
                                                                 
    
     164256  TOR.TXT
                                                                 
    
    1356104  GPS.TXT
                                                                 
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
    
    ....
     app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (294)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    
    0:00:00.000,000] <info> app: data: 
                                              
    
    1;31mLogs dropped (295)
                                                      
    [00:00:00.000,000] <info> app: Finished reading file.. 
                     

  • with :

    NRF_LOG_INFO("Reading file \r \n");
    		f_open(&fil, "HRM.TXT", FA_READ);
    								uint32_t bytes_written;	
    								/* Read all lines and display it */
    								while (f_gets( line, sizeof  line,   &fil))
    							  //while (f_read(&fil, line_data, 10, (UINT *) &bytes_written);
    								 //nrf_fprintf(line);
    								//NRF_LOG_INFO("data: %s",line); 
    								NRF_LOG_RAW_INFO("data %s",line);
    										/* Close the file */
    						
    								NRF_LOG_INFO("Finished reading file.. \n \r\n");
    
    								f_close(&fil);
    }

    Output :

    1356104  GPS.TXT
                                                                 
    
    1;31mLogs dropped (294)
                                                      
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (294)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    
    ta Logs dropped (295)
                                                 
    [00:00:00.000,000] <info> app: Finished reading file.. 
                           
    
    
                                       
    

Related