<?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>nRF5340: LC3 initialization causes a reboot due to error: LC3_RESULT_INSUFFICIENT_RESOURCES</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/121503/nrf5340-lc3-initialization-causes-a-reboot-due-to-error-lc3_result_insufficient_resources</link><description>Hi, 
 I am trying to integrate the nRF5340 Audio application (CIS Unicast Server role with bidirectional streaming enabled) from NCS 2.9.0 into on my custom nRF5340 based hardware. I am encountering an issue that LC3_API LC3Initialize() always returns</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 23 May 2025 09:49:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/121503/nrf5340-lc3-initialization-causes-a-reboot-due-to-error-lc3_result_insufficient_resources" /><item><title>RE: nRF5340: LC3 initialization causes a reboot due to error: LC3_RESULT_INSUFFICIENT_RESOURCES</title><link>https://devzone.nordicsemi.com/thread/536748?ContentTypeID=1</link><pubDate>Fri, 23 May 2025 09:49:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68b4af94-f152-4acd-bdfe-c79819eed0d2</guid><dc:creator>Maria Gilje</dc:creator><description>&lt;p&gt;Hello, &lt;/p&gt;
&lt;p&gt;Thank you for your patience. &lt;/p&gt;
&lt;p&gt;I asked for some feedback regarding the resampling feature, and this is what I was told: &lt;/p&gt;
&lt;p&gt;You can only disable the resampling if you only plan on using 48kHz sampling. However this means that 16kHz and 24kHz is not supported, which will make your solution non-compliant with the LE Audio standard. &lt;/p&gt;
&lt;p&gt;I was also informed that the stack sizes used in the application have some room for reduction, and are meant to be experimented with to reduce to a suitable size. &lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Maria&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340: LC3 initialization causes a reboot due to error: LC3_RESULT_INSUFFICIENT_RESOURCES</title><link>https://devzone.nordicsemi.com/thread/536456?ContentTypeID=1</link><pubDate>Wed, 21 May 2025 13:23:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9edd28aa-fcfe-4058-802a-13c0d57db574</guid><dc:creator>lincoln-lu</dc:creator><description>[quote userid="116814" url="~/f/nordic-q-a/121503/nrf5340-lc3-initialization-causes-a-reboot-due-to-error-lc3_result_insufficient_resources/536326"]Did you also have a chance to look into disabling the resampling feature?[/quote]
&lt;p&gt;what is impact if I disable&amp;nbsp;&lt;span&gt;resampling feature in headset(unicast server) when it works in bidirection streaming mode, i.e sending mic data to gatewat via LE audio?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340: LC3 initialization causes a reboot due to error: LC3_RESULT_INSUFFICIENT_RESOURCES</title><link>https://devzone.nordicsemi.com/thread/536326?ContentTypeID=1</link><pubDate>Wed, 21 May 2025 07:24:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:794d89aa-304e-4ee9-8c3a-6a7d2fb3f20d</guid><dc:creator>Maria Gilje</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="lincoln-lu"]No, I do not think the error was caused by the stack size of&amp;nbsp;&lt;span&gt;CONFIG_LE_AUDIO_MSG_SUB_STACK_SIZE. In fact I did not change this config, its value is 2048,&amp;nbsp; the same as out-of-box 5340 Audio application.&lt;br /&gt;&lt;br /&gt;The real problem is: in&amp;nbsp;&lt;/span&gt;le_audio_msg_sub_thread, it is &lt;span&gt;in&lt;/span&gt;&lt;span&gt;itializing&amp;nbsp;&lt;/span&gt;&lt;span&gt;lc3 encoder by calling&lt;/span&gt;&lt;span&gt;sw_codec_lc3_enc_init(), which treis to dynamically allocate 3740Bytes from heap but failed.&lt;/span&gt;[/quote]
&lt;p&gt;Thank you for correcting my misunderstanding. &lt;/p&gt;
[quote user="lincoln-lu"]I fianlly fixed this issue again using static array as the buffer passed to LC3 API&amp;nbsp;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;LC3EncodeSessionOpen() , like below&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;Great! Thank you for sharing your solution. &lt;/p&gt;
&lt;p&gt;Did you also have a chance to look into disabling the resampling feature? &lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Maria&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340: LC3 initialization causes a reboot due to error: LC3_RESULT_INSUFFICIENT_RESOURCES</title><link>https://devzone.nordicsemi.com/thread/536292?ContentTypeID=1</link><pubDate>Wed, 21 May 2025 01:15:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ef97365-2941-41dd-a325-bfdaf434e4a2</guid><dc:creator>lincoln-lu</dc:creator><description>[quote userid="116814" url="~/f/nordic-q-a/121503/nrf5340-lc3-initialization-causes-a-reboot-due-to-error-lc3_result_insufficient_resources/536241"]&lt;p&gt;The stack which seems to be too small here is the CONFIG_LE_AUDIO_MSG_SUB_STACK_SIZE. The log above is lines 13 and 14 in your latest device log. &lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;[/quote]
&lt;p&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/maria-gilje"&gt;Maria Gilje&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;No, I do not think the error was caused by the stack size of&amp;nbsp;&lt;span&gt;CONFIG_LE_AUDIO_MSG_SUB_STACK_SIZE. In fact I did not change this config, its value is 2048,&amp;nbsp; the same as out-of-box 5340 Audio application.&lt;br /&gt;&lt;br /&gt;The real problem is: in&amp;nbsp;&lt;/span&gt;le_audio_msg_sub_thread, it is &lt;span&gt;in&lt;/span&gt;&lt;span&gt;itializing&amp;nbsp;&lt;/span&gt;&lt;span&gt;lc3 encoder by calling&lt;/span&gt;&lt;span&gt;sw_codec_lc3_enc_init(), which treis to dynamically allocate 3740Bytes from heap but failed.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;see the call stack below:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;em&gt;le_audio_msg_sub_thread -&amp;gt;&amp;nbsp;audio_system_start -&amp;gt;&amp;nbsp; sw_codec_init -&amp;gt;&amp;nbsp;sw_codec_lc3_enc_init&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I fianlly fixed this issue again using static array as the buffer passed to LC3 API&amp;nbsp;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;LC3EncodeSessionOpen() , like below&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define LC3_ENCODER_BUFFER_SIZE &amp;#160; (4 * 1024) &amp;#160;// 4K bytes
static uint8_t lc3_encoder_buf[2][LC3_ENCODER_BUFFER_SIZE];	
uint16_t required_size = 0;
	
