libuarte and sdcard spi ?

Dear Members,

I run 3 devices,

GPS on libuarte1

LCD on SPI2

Sdcard on SPI 1,

I'm using ANT and softdevice 340,

When I run LCD and SDcard outside the main loop, it's working ok,

by the time it's inside the main loop, it crashes with libuarte1,

Code :

									nrf_libuarte_async_config_t nrf_libuarte_async_config1 = {
            .tx_pin     = SER_APP_TX_PIN,
            .rx_pin     = SER_APP_RX_PIN,
            .baudrate   = NRF_UARTE_BAUDRATE_9600, //originally 28 Sept 2021
					  //.baudrate   = NRF_UARTE_BAUDRATE_38400,
            .parity     = NRF_UARTE_PARITY_EXCLUDED,
            .hwfc       = NRF_UARTE_HWFC_DISABLED,
            .timeout_us = 1000,
            .int_prio   = APP_IRQ_PRIORITY_LOW
			      
    };
		err_code=nrf_libuarte_async_init(&libuarte1, &nrf_libuarte_async_config1, uart_event_handler1, (void *)&libuarte1);
 /******************SDCARD  Sequence****************/   
 
			 
						NRF_SPI2->ENABLE = 0; //ILI9341 off
		          nrf_delay_ms(100);
			        NRF_SPI1->ENABLE = 1; //SDcard on
								
								fatfs_example();
								nrf_delay_ms(100);
								
		  /******************SDCARD  Sequence****************/   					  					
            printf("\rRixtronix LAB GPS Query.... \r\n");		
						 nrf_delay_ms(2000);
						GPSNeo_Process();

Debug :

nfo> app: 
                                                                   

isting directory: /
                                                          

   9550  RIXTRO.TXT<info> app: Writing to file RIXTRO.TXT...
                 

nfo> app: 50 bytes written.
                                                  

nfo> app: LOOP Rixtronix LAB.


rror> app: SOFTDEVICE: ASSERTION FAILED
     

                                                


                                                                             

nfo> app: Support us by subscribing,thanks...
                                


                                                                             

nfo> app: Initializing disk 0 (SDC)...
                                       

nfo> app: Capacity: 30436 MB
                                                 

nfo> app: Mounting volume...
                                                 
<error> app: ERROR 0 [NRF_SUCCESS] at ..\..\..\..\..\..\..\..\components\librari

\libuarte\nrf_libuarte_async.c:230
                                           

 at: 0x0004877B
                                                              

rror> app: End of error report

Any ideas on resolving it ? thanks

