<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>k_work_reschedule failed after 53 interacts</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/98546/k_work_reschedule-failed-after-53-interacts</link><description>I have two uart inputs. UART1 and UART2. 
 Uart1 is connected to bluetooth routines 
 Uart2 is connected to an external input. I am using the HTerm to send sequences of character&amp;#39;s string of 40bytes 
 this is the kprint output: 
 k=number of bytes j=buffers</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Apr 2023 10:51:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/98546/k_work_reschedule-failed-after-53-interacts" /><item><title>RE: k_work_reschedule failed after 53 interacts</title><link>https://devzone.nordicsemi.com/thread/419631?ContentTypeID=1</link><pubDate>Tue, 11 Apr 2023 10:51:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0887add-704f-4235-ba67-08697bcca7e6</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Thanks for sharing!&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: k_work_reschedule failed after 53 interacts</title><link>https://devzone.nordicsemi.com/thread/419451?ContentTypeID=1</link><pubDate>Sat, 08 Apr 2023 23:11:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bfba7db1-c0fb-44c5-8abb-7c49f4ce6631</guid><dc:creator>FlavioPiracicaba</dc:creator><description>&lt;p&gt;&lt;span style="font-family:courier new, courier;font-size:inherit;"&gt;&lt;strong&gt;Now it&amp;#39;s working. The problem is the k_malloc() was taking space on the memory until filled it all up&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:courier new, courier;font-size:inherit;"&gt;&lt;strong&gt;In Peripheral_Uart example, there is two k_malloc() and one k_free(). After I installed the logical analyser, I could see a signal I instaled, the k_free() was never being called. Then I removed the case of &lt;/strong&gt;&lt;strong style="white-space:pre;"&gt;&lt;span style="color:#098658;"&gt;UART_RX_BUF_REQUEST&lt;/span&gt;&lt;span style="white-space:normal;"&gt;&amp;nbsp; because is not being used. Now there is a pair k_malloc and k_free. My suggest is correct the peripheral_uart example.&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void uart_cb_2(const struct device *dev, struct uart_event *evt, void *user_data){
    
	ARG_UNUSED(dev);
	static bool disable_req;
    struct uart_data_t *buf2;
   
 	switch (evt-&amp;gt;type) {
	
    case UART_RX_RDY:
		buf2 = CONTAINER_OF(evt-&amp;gt;data.rx.buf, struct uart_data_t, data);
		buf2-&amp;gt;len += evt-&amp;gt;data.rx.len;
		if (disable_req) {
			return;
		}
        //CR = Carriage Return ( \r , 0x0D in hexadecimal, 13 in decimal) 
		if (evt-&amp;gt;data.rx.buf[buf2-&amp;gt;len - 1] == 0x0D) {
			blink(LED4,3);
            uart_rx_disable(uart_2);
			disable_req = true;
		}
      	break;

	case UART_RX_DISABLED:
	    disable_req = false;
		blink(LED3,5);
        
		buf2 = k_malloc(sizeof(*buf2)); //THE SIZE IS 92 BYTES
		if (buf2) {
			buf2-&amp;gt;len = 0;
		} else {
			
			k_work_reschedule(&amp;amp;uart_work_2, UART_WAIT_FOR_BUF_DELAY);
			return;
		}
        
        buf2-&amp;gt;len = 0;
  		uart_rx_enable(uart_2, buf2-&amp;gt;data, sizeof(buf2-&amp;gt;data),UART_WAIT_FOR_RX);
		break;
   
	case UART_RX_BUF_RELEASED:
	    buf2 = CONTAINER_OF(evt-&amp;gt;data.rx_buf.buf, struct uart_data_t,data);
		if (buf2-&amp;gt;len &amp;gt; 0){
		   k_fifo_put(&amp;amp;fifo_uart2_rx_data, buf2);
		   blink(LED4,6);
		   k_free(buf2);
		}
		break;
	}

    
   
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12086
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12087
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12088
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12089
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12090
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12091
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12092
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12093
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12094
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12095
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12096
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12097
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12098
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12099
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12100
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12101
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12102
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12103
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12104
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12105
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12106
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12107
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12108
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12109
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12110
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12111
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12112
k:40 UART2:30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 j:12113
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:inherit;"&gt;&lt;strong&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;I tested for 12117 times without failure.&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:inherit;"&gt;&lt;strong&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;The full code it&amp;#39;s &lt;a href="https://github.com/flavioafferreira/peripheral_uart_new.git"&gt;here&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: k_work_reschedule failed after 53 interacts</title><link>https://devzone.nordicsemi.com/thread/419450?ContentTypeID=1</link><pubDate>Sat, 08 Apr 2023 22:13:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64882909-b6de-49ff-b70c-add670e76100</guid><dc:creator>FlavioPiracicaba</dc:creator><description>&lt;p&gt;on line 123:&amp;nbsp; k_work_reschedule(&amp;amp;uart_work, UART_WAIT_FOR_BUF_DELAY); there is a mistake should be &amp;amp;uart_work_2. The problem continue. The k_free() never is called.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: k_work_reschedule failed after 53 interacts</title><link>https://devzone.nordicsemi.com/thread/419427?ContentTypeID=1</link><pubDate>Fri, 07 Apr 2023 09:46:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2c58ec5-3784-43ca-aa68-0ad35342a711</guid><dc:creator>FlavioPiracicaba</dc:creator><description>&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/imagem_5F00_nrf.jpeg" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>