int sw_codec_lc3_enc_init()
{
  ...
	for (uint8_t i = 0; i &amp;lt; num_channels; i++) {
		if (enc_handle_ch[i]) {
			LOG_ERR(&amp;quot;LC3 enc ch: %d already initialized&amp;quot;, i);
			return -EALREADY;
		}
		enc_handle_ch[i] = LC3EncodeSessionOpen(pcm_sample_rate, pcm_bit_depth, framesize,
							NULL, &amp;amp;required_size, &amp;amp;ret);
		printk(&amp;quot;chan %d, first call of LC3EncodeSessionOpen: ret=%d, required buffer size=%d\r\n&amp;quot;, i, ret, required_size);

		if ( LC3_RESULT_INSUFFICIENT_RESOURCES == ret ) // failed to allocate memory dynamically, now open LC3 encoder again using static buffer
		{
			if ( required_size &amp;gt; LC3_ENCODER_BUFFER_SIZE ) {
				printk(&amp;quot;LC3 encoder static buffer is too small!!\r\n&amp;quot;);
				return ret;
			}
	
			memset(lc3_encoder_buf[i], 0, LC3_ENCODER_BUFFER_SIZE);
			enc_handle_ch[i] = LC3EncodeSessionOpen(pcm_sample_rate, pcm_bit_depth, framesize,
													lc3_encoder_buf[i], &amp;amp;required_size, &amp;amp;ret);
			printk(&amp;quot;chan %d, second call of LC3EncodeSessionOpen with static buffer: ret=%d, actual buf_size=%d\r\n&amp;quot;, i, ret, required_size);
		}
	
		if (ret) {
			return ret;
		}
	}
	
}&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340: LC3 initialization causes a reboot due to error: LC3_RESULT_INSUFFICIENT_RESOURCES</title><link>https://devzone.nordicsemi.com/thread/536241?ContentTypeID=1</link><pubDate>Tue, 20 May 2025 14:04:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b715cf9e-4bc3-4b3a-8cc1-c9b59c26d34f</guid><dc:creator>Maria Gilje</dc:creator><description>&lt;p&gt;Hello, &lt;/p&gt;
&lt;p&gt;Thank you for your updates. &lt;/p&gt;
[quote user="lincoln-lu"]So my next question is: I see the stack size of the encoder and audio_datapath theads in NCS 2.9.0 5340 Audio application code are very big to me,&amp;nbsp; see the defualt values of CONFIG_ENCODER_STACK_SIZE and&amp;nbsp;CONFIG_AUDIO_DATAPATH_STACK_SIZE below:[/quote]
&lt;p&gt;These values were increased some time ago (february 2024) when the resampling feature was introduced. The increase accounts for higher stack usage when the feature is in use. The resampling feature can be disabled with CONFIG_SAMPLE_RATE_CONVERTER=y. When the feature is disabled, you should be able to safely reduce the stack sizes for the encoder and audio datapath. &lt;/p&gt;
&lt;p&gt;You can see what the values for the stacks were before the resampling addition here: &lt;a href="https://github.com/nrfconnect/sdk-nrf/commit/0a2ef78ea8a82aa84539037d17eaff9a39b8c248#diff-47659bfa917ed5f5bf471b2e405f09d84c304281115895f9915ea784c6e30a68L344"&gt;https://github.com/nrfconnect/sdk-nrf/commit/0a2ef78ea8a82aa84539037d17eaff9a39b8c248#diff-47659bfa917ed5f5bf471b2e405f09d84c304281115895f9915ea784c6e30a68L344&lt;/a&gt; (lines 344/343-352/351). &lt;/p&gt;
[quote user="lincoln-lu"]&lt;span&gt;&lt;span&gt;However, the subsequent call to&amp;nbsp;&lt;/span&gt;&lt;/span&gt;sw_codec_lc3_enc_init() failed and cause system reboot again.[/quote]
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00:00:05.131,286] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
[00:00:05.131,317] &amp;lt;err&amp;gt; os: Current thread: 0x200043e8 (LE_AUDIO_MSG_SUB)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The stack which seems to be too small here is the CONFIG_LE_AUDIO_MSG_SUB_STACK_SIZE. The log above is lines 13 and 14 in your latest device log. &lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Maria&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340: LC3 initialization causes a reboot due to error: LC3_RESULT_INSUFFICIENT_RESOURCES</title><link>https://devzone.nordicsemi.com/thread/536090?ContentTypeID=1</link><pubDate>Tue, 20 May 2025 06:52:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2f53bbe-1652-4219-9483-5491febd3cf5</guid><dc:creator>lincoln-lu</dc:creator><description>&lt;p&gt;Well, after I tried my best to save RAM memory from my project, and then defined a &lt;strong&gt;static buffer of 32KB&lt;/strong&gt; for&amp;nbsp; LC3Initialize(), it succeeded to inilalize LC3. see the code below:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define LC3_STATIC_BUFFER_SIZE   (32 * 1024) // 32K bytes
static uint8_t lc3_codec_buf[LC3_STATIC_BUFFER_SIZE];