Parents
  • How can I use :

    nrf_sdh_soc_evt_handler

    with flag and callback ? any examples in sdk ?

    Thanks

  • When it's not working :

    Error at

    <error> app: ERROR 0 [NRF_SUCCESS] at ..\..\..\..\..\..\..\..\components\librari

    \libuarte\nrf_libuarte_async.c:230

  • Hi,

    I'm sorry for the late response. Jared is on vacation so I will take over the case. 

    Please let us know if you managed to solve the issue or not ?

    Please note that the call nrf_libuarte_async_rx_free() is used after you have done with processing the data. This call is to return the buffer to the library so that it can receive more data. 
    So it's the best if you can call the function after you process data, not by a periodically timer.  

  • ............

    Please note that the call nrf_libuarte_async_rx_free() is used after you have done with processing the data. This call is to return the buffer to the library so that it can receive more data. 
    So it's the best if you can call the function after you process data, not by a periodically timer.  

    ...............

    I put it on my callback, and it's crashed, I'm using simple timer state machine now and still crashed,

    The sequence :

    1 .

      case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
                       
                       GPS_CallBack(); //originally on 1 Dec 21 Rixtronix LAB

    2. in the call back :

    if(GPS.rxIndex < sizeof(GPS.rxBuffer)-2)
        {
            GPS.rxBuffer[GPS.rxIndex] = GPS.rxTmp; //originally
            
            GPS.rxIndex++;
            memcpy((void *)line_buffer_GPS, (void *)GPS.rxBuffer, GPS.rxIndex);
               
        }

      nrf_libuarte_async_rx_free(&libuarte1, (uint8_t *)&GPS.rxTmp, 1); //originally Rixtronix LAB

    ....

    it's the best if you can call the function after you process data, not by a periodically timer.  
      ....   

    3. GPS process :

    in main()

    if (GPS_flag_timer ==1)
                {//turn on LED
                        nrf_gpio_pin_set(15);
                    
                     GPSNeo_Process();

              }

    Do you reckon I put

      nrf_libuarte_async_rx_free(&libuarte1, (uint8_t *)&GPS.rxTmp, 1); //originally Rixtronix LAB

    at the end of GPSNeo_Process(); ?

    Thanks

  • Hi Rixtronik, 


    Could you explain why you call nrf_libuarte_async_rx_free() with the length = 1 ? 
    I don't have an overview of how you transmit your data via UART, but basically when you receive data over UART in NRF_LIBUARTE_ASYNC_EVT_RX_DATA event, you will have the length of the number of bytes you receive in p_evt->data.rxtx.length. Then after you have copied the data or have processed the data you can free the same amount of data.

    If you receive 10 bytes but only free 1 byte you will receive the error at line 230 of nrf_libuarte_async.c as shown in your log in your first post. 

  • so I need to put length = size of buffer, in my case 255 ? thanks

  • No, you should free the amount of byte equal to the amount of bytes you receive (or you have processed) in this case p_evt->data.rxtx.length

Reply Children
  • Is my libuarte setting correct ?

    NRF_LIBUARTE_ASYNC_DEFINE(libuarte1, 1, 3, 2, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3);

  • Hi Rixtronix,
    I don't see a problem with the NRF_LIBUARTE_ASYNC_DEFINE setup. Do you still have an issue with the freeing length of the buffer ? 
    I would strongly suggest to try adapting the libuart example to your system for testing before you move to the communication with GPS. (Copy the same loopback code, only modify NRF_LIBUARTE_ASYNC_DEFINE() to match with your setup) 

  • Hi Hung Bui,

    Thanks for the reply,

    I changed these lines

     ret = nrf_libuarte_async_tx(p_libuarte,p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
                if (ret == NRF_ERROR_BUSY)
                {
                    buffer_t buf = {
                        .p_data = p_evt->data.rxtx.p_data,
                        .length = p_evt->data.rxtx.length,
                    };
    
                    ret = nrf_queue_push(&m_buf_queue, &buf);
                    APP_ERROR_CHECK(ret);
                }
                else
                {
                    APP_ERROR_CHECK(ret);
                }

    to :

      case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
                       GPS_CallBack();

    void	GPS_CallBack(void)
    
    {
    	
    	GPS.LastTime=nrf_systick_val_get(); //originally
    	 
    	
    	if(GPS.rxIndex < sizeof(GPS.rxBuffer)-2)
    	{
    		GPS.rxBuffer[GPS.rxIndex] = GPS.rxTmp; //originally
    		 
    		GPS.rxIndex++;
    		memcpy((void *)line_buffer_GPS, GPS.rxBuffer, GPS.rxIndex); 
    			
    	}
       nrf_libuarte_async_rx_free(&libuarte1, (uint8_t *)&GPS.rxTmp, 1);
    	 
    	
    }
    

    The callback was working with different MCU,

    Any suggestions ?

    Thanks

  • Hi , 

    How many bytes do you receive when NRF_LIBUARTE_ASYNC_EVT_RX_DATA occurs ? You need to check the p_evt->data.rxtx.length to know the number of byte you received. I assume it's more than 1 byte   ? 


    I can see you still calling nrf_libuarte_async_rx_free(&libuarte1, (uint8_t *)&GPS.rxTmp, 1); with just one byte in length. 

    Please try to get to know how the libuarte works before using it. 

Related