<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>S32 Design StudioのトピックRe: UART non blocking send seems to get stuck</title>
    <link>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1357499#M7890</link>
    <description>&lt;P&gt;Hi@&lt;SPAN&gt;Joao_Roscoe&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I tried to write some demo code for you , hope these can help you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "pin_mux.h"
#include "dmaController1.h"
#include "clockMan1.h"
#include "lpuart1.h"

/* User includes (#include below this line is not maintained by Processor Expert) */
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;

/* Welcome message displayed at the console */
#define welcomeMsg "This example is an simple echo using LPUART\r\n\
it will send back any character you send to it.\r\n\
The board will greet you if you send 'Hello Board'\r\
\nNow you can begin typing:\r\n"

/* Timeout in ms for blocking operations */
#define TIMEOUT     100U

/* Receive buffer size */
#define BUFFER_SIZE 256U

/* Buffer used to receive data from the console */
uint8_t txBuffer[BUFFER_SIZE];
uint8_t txBufferIdx;

uint8_t rxBuffer[BUFFER_SIZE];
uint8_t rxBufferIdx;

/* UART rx callback for continuous reception, byte by byte */
void rxCallback(void *driverState, uart_event_t event, void *userData)
{
    /* Unused parameters */
    (void)driverState;
    (void)userData;
		uint32_t bytesRemaining;

    /* Check the event type */
    if (event == UART_EVENT_RX_FULL)
    {				
		/* The reception stops when newline is received or the buffer is full */
			if ((rxBuffer[rxBufferIdx] != '\n') &amp;amp;&amp;amp; (rxBufferIdx != (BUFFER_SIZE - 2U)))
		 {
				/* Update the buffer index and the rx buffer */
				rxBufferIdx++;
				LPUART_DRV_SetRxBuffer(INST_LPUART1, &amp;amp;rxBuffer[rxBufferIdx], 1U);
		 }
    }
}


void txCallback(void *driverState,uart_event_t event,void * userData)
{
	if(event == UART_EVENT_TX_EMPTY)
	{
		txBufferIdx++;
		LPUART_DRV_SendData(INST_LPUART1,&amp;amp;txBuffer[txBufferIdx],1);
		if(txBufferIdx &amp;gt; BUFFER_SIZE - 1)
		{
			txBufferIdx = 0;
		}
	};
	
	if(event == UART_EVENT_END_TRANSFER)
	{
		;
	};
	
	if(event == UART_EVENT_ERROR)
	{
		;
	};
}

/*!
 \brief The main function for the project.
 \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
 */
int main(void)
{
  /* Write your local variable definition here */
  status_t status;
  /* Declare a buffer used to store the received data */
  uint32_t bytesRemaining;

  CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
  CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

  PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
  
  /* Initialize LPUART instance */
  LPUART_DRV_Init(INST_LPUART1, &amp;amp;lpuart1_State, &amp;amp;lpuart1_InitConfig0);
  /* Install the callback for rx events */
  LPUART_DRV_InstallRxCallback(INST_LPUART1, rxCallback, NULL);
	
	LPUART_DRV_InstallTxCallback(INST_LPUART1, txCallback,NULL);
  /* Send a welcome message */
  LPUART_DRV_SendDataBlocking(INST_LPUART1, (uint8_t *)welcomeMsg, strlen(welcomeMsg), TIMEOUT);
	
	LPUART_DRV_ReceiveData(INST_LPUART1, rxBuffer, 1U);
	
  while (1)
  {
		OSIF_TimeDelay(100);
		uint8_t test = 12;
		LPUART_DRV_SendData(INST_LPUART1,&amp;amp;test,1);
  }
}