int sw_codec_lc3_init(uint8_t *sw_codec_lc3_buffer, uint32_t *sw_codec_lc3_buffer_size,
		      uint16_t framesize_us)
{
	int ret;
	uint8_t enc_sample_rates = 0;
	uint8_t dec_sample_rates = 0;

	/* Set unique session to 0 for using the default sharing memory setting.
	 *
	 * This could lead to higher heap consumption, but is able to manipulate
	 * different sample rate setting between encoder/decoder.
	 */
	uint8_t unique_session = 0;

	/* Check supported sample rates for encoder */
	if (IS_ENABLED(CONFIG_LC3_ENC_SAMPLE_RATE_8KHZ_SUPPORT)) {
		enc_sample_rates |= LC3_SAMPLE_RATE_8_KHZ;
	}
	if (IS_ENABLED(CONFIG_LC3_ENC_SAMPLE_RATE_16KHZ_SUPPORT)) {
		enc_sample_rates |= LC3_SAMPLE_RATE_16_KHZ;
	}
	if (IS_ENABLED(CONFIG_LC3_ENC_SAMPLE_RATE_24KHZ_SUPPORT)) {
		enc_sample_rates |= LC3_SAMPLE_RATE_24_KHZ;
	}
	if (IS_ENABLED(CONFIG_LC3_ENC_SAMPLE_RATE_32KHZ_SUPPORT)) {
		enc_sample_rates |= LC3_SAMPLE_RATE_32_KHZ;
	}
	if (IS_ENABLED(CONFIG_LC3_ENC_SAMPLE_RATE_441KHZ_SUPPORT)) {
		enc_sample_rates |= LC3_SAMPLE_RATE_441_KHZ;
	}
	if (IS_ENABLED(CONFIG_LC3_ENC_SAMPLE_RATE_48KHZ_SUPPORT)) {
		enc_sample_rates |= LC3_SAMPLE_RATE_48_KHZ;
	}

	/* Check supported sample rates for decoder */
	if (IS_ENABLED(CONFIG_LC3_DEC_SAMPLE_RATE_8KHZ_SUPPORT)) {
		dec_sample_rates |= LC3_SAMPLE_RATE_8_KHZ;
	}
	if (IS_ENABLED(CONFIG_LC3_DEC_SAMPLE_RATE_16KHZ_SUPPORT)) {
		dec_sample_rates |= LC3_SAMPLE_RATE_16_KHZ;
	}
	if (IS_ENABLED(CONFIG_LC3_DEC_SAMPLE_RATE_24KHZ_SUPPORT)) {
		dec_sample_rates |= LC3_SAMPLE_RATE_24_KHZ;
	}
	if (IS_ENABLED(CONFIG_LC3_DEC_SAMPLE_RATE_32KHZ_SUPPORT)) {
		dec_sample_rates |= LC3_SAMPLE_RATE_32_KHZ;
	}
	if (IS_ENABLED(CONFIG_LC3_DEC_SAMPLE_RATE_441KHZ_SUPPORT)) {
		dec_sample_rates |= LC3_SAMPLE_RATE_441_KHZ;
	}
	if (IS_ENABLED(CONFIG_LC3_DEC_SAMPLE_RATE_48KHZ_SUPPORT)) {
		dec_sample_rates |= LC3_SAMPLE_RATE_48_KHZ;
	}

	LC3FrameSize_t framesize;

	switch (framesize_us) {
	case 7500:
		framesize = LC3FrameSize7_5Ms;
		break;
	case 10000:
		framesize = LC3FrameSize10Ms;
		break;
	default:
		LOG_ERR(&amp;quot;Unsupported framesize: %d&amp;quot;, framesize_us);
		return -EINVAL;
	}


	uint32_t required_size = 0;
	ret = LC3Initialize(enc_sample_rates, dec_sample_rates, framesize, unique_session,
			   NULL, &amp;amp;required_size);
	printk(&amp;quot;First call of LC3Initialize: ret=%d, required buffer size=%d\r\n&amp;quot;, ret, required_size);
	
	if ( LC3_RESULT_INSUFFICIENT_RESOURCES == ret ) // failed to allocate memory dynamically, now Initialize LC3 again using static buffer
	{
		if ( required_size &amp;gt; LC3_STATIC_BUFFER_SIZE ) {
			printk(&amp;quot;Static LC3 buffer is too small!!\r\n&amp;quot;);
			return ret;
		}

		memset(lc3_codec_buf, 0, required_size);
		ret = LC3Initialize(enc_sample_rates, dec_sample_rates, framesize, unique_session,
					lc3_codec_buf, &amp;amp;required_size);
		
		printk(&amp;quot;Second call of LC3Initialize with static buffer: ret=%d, actual buf_size=%d\r\n&amp;quot;, ret, required_size);
	}


	ret = LC3Initialize(enc_sample_rates, dec_sample_rates, framesize, unique_session,
		sw_codec_lc3_buffer, sw_codec_lc3_buffer_size);
	return ret;
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;However, the subsequent call to&amp;nbsp;&lt;/span&gt;&lt;/span&gt;sw_codec_lc3_enc_init() failed and cause system reboot again.&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00:00:05.131,072] &amp;lt;err&amp;gt; audio_system: Failed to set up codec
[00:00:05.131,072] &amp;lt;err&amp;gt; audio_system: ERR_CHK Err_code: [-5002] @ line: 406
[00:00:05.131,103] &amp;lt;err&amp;gt; os: r0/a1:  0x00000003  r1/a2:  0x00000014  r2/a3:  0x00000013
[00:00:05.131,103] &amp;lt;err&amp;gt; os: r3/a4:  0x00000003 r12/ip:  0x200052e8 r14/lr:  0x0009cdeb
[00:00:05.131,103] &amp;lt;err&amp;gt; os:  xpsr:  0x21100000
[00:00:05.131,134] &amp;lt;err&amp;gt; os: s[ 0]:  0x000b9d54  s[ 1]:  0x0009cea7  s[ 2]:  0xffffec76  s[ 3]:  0x00000004
[00:00:05.131,134] &amp;lt;err&amp;gt; os: s[ 4]:  0x200340f0  s[ 5]:  0x00000001  s[ 6]:  0xffffec76  s[ 7]:  0x200340d0
[00:00:05.007,751] &amp;lt;dbg&amp;gt; main: le_audio_msg_sub_thread: Received event = 2, current state = 1
[00:00:05.131,164] &amp;lt;err&amp;gt; os: s[ 8]:  0x200340f0  s[ 9]:  0x000b9d54  s[10]:  0x00001900  s[11]:  0x0009ceeb
[00:00:05.131,195] &amp;lt;err&amp;gt; os: s[12]:  0x200340f0  s[13]:  0x000baa44  s[14]:  0xffffec76  s[15]:  0x00000196
[00:00:05.131,225] &amp;lt;err&amp;gt; os: fpscr:  0x00000000
[00:00:05.131,225] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x00017a4e
[00:00:05.131,286] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
[00:00:05.131,317] &amp;lt;err&amp;gt; os: Current thread: 0x200043e8 (LE_AUDIO_MSG_SUB)
*** Booting MCUboot v2.1.0-dev-12e5ee106034 ***ystem error -- reason 3. Cold rebooting.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I narrowed down the error position, it is&lt;strong&gt;&amp;nbsp;LC3EncodeSessionOpen(pcm_sample_rate, pcm_bit_depth, framesize,&lt;/strong&gt;&lt;strong&gt;&amp;nbsp;NULL, NULL, &amp;amp;ret&lt;/strong&gt;&lt;span&gt;&lt;strong&gt;);&lt;/strong&gt; rurturning -5002:&amp;nbsp;LC3_RESULT_INSUFFICIENT_RESOURCES&amp;nbsp; again!&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;br /&gt;so it is obvious that not only LC3 lib needs to allocate a very big buffer, but also lc3 encoder session!&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int sw_codec_lc3_enc_init(uint16_t pcm_sample_rate, uint8_t pcm_bit_depth, uint16_t framesize_us,
			  uint32_t enc_bitrate, uint8_t num_channels, uint16_t *const pcm_bytes_req)
{
	int ret;
	LC3FrameSize_t framesize;

	switch (framesize_us) {
	case 7500:
		framesize = LC3FrameSize7_5Ms;
		break;
	case 10000:
		framesize = LC3FrameSize10Ms;
		break;
	default:
		LOG_ERR(&amp;quot;Unsupported framesize: %d&amp;quot;, framesize_us);
		return -EINVAL;
	}

	if (enc_bitrate == 0) {
		LOG_ERR(&amp;quot;LC3 enc_bitrate is 0&amp;quot;);
		return -EINVAL;
	} else if (enc_bitrate &amp;lt;= ENC_BITRATE_WRN_LVL_LOW) {
		LOG_WRN(&amp;quot;LC3 enc_bitrate: %d : likely too low&amp;quot;, enc_bitrate);
	} else if (enc_bitrate &amp;gt;= ENC_BITRATE_WRN_LVL_HIGH) {
		LOG_WRN(&amp;quot;LC3 enc_bitrate: %d : likely too high&amp;quot;, enc_bitrate);
	}

	enc_pcm_bytes_req = LC3PCMBuffersize(pcm_sample_rate, pcm_bit_depth, framesize, &amp;amp;ret);
	*pcm_bytes_req = enc_pcm_bytes_req;

	if (enc_pcm_bytes_req == 0) {
		LOG_ERR(&amp;quot;Required PCM bytes to encode LC3 is zero.&amp;quot;);
		return -EPERM;
	}

	for (uint8_t i = 0; i &amp;lt; num_channels; i++) {
		if (enc_handle_ch[i]) {
			LOG_ERR(&amp;quot;LC3 enc ch: %d already initialized&amp;quot;, i);
			return -EALREADY;
		}
		enc_handle_ch[i] = LC3EncodeSessionOpen(pcm_sample_rate, pcm_bit_depth, framesize,
							NULL, NULL, &amp;amp;ret);
		if (ret) {
			return ret;
		}
	}

	m_enc_bitrate = enc_bitrate;

	enc_num_instances = num_channels;

	return ret;
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340: LC3 initialization causes a reboot due to error: LC3_RESULT_INSUFFICIENT_RESOURCES</title><link>https://devzone.nordicsemi.com/thread/535965?ContentTypeID=1</link><pubDate>Mon, 19 May 2025 11:43:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b5c6871-e9d2-4197-a8fa-0c7d11ca75d7</guid><dc:creator>lincoln-lu</dc:creator><description>&lt;p&gt;As to my first question, I have figured out a way to know how much RAM is required by LC3 codec for 48KHz, 10ms duration time as below&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; uint32_t bufferSize = 4096;
 ret = LC3Initialize(enc_sample_rates, dec_sample_rates, framesize, unique_session,
      NULL, &amp;amp;bufferSize);

 printk(&amp;quot;LC3Initialize: ret = %d\r\n&amp;quot;, ret);
 printk(&amp;quot;LC3Initialize reurens bufferSize: %d\r\n&amp;quot;, bufferSize);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The result is&lt;/p&gt;
&lt;p&gt;LC3Initialize: ret = -5002&lt;br /&gt; LC3Initialize reurens bufferSize: &lt;span&gt;&lt;strong&gt;29584&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;so it needs 29584&amp;nbsp; bytes.&lt;br /&gt;&lt;br /&gt;I guess the reason why &lt;strong&gt;sw_codec_lc3_init(NULL, NULL, CONFIG_AUDIO_FRAME_DURATION_US&lt;/strong&gt;&lt;span&gt;&lt;strong&gt;)&lt;/strong&gt;; returns success on 5340ADK is the nRF audio application is relatively simpler(waht I can see it only includes main thread, encoder thread, decoder threads, le-audio-rx thread) than my own project, so the 512KB RAM insider nRF5340 is enough to it. while in my project I have many other user threads, thus there is far less than 29KB RAM remining for heap.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So my next question is: I see the stack size of the encoder and audio_datapath theads in NCS 2.9.0 5340 Audio application code are very big to me,&amp;nbsp; see the defualt values of CONFIG_ENCODER_STACK_SIZE and&amp;nbsp;CONFIG_AUDIO_DATAPATH_STACK_SIZE below:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#----------------------------------------------------------------------------#
menu &amp;quot;Stack sizes&amp;quot;

config ENCODER_STACK_SIZE
	int &amp;quot;Stack size for encoder thread&amp;quot;
	default 11000 if AUDIO_BIT_DEPTH_16
	default 21400 if AUDIO_BIT_DEPTH_32

config AUDIO_DATAPATH_STACK_SIZE
	int &amp;quot;Stack size for audio datapath thread&amp;quot;
	default 7600 if AUDIO_BIT_DEPTH_16
	default 14700 if AUDIO_BIT_DEPTH_32

config LE_AUDIO_MSG_SUB_STACK_SIZE
	int &amp;quot;Stack size for LE Audio subscriber&amp;quot;
	default 2048

config BT_MGMT_MSG_SUB_STACK_SIZE
	int &amp;quot;Stack size for bt_mgmt subscriber&amp;quot;
	default 2048

config CONTENT_CONTROL_MSG_SUB_STACK_SIZE
	int &amp;quot;Stack size for content control subscriber&amp;quot;
	default 1024

endmenu # Stack sizes
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Can you check with your audio team that if I can reduce these stack sizes safely?&lt;br /&gt;thanks&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340: LC3 initialization causes a reboot due to error: LC3_RESULT_INSUFFICIENT_RESOURCES</title><link>https://devzone.nordicsemi.com/thread/535825?ContentTypeID=1</link><pubDate>Fri, 16 May 2025 14:41:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1ec33f9-4274-4f0b-b1ba-092f75183395</guid><dc:creator>Maria Gilje</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]1. So can you tell if there is any special memory reuqirement for LC3 code? Is it different from system heap memory?&amp;nbsp;[/quote]
&lt;p&gt;I am not sure, but it would be interesting to see if there are any obvious differences for the same application built for your custom board and the nRF5340 Audio DK. Are you willing to build both versions and share the resulting .config for the application core and sysbuild with us?&lt;/p&gt;
&lt;p&gt;There could be configurations which are invoked for the Audio DK but not for your custom board.&lt;/p&gt;
[quote user=""]&lt;span&gt;2. As you can see the first parmater(i.e. sw_codec_lc3_buffer) is passed in as &lt;strong&gt;NULL&lt;/strong&gt; when calling&amp;nbsp;&lt;/span&gt;&lt;strong&gt;sw_codec_lc3_init(NULL, NULL, CONFIG_AUDIO_FRAME_DURATION_US&lt;/strong&gt;&lt;span&gt;&lt;strong&gt;)&lt;/strong&gt;;&amp;nbsp;&lt;br /&gt; does that mean it will let LC3 lib allocate the memory dynamically on its own? &lt;/span&gt;[/quote]
&lt;p&gt;According to the function description, the needed memory should be allocated. (ref &lt;a href="https://github.com/nrfconnect/sdk-nrfxlib/blame/v2.9.0/lc3/codec/inc/LC3API.h#L213"&gt;https://github.com/nrfconnect/sdk-nrfxlib/blame/v2.9.0/lc3/codec/inc/LC3API.h#L213&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;Since it is not succeeding to do so, it is interesting to find out which value *sw_codec_lc3_buffer points to after the initialization function fails.&lt;/p&gt;
&lt;p&gt;I am not sure if the value is updated when the input parameters are NULL, but it will be updated if the bufferSize value is too small. Since LC3_RESULT_INSUFFICIENT_RESOURCES is returned it does indicate that the initialization function is called with a *bufferSize &amp;lt; &amp;quot;required memory for codec&amp;quot; at some point.&lt;/p&gt;
&lt;p&gt;As another trial to see if the LC3 codec will run on your hardware is to look into the sw_code_lc3 test sample: &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.9.0/tests/nrf5340_audio/sw_codec_lc3/main.c"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v2.9.0/tests/nrf5340_audio/sw_codec_lc3/main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Maria&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>