<?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>Peripheral UART - 20 Byte Limitation</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/115095/peripheral-uart---20-byte-limitation</link><description>Hi folks, 
 I&amp;#39;m making an application which needs to transmit a few kB of config data (for a configuration utility), and I was hoping to do it via UART. 
 To that end, I loaded up the peripheral uart sample (nrf/samples/bluetooth/peripheral_uart), and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 30 Sep 2024 21:52:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/115095/peripheral-uart---20-byte-limitation" /><item><title>RE: Peripheral UART - 20 Byte Limitation</title><link>https://devzone.nordicsemi.com/thread/504444?ContentTypeID=1</link><pubDate>Mon, 30 Sep 2024 21:52:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0165e7b1-e3f0-4ac0-8147-68305e0469df</guid><dc:creator>FinnBiggs</dc:creator><description>&lt;p&gt;Hi again Susheel,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve located what I was missing.&lt;/p&gt;
&lt;p&gt;I needed to either:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add MTU negotiation to the .connected callback&lt;/li&gt;
&lt;li&gt;OR&lt;/li&gt;
&lt;li&gt;Add
&lt;ul&gt;
&lt;li&gt;
&lt;div style="background-color:#002b36;color:#839496;font-family:Consolas, &amp;#39;Courier New&amp;#39;, monospace;font-size:14px;font-weight:normal;line-height:19px;white-space:pre;"&gt;
&lt;div&gt;&lt;span style="color:#586e75;font-style:italic;"&gt;# Auto negotiate MTU on connection&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#859900;"&gt;CONFIG_BT_GATT_CLIENT&lt;/span&gt;&lt;span style="color:#839496;"&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#859900;"&gt;CONFIG_BT_GATT_AUTO_UPDATE_MTU&lt;/span&gt;&lt;span style="color:#839496;"&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I opted to add the two config options above. Now, my sniffer trace indicates that the MTU negotiations happen immediately on connection, and my messages are sent as blocks limited by the option&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div style="background-color:#002b36;color:#839496;font-family:Consolas, &amp;#39;Courier New&amp;#39;, monospace;font-size:14px;font-weight:normal;line-height:19px;white-space:pre;"&gt;
&lt;div&gt;&lt;span style="color:#586e75;font-style:italic;"&gt;# UART Chunk Size (40 original --&amp;gt; increase)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#859900;"&gt;CONFIG_BT_NUS_UART_BUFFER_SIZE&lt;/span&gt;&lt;span style="color:#839496;"&gt;=80&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thank you very much for looking at my post -- I&amp;#39;ll mark this reply as a solution and hope this helps other people who encounter this in the future.&lt;/p&gt;
&lt;p&gt;Enjoy your week!&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Finn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peripheral UART - 20 Byte Limitation</title><link>https://devzone.nordicsemi.com/thread/504434?ContentTypeID=1</link><pubDate>Mon, 30 Sep 2024 19:38:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc578602-3010-4782-945d-aea939e1b253</guid><dc:creator>FinnBiggs</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;Thanks for getting back to me!&lt;/p&gt;
&lt;p&gt;Unfortunately, there may be more than just enabling the KConfig MTU options involved in fixing this.&lt;/p&gt;
&lt;p&gt;Before my first post, I experimented with the config options that seemed to make sense until I got frustrated with my lack of progress. I followed the options within the ble_throughput sample and didn&amp;#39;t manage to succeed at increasing the allowed send size.&lt;/p&gt;
&lt;p&gt;-----------------------------------&lt;/p&gt;
&lt;p&gt;To that end, please find attached my application &amp;quot;peripheral_uart_ext (zip)&amp;quot;&lt;/p&gt;
&lt;p&gt;This application is the peripheral_uart sample, modified to include the config options for increasing MTU size. I also organized the prj.conf differently than in the sample.&lt;/p&gt;
&lt;p&gt;Checking the autoconf.h after building, I find that the MTU size is updated. In this sample, one cannot send more than 20 bytes from app-&amp;gt; remote, and cannot send more than 20 bytes from remote -&amp;gt; app, which is unchanged by the MTU KConfig options.&lt;/p&gt;
&lt;p&gt;Grateful for advice on how to proceed.&lt;/p&gt;
&lt;p&gt;---------------------------------&lt;/p&gt;
&lt;p&gt;Application build instructions&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;zip file contains source and config options&lt;/li&gt;
&lt;li&gt;west build command contained in scripts/dk.sh
&lt;ul&gt;
&lt;li&gt;(either run this command on CLI from nrfConnect terminal, or use information within for build configuration options)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Behavior replication instructions&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Build and flash attached application to nrf52840dk&lt;/li&gt;
&lt;li&gt;Connect to NORDIC_UART_SERVICE using external application
&lt;ul&gt;
&lt;li&gt;I used nRF Connect Android App&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Subscribe to Nordic UART Service TX Characteristic&lt;/li&gt;
&lt;li&gt;Send string of 20 characters to RX Characteristic
&lt;ul&gt;
&lt;li&gt;Observe successful send to device and print to logging&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Send string of 21+ characters to RX characteristic
&lt;ul&gt;
&lt;li&gt;Observe failure to send&lt;/li&gt;
&lt;li&gt;App Logs Error: &amp;quot;Error 6 (0x6): GATT REQ NOT SUPPORTED&amp;quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Open Serial connection to Dev Kit&lt;/li&gt;
&lt;li&gt;Send 20 char string (18 + &amp;#39;\r&amp;#39; + &amp;#39;\n&amp;#39;)
&lt;ul&gt;
&lt;li&gt;Observe success of transfer to external application (TX Characteristic)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Send 21+ char string
&lt;ul&gt;
&lt;li&gt;Observe failure to send&lt;/li&gt;
&lt;li&gt;Example warnings from sending following string &amp;quot;0000000000000000000\r\n&amp;quot; (19 zeros, \r\n = 21 char)&lt;/li&gt;
&lt;li&gt;&amp;lt;wrn&amp;gt; bt_att: No ATT channel for MTU 24&lt;br /&gt;&amp;lt;wrn&amp;gt; bt_gatt: No buffer available to send notification&lt;br /&gt;&amp;lt;wrn&amp;gt; peripheral_uart: Failed to send data over BLE connection&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;----------------------------------&lt;/p&gt;
&lt;p&gt;Did you find success with the modifications you suggested? If so, I wonder if something else is wrong with my app setup, build system, or environment.&lt;/p&gt;
&lt;p&gt;Thank you for your advice and time.&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Finn&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/peripheral_5F00_uart_5F00_ext.zip"&gt;devzone.nordicsemi.com/.../peripheral_5F00_uart_5F00_ext.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peripheral UART - 20 Byte Limitation</title><link>https://devzone.nordicsemi.com/thread/504292?ContentTypeID=1</link><pubDate>Mon, 30 Sep 2024 08:05:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:113f1623-e294-4fb4-b424-7d8abb1c649b</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;&lt;span&gt;n peripheral_uart sample, it looks like&amp;nbsp;CONFIG_BT_NUS_UART_BUFFER_SIZE plays a role in fifo size used to save data while BT or UART is busy. Need to reconfigure this size aswell to get bigger chunk transfers.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;To increase the limit of data you can send over BLE, you can adjust the Maximum Transmission Unit (MTU) size. The MTU size determines the maximum amount of data that can be sent in a single packet. By default, the MTU size is set to 23 bytes, which includes the L2CAP header of 4 bytes, leaving 20 bytes for payload. However, the MTU size can be increased up to 247 bytes.&lt;/div&gt;
&lt;div&gt;In the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;prj.conf&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;file of your project, you can add or modify the following configuration options:&lt;/div&gt;
&lt;div&gt;
&lt;div dir="ltr"&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_BT_USER_DATA_LEN_UPDATE=y
CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;This will increase the MTU size to 247 bytes, allowing you to send more data in a single packet.&lt;/div&gt;
&lt;div&gt;Regarding your second question, if you want to send data in batches, you can use the UART driver&amp;#39;s asynchronous API. This API provides functions for sending and receiving data in a non-blocking manner. You can use the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;uart_tx&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;function to send data, and the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;uart_callback_set&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;function to set a callback that will be called when the transmission is complete. This way, you can send the next batch of data in the callback function.&lt;/div&gt;
&lt;div&gt;Here is an example of how you can use the asynchronous API:&lt;/div&gt;
&lt;div&gt;
&lt;div dir="ltr"&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;struct uart_data_t *buf;

buf = k_malloc(sizeof(*buf));
if (buf) {
buf-&amp;gt;len = 0;
} else {
   LOG_WRN(&amp;quot;Not able to allocate UART receive buffer&amp;quot;);
   k_work_reschedule(&amp;amp;uart_work, UART_WAIT_FOR_BUF_DELAY);
   return;
}

uart_rx_enable(uart, buf-&amp;gt;data, sizeof(buf-&amp;gt;data), UART_WAIT_FOR_RX);&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;In this example, a buffer is allocated and then passed to the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;uart_rx_enable&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;function, which starts the reception of data. When the reception is complete, the callback function set with&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;uart_callback_set&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;will be called.&lt;/div&gt;
&lt;div&gt;Please note that the actual implementation may vary depending on your specific requirements and the structure of your code.&lt;/div&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>