&lt;/LI-CODE&gt;
&lt;P&gt;BR!&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Jim,&lt;/P&gt;</description>
    <pubDate>Tue, 19 Oct 2021 02:58:09 GMT</pubDate>
    <dc:creator>Senlent</dc:creator>
    <dc:date>2021-10-19T02:58:09Z</dc:date>
    <item>
      <title>UART non blocking send seems to get stuck</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1343388#M7802</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm porting an existing code base from another MCU. The existing code uses a UartAccessSend(UART_INSTANCE_t uart_inst, uint8_t datum) function to send a single byte from a software fifo, and expects to called back by ISR to send another byte, if any. My current implementation of&amp;nbsp;UartAccessSend() function is as follows:&lt;/P&gt;&lt;P&gt;--------&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;/* Get Tx transfer status */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;tx_status = LPUART_DRV_GetTransmitStatus(uart_inst, &amp;amp;remaining_bytes);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if ((0U) == remaining_bytes)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* Update Tx byte */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;uart_inst_state[uart_index].tx_byte = datum;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* Check Tx transfer status */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if (STATUS_BUSY == tx_status)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* Transfer still running, just reset buffer for next byte */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;LPUART_DRV_SetTxBuffer(uart_inst, &amp;amp;(uart_inst_state[uart_index].tx_byte), (1U));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;else&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* Transfer has stopped, restart it */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;LPUART_DRV_SendData(uart_inst, &amp;amp;(uart_inst_state[uart_index].tx_byte), (1U));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* Report success to caller */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;result = STATUS_OK;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;--------&lt;/P&gt;&lt;P&gt;Also, my ISR callback function (for both buffer empty e transmission end events) includes:&lt;/P&gt;&lt;P&gt;--------&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;/* Get next datum from queue (but don't remove it from queue, yet) */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if (STATUS_OK == ByteFifoReadSingleByte(terminal_tx_queue, 0U, &amp;amp;datum))&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* Request IRQ driven transmission */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if (STATUS_OK == UartAccessSend(TERMINAL_UART_INSTANCE, datum))&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* If successfully requested transmission, remove datum from queue */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;ByteFifoGetSingleByte(&amp;amp;terminal_tx_queue, NULL);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;--------&lt;/P&gt;&lt;P&gt;With the code above, Tx works, as far as I insert a single byte at a time, into the fifo. If I queue several bytes at once, however, lpuart driver gets stuck in a IRQ deadloop and my registered callback is never called. What am I missing/doing wrong?&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Joao&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;UPDATE:&lt;/P&gt;&lt;P&gt;Have just found what seems to be some kind of race condition.&lt;/P&gt;&lt;P&gt;Code gets stuck because&amp;nbsp;LPUART_DRV_TxCompleteIrqHandler() does nothing, due to&amp;nbsp;if (lpuartState-&amp;gt;txSize == 0U) failure. So it seems that I'm sending the next character at the wrong time, somehow.&lt;/P&gt;&lt;P&gt;Since this is a 'end of tx' processing, I tried changing port speed to 9600, and that seems to mask the issue. So I guess I'm getting the 'end of tx' event while I'm still processing the 'buffer empty' irq.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 14:27:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1343388#M7802</guid>
      <dc:creator>Joao_Roscoe</dc:creator>
      <dc:date>2021-09-22T14:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: UART non blocking send seems to get stuck</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1344811#M7804</link>
      <description>&lt;P&gt;Hi@&lt;SPAN&gt;Joao_Roscoe&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Happy to see you find the problem!&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I don't think it is necessary to trigger a send operation when a new data enters the queue.&lt;BR /&gt;You can set the timing to send data, and check whether the queue data is empty every time you send data. The length of the queue can be set as required, so that the program can avoid competition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR!&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Jim,&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 07:09:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1344811#M7804</guid>
      <dc:creator>Senlent</dc:creator>
      <dc:date>2021-09-23T07:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: UART non blocking send seems to get stuck</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1356858#M7885</link>
      <description>&lt;P&gt;Update:&lt;/P&gt;&lt;P&gt;I have done some progress, and now my code is not getting stuck anymore. However, I still have a number of glitches to solve, and obviously, I still do not have a complete understanding of how to use lpuart driver properly. Could anyone give me a pointer to exemple code using IRQs -&amp;nbsp; no polling or waiting at all - to control UART Tx and Rx, using single byte buffers?&lt;/P&gt;&lt;P&gt;A simple&amp;nbsp;'one character at a time' UART echo would do.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;João&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 03:42:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1356858#M7885</guid>
      <dc:creator>Joao_Roscoe</dc:creator>
      <dc:date>2021-10-18T03:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: UART non blocking send seems to get stuck</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1357046#M7887</link>
      <description>&lt;P&gt;Hi@&lt;SPAN&gt;Joao_Roscoe&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;There is a routine about LPUART in S32 DS IDE，I don't know if you know it before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Currently I don’t have more routines about LPUART and hope this routine can help you.&lt;/P&gt;
&lt;P&gt;BR!&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Jim,&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 08:15:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1357046#M7887</guid>
      <dc:creator>Senlent</dc:creator>
      <dc:date>2021-10-18T08:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: UART non blocking send seems to get stuck</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1357225#M7888</link>
      <description>&lt;P&gt;Yes, I have seen the exemple packed with the SDK itself. Unfortunately, that exemple does not use interrupts for UART transmission, only for updating Rx buffer/pointer.&lt;/P&gt;&lt;P&gt;Thank you for your time,&lt;/P&gt;&lt;P&gt;João&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 13:18:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1357225#M7888</guid>
      <dc:creator>Joao_Roscoe</dc:creator>
      <dc:date>2021-10-18T13:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: UART non blocking send seems to get stuck</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1357499#M7890</link>
      <description>&lt;P&gt;Hi@&lt;SPAN&gt;Joao_Roscoe&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I tried to write some demo code for you , hope these can help you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "pin_mux.h"
#include "dmaController1.h"
#include "clockMan1.h"
#include "lpuart1.h"

/* User includes (#include below this line is not maintained by Processor Expert) */
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;

/* Welcome message displayed at the console */
#define welcomeMsg "This example is an simple echo using LPUART\r\n\
it will send back any character you send to it.\r\n\
The board will greet you if you send 'Hello Board'\r\
\nNow you can begin typing:\r\n"

/* Timeout in ms for blocking operations */
#define TIMEOUT     100U

/* Receive buffer size */
#define BUFFER_SIZE 256U

/* Buffer used to receive data from the console */
uint8_t txBuffer[BUFFER_SIZE];
uint8_t txBufferIdx;

uint8_t rxBuffer[BUFFER_SIZE];
uint8_t rxBufferIdx;

/* UART rx callback for continuous reception, byte by byte */
void rxCallback(void *driverState, uart_event_t event, void *userData)
{
    /* Unused parameters */
    (void)driverState;
    (void)userData;
		uint32_t bytesRemaining;

    /* Check the event type */
    if (event == UART_EVENT_RX_FULL)
    {				
		/* The reception stops when newline is received or the buffer is full */
			if ((rxBuffer[rxBufferIdx] != '\n') &amp;amp;&amp;amp; (rxBufferIdx != (BUFFER_SIZE - 2U)))
		 {
				/* Update the buffer index and the rx buffer */
				rxBufferIdx++;
				LPUART_DRV_SetRxBuffer(INST_LPUART1, &amp;amp;rxBuffer[rxBufferIdx], 1U);
		 }
    }
}


void txCallback(void *driverState,uart_event_t event,void * userData)
{
	if(event == UART_EVENT_TX_EMPTY)
	{
		txBufferIdx++;
		LPUART_DRV_SendData(INST_LPUART1,&amp;amp;txBuffer[txBufferIdx],1);
		if(txBufferIdx &amp;gt; BUFFER_SIZE - 1)
		{
			txBufferIdx = 0;
		}
	};
	
	if(event == UART_EVENT_END_TRANSFER)
	{
		;
	};
	
	if(event == UART_EVENT_ERROR)
	{
		;
	};
}

/*!
 \brief The main function for the project.
 \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
 */
int main(void)
{
  /* Write your local variable definition here */
  status_t status;
  /* Declare a buffer used to store the received data */
  uint32_t bytesRemaining;

  CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
  CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

  PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
  
  /* Initialize LPUART instance */
  LPUART_DRV_Init(INST_LPUART1, &amp;amp;lpuart1_State, &amp;amp;lpuart1_InitConfig0);
  /* Install the callback for rx events */
  LPUART_DRV_InstallRxCallback(INST_LPUART1, rxCallback, NULL);
	
	LPUART_DRV_InstallTxCallback(INST_LPUART1, txCallback,NULL);
  /* Send a welcome message */
  LPUART_DRV_SendDataBlocking(INST_LPUART1, (uint8_t *)welcomeMsg, strlen(welcomeMsg), TIMEOUT);
	
	LPUART_DRV_ReceiveData(INST_LPUART1, rxBuffer, 1U);
	
  while (1)
  {
		OSIF_TimeDelay(100);
		uint8_t test = 12;
		LPUART_DRV_SendData(INST_LPUART1,&amp;amp;test,1);
  }
}

&lt;/LI-CODE&gt;
&lt;P&gt;BR!&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Jim,&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 02:58:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1357499#M7890</guid>
      <dc:creator>Senlent</dc:creator>
      <dc:date>2021-10-19T02:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: UART non blocking send seems to get stuck</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1678306#M10428</link>
      <description>&lt;P&gt;What to do if my buffer gets updated even before LPUART transmission gets completed , I cannot use a blocking method since I have other processes which might get affected . Can anyone share an example , I am fine with byte by byte transmission as well .&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 04:20:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1678306#M10428</guid>
      <dc:creator>Jay_Starter</dc:creator>
      <dc:date>2023-06-29T04:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: UART non blocking send seems to get stuck</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1678312#M10429</link>
      <description>Could you please help me with this, I am stuck at a similar problem.</description>
      <pubDate>Thu, 29 Jun 2023 04:28:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/UART-non-blocking-send-seems-to-get-stuck/m-p/1678312#M10429</guid>
      <dc:creator>Jay_Starter</dc:creator>
      <dc:date>2023-06-29T04:28:39Z</dc:date>
    </item>
  </channel>
</rss>

