<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Welcome to Hang&#039;s Website!</title>
	<atom:link href="https://hangpersonal.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://hangpersonal.com</link>
	<description>Embedded Systems</description>
	<lastBuildDate>Mon, 28 Sep 2026 03:50:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://hangpersonal.com/wp-content/uploads/2024/10/cropped-HC-32x32.jpg</url>
	<title>Welcome to Hang&#039;s Website!</title>
	<link>https://hangpersonal.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">252449636</site>	<item>
		<title>STM32 Zephyr: Multithreading</title>
		<link>https://hangpersonal.com/2026/09/22/stm32-zephyr-multithreading/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Wed, 23 Sep 2026 05:09:21 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=8672</guid>

					<description><![CDATA[Work in Progress STM32 Microcontroller and Zephyr RTOS Development]]></description>
										<content:encoded><![CDATA[
<p>
<span style="font-size: 22px; color: red;">
Work in Progress
</span>
</p>



<a href="https://hangpersonal.com/embedded-system/stm32-mcu/zephyr-tutorials/" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
STM32 Microcontroller and Zephyr RTOS Development
</a>
<br><br>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8672</post-id>	</item>
		<item>
		<title>STM32 Zephyr: Device Driver Model</title>
		<link>https://hangpersonal.com/2026/09/21/stm32-zephyr-device-driver-model/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Tue, 22 Sep 2026 05:20:26 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=8617</guid>

					<description><![CDATA[Work in Progress STM32 Microcontroller and Zephyr RTOS Development Zephyr applications typically interact with hardware through standardized subsystem APIs rather than accessing registers directly or relying on vendor-specific hardware abstraction layers (HALs). This hardware abstraction is provided by Zephyr’s device driver model and devicetree system: devicetree describes the hardware independently of the application, while the...]]></description>
										<content:encoded><![CDATA[
<p>
<span style="font-size: 22px; color: red;">
Work in Progress
</span>
</p>



<a href="https://hangpersonal.com/embedded-system/stm32-mcu/zephyr-tutorials/" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
STM32 Microcontroller and Zephyr RTOS Development
</a>
<br><br>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<p>
Zephyr applications typically interact with hardware through standardized subsystem APIs rather than accessing registers directly or relying on vendor-specific hardware abstraction layers (HALs). This hardware abstraction is provided by Zephyr’s device driver model and devicetree system: devicetree describes the hardware independently of the application, while the build system selects and configures the appropriate drivers automatically.
</p>

</div>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8617</post-id>	</item>
		<item>
		<title>STM32 FreeRTOS: Interrupt Integration</title>
		<link>https://hangpersonal.com/2026/09/13/stm32-freertos-interrupt/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Mon, 14 Sep 2026 06:00:02 +0000</pubDate>
				<category><![CDATA[Embedded System]]></category>
		<category><![CDATA[FreeRTOS]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=8573</guid>

					<description><![CDATA[Work in Progress STM32 Microcontroller and FreeRTOS Development PendSV (Pendable Service) Exception SVC (Supervisor Call) Exception SysTick Timer Exception Scheduling and Exception Handling on Cortex-M STM32/Cortex-M Interrupt Priorities PendSV (Pendable Service) Exception Used by the RTOS to perform deferred context switches between tasks Usually pended by the SysTick handler or when a task explicitly yields...]]></description>
										<content:encoded><![CDATA[
<p>
<span style="font-size: 22px; color: red;">
Work in Progress
</span>
</p>



<a href="https://hangpersonal.com/embedded-system/stm32-mcu/freertos-tutorials/" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
STM32 Microcontroller and FreeRTOS Development
</a>
<br><br>



<ul style="margin-top:30px; margin-bottom:30px;">

<li style="margin-bottom:16px;">
<a href="#interrupt_pendsv" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
PendSV (Pendable Service) Exception
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#interrupt_svc" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
SVC (Supervisor Call) Exception
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#interrupt_systick" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
SysTick Timer Exception
</a>
</li>

<li style="margin-bottom:16px;">
<a href="#interrupt_scheduling_exception" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Scheduling and Exception Handling on Cortex-M
</a>
</li>

<li style="margin-bottom:16px;">
<a href="#interrupt_prio" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
STM32/Cortex-M Interrupt Priorities 
</a>
</li>

</ul>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="interrupt_pendsv" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
PendSV (Pendable Service) Exception
</b>

<p>
<ul>

<li> Used by the RTOS to perform deferred context switches between tasks
</li>

<li> Usually pended by the SysTick handler or when a task explicitly yields
</li>

<li> Configured at the lowest interrupt priority so that context switching occurs only after higher-priority interrupt handlers have finished
</li>

<li> Triggered by software through the NVIC’s Interrupt Control and State Register, not directly by a peripheral
</li>

</ul>
</p>

</div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="interrupt_svc" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
SVC (Supervisor Call) Exception
</b>

<p>
</p><ul>

<li> Synchronously triggered by executing an <span class="highlight">SVC</span> instruction
</li>

<li> Used to request privileged operating-system services
</li>

<li> In FreeRTOS Cortex-M ports, <span class="highlight">SVC 0</span> is executed by <span class="highlight">vPortStartFirstTask()</span> to start the scheduler and restore the first task’s context
</li>

<li> In those ports, this startup call normally occurs only once; other ports, particularly MPU-enabled ones, may use <span class="highlight">SVC</span> for additional services
</li>

</ul>
<p></p>

</div>



<div class="article-text" style="margin-top:50px; margin-bottom:40px;">

<b id="interrupt_systick" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
SysTick Timer Exception
</b>

<p>
</p><ul>

<li> Provides the FreeRTOS timebase at <span class="highlight">configTICK_RATE_HZ</span>
</li>

<li> Runs at the lowest interrupt priority in typical Cortex-M ports
</li>

<li> Updates delays and timeouts on every tick
</li>

<li> Pends PendSV when task rescheduling is needed
</li>

</ul>
<p></p>

</div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="interrupt_scheduling_exception" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Scheduling and Exception Handling on Cortex-M
</b>

</div>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="543" src="https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_pendsv_svc-1024x543.png" alt="" class="wp-image-8623" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_pendsv_svc-1024x543.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_pendsv_svc-300x159-1.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_pendsv_svc-767x407.png 767w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_pendsv_svc-1536x815.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_pendsv_svc-848x450.png 848w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_pendsv_svc.png 1646w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">
</div>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="573" src="https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_nvic_prio-1024x573.png" alt="" class="wp-image-8625" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_nvic_prio-1024x573.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_nvic_prio-300x168.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_nvic_prio-767x429.png 767w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_nvic_prio-298x167.png 298w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_nvic_prio-1536x859.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_nvic_prio-849x475.png 849w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_nvic_prio.png 1655w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:50px; margin-bottom:40px;">

<b id="interrupt_prio" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
STM32/Cortex-M Interrupt Priorities 
</b>

<p>
On STM32 microcontrollers, FreeRTOS configures <span class="highlight">PendSV</span> and <span class="highlight">SysTick</span> at the lowest NVIC priority using <span class="highlight">configKERNEL_INTERRUPT_PRIORITY</span>. Interrupts with a numeric priority value equal to or greater than <span class="highlight">configMAX_SYSCALL_INTERRUPT_PRIORITY</span> may call only <span class="highlight">FromISR()</span> APIs, while higher-priority interrupts with smaller numeric values must not call FreeRTOS APIs. The NVIC also supports nesting, allowing higher-priority interrupts to preempt lower-priority ones.
</p>

</div>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="559" src="https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_interrupts-1024x559.png" alt="" class="wp-image-8627" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_interrupts-1024x559.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_interrupts-300x164.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_interrupts-299x163.png 299w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_interrupts-768x419.png 768w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_interrupts-850x464.png 850w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_interrupts-1536x838.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/09/freertos_stm32_interrupts.png 1689w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:30px; margin-bottom:40px;">
</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>// FreeRTOSConfig.h
#define vPortSVCHandler  SVC_Handler
#define xPortPendSVHandler 	PendSV_Handler

#ifdef __NVIC_PRIO_BITS
	#define configPRIO_BITS  __NVIC_PRIO_BITS
#else
	#define configPRIO_BITS  4
#endif

// Lowest priority allowed in priority-setting functions
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY  15 

// Priorities 0–4: High-priority ISRs; must not call FreeRTOS APIs
// Priorities 5–15: RTOS-aware ISRs; may call only xxxFromISR() APIs
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY  5  </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #A0A1A7CC">// FreeRTOSConfig.h</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vPortSVCHandler</span><span style="color: #D5CED9">  SVC_Handler</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xPortPendSVHandler</span><span style="color: #D5CED9"> 	PendSV_Handler</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">#ifdef</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">__NVIC_PRIO_BITS</span></span>
<span class="line"><span style="color: #D5CED9">	</span><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configPRIO_BITS</span><span style="color: #D5CED9">  __NVIC_PRIO_BITS</span></span>
<span class="line"><span style="color: #C74DED">#else</span></span>
<span class="line"><span style="color: #D5CED9">	</span><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configPRIO_BITS</span><span style="color: #D5CED9">  </span><span style="color: #F39C12">4</span></span>
<span class="line"><span style="color: #C74DED">#endif</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// Lowest priority allowed in priority-setting functions</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configLIBRARY_LOWEST_INTERRUPT_PRIORITY</span><span style="color: #D5CED9">  </span><span style="color: #F39C12">15</span><span style="color: #D5CED9"> </span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// Priorities 0–4: High-priority ISRs; must not call FreeRTOS APIs</span></span>
<span class="line"><span style="color: #A0A1A7CC">// Priorities 5–15: RTOS-aware ISRs; may call only xxxFromISR() APIs</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY</span><span style="color: #D5CED9">  </span><span style="color: #F39C12">5</span><span style="color: #D5CED9">  </span></span></code></pre></div>



<br><br>
<a href="#top" style="font-size:20px; color: blue;">Back to top of the page</a>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8573</post-id>	</item>
		<item>
		<title>TI C2000 C28x Microcontroller with Simulink Embedded Coder</title>
		<link>https://hangpersonal.com/2026/09/09/c2000-c28x-embedded-coder/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Wed, 09 Sep 2026 20:21:39 +0000</pubDate>
				<category><![CDATA[Embedded System]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=8437</guid>

					<description><![CDATA[This Guide Is Still Being Expanded &#8211; More to Come TI C2000 Microcontrollers (TMS320F2837xx, TMS320F2838xx) Embedded Coder Version 26.1 (R2026a) TI Code Composer Studio 12.8.1 TI C2000 Code Generation Tools (compiler) 22.6.1 TI C2000Ware 5_04_00_00 TI ARM Code Generation Tools (compiler) 20.2.7 Example: LED Blinking and Button-Controlled LED Button: GPIO10 Red LED: GPIO41 Blue LED:...]]></description>
										<content:encoded><![CDATA[
<p>
<span style="font-size: 22px; color: green;">
This Guide Is Still Being Expanded &#8211; More to Come
</span>
</p>



<div class="article-text" style="margin-top:30px; margin-bottom:20px;">

<b style="font-family: 'Inter', sans-serif; 
           font-size: 22px; 
           color: black; 
           margin-top:0px; 
           margin-bottom:0px;">
TI C2000 Microcontrollers (TMS320F2837xx, TMS320F2838xx)
</b>

</p>

<ul>

<li> Embedded Coder Version 26.1 (R2026a)
</li>

<li> TI Code Composer Studio 12.8.1
</li>

<li> TI C2000 Code Generation Tools (compiler) 22.6.1
</li>

<li> TI C2000Ware 5_04_00_00
</li>

<li> TI ARM Code Generation Tools (compiler) 20.2.7
</li>

</ul>

</p>

</div>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="882" src="https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-1-1024x882.png" alt="" class="wp-image-8541" style="width:400px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-1-1024x882.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-1-300x258.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-1-767x661.png 767w, https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-1-299x258.png 299w, https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-1-850x732.png 850w, https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-1.png 1047w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:30px; margin-bottom:40px;">
</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(1 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>>> c2000setup
>> c2000lib</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">&gt;&gt; c2000setup</span></span>
<span class="line"><span style="color: #D5CED9">&gt;&gt; c2000lib</span></span></code></pre></div>



<div class="article-text" style="margin-top:50px; margin-bottom:20px;">

<b style="font-family: 'Inter', sans-serif; 
           font-size: 22px; 
           color: black; 
           margin-top:0px; 
           margin-bottom:0px;">
Example: LED Blinking and Button-Controlled LED
</b>

<p>
<ul> 
<li> Button: GPIO10
</li>
<li> Red LED: GPIO41
</li>
<li> Blue LED: GPIO58
</li>
</ul>
</p>

</div>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="687" src="https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED-1024x687.png" alt="" class="wp-image-8533" style="width:650px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED-1024x687.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED-300x201-1.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED-768x515.png 768w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED-1536x1030.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED-849x569.png 849w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED.png 1703w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">
</div>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="423" src="https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED_CLA-1024x423.png" alt="" class="wp-image-8546" style="width:1100px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED_CLA-1024x423.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED_CLA-300x124.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED_CLA-767x317.png 767w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED_CLA-1536x635.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED_CLA-2048x846.png 2048w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED_CLA-298x123.png 298w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_LED_CLA-849x351.png 849w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:50px; margin-bottom:20px;">

<b style="font-family: 'Inter', sans-serif; 
           font-size: 22px; 
           color: black; 
           margin-top:0px; 
           margin-bottom:0px;">
Example: Real-time Control Module for HIL
</b>

</div>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="699" src="https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_pacmod2-1024x699.png" alt="" class="wp-image-8566" style="width:1100px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_pacmod2-1024x699.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_pacmod2-300x205.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_pacmod2-768x524.png 768w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_pacmod2-299x204.png 299w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_pacmod2-1536x1048.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_pacmod2-850x580.png 850w, https://hangpersonal.com/wp-content/uploads/2026/09/embedded_coder_pacmod2.png 1729w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:60px; margin-bottom:40px;">

<b style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Reference
</b>

<p>

[1] <a href="https://www.mathworks.com/help/ti-c2000/index.html?s_tid=CRUX_lftnav" style="color: blue;">
C2000 Microcontroller Blockset
</a>
<br>

[2] <a href="https://www.mathworks.com/help/releases/R2024b/ti-c2000/examples.html" style="color: blue;">
C2000 Microcontroller Blockset &#8211; Examples
</a>
<br>

[3] <a href="https://www.mathworks.com/support/search.html?fq%5B%5D=asset_type_name:video&amp;fq%5B%5D=category:ti-c2000/index&amp;page=1&amp;s_tid=CRUX_topnav" style="color: blue;">
C2000 Microcontroller Blockset &#8211; Videos
</a>
<br>

[4] <a href="https://www.mathworks.com/help/ti-c2000/referencelist.html?type=block&#038;s_tid=CRUX_topnav&#038;category=index" style="color: blue;">
C2000 Microcontroller Blockset &#8211; Blocks
</a>
<br>


[5] <a href="https://www.mathworks.com/help/ti-c2000/getting-started-with-c2b.html" style="color: blue;">
Get Started with C2000 Microcontroller Blockset
</a>
<br>

[6] <a href="https://www.mathworks.com/help/ti-c2000/application-examples-using-motor-control.html" style="color: blue;">
Applications
</a>
<br>

[7] <a href="https://www.mathworks.com/help/ti-c2000/group_block.html" style="color: blue;">
Peripherals
</a>
<br>

[8] <a href="https://www.mathworks.com/help/ti-c2000/multicore-modeling.html" style="color: blue;">
Multiprocessor Architecture Modeling
</a>
<br>

[9] <a href="https://www.mathworks.com/help/ti-c2000/connected-io-simulation.html" style="color: blue;">
Connected IO Simulation
</a>
<br>

[10] <a href="https://www.mathworks.com/help/ti-c2000/signal-monitoring-parameter-tuning.html" style="color: blue;">
Signal Monitoring and Parameter Tuning
</a>
<br>

[11] <a href="https://www.mathworks.com/help/ti-c2000/deploy-and-validate.html" style="color: blue;">
Deployment and Validation
</a>
<br>

</p>

</div>



<br><br>
<a href="#top" style="font-size:20px; color: blue;">Back to top of the page</a>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8437</post-id>	</item>
		<item>
		<title>STM32 Zephyr: Hardware Description with Devicetree</title>
		<link>https://hangpersonal.com/2026/09/06/stm32-zephyr-devicetree/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Mon, 07 Sep 2026 04:36:57 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=8278</guid>

					<description><![CDATA[STM32 Microcontroller and Zephyr RTOS Development Zephyr Devicetree Devicetree Overlays Devicetree Build Flow Modifying Devicetree Nodes with Overlays Zephyr Devicetree Structure: ADC Configuration Example Zephyr Devicetree: Separating Hardware from Application Logic Zephyr uses devicetree to describe hardware separately from application logic. Peripheral addresses, interrupt numbers, pin assignments, and other hardware-specific details are defined at build...]]></description>
										<content:encoded><![CDATA[
<a href="https://hangpersonal.com/embedded-system/stm32-mcu/zephyr-tutorials/" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
STM32 Microcontroller and Zephyr RTOS Development
</a>
<br><br>



<ul style="margin-top:30px; margin-bottom:30px;">

<li style="margin-bottom:16px;">
<a href="#zephyr_devicetree" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Zephyr Devicetree
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#zephyr_devicetree_overlay" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Devicetree Overlays
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#zephyr_devicetree_build" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Devicetree Build Flow
</a>
</li>

<li style="margin-bottom:16px;">
<a href="#zephyr_devicetree_node_modification" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Modifying Devicetree Nodes with Overlays 
</a>
</li>


<li style="margin-bottom:16px;">
<a href="#zephyr_devicetree_structure" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Zephyr Devicetree Structure: ADC Configuration Example
</a>
</li>

</ul>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="zephyr_devicetree" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Zephyr Devicetree: Separating Hardware from Application Logic
</b>

<p>
Zephyr uses <b>devicetree</b> to describe hardware separately from application logic. Peripheral addresses, interrupt numbers, pin assignments, and other hardware-specific details are defined at build time rather than hardcoded in source code.
</p>

<p>
The devicetree is then processed into compile-time information that drivers and applications can access through generated macros. This separation improves portability and maintainability, allowing the same application code to run on different boards and SoCs while board-specific hardware configuration is selected during the build process.
</p>

<p>
With devicetree, each vendor describes hardware in its own <span class="highlight">.dts</span> file. The hardware description differs, but the application code does not change time. This approach is lightweight and efficient for embedded systems.
</p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly># Vendor A
uart0: uart@40021000 {
  compatible = "vendora,uart";
  reg = &lt;0x40021000 0x400>;
  status = "okay";
};

# Vendor B
uart0: uart@50003000 {
  compatible = "vendorb,uart";
  reg = &lt;0x50003000 0x400>;
  status = "okay";
};</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #A0A1A7CC"># Vendor A</span></span>
<span class="line"><span style="color: #D5CED9">uart0: uart</span><span style="color: #EE5D43">@</span><span style="color: #F39C12">40021000</span><span style="color: #D5CED9"> {</span></span>
<span class="line"><span style="color: #D5CED9">  compatible = </span><span style="color: #96E072">&quot;vendora,uart&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">  reg = </span><span style="color: #EE5D43">&lt;</span><span style="color: #C74DED">0x</span><span style="color: #F39C12">40021000</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">0x</span><span style="color: #F39C12">400</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">  status = </span><span style="color: #96E072">&quot;okay&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">};</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># Vendor B</span></span>
<span class="line"><span style="color: #D5CED9">uart0: uart</span><span style="color: #EE5D43">@</span><span style="color: #F39C12">50003000</span><span style="color: #D5CED9"> {</span></span>
<span class="line"><span style="color: #D5CED9">  compatible = </span><span style="color: #96E072">&quot;vendorb,uart&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">  reg = </span><span style="color: #EE5D43">&lt;</span><span style="color: #C74DED">0x</span><span style="color: #F39C12">50003000</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">0x</span><span style="color: #F39C12">400</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">  status = </span><span style="color: #96E072">&quot;okay&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">};</span></span></code></pre></div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<p>
A Zephyr board typically does not describe all hardware in a single .dts file.
</p>

<p>

The main board devicetree file: 

<span class="highlight">zephyr/boards/&lt;vendor&gt;/&lt;board&gt;/&lt;board&gt;.dts</span>
<br>

usually includes one or more <span class="highlight">.dtsi</span> files that provide shared hardware descriptions, such as:

</p><ul>

<li> SoC configuration
</li>

<li> Pin control definitions
</li>

<li> Shared peripherals
</li>

<li> Common board-level hardware features
</li>

</ul>

This layered structure avoids duplication and allows related boards to reuse the same SoC and hardware definitions. During the build, the <span class="highlight">.dts</span>, included <span class="highlight">.dtsi</span> files, and any applicable overlays are merged into a final resolved devicetree:
<span class="highlight">build/&lt;project_name&gt;/zephyr/zephyr.dts</span>

<p></p>

<p>
This generated file represents the final hardware description used by the build system and is useful for verifying the effective configuration and debugging devicetree-related issues.
</p>

</div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="zephyr_devicetree_overlay" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Devicetree Overlays
</b>

<p>
Board devicetree files define the default hardware configuration for a board. However, applications often need to enable additional peripherals, modify existing properties, or describe application-specific hardware without changing the original board files. <b>Devicetree overlays</b> provide a flexible way to extend or override the board’s default hardware configuration at build time while keeping the base board definition unchanged.
</p>

<p>
Alternatively, an <span class="highlight">app.overlay</span> file can be created in the application root directory. If both <span class="highlight">app.overlay</span> and <span class="highlight">boards/&lt;board_name&gt;.overlay</span> are present, Zephyr uses the board-specific overlay for the selected board.
</p>


</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>└── apps/  
      └── project
             ├── CMakeLists.txt
             ├── Kconfig
             ├── prj.conf
             ├── extra.conf
             ├── app.overlay
             └── boards/
                  ├── &lt;board_name>.conf 
                  └── &lt;board_name>.overlay
             └── src/
                  └── main.c</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">└── apps/  </span></span>
<span class="line"><span style="color: #D5CED9">      └── project</span></span>
<span class="line"><span style="color: #D5CED9">             ├── CMakeLists.txt</span></span>
<span class="line"><span style="color: #D5CED9">             ├── Kconfig</span></span>
<span class="line"><span style="color: #D5CED9">             ├── prj.conf</span></span>
<span class="line"><span style="color: #D5CED9">             ├── extra.conf</span></span>
<span class="line"><span style="color: #D5CED9">             ├── app.overlay</span></span>
<span class="line"><span style="color: #D5CED9">             └── boards/</span></span>
<span class="line"><span style="color: #D5CED9">                  ├── &lt;board_name&gt;.conf </span></span>
<span class="line"><span style="color: #D5CED9">                  └── &lt;board_name&gt;.overlay</span></span>
<span class="line"><span style="color: #D5CED9">             └── src/</span></span>
<span class="line"><span style="color: #D5CED9">                  └── main.c</span></span></code></pre></div>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">
</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly># app.overlay
&amp;i2c1 {
  status = "okay";
  mpu6050: mpu6050@68 {
    compatible = "invensense,mpu6050";
    reg = &lt;0x68>;
  };
};

# boards/stm32f4_disco.overlay
/ {
  aliases {
    led0 = &amp;red_led_5;
    led1 = &amp;blue_led_6;
    led2 = &amp;green_led_4;
    led3 = &amp;orange_led_3;
		sw0 = &amp;user_button;
  };
};

&amp;adc1{
  pinctrl-0 = &lt;&amp;adc1_in1_pa1>;
  pinctrl-names = "default";
	st,adc-prescaler = &lt;4>;
	status = "okay";
};</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #A0A1A7CC"># app.overlay</span></span>
<span class="line"><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">i2c1 {</span></span>
<span class="line"><span style="color: #D5CED9">  status = </span><span style="color: #96E072">&quot;okay&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">  mpu6050: mpu6050</span><span style="color: #EE5D43">@</span><span style="color: #F39C12">68</span><span style="color: #D5CED9"> {</span></span>
<span class="line"><span style="color: #D5CED9">    compatible = </span><span style="color: #96E072">&quot;invensense,mpu6050&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">    reg = </span><span style="color: #EE5D43">&lt;</span><span style="color: #C74DED">0x</span><span style="color: #F39C12">68</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">  };</span></span>
<span class="line"><span style="color: #D5CED9">};</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># boards/stm32f4_disco.overlay</span></span>
<span class="line"><span style="color: #EE5D43">/</span><span style="color: #D5CED9"> {</span></span>
<span class="line"><span style="color: #D5CED9">  aliases {</span></span>
<span class="line"><span style="color: #D5CED9">    led0 = </span><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">red_led_5;</span></span>
<span class="line"><span style="color: #D5CED9">    led1 = </span><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">blue_led_6;</span></span>
<span class="line"><span style="color: #D5CED9">    led2 = </span><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">green_led_4;</span></span>
<span class="line"><span style="color: #D5CED9">    led3 = </span><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">orange_led_3;</span></span>
<span class="line"><span style="color: #D5CED9">		sw0 = </span><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">user_button;</span></span>
<span class="line"><span style="color: #D5CED9">  };</span></span>
<span class="line"><span style="color: #D5CED9">};</span></span>
<span class="line cbp-see-more-line "></span>
<span class="line"><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">adc1{</span></span>
<span class="line"><span style="color: #D5CED9">  pinctrl</span><span style="color: #EE5D43">-</span><span style="color: #F39C12">0</span><span style="color: #D5CED9"> = </span><span style="color: #EE5D43">&lt;&amp;</span><span style="color: #D5CED9">adc1_in1_pa1</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">  pinctrl</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">names = </span><span style="color: #96E072">&quot;default&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	st,adc</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">prescaler = </span><span style="color: #EE5D43">&lt;</span><span style="color: #F39C12">4</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	status = </span><span style="color: #96E072">&quot;okay&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">};</span></span></code></pre></div>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">

<p>
Devicetree overlays do not replace the board&#8217;s devicetree source file. Instead, they are merged with the base devicetree to extend or override its configuration.
</p>

<p>
Because overlays are applied during the build process, they can:
<ul>
<li> Override existing property values
</li>
<li> Change a node&#8217;s <span class="highlight">status</span>
</li>
<li> Add new nodes or properties
</li>
</ul>
The final devicetree is generated entirely at build time. Devicetree overlays do not provide runtime hardware reconfiguration.
</p>

</div>



<div class="article-text" style="margin-top:50px; margin-bottom:50px;">

<b id="zephyr_devicetree_build" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Devicetree Build Flow: Overlays, <span class="highlight">zephyr.dts</span>, and Generated Headers
</b>

<p>

The build process is:

</p><ul>
<li> Devicetree source files and overlays are merged into a single hardware description
</li>
<li> The merged result is written to <span class="highlight">zephyr.dts</span>
</li>
<li> Zephyr generates 
<span class="highlight">devicetree_generated.h</span> from the final devicetree
</li>
</ul>

The <span class="highlight">zephyr.dts</span> file represents the complete hardware description used for the build after all board definitions and overlays have been applied. It is especially useful for verifying the final configuration and debugging devicetree-related issues.

<p></p>


<p>
The <span class="highlight">devicetree_generated.h</span> file contains C macros generated from the final merged devicetree. These macros are automatically made available to the application and drivers during compilation.
</p>

<p>
They allow source code to:
</p><ul>
<li> Reference devicetree nodes
</li>
<li> Read properties defined in the devicetree
</li>
<li> Check whether a node or device is enabled
</li>
<li> Access hardware information such as addresses, interrupts, GPIOs, and other configuration data
</li>
</ul>
Application code and drivers do not parse <span class="highlight">.dts</span> files directly. Instead, they use the generated devicetree macros and helper APIs provided by Zephyr.
<p></p>

</div>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="283" src="https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_devicetree_build-1024x283.png" alt="" class="wp-image-8423" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_devicetree_build-1024x283.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_devicetree_build-300x83-1.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_devicetree_build-766x212.png 766w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_devicetree_build-1536x425.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_devicetree_build-2048x567.png 2048w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_devicetree_build-849x235.png 849w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:30px; margin-bottom:50px;">
</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(1 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>└── build/project/zephyr/
      ├── zephyr.dts (merged Devicetree output)
      └── include/generated/zephyr/
              └── devicetree_generated.h (Devicetree macros)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">└── build/project/zephyr/</span></span>
<span class="line"><span style="color: #D5CED9">      ├── zephyr.dts (merged Devicetree output)</span></span>
<span class="line"><span style="color: #D5CED9">      └── include/generated/zephyr/</span></span>
<span class="line"><span style="color: #D5CED9">              └── devicetree_generated.h (Devicetree macros)</span></span></code></pre></div>



<div class="article-text" style="margin-top:60px; margin-bottom:30px;">

<b id="zephyr_devicetree_node_modification" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Modifying Devicetree Nodes with Overlays
</b>

<p>
Board devicetree files define the default hardware configuration for most peripherals and devices. However, applications often need to enable a disabled peripheral, modify an existing property, or add application-specific hardware settings without changing the original board definition. Devicetree overlays provide a clean way to extend or override only the required parts of the hardware description.
</p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly># stm32f4.dtsi
adc1: adc@40012000 {
  compatible = "st,stm32f4-adc", "st,stm32-adc";
	reg = &lt;0x40012000 0x400>;
	clocks = &lt;&amp;rcc STM32_CLOCK(APB2, 8)>;
	clock-names = "adcx";
	interrupts = &lt;18 0>;
	#io-channel-cells = &lt;1>;
	st,adc-resolutions = &lt;12 10 8 6>;
	sampling-times = &lt;3 15 28 56 84 112 144 480>;
	st,adc-clock-source = "SYNC";
	st,adc-sequencer = "programmable";
	st,adc-oversampler = "none";
	st,adc-internal-regulator = "none";
	st,adc-has-injected-support;
	status = "disabled";
};

# stm32f4_disco.dts
&amp;adc1 {
	pinctrl-0 = &lt;&amp;adc1_in1_pa1 &amp;adc1_in6_pa6>;
	pinctrl-names = "default"; # Index 0 corresponds to "default"
	st,adc-prescaler = &lt;2>;
	status = "okay"; # Enable this hardware peripheral for use by Zephyr
};</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #A0A1A7CC"># stm32f4.dtsi</span></span>
<span class="line"><span style="color: #D5CED9">adc1: adc</span><span style="color: #EE5D43">@</span><span style="color: #F39C12">40012000</span><span style="color: #D5CED9"> {</span></span>
<span class="line"><span style="color: #D5CED9">  compatible = </span><span style="color: #96E072">&quot;st,stm32f4-adc&quot;</span><span style="color: #D5CED9">, </span><span style="color: #96E072">&quot;st,stm32-adc&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	reg = </span><span style="color: #EE5D43">&lt;</span><span style="color: #C74DED">0x</span><span style="color: #F39C12">40012000</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">0x</span><span style="color: #F39C12">400</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	clocks = </span><span style="color: #EE5D43">&lt;&amp;</span><span style="color: #D5CED9">rcc </span><span style="color: #FFE66D">STM32_CLOCK</span><span style="color: #D5CED9">(</span><span style="color: #F39C12">APB2</span><span style="color: #D5CED9">, </span><span style="color: #F39C12">8</span><span style="color: #D5CED9">)</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	clock</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">names = </span><span style="color: #96E072">&quot;adcx&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	interrupts = </span><span style="color: #EE5D43">&lt;</span><span style="color: #F39C12">18</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">0</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	</span><span style="color: #A0A1A7CC">#io-channel-cells = &lt;1&gt;;</span></span>
<span class="line"><span style="color: #D5CED9">	st,adc</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">resolutions = </span><span style="color: #EE5D43">&lt;</span><span style="color: #F39C12">12</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">10</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">8</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">6</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	sampling</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">times = </span><span style="color: #EE5D43">&lt;</span><span style="color: #F39C12">3</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">15</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">28</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">56</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">84</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">112</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">144</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">480</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	st,adc</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">clock</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">source = </span><span style="color: #96E072">&quot;SYNC&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	st,adc</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">sequencer = </span><span style="color: #96E072">&quot;programmable&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	st,adc</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">oversampler = </span><span style="color: #96E072">&quot;none&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	st,adc</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">internal</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">regulator = </span><span style="color: #96E072">&quot;none&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	st,adc</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">has</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">injected</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">support;</span></span>
<span class="line"><span style="color: #D5CED9">	status = </span><span style="color: #96E072">&quot;disabled&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">};</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># stm32f4_disco.dts</span></span>
<span class="line cbp-see-more-line "><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">adc1 {</span></span>
<span class="line"><span style="color: #D5CED9">	pinctrl</span><span style="color: #EE5D43">-</span><span style="color: #F39C12">0</span><span style="color: #D5CED9"> = </span><span style="color: #EE5D43">&lt;&amp;</span><span style="color: #D5CED9">adc1_in1_pa1 </span><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">adc1_in6_pa6</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	pinctrl</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">names = </span><span style="color: #96E072">&quot;default&quot;</span><span style="color: #D5CED9">; </span><span style="color: #A0A1A7CC"># Index 0 corresponds to &quot;default&quot;</span></span>
<span class="line"><span style="color: #D5CED9">	st,adc</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">prescaler = </span><span style="color: #EE5D43">&lt;</span><span style="color: #F39C12">2</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	status = </span><span style="color: #96E072">&quot;okay&quot;</span><span style="color: #D5CED9">; </span><span style="color: #A0A1A7CC"># Enable this hardware peripheral for use by Zephyr</span></span>
<span class="line"><span style="color: #D5CED9">};</span></span></code></pre></div>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">

<p>
Enable STM32 ADC1, configure PA1 as ADC1 channel 1 and PA6 as ADC1 channel 6, use these pins as ADC1&#8217;s default pin configuration, and configure the STM32-specific ADC clock prescaler.
</p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>pinctrl-0 = &lt;&amp;adc1_in1_pa1 &amp;adc1_in6_pa6>;

# PA1 -> ADC1_IN1
adc1_in1_pa1
     │   │
     │   └── PA1
     └────── ADC1 input channel 1

# PA6 -> ADC1_IN6
adc1_in6_pa6
     │   │
     │   └── PA6
     └────── ADC1 input channel 6     </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">pinctrl</span><span style="color: #EE5D43">-</span><span style="color: #F39C12">0</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">&lt;&amp;</span><span style="color: #D5CED9">adc1_in1_pa1 </span><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">adc1_in6_pa6</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># PA1 -&gt; ADC1_IN1</span></span>
<span class="line"><span style="color: #D5CED9">adc1_in1_pa1</span></span>
<span class="line"><span style="color: #D5CED9">     │   │</span></span>
<span class="line"><span style="color: #D5CED9">     │   └── </span><span style="color: #F39C12">PA1</span></span>
<span class="line"><span style="color: #D5CED9">     └────── </span><span style="color: #F39C12">ADC1</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">input</span><span style="color: #D5CED9"> channel </span><span style="color: #F39C12">1</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># PA6 -&gt; ADC1_IN6</span></span>
<span class="line"><span style="color: #D5CED9">adc1_in6_pa6</span></span>
<span class="line"><span style="color: #D5CED9">     │   │</span></span>
<span class="line"><span style="color: #D5CED9">     │   └── </span><span style="color: #F39C12">PA6</span></span>
<span class="line"><span style="color: #D5CED9">     └────── </span><span style="color: #F39C12">ADC1</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">input</span><span style="color: #D5CED9"> channel </span><span style="color: #F39C12">6</span><span style="color: #D5CED9">     </span></span></code></pre></div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<p>
<span class="highlight">boards/stm32f4_disco.overlay</span>
</p>

<p>
This overlay modifies the existing adc1 node for the <span class="highlight">stm32f4_disco</span> board and then defines one ADC channel configuration for the application.
</p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&amp;adc1 {
  # Overrides the board's default pinctrl list
  pinctrl-0 = &lt;&amp;adc1_in1_pa1>;
  # Reconfigures an ST-specific ADC clock prescaler
  st,adc-prescaler = &lt;4>;
  # Enables ADC1 
  status = "okay"; 
	
	# Creates a child node describing an ADC channel configuration
	channel@1 {
		reg = &lt;1>; # ADC channel 3
		# Sets the ADC gain to 1
		zephyr,gain = "ADC_GAIN_1";
		# Selects the ADC reference configuration used by Zephyr 
		zephyr,reference = "ADC_REF_INTERNAL";
		# Sets the ADC sample/acquisition time
		zephyr,acquisition-time = &lt;ADC_ACQ_TIME_DEFAULT>;
		# Perform the ADC conversion using 12-bit resolution 
		zephyr,resolution = &lt;12>;
	}; 
};</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9">adc1 {</span></span>
<span class="line"><span style="color: #D5CED9">  </span><span style="color: #A0A1A7CC"># Overrides the board&#39;s default pinctrl list</span></span>
<span class="line"><span style="color: #D5CED9">  pinctrl</span><span style="color: #EE5D43">-</span><span style="color: #F39C12">0</span><span style="color: #D5CED9"> = </span><span style="color: #EE5D43">&lt;&amp;</span><span style="color: #D5CED9">adc1_in1_pa1</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">  </span><span style="color: #A0A1A7CC"># Reconfigures an ST-specific ADC clock prescaler</span></span>
<span class="line"><span style="color: #D5CED9">  st,adc</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">prescaler = </span><span style="color: #EE5D43">&lt;</span><span style="color: #F39C12">4</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">  </span><span style="color: #A0A1A7CC"># Enables ADC1 </span></span>
<span class="line"><span style="color: #D5CED9">  status = </span><span style="color: #96E072">&quot;okay&quot;</span><span style="color: #D5CED9">; </span></span>
<span class="line"><span style="color: #D5CED9">	</span></span>
<span class="line"><span style="color: #D5CED9">	</span><span style="color: #A0A1A7CC"># Creates a child node describing an ADC channel configuration</span></span>
<span class="line"><span style="color: #D5CED9">	channel</span><span style="color: #EE5D43">@</span><span style="color: #F39C12">1</span><span style="color: #D5CED9"> {</span></span>
<span class="line"><span style="color: #D5CED9">		reg = </span><span style="color: #EE5D43">&lt;</span><span style="color: #F39C12">1</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">; </span><span style="color: #A0A1A7CC"># ADC channel 3</span></span>
<span class="line"><span style="color: #D5CED9">		</span><span style="color: #A0A1A7CC"># Sets the ADC gain to 1</span></span>
<span class="line"><span style="color: #D5CED9">		zephyr,gain = </span><span style="color: #96E072">&quot;ADC_GAIN_1&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">		</span><span style="color: #A0A1A7CC"># Selects the ADC reference configuration used by Zephyr </span></span>
<span class="line cbp-see-more-line "><span style="color: #D5CED9">		zephyr,reference = </span><span style="color: #96E072">&quot;ADC_REF_INTERNAL&quot;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">		</span><span style="color: #A0A1A7CC"># Sets the ADC sample/acquisition time</span></span>
<span class="line"><span style="color: #D5CED9">		zephyr,acquisition</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">time = </span><span style="color: #EE5D43">&lt;</span><span style="color: #F39C12">ADC_ACQ_TIME_DEFAULT</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">		</span><span style="color: #A0A1A7CC"># Perform the ADC conversion using 12-bit resolution </span></span>
<span class="line"><span style="color: #D5CED9">		zephyr,resolution = </span><span style="color: #EE5D43">&lt;</span><span style="color: #F39C12">12</span><span style="color: #EE5D43">&gt;</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">	}; </span></span>
<span class="line"><span style="color: #D5CED9">};</span></span></code></pre></div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<p>
Perform a pristine rebuild and inspect <span class="highlight">zephyr.dts</span>
</p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(1 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>└── build/project/zephyr/
      ├── zephyr.dts (merged Devicetree output)
      └── include/generated/zephyr/
              └── devicetree_generated.h (Devicetree macros)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">└── build/project/zephyr/</span></span>
<span class="line"><span style="color: #D5CED9">      ├── zephyr.dts (merged Devicetree output)</span></span>
<span class="line"><span style="color: #D5CED9">      └── include/generated/zephyr/</span></span>
<span class="line"><span style="color: #D5CED9">              └── devicetree_generated.h (Devicetree macros)</span></span></code></pre></div>



<div class="article-text" style="margin-top:60px; margin-bottom:30px;">

<b id="zephyr_devicetree_structure" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Zephyr Devicetree Structure: ADC Configuration Example
</b>


</div>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_stm32_devicetree-1024x576.png" alt="" class="wp-image-8662" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_stm32_devicetree-1024x576.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_stm32_devicetree-300x169.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_stm32_devicetree-768x432.png 768w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_stm32_devicetree-299x168.png 299w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_stm32_devicetree-1536x864.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_stm32_devicetree-849x478.png 849w, https://hangpersonal.com/wp-content/uploads/2026/09/zephyr_stm32_devicetree.png 1672w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">

<p>

<ul>

<li> <span class="highlight">adc1</span> is the node label. It allows references using <span class="highlight">&amp;adc1</span>
</li>

<li> <span class="highlight">adc@42028000</span> is the node name and unit address
</li>

</ul>

</p>

</div>



<div class="article-text" style="margin-top:60px; margin-bottom:40px;">

<b style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Reference
</b>

<p>
[1] <a href="https://docs.zephyrproject.org/latest/build/dts/index.html" style="color: blue;">Zephyr Devicetree</a>
<br>

[2] <a href="https://docs.zephyrproject.org/latest/build/dts/intro-syntax-structure.html" style="color: blue;">Zephyr Project Documentation &#8211; Devicetree syntax and structure</a>
<br>

</p>


</div>



<br><br>
<a href="#top" style="font-size:20px; color: blue;">Back to top of the page</a>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8278</post-id>	</item>
		<item>
		<title>STM32 Zephyr: Application Configuration with Kconfig</title>
		<link>https://hangpersonal.com/2026/09/06/stm32-zephyr-kconfig/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Mon, 07 Sep 2026 04:29:13 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=8274</guid>

					<description><![CDATA[STM32 Microcontroller and Zephyr RTOS Development STM32xx SoC Support Directory Zephyr Application Directory Zephyr Kconfig Configuration Flow Zephyr uses Kconfig as its primary configuration system to control which features are enabled, how subsystems behave, and how the final firmware image is built. Instead of hardcoding feature choices into source files, developers can use Kconfig to...]]></description>
										<content:encoded><![CDATA[
<a href="https://hangpersonal.com/embedded-system/stm32-mcu/zephyr-tutorials/" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
STM32 Microcontroller and Zephyr RTOS Development
</a>
<br><br>



<ul style="margin-top:30px; margin-bottom:30px;">

<li style="margin-bottom:16px;">
<a href="#zephyr_stm32_soc_dir" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
STM32xx SoC Support Directory
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#zephyr_app_dir" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Zephyr Application Directory
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#zephyr_kconfig_flow" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Zephyr Kconfig Configuration Flow
</a>
</li> 

</ul>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">

<p>
Zephyr uses Kconfig as its primary configuration system to control which features are enabled, how subsystems behave, and how the final firmware image is built. Instead of hardcoding feature choices into source files, developers can use Kconfig to manage configuration in a structured and scalable way, making it easier to adapt applications across boards and use cases. Zephyr applications often need to enable features such as logging, networking, or debugging support while keeping unnecessary code out of the final firmware.
</p>

<p>

</p><ul>

<li> Each feature, such as a driver, network stack, or logging option, is controlled by a  <span class="highlight">CONFIG_</span> setting.
</li>

<li> These <span class="highlight">CONFIG_</span> settings are enabled or configured in the  <span class="highlight">prj.conf</span> file
</li>

</ul>

<p></p>

<p>
The file <span class="highlight">prj.conf</span> defines project-specific configuration options by setting Kconfig symbols that enable, disable, or customize Zephyr features, drivers, subsystems, and build settings.
</p>



</div>



<div class="article-text" style="margin-top:10px; margin-bottom:20px;">

<b id="zephyr_stm32_soc_dir" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
STM32xx SoC Support Directory
</b>

<p>
Provides the common SoC-level support used by STM32xx-based boards, including Kconfig definitions and defaults, CMake build integration, early SoC initialization, shared headers, and power-management or power-off functionality. It contains code and configuration that are specific to the STM32xx family but shared across multiple STM32xx boards.
</p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>└── zephyr/
      └── soc/st/stm32/
              └── stm32f4x/
                     ├── CMakeLists.txt
                     ├── Kconfig
                     ├── Kconfig.defconfig
                     ├── Kconfig.soc
                     ├── power.c
                     ├── poweroff.c
                     ├── soc.c
                     └── soc.h
              └── stm32f7x/
                     ├── CMakeLists.txt
                     ├── Kconfig
                     ├── Kconfig.defconfig
                     ├── Kconfig.defconfig.stm32f765xx                  
                     ├── Kconfig.defconfig.stm32f767xx
                     ├── Kconfig.defconfig.stm32f769xx
                     ├── Kconfig.soc
                     ├── soc.c
                     └── soc.h
              └── stm32h7x/
                     ├── CMakeLists.txt
                     ├── Kconfig
                     ├── Kconfig.defconfig
                     ├── Kconfig
                     ├── Kconfig.defconfig.stm32h745xx                  
                     ├── Kconfig.defconfig.stm32h747xx
                     ├── Kconfig.defconfig.stm32h755xx
                     ├── Kconfig.defconfig.stm32h757xx
                     ├── Kconfig.soc
                     ├── mpu_regions.c
                     ├── sections.ld
                     ├── soc_m4.c
                     ├── soc_m7.c
                     └── soc.h                                                </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">└── zephyr/</span></span>
<span class="line"><span style="color: #D5CED9">      └── soc/st/stm32/</span></span>
<span class="line"><span style="color: #D5CED9">              └── stm32f4x/</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── CMakeLists.txt</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.defconfig</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.soc</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── power.c</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── poweroff.c</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── soc.c</span></span>
<span class="line"><span style="color: #D5CED9">                     └── soc.h</span></span>
<span class="line"><span style="color: #D5CED9">              └── stm32f7x/</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── CMakeLists.txt</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig</span></span>
<span class="line cbp-see-more-line "><span style="color: #D5CED9">                     ├── Kconfig.defconfig</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.defconfig.stm32f765xx                  </span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.defconfig.stm32f767xx</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.defconfig.stm32f769xx</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.soc</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── soc.c</span></span>
<span class="line"><span style="color: #D5CED9">                     └── soc.h</span></span>
<span class="line"><span style="color: #D5CED9">              └── stm32h7x/</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── CMakeLists.txt</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.defconfig</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.defconfig.stm32h745xx                  </span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.defconfig.stm32h747xx</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.defconfig.stm32h755xx</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.defconfig.stm32h757xx</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── Kconfig.soc</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── mpu_regions.c</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── sections.ld</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── soc_m4.c</span></span>
<span class="line"><span style="color: #D5CED9">                     ├── soc_m7.c</span></span>
<span class="line"><span style="color: #D5CED9">                     └── soc.h                                                </span></span></code></pre></div>



<div class="article-text" style="margin-top:50px; margin-bottom:20px;">

<b id="" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
Example of <span class="highlight">prj.conf</span>
</b>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly># GPIO
CONFIG_GPIO=y

# ADC
CONFIG_ADC=y

# I2C
CONFIG_I2C=y

# Serial / UART
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y

# Console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_PRINTK=y

# Logging
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_PROCESS_THREAD=y
CONFIG_ASSERT=y

# C Library
CONFIG_MINIMAL_LIBC=y
CONFIG_PICOLIBC=n
CONFIG_NEWLIB_LIBC=n

# Increase the main thread stack size
CONFIG_MAIN_STACK_SIZE=4096</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #A0A1A7CC"># GPIO</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_GPIO</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># ADC</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_ADC</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># I2C</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_I2C</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># Serial / UART</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_SERIAL</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_UART_INTERRUPT_DRIVEN</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># Console</span></span>
<span class="line cbp-see-more-line "><span style="color: #F39C12">CONFIG_CONSOLE</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_UART_CONSOLE</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_STDOUT_CONSOLE</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_PRINTK</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># Logging</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_LOG</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_LOG_DEFAULT_LEVEL</span><span style="color: #EE5D43">=</span><span style="color: #F39C12">3</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_LOG_MODE_DEFERRED</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_LOG_PROCESS_THREAD</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_ASSERT</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># C Library</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_MINIMAL_LIBC</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">y</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_PICOLIBC</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">n</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_NEWLIB_LIBC</span><span style="color: #EE5D43">=</span><span style="color: #D5CED9">n</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># Increase the main thread stack size</span></span>
<span class="line"><span style="color: #F39C12">CONFIG_MAIN_STACK_SIZE</span><span style="color: #EE5D43">=</span><span style="color: #F39C12">4096</span></span></code></pre></div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="zephyr_app_dir" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
Zephyr Application Directory
</b>

<p>
</p><ul>

<li> <span class="highlight">CMakeLists.txt</span>: Connects the project to Zephyr&#8217;s build system 
</li>

<li> <span class="highlight">Kconfig</span>: Defines application options, their types, defaults, and dependencies
</li>

<li> <span class="highlight">prj.conf</span>: Configures application, Zephyr, and module features by setting option values
</li>

<li> <span class="highlight">extra.conf</span>: Optional Kconfig configuration fragment used to add or override settings in <span class="highlight">prj.conf</span> for a particular build
</li>

<li> <span class="highlight">&lt;board_name&gt;.conf</span>: Board-specific Kconfig settings
</li>

<li> <span class="highlight">&lt;board_name&gt;.overlay</span>: Board-specific Devicetree hardware changes
</li>

</ul>
<p></p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>└── apps/  
      └── project_1
             ├── CMakeLists.txt
             ├── Kconfig
             ├── prj.conf
             ├── extra_1.conf
             ├── extra_2.conf
             └── boards/
                  ├── &lt;board_name_1>.conf 
                  ├── &lt;board_name_1>.overlay
                  ├── &lt;board_name_2>.conf
                  └── &lt;board_name_2>.overlay
             └── src/
                  └── main.c</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">└── apps/  </span></span>
<span class="line"><span style="color: #D5CED9">      └── project_1</span></span>
<span class="line"><span style="color: #D5CED9">             ├── CMakeLists.txt</span></span>
<span class="line"><span style="color: #D5CED9">             ├── Kconfig</span></span>
<span class="line"><span style="color: #D5CED9">             ├── prj.conf</span></span>
<span class="line"><span style="color: #D5CED9">             ├── extra_1.conf</span></span>
<span class="line"><span style="color: #D5CED9">             ├── extra_2.conf</span></span>
<span class="line"><span style="color: #D5CED9">             └── boards/</span></span>
<span class="line"><span style="color: #D5CED9">                  ├── &lt;board_name_1&gt;.conf </span></span>
<span class="line"><span style="color: #D5CED9">                  ├── &lt;board_name_1&gt;.overlay</span></span>
<span class="line"><span style="color: #D5CED9">                  ├── &lt;board_name_2&gt;.conf</span></span>
<span class="line"><span style="color: #D5CED9">                  └── &lt;board_name_2&gt;.overlay</span></span>
<span class="line"><span style="color: #D5CED9">             └── src/</span></span>
<span class="line"><span style="color: #D5CED9">                  └── main.c</span></span></code></pre></div>



<div class="article-text" style="margin-top:50px; margin-bottom:20px;">

<b id="zephyr_kconfig_flow" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
Zephyr Kconfig Configuration Flow
</b>

<p>
When a Zephyr application is built, the build system first runs the Kconfig configuration phase. During this phase:

</p><ul>

<li> Load Kconfig definitions from Zephyr, modules, and the application
</li>

<li> Load board defaults from <span class="highlight">&lt;BOARD&gt;_defconfig</span>
</li>

<li> Merge application settings from <span class="highlight">prj.conf</span>, followed by additional <span class="highlight">&lt;FRAGMENT&gt;.conf</span> fragments
</li>

<li> Resolve Kconfig defaults, dependencies, and symbol selections
</li>

<li> Save the resolved configuration to <span class="highlight">.config</span>
</li>

<li> Generate <span class="highlight">autoconf.h</span> with configuration macros used during compilation
</li>

</ul>

<p></p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(1 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly># The resulting configuration is stored in:
&lt;build-dir>/zephyr/.config

# The build system also generates:
&lt;build-dir>/zephyr/include/generated/zephyr/autoconf.h</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #A0A1A7CC"># The resulting configuration is stored in:</span></span>
<span class="line"><span style="color: #EE5D43">&lt;</span><span style="color: #D5CED9">build</span><span style="color: #EE5D43">-</span><span style="color: #FFE66D">dir</span><span style="color: #EE5D43">&gt;/</span><span style="color: #D5CED9">zephyr</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">.config</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC"># The build system also generates:</span></span>
<span class="line"><span style="color: #EE5D43">&lt;</span><span style="color: #D5CED9">build</span><span style="color: #EE5D43">-</span><span style="color: #FFE66D">dir</span><span style="color: #EE5D43">&gt;/</span><span style="color: #D5CED9">zephyr</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">include</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">generated</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">zephyr</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">autoconf.h</span></span></code></pre></div>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">
</div>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="262" src="https://hangpersonal.com/wp-content/uploads/2026/09/kconfig_flow-1024x262.png" alt="" class="wp-image-8369" style="object-fit:cover" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/kconfig_flow-1024x262.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/kconfig_flow-300x77.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/kconfig_flow-765x196.png 765w, https://hangpersonal.com/wp-content/uploads/2026/09/kconfig_flow-1536x393.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/09/kconfig_flow-2048x525.png 2048w, https://hangpersonal.com/wp-content/uploads/2026/09/kconfig_flow-297x76.png 297w, https://hangpersonal.com/wp-content/uploads/2026/09/kconfig_flow-847x217.png 847w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<div class="article-text" style="margin-top:60px; margin-bottom:40px;">

<b style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Reference
</b>

<p>
[1] <a href="https://docs.zephyrproject.org/latest/build/kconfig/index.html" style="color: blue;">Zephyr Configuration System (Kconfig)</a>
<br>

[2] <a href="https://docs.zephyrproject.org/latest/build/kconfig/setting.html" style="color: blue;">Zephyr: Setting Kconfig Configuration Values</a>
<br>

</p>


</div>



<br><br>
<a href="#top" style="font-size:20px; color: blue;">Back to top of the page</a>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8274</post-id>	</item>
		<item>
		<title>TI C2000 C28x Microcontroller with FreeRTOS</title>
		<link>https://hangpersonal.com/2026/09/05/c2000-c28x-freertos/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Sun, 06 Sep 2026 04:22:03 +0000</pubDate>
				<category><![CDATA[Embedded System]]></category>
		<category><![CDATA[FreeRTOS]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=8200</guid>

					<description><![CDATA[This Guide Is Still Being Expanded &#8211; More to Come STM32 Microcontroller and FreeRTOS Development FreeRTOS on TI C2000 C28x vs. STM32 MCUs Stack Differences FreeRTOS Data Type Mapping for TI C2000 C28x MCU Heap and Memory Differences Interrupt Model Example: FreeRTOS Demo for F28377S Coreboard V1.3 FreeRTOS on TI C2000 C28x vs. STM32 MCUs...]]></description>
										<content:encoded><![CDATA[
<p>
<span style="font-size: 22px; color: green;">
This Guide Is Still Being Expanded &#8211; More to Come
</span>
</p>



<a href="https://hangpersonal.com/embedded-system/stm32-mcu/freertos-tutorials/" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
STM32 Microcontroller and FreeRTOS Development
</a>
<br><br>



<ul style="margin-top:30px; margin-bottom:30px;">

<li style="margin-bottom:16px;">
<a href="#freertos_c2000_stm32" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
FreeRTOS on TI C2000 C28x vs. STM32 MCUs
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#freertos_c2000_stack_difference" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Stack Differences
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#freertos_c2000_data_type" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
FreeRTOS Data Type Mapping for TI C2000 C28x MCU
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#freertos_c2000_heap_memory" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Heap and Memory Differences
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#freertos_c2000_interrupt" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Interrupt Model
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#freertos_c2000_example" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Example: FreeRTOS Demo for F28377S Coreboard V1.3
</a>
</li> 


</ul>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="freertos_c2000_stm32" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
FreeRTOS on TI C2000 C28x vs. STM32 MCUs
</b>

</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode spbtbl-fullwidth" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS on TI C2000 C28x vs STM32"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">Setting</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">TI C2000 C28x (TMS320F2837xx)</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">STM32F407xx</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >CPU architecture</td>                                    <td style="font-size:18px !important;" itemprop="description" >TI C28x, 16-bit address unit</td>                                    <td style="font-size:18px !important;" itemprop="description" >ARM Cortex-M4F, 8-bit byte</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >CPU clock</td>                                    <td style="font-size:18px !important;" itemprop="description" >Up to 200 MHz</td>                                    <td style="font-size:18px !important;" itemprop="description" >Up to 168 MHz</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Tick rate</td>                                    <td style="font-size:18px !important;" itemprop="description" >1 kHz</td>                                    <td style="font-size:18px !important;" itemprop="description" >1 kHz</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >FreeRTOS tick source</td>                                    <td style="font-size:18px !important;" itemprop="description" >CPU Timer 2</td>                                    <td style="font-size:18px !important;" itemprop="description" >Cortex-M SysTick</td>                            </tr>
                                            </tbody>
                </table>
                            </div>




<div class="article-text" style="margin-top:20px; margin-bottom:30px;">

<b id="freertos_c2000_stack_difference" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
Stack Differences
</b>

</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode spbtbl-fullwidth" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS on TI C2000 C28x vs STM32 Stack Differences"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">Property</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">TI C2000 C28x (TMS320F2837xx)</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">STM32F407xx</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">CHAR_BIT</span></td>                                    <td style="font-size:18px !important;" itemprop="description" >16</td>                                    <td style="font-size:18px !important;" itemprop="description" >8</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">sizeof(StackType_t)</span></td>                                    <td style="font-size:18px !important;" itemprop="description" >1 C byte = 16 bits</td>                                    <td style="font-size:18px !important;" itemprop="description" >4 bytes = 32 bits</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Physical bytes per stack element</td>                                    <td style="font-size:18px !important;" itemprop="description" >2</td>                                    <td style="font-size:18px !important;" itemprop="description" >4</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Stack growth</td>                                    <td style="font-size:18px !important;" itemprop="description" >Upward</td>                                    <td style="font-size:18px !important;" itemprop="description" >Downward</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">BaseType_t</span></td>                                    <td style="font-size:18px !important;" itemprop="description" >16-bit</td>                                    <td style="font-size:18px !important;" itemprop="description" >32-bit</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Stack alignment</td>                                    <td style="font-size:18px !important;" itemprop="description" >2 C address units = 4 physical bytes</td>                                    <td style="font-size:18px !important;" itemprop="description" >8 physical bytes</td>                            </tr>
                                            </tbody>
                </table>
                            </div>




<div class="article-text" style="margin-top:10px; margin-bottom:30px;">

<p>
On TI C2000, FreeRTOS-allocated memory begins on a boundary aligned to two C28x address units, equivalent to four conventional bytes. On STM32, FreeRTOS-allocated memory begins on an 8-byte boundary, meaning its starting address is a multiple of eight.
</p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(1 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>// TI C2000 C28x, portmacro.h
#define portBYTE_ALIGNMENT 2

// STM32, portmacro.h
#define portBYTE_ALIGNMENT 8</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #A0A1A7CC">// TI C2000 C28x, portmacro.h</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">portBYTE_ALIGNMENT</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">2</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// STM32, portmacro.h</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">portBYTE_ALIGNMENT</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">8</span></span></code></pre></div>



<div class="article-text" style="margin-top:60px; margin-bottom:30px;">

<b id="freertos_c2000_data_type" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
FreeRTOS Data Type Mapping for TI C2000 C28x MCU
</b>

</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode spbtbl-fullwidth" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS C2000 C28x Data Type"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">FreeRTOS Type</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">C28x Underlying Type</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">BaseType_t</span></td>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">int16_t</span></td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">UBaseType_t</span></td>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">uint16_t</span></td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">StackType_t</span></td>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">uint16_t</span></td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">TickType_t</span></td>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">uint32_t</span></td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">portCHAR</span></td>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">uint16_t</span></td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">portSHORT</span></td>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">uint16_t</span></td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">portLONG</span></td>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">uint32_t</span></td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">portBASE_TYPE</span></td>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">uint16_t</span></td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">portSTACK_TYPE</span></td>                                    <td style="font-size:18px !important;" itemprop="description" ><span class="highlight">uint16_t</span></td>                            </tr>
                                            </tbody>
                </table>
                            </div>




<div class="article-text" style="margin-top:30px; margin-bottom:30px;">

<b id="freertos_c2000_heap_memory" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Heap and Memory Differences
</b>

<p>
The C28 project explicitly declares <span class="highlight">ucHeap[]</span> and places it in <span class="highlight">.freertosHeap</span>. The STM32 project lets <span class="highlight">heap_4.c</span> declare the heap internally in <span class="highlight">.bss</span>.
</p>

<p>
The C28x stack pointer is more restricted than the Cortex-M stack pointer. C28x task stacks generally must reside in the lower, stack-addressable data-memory range. This is why C28x projects often explicitly place the FreeRTOS heap in a suitable RAM section:
</p>

<p>
With FPU32 enabled, C28x saves floating-point state on every task context switch, increasing task stack usage. Cortex-M4F typically uses lazy FPU stacking, saving extra floating-point registers only when needed.
</p>

<p>
On C28x, a request of <span class="highlight">100</span> allocates 100 sixteen-bit addressable units because the smallest addressable unit is 16 bits. This corresponds to 200 conventional eight-bit bytes of physical storage. On STM32, a request of 100 allocates <span class="highlight">100</span> standard eight-bit bytes, since memory is byte-addressable.
</p>

</div>



<div class="article-text" style="margin-top:60px; margin-bottom:30px;">

<b id="freertos_c2000_interrupt" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Interrupt Model
</b>

<p>
C2000 does not use NVIC or <span class="highlight">BASEPRI</span>. It uses:
</p><ul>
<li> <span class="highlight">INTM</span>: global maskable-interrupt enable/disable bit
</li>
<li> <span class="highlight">IER</span>: CPU interrupt enable register
</li>
<li> <span class="highlight">IFR</span>: CPU interrupt flag register
</li>
<li> PIE: Peripheral Interrupt Expansion controller
</li>
<li> PIE: Peripheral Interrupt Expansion controller
</li> CPU interrupt groups <span class="highlight">INT1</span> through <span class="highlight">INT14</span>
</ul>
<p></p>

</div>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">

The C28x port protects the kernel using the global <span class="highlight">INTM</span> bit:

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(1 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>// portmacro.h
#define portDISABLE_INTERRUPTS() __asm(" setc INTM")
#define portENABLE_INTERRUPTS()  __asm(" clrc INTM")</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #A0A1A7CC">// portmacro.h</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">portDISABLE_INTERRUPTS</span><span style="color: #D5CED9">() </span><span style="color: #FFE66D">__asm</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot; setc INTM&quot;</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">portENABLE_INTERRUPTS</span><span style="color: #D5CED9">()  </span><span style="color: #FFE66D">__asm</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot; clrc INTM&quot;</span><span style="color: #D5CED9">)</span></span></code></pre></div>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">

Therefore, during a FreeRTOS critical section:

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(1 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>INTM = 1 -> all normal maskable C28x interrupts are disabled
INTM = 0 -> normal maskable interrupts are allowed</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">INTM = 1 -&gt; all normal maskable C28x interrupts are disabled</span></span>
<span class="line"><span style="color: #D5CED9">INTM = 0 -&gt; normal maskable interrupts are allowed</span></span></code></pre></div>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">

Unlike STM32, C2000 FreeRTOS does not leave a class of high-priority maskable interrupts running. Consequently, it does not need a “maximum syscall interrupt priority” boundary.

</div>



<div class="article-text" style="margin-top:60px; margin-bottom:30px;">

<b id="freertos_c2000_example" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:30px;">
Example: FreeRTOS Demo for F28377S Coreboard V1.3
</b>

<p>
<a href="https://gitea.cuihang1201.synology.me/hangpersonal/TI_C2000_F28377S_FreeRTOS" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
FreeRTOS TI C2000 F28377S Demo Code
</a>
</p>

</div>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="882" src="https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-1024x882.png" alt="" class="wp-image-8259" style="width:400px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-1024x882.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-300x258.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-767x661.png 767w, https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-299x258.png 299w, https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front-850x732.png 850w, https://hangpersonal.com/wp-content/uploads/2026/09/f28377s_coreboard_front.png 1047w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">
</div>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="745" src="https://hangpersonal.com/wp-content/uploads/2026/09/UART_SCIA-1-1024x745.png" alt="" class="wp-image-8265" style="width:1000px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/09/UART_SCIA-1-1024x745.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/09/UART_SCIA-1-300x218-1.png 300w, https://hangpersonal.com/wp-content/uploads/2026/09/UART_SCIA-1-767x558.png 767w, https://hangpersonal.com/wp-content/uploads/2026/09/UART_SCIA-1-850x618.png 850w, https://hangpersonal.com/wp-content/uploads/2026/09/UART_SCIA-1.png 1294w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<br><br>
<a href="#top" style="font-size:20px; color: blue;">Back to top of the page</a>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8200</post-id>	</item>
		<item>
		<title>Light Weight Internet Protocol (LwIP)</title>
		<link>https://hangpersonal.com/2026/08/12/lwip/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Wed, 12 Aug 2026 17:21:48 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=8098</guid>

					<description><![CDATA[Embedded Communication Interfaces Protocols of the LwIP Stack Protocol Files of LwIP Stack Ethernet Controller Interface Buffer Management Types of pbufs APIs for Managing pbufs Protocols of the LwIP Stack IPv4 and IPv6 (Internet Protocol v4 and v6) TCP (Transmission Control Protocol) UDP (User Datagram Protocol) DNS (Domain Name Server) SNMP (Simple Network Management Protocol)...]]></description>
										<content:encoded><![CDATA[
<a href="https://hangpersonal.com/embedded-system/comm-interfaces/" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Embedded Communication Interfaces
</a>
<br><br>



<ul style="margin-top:30px; margin-bottom:30px;">

<li style="margin-bottom:16px;">
<a href="#lwip_protocol_stack" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Protocols of the LwIP Stack
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#lwip_file" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Protocol Files of LwIP Stack
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#lwip_eth_interface" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Ethernet Controller Interface
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#lwip_buffer_management" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Buffer Management
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#lwip_pbufs" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Types of pbufs
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#lwip_pbufs_api" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
APIs for Managing pbufs
</a>
</li> 

</ul>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="lwip_protocol_stack" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
Protocols of the LwIP Stack
</b>

<p>
</p><ul>
<li>IPv4 and IPv6 (Internet Protocol v4 and v6)
</li>

<li>TCP (Transmission Control Protocol)
</li>

<li>UDP (User Datagram Protocol)
</li>

<li>DNS (Domain Name Server)
</li>

<li>SNMP (Simple Network Management Protocol)
</li>

<li>DHCP (Dynamic Host Configuration Protocol)
</li>

<li>PPP (Point to Point Protocol)
</li>

<li>ARP (Address Resolution Protocol)
</li>

<li>ICMP (Internet Control Message Protocol)
</li>

<li>IGMP (Internet Group Management Protocol)
</li>

</ul>
<p></p>

</div>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="634" src="https://hangpersonal.com/wp-content/uploads/2026/08/lwip_protocol_stack-1024x634.png" alt="" class="wp-image-8112" style="width:700px" srcset="https://hangpersonal.com/wp-content/uploads/2026/08/lwip_protocol_stack-1024x634.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/08/lwip_protocol_stack-300x186.png 300w, https://hangpersonal.com/wp-content/uploads/2026/08/lwip_protocol_stack-768x476.png 768w, https://hangpersonal.com/wp-content/uploads/2026/08/lwip_protocol_stack-1536x951.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/08/lwip_protocol_stack-850x526.png 850w, https://hangpersonal.com/wp-content/uploads/2026/08/lwip_protocol_stack.png 1594w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="lwip_file" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
Protocol Files of LwIP Stack
</b>

<p>
<ul>
<li>Application Layer: <span class="highlight">dhcp.c</span>, <span class="highlight">dns.c</span>
</li>

<li>Transport Layer: <span class="highlight">udp.c</span>, <span class="highlight">tcp.c</span>
</li>

<li>Internet Layer: <span class="highlight">ip.c</span>
</li>

<li>Network Interface Layer: <span class="highlight">netif.c</span>
</li>

</ul>
</p>

</div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

    <b id="lwip_eth_interface" style="
        display:block;
        font-family:'Inter', sans-serif;
        font-size:22px;
        color:black;
        margin-top:0;
        margin-bottom:20px;">
        Ethernet Controller Interface
    </b>

    <ol style="
        margin-top:0;
        margin-bottom:0;
        margin-left:0;
        padding-left:22px;">

        <li style="margin-bottom:20px;">
            The official LwIP core stack is hardware-independent and does not include
            MCU-specific Ethernet MAC/PHY drivers. Hardware-specific drivers are normally
            provided by the MCU vendor, SDK, BSP, or application.
        </li>

        <li style="margin-bottom:20px;">
            For MCU integrations, such as STM32 projects generated by STM32CubeMX,
            a file named <span class="highlight">ethernetif.c</span> provides the interface
            between the LwIP network stack and the underlying Ethernet hardware driver.
        </li>

        <li style="margin-bottom:20px;">
            The <span class="highlight">ethernetif.c</span> is essentially a
            hardware-abstraction/adaptation layer. It must be implemented or customized
            for the target MCU, Ethernet MAC, PHY, DMA configuration, and operating environment.
        </li>

        <li style="margin-bottom:20px;">
            The main responsibility of <span class="highlight">ethernetif.c</span> is to
            transfer Ethernet frames between LwIP and the low-level Ethernet driver:

            <ul style="
                margin-top:8px;
                margin-bottom:0;
                margin-left:0;
                padding-left:0;
                list-style-position:inside;">

                <li style="margin-bottom:6px;">
                    <b>Transmit</b>:
                    LwIP <span class="highlight">pbuf</span>
                    &rarr;
                    <span class="highlight">ethernetif.c</span>
                    &rarr;
                    Ethernet MAC/DMA driver
                    &rarr;
                    Ethernet hardware
                </li>

                <li>
                    <b>Receive</b>:
                    Ethernet hardware
                    &rarr;
                    Ethernet MAC/DMA driver
                    &rarr;
                    <span class="highlight">ethernetif.c</span>
                    &rarr;
                    LwIP <span class="highlight">pbuf</span>
                </li>

            </ul>
        </li>

        <li style="margin-bottom:20px;">
            Typical functions implemented in
            <span class="highlight">ethernetif.c</span> include:

            <ul style="
                margin-top:8px;
                margin-bottom:0;
                margin-left:0;
                padding-left:0;
                list-style-position:inside;">

                <li style="margin-bottom:6px;">
                  <span class="highlight">low_level_init()</span>: initializes the Ethernet interface and related hardware
                </li>

                <li style="margin-bottom:6px;">
                  <span class="highlight">low_level_output()</span>: sends an Ethernet frame
                </li>

                <li style="margin-bottom:6px;">
                  <span class="highlight">low_level_input()</span>: receives an Ethernet frame
                </li>

                <li style="margin-bottom:6px;">
                  <span class="highlight">ethernetif_input()</span>: passes received packets to the LwIP stack
                </li>

                <li style="margin-bottom:6px;">
                  <span class="highlight">ethernetif_init()</span>: initializes and registers the network interface
                </li>

            </ul>

        </li>

    </ol>

</div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

    <b id="lwip_buffer_management" style="
        display:block;
        font-family:'Inter', sans-serif;
        font-size:22px;
        color:black;
        margin-top:0;
        margin-bottom:20px;">
        Buffer Management
    </b>

    <ol style="
        margin-top:0;
        margin-bottom:0;
        margin-left:0;
        padding-left:22px;">

        <li style="margin-bottom:20px;">
            A <span class="highlight">pbuf</span> (packet buffer) is a core LwIP data structure used to store and manage network packet data.
        </li>

        <li style="margin-bottom:20px;">
            A <span class="highlight">pbuf</span> can either contain dynamically allocated packet data or reference packet data stored elsewhere, 
            including RAM or ROM, depending on the <span class="highlight">pbuf</span> type and allocation method.
        </li>

        <li style="margin-bottom:20px;">
            A single packet may be divided across multiple <span class="highlight">pbuf</span> structures linked together through the 
            <span class="highlight">next</span> pointer. This is called a <b>pbuf chain</b>.
        </li>

        <li style="margin-bottom:20px;">
            Multiple packets can also be linked using the same <span class="highlight">next</span> pointer mechanism, forming a <b>packet queue</b>. LwIP distinguishes 
            packet boundaries using fields such as <span class="highlight">len</span> and <span class="highlight">tot_len</span>.
        </li>

        <li style="margin-bottom:20px;">
            Important fields in <span class="highlight">struct pbuf</span> include:

            <ul style="
                margin-top:8px;
                margin-bottom:0;
                margin-left:0;
                padding-left:0;
                list-style-position:inside;">

                <li style="margin-bottom:6px;">
                    <b>next</b>: pointer to next <span class="highlight">pbuf</span> in a pbuf chain
                </li>

                <li>
                    <b>payload</b>: pointer to packet data
                </li>

                <li style="margin-bottom:6px;">
                    <b>len</b>: number of data bytes stored in the current <span class="highlight">pbuf</span>
                </li>

                <li style="margin-bottom:6px;">
                    <b>tot_len</b>: total number of bytes from the current <span class="highlight">pbuf</span> to the end of the current packet
                </li>

                <li style="margin-bottom:6px;">
                    <b>ref (on 4 bits)</b>: reference count that indicates the number of pointers that reference the <span class="highlight">pbuf</span>. 
                    A <span class="highlight">pbuf</span> can be released from memory only when its reference count is zero
                </li>

            </ul>

        </li>

    </ol>

</div>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="411" src="https://hangpersonal.com/wp-content/uploads/2026/08/lwip_buf-1024x411.png" alt="" class="wp-image-8161" style="width:850px" srcset="https://hangpersonal.com/wp-content/uploads/2026/08/lwip_buf-1024x411.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/08/lwip_buf-300x121.png 300w, https://hangpersonal.com/wp-content/uploads/2026/08/lwip_buf-768x309.png 768w, https://hangpersonal.com/wp-content/uploads/2026/08/lwip_buf-1536x617.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/08/lwip_buf-850x341.png 850w, https://hangpersonal.com/wp-content/uploads/2026/08/lwip_buf.png 1934w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

    <b id="lwip_pbufs" style="
        display:block;
        font-family:'Inter', sans-serif;
        font-size:22px;
        color:black;
        margin-top:0;
        margin-bottom:20px;">
        Types of pbufs
    </b>

    <ol style="
        margin-top:0;
        margin-bottom:0;
        margin-left:0;
        padding-left:22px;">

        <b style="display:block; margin-bottom:12px; font-size:20px;">PBUF_POOL</b>

        <li style="margin-bottom:20px;">
            With <span class="highlight">PBUF_POOL</span>, pbufs are allocated from a statically configured memory 
            pool containing a fixed number of fixed-size buffers.
        </li>

        <li style="margin-bottom:20px;">
            Each allocated pbuf contains both the <span class="highlight">pbuf</span> structure and a payload buffer.
        </li>

        <li style="margin-bottom:20px;">
            If the packet is larger than the payload capacity of a single pool buffer, LwIP allocates multiple pbufs 
            and links them together to form a <b>pbuf chain</b>.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">PBUF_POOL</span> is commonly used for receiving Ethernet packets, where fast and 
            predictable allocation is important.
        </li>

    </ol>

    <ol style="
        margin-top:0;
        margin-bottom:0;
        margin-left:0;
        padding-left:22px;">

        <b style="display:block; margin-bottom:12px; font-size:20px;">PBUF_RAM</b>

        <li style="margin-bottom:20px;">
            With <span class="highlight">PBUF_RAM</span>, memory is dynamically allocated from LwIP&#8217;s heap.
        </li>

        <li style="margin-bottom:20px;">
            The <span class="highlight">pbuf</span> structure and its payload are normally allocated as one 
            contiguous block of memory.
        </li>

        <li style="margin-bottom:20px;">
            Unlike <span class="highlight">PBUF_POOL</span>, a <span class="highlight">PBUF_RAM</span> allocation 
            normally creates a single pbuf large enough to hold the requested packet, rather than chaining multiple 
            fixed-size pool buffers.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">PBUF_RAM</span> is commonly used when constructing or transmitting packets whose 
            size is known at allocation time.
        </li>

    </ol>


</div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

    <b id="lwip_pbufs_api" style="
        display:block;
        font-family:'Inter', sans-serif;
        font-size:22px;
        color:black;
        margin-top:0;
        margin-bottom:20px;">
        APIs for Managing pbufs
    </b>

    <ol style="
        margin-top:0;
        margin-bottom:0;
        margin-left:0;
        padding-left:22px;">

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_alloc()</span>: Allocates a new <span class="highlight">pbuf</span> of the specified type and size. For <span class="highlight">PBUF_POOL</span>, the result may be a chain of multiple pbufs.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_realloc()</span>: Shrinks a pbuf or pbuf chain to a specified length. Despite its name, it cannot enlarge a pbuf. Any unused pbufs at the end of the chain are freed.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_ref()</span>: Increments the reference count (<span class="highlight">ref</span>) of a pbuf, indicating that another reference to the pbuf exists.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_free()</span>: Decrements the reference count of a pbuf. If the reference count reaches 0, the pbuf is deallocated. For a chain, this process continues until a pbuf with a remaining nonzero reference count is encountered.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_clen()</span>: Returns the number of individual pbufs in a pbuf chain.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_cat()</span>: Concatenates two pbufs or pbuf chains. It does not increment the reference count of the tail chain; ownership of the caller&#8217;s tail reference is transferred to the resulting chain.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_chain()</span>: Chains two pbufs or pbuf chains together and increments the reference count of the first pbuf in the tail chain, allowing the caller to retain its own reference to the tail.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_dechain()</span>: Detaches the first pbuf from the remainder of a pbuf chain. The first pbuf becomes a standalone pbuf, and the function returns the remaining chain if it is still allocated.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_copy_partial()</span>: Copies a specified number of bytes from a pbuf or pbuf chain, starting at a specified offset, into an application-provided buffer.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_take()</span>: Copies application-provided data into an existing pbuf or pbuf chain. The destination pbuf must have sufficient capacity.
        </li>

        <li style="margin-bottom:20px;">
            <span class="highlight">pbuf_coalesce()</span>: Converts a chained pbuf into a single contiguous pbuf. If allocation fails, the original pbuf is returned unchanged.
        </li>
    </ol>


</div>



<div class="article-text" style="margin-top:60px; margin-bottom:40px;">

<b style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Reference
</b>

<p>
[1] <a href="https://savannah.nongnu.org/projects/lwip/" style="color: blue;">Light Weight Internet Protocol</a>
<br>

[2] <a href="https://study.embeddedexpert.io/p/embedded-ethernet-firmware-development-learning-path" style="color: blue;">Embedded Ethernet Firmware Development Learning Path</a>

</p></div>



<br><br>
<a href="#top" style="font-size:20px; color: blue;">Back to top of the page</a>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8098</post-id>	</item>
		<item>
		<title>STM32 Zephyr: Introduction to Zephyr</title>
		<link>https://hangpersonal.com/2026/08/09/stm32-zephyr/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Sun, 09 Aug 2026 20:49:19 +0000</pubDate>
				<category><![CDATA[Embedded System]]></category>
		<category><![CDATA[Zephyr]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=8025</guid>

					<description><![CDATA[STM32 Microcontroller and Zephyr RTOS Development Zephyr Workspace and Project Directory Zephyr Board Directory Zephyr Application Directory Zephyr Build Directory Zephyr is an open-source, scalable, and secure real-time operating system (RTOS) designed for modern embedded and connected devices. It supports a wide range of hardware platforms, from small resource-constrained microcontrollers to more capable edge-computing systems....]]></description>
										<content:encoded><![CDATA[
<a href="https://hangpersonal.com/embedded-system/stm32-mcu/zephyr-tutorials/" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
STM32 Microcontroller and Zephyr RTOS Development
</a>
<br><br>



<ul style="margin-top:30px; margin-bottom:30px;">

<li style="margin-bottom:16px;">
<a href="#zephyr_workspace" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Zephyr Workspace and Project Directory
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#zephyr_board_directory" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Zephyr Board Directory
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#zephyr_app_directory" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Zephyr Application Directory
</a>
</li> 

<li style="margin-bottom:16px;">
<a href="#zephyr_build_directory" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Zephyr Build Directory
</a>
</li> 

</ul>



<div class="article-text" style="margin-top:30px; margin-bottom:30px;">

<p>
<b>Zephyr</b> is an <b>open-source, scalable, and secure real-time operating system (RTOS)</b> designed for modern embedded and connected devices. It supports a wide range of hardware platforms, from small resource-constrained microcontrollers to more capable edge-computing systems.
</p>

<p>

<ul>

<li><b>Kernel</b>: It manages threads, scheduling, interrupts, synchronization, timing, and other system resources.
</li>

<li><b>Multithreading</b>: Allows multiple threads to execute concurrently, enabling applications to handle several operations while maintaining responsiveness and real-time behavior.
</li>

<li><b>Memory Management</b>: Provides mechanisms for efficient and predictable use of limited memory, including dynamic allocation, memory pools, stacks, and memory protection.
</li>

</ul>

</p>

</div>



<div class="article-text" style="margin-top:10px; margin-bottom:20px;">

<b id="zephyr_workspace" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
Zephyr Workspace and Project Directory
</b>

<p>
A Zephyr application is more than a set of source files. It exists within a structured workspace, integrates with a multi-stage build system, and depends on multiple repositories working together. In practice, developers often need to set up a workspace, organize application code, and manage dependencies while ensuring that builds remain reproducible across environments. 
</p>

<p>
A West workspace is identified by the presence of the .west/ directory at its root. When a West command runs, it searches upward in the directory tree until it finds this directory, then performs all operations relative to that workspace root. Inside the workspace, multiple repositories coexist, including the Zephyr repository, which contains the kernel, subsystems, drivers, and build system. Applications are typically placed alongside the Zephyr repository rather than inside it, and a workspace may contain one or many applications. 
</p>

<p>
A Zephyr workspace is defined by a manifest file that specifies which repositories are used, where they are fetched from, and how they are organized locally. The West manifest is a YAML file named <span class="highlight">west.yml</span>. It describes the repositories (called projects in West terminology) that belong to a workspace. The manifest may live in different locations depending on the chosen workspace topology, but its purpose remains the same: to define the composition of the workspace. 
</p>

<p>

</p><ul>

<li> <span class="highlight">arch/</span>: CPU architecture support  
</li>

<li> <span class="highlight">boards/</span>: Board definitions, Devicetree, Kconfig, and default settings
</li>

<li> <span class="highlight">cmake/</span>: CMake build-system modules
</li>

<li> <span class="highlight">drivers/</span>: Hardware drivers: GPIO, I2C, SPI, UART, ADC, sensors, etc
</li>

<li> <span class="highlight">include/</span>: Public Zephyr API headers  
</li>

<li> <span class="highlight">kernel/</span>: Kernel: scheduler, threads, synchronization, timers
</li>

<li> <span class="highlight">samples/</span>: Example and reference applications
</li>

<li> <span class="highlight">scripts/</span>: Build, configuration, flashing, testing, and helper tools  
</li>

<li> <span class="highlight">soc/</span>: Vendor- and SoC-specific support
</li>
 
<li> <span class="highlight">subsys/</span>: System services: logging, shell, networking, settings, etc
</li>

<li> <span class="highlight">tests/</span>: Kernel, driver, subsystem, and API tests
</li>

<li> <span class="highlight">west.yml</span>: Defines which repositories West uses and where to find them     
</li>

</ul>

<p></p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>zephyr-sdk-&lt;version>/

zephyr_workspace/
     ├── .venv/
     └── .west/
           └── config
     └── bootloader/
           └── mcuboot/
     └── modules/
           └── hal/
                ├── cmsis/ 
                └── stm32/        
           └── lib/
                ├──cmsis-dsp/
                └──cmsis-nn/
           └── fs/
                ├── fatfs/
                └── littlefs/  
     └── zephyr/
           ├── arch/
           ├── boards/
           ├── cmake/
           ├── drivers/
           ├── include/
           ├── kernel/
           ├── samples/
           ├── scripts/
           ├── soc/
           ├── subsys/
           ├── tests/
           └── west.yml
     ├── tools/     
     └── apps/  
          ├── project_1
          └── project_2
     └── build/
          ├── project_1
          └── project_2            </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">zephyr-sdk-&lt;version&gt;/</span></span>
<span class="line"><span style="color: #D5CED9"></span></span>
<span class="line"><span style="color: #D5CED9">zephyr_workspace/</span></span>
<span class="line"><span style="color: #D5CED9">     ├── .venv/</span></span>
<span class="line"><span style="color: #D5CED9">     └── .west/</span></span>
<span class="line"><span style="color: #D5CED9">           └── config</span></span>
<span class="line"><span style="color: #D5CED9">     └── bootloader/</span></span>
<span class="line"><span style="color: #D5CED9">           └── mcuboot/</span></span>
<span class="line"><span style="color: #D5CED9">     └── modules/</span></span>
<span class="line"><span style="color: #D5CED9">           └── hal/</span></span>
<span class="line"><span style="color: #D5CED9">                ├── cmsis/ </span></span>
<span class="line"><span style="color: #D5CED9">                └── stm32/        </span></span>
<span class="line"><span style="color: #D5CED9">           └── lib/</span></span>
<span class="line"><span style="color: #D5CED9">                ├──cmsis-dsp/</span></span>
<span class="line"><span style="color: #D5CED9">                └──cmsis-nn/</span></span>
<span class="line"><span style="color: #D5CED9">           └── fs/</span></span>
<span class="line"><span style="color: #D5CED9">                ├── fatfs/</span></span>
<span class="line"><span style="color: #D5CED9">                └── littlefs/  </span></span>
<span class="line"><span style="color: #D5CED9">     └── zephyr/</span></span>
<span class="line cbp-see-more-line "><span style="color: #D5CED9">           ├── arch/</span></span>
<span class="line"><span style="color: #D5CED9">           ├── boards/</span></span>
<span class="line"><span style="color: #D5CED9">           ├── cmake/</span></span>
<span class="line"><span style="color: #D5CED9">           ├── drivers/</span></span>
<span class="line"><span style="color: #D5CED9">           ├── include/</span></span>
<span class="line"><span style="color: #D5CED9">           ├── kernel/</span></span>
<span class="line"><span style="color: #D5CED9">           ├── samples/</span></span>
<span class="line"><span style="color: #D5CED9">           ├── scripts/</span></span>
<span class="line"><span style="color: #D5CED9">           ├── soc/</span></span>
<span class="line"><span style="color: #D5CED9">           ├── subsys/</span></span>
<span class="line"><span style="color: #D5CED9">           ├── tests/</span></span>
<span class="line"><span style="color: #D5CED9">           └── west.yml</span></span>
<span class="line"><span style="color: #D5CED9">     ├── tools/     </span></span>
<span class="line"><span style="color: #D5CED9">     └── apps/  </span></span>
<span class="line"><span style="color: #D5CED9">          ├── project_1</span></span>
<span class="line"><span style="color: #D5CED9">          └── project_2</span></span>
<span class="line"><span style="color: #D5CED9">     └── build/</span></span>
<span class="line"><span style="color: #D5CED9">          ├── project_1</span></span>
<span class="line"><span style="color: #D5CED9">          └── project_2            </span></span></code></pre></div>



<div class="article-text" style="margin-top:30px; margin-bottom:20px;">
</div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="zephyr_board_directory" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
Zephyr Board Directory
</b>

<p>
<ul>

<li> <span class="highlight">Kconfig.&lt;board_name&gt;</span>: Defines board- and SoC-related Kconfig settings
</li>

<li> <span class="highlight">&lt;board_name&gt;_defconfig</span>: Defines default Kconfig options for the board
</li>

<li> <span class="highlight">&lt;board_name&gt;.dts</span>: Describes the board&#8217;s hardware using Devicetree
</li>

<li> <span class="highlight">&lt;board_name&gt;.yaml</span>: Defines board metadata and capabilities for automated testing
</li>

<li> <span class="highlight">board.cmake</span>: Configures runners for flashing and debugging
</li>

<li> <span class="highlight">board.yml</span>: Defines board identity, SoC, revisions, and variants
</li>

</ul>
</p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>└── zephyr/
      └── boards/
            └── vendor/
                  └── &lt;board_name>/
                          ├── Kconfig.&lt;board_name>
                          ├── &lt;board_name>_defconfig
                          ├── &lt;board_name>.dts
                          ├── &lt;board_name>.yaml
                          ├── board.cmake
                          └── board.yml</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">└── zephyr/</span></span>
<span class="line"><span style="color: #D5CED9">      └── boards/</span></span>
<span class="line"><span style="color: #D5CED9">            └── vendor/</span></span>
<span class="line"><span style="color: #D5CED9">                  └── &lt;board_name&gt;/</span></span>
<span class="line"><span style="color: #D5CED9">                          ├── Kconfig.&lt;board_name&gt;</span></span>
<span class="line"><span style="color: #D5CED9">                          ├── &lt;board_name&gt;_defconfig</span></span>
<span class="line"><span style="color: #D5CED9">                          ├── &lt;board_name&gt;.dts</span></span>
<span class="line"><span style="color: #D5CED9">                          ├── &lt;board_name&gt;.yaml</span></span>
<span class="line"><span style="color: #D5CED9">                          ├── board.cmake</span></span>
<span class="line"><span style="color: #D5CED9">                          └── board.yml</span></span></code></pre></div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="zephyr_app_directory" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
Zephyr Application Directory
</b>

<p>
</p><ul>

<li> <span class="highlight">CMakeLists.txt</span>: Connects the project to Zephyr&#8217;s build system 
</li>

<li> <span class="highlight">Kconfig</span>: Defines application options, their types, defaults, and dependencies
</li>

<li> <span class="highlight">prj.conf</span>: Configures application, Zephyr, and module features by setting option values
</li>

<li> <span class="highlight">extra.conf</span>: Optional Kconfig configuration fragment used to add or override settings in <span class="highlight">prj.conf</span> for a particular build
</li>

<li> <span class="highlight">&lt;board_name&gt;.conf</span>: Board-specific Kconfig settings
</li>

<li> <span class="highlight">&lt;board_name&gt;.overlay</span>: Board-specific Devicetree hardware changes
</li>

</ul>
<p></p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>└── apps/  
      └── project_1
             ├── CMakeLists.txt
             ├── Kconfig
             ├── prj.conf
             ├── extra_1.conf
             ├── extra_2.conf
             ├── app.overlay
             └── boards/
                  ├── &lt;board_name_1>.conf 
                  ├── &lt;board_name_1>.overlay
                  ├── &lt;board_name_2>.conf
                  └── &lt;board_name_2>.overlay
             └── src/
                  └── main.c</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">└── apps/  </span></span>
<span class="line"><span style="color: #D5CED9">      └── project_1</span></span>
<span class="line"><span style="color: #D5CED9">             ├── CMakeLists.txt</span></span>
<span class="line"><span style="color: #D5CED9">             ├── Kconfig</span></span>
<span class="line"><span style="color: #D5CED9">             ├── prj.conf</span></span>
<span class="line"><span style="color: #D5CED9">             ├── extra_1.conf</span></span>
<span class="line"><span style="color: #D5CED9">             ├── extra_2.conf</span></span>
<span class="line"><span style="color: #D5CED9">             ├── app.overlay</span></span>
<span class="line"><span style="color: #D5CED9">             └── boards/</span></span>
<span class="line"><span style="color: #D5CED9">                  ├── &lt;board_name_1&gt;.conf </span></span>
<span class="line"><span style="color: #D5CED9">                  ├── &lt;board_name_1&gt;.overlay</span></span>
<span class="line"><span style="color: #D5CED9">                  ├── &lt;board_name_2&gt;.conf</span></span>
<span class="line"><span style="color: #D5CED9">                  └── &lt;board_name_2&gt;.overlay</span></span>
<span class="line"><span style="color: #D5CED9">             └── src/</span></span>
<span class="line"><span style="color: #D5CED9">                  └── main.c</span></span></code></pre></div>



<div class="article-text" style="margin-top:50px; margin-bottom:30px;">

<b id="zephyr_build_directory" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:10px;">
Zephyr Build Directory
</b>

<p>
A Zephyr application goes through multiple build stages before producing the final executable. A pristine build removes the existing build directory before starting a new build. This forces CMake, Kconfig, and Devicetree to run from scratch instead of reusing cached results.
</p>

<p>
</p>

<ul>

<li> <span class="highlight">.conf</span>: The final resolved Kconfig configuration for the current build
</li>

<li> <span class="highlight">autoconf.h</span>: The C header generated from <span class="highlight">.config</span> so the selected Kconfig options can be used by C/C++ source code.
</li>


</ul>
<p></p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="683" height="1024" src="https://hangpersonal.com/wp-content/uploads/2026/08/zephyr_build-683x1024.png" alt="" class="wp-image-8329" style="width:600px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/08/zephyr_build-683x1024.png 683w, https://hangpersonal.com/wp-content/uploads/2026/08/zephyr_build-200x300.png 200w, https://hangpersonal.com/wp-content/uploads/2026/08/zephyr_build-768x1152.png 768w, https://hangpersonal.com/wp-content/uploads/2026/08/zephyr_build-300x450.png 300w, https://hangpersonal.com/wp-content/uploads/2026/08/zephyr_build-850x1275.png 850w, https://hangpersonal.com/wp-content/uploads/2026/08/zephyr_build.png 1024w" sizes="auto, (max-width: 683px) 100vw, 683px" /></figure>
</div>


<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>└── build/
      └── project_1
              └── zephyr/
                    ├── zephyr.elf
                    ├── zephyr.hex
                    ├── zephyr.bin
                    ├── zephyr.map
                    ├── zephyr.dts (merged Devicetree output)
                    ├── .config
                    └── include/generated/zephyr/
                            ├── autoconf.h (Kconfig output)
                            └── devicetree_generated.h (Devicetree macros)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #D5CED9">└── build/</span></span>
<span class="line"><span style="color: #D5CED9">      └── project_1</span></span>
<span class="line"><span style="color: #D5CED9">              └── zephyr/</span></span>
<span class="line"><span style="color: #D5CED9">                    ├── zephyr.elf</span></span>
<span class="line"><span style="color: #D5CED9">                    ├── zephyr.hex</span></span>
<span class="line"><span style="color: #D5CED9">                    ├── zephyr.bin</span></span>
<span class="line"><span style="color: #D5CED9">                    ├── zephyr.map</span></span>
<span class="line"><span style="color: #D5CED9">                    ├── zephyr.dts (merged Devicetree output)</span></span>
<span class="line"><span style="color: #D5CED9">                    ├── .config</span></span>
<span class="line"><span style="color: #D5CED9">                    └── include/generated/zephyr/</span></span>
<span class="line"><span style="color: #D5CED9">                            ├── autoconf.h (Kconfig output)</span></span>
<span class="line"><span style="color: #D5CED9">                            └── devicetree_generated.h (Devicetree macros)</span></span></code></pre></div>



<div class="article-text" style="margin-top:60px; margin-bottom:40px;">

<b style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Reference
</b>

<p>
[1] <a href="https://docs.zephyrproject.org" style="color: blue;">Zephyr Project Documentation</a>
<br>

[2] <a href="https://docs.zephyrproject.org/latest/doxygen/html" style="color: blue;">Zephyr API Reference</a>
<br>

[3] <a href="https://docs.zephyrproject.org/latest/samples/index.html" style="color: blue;">Samples and Demos</a>
<br>

[4] <a href="https://docs.zephyrproject.org/latest/boards/index.html" style="color: blue;">Supported Boards and Shields</a>
<br>

[5] <a href="https://docs.zephyrproject.org/latest/develop/west/workspaces.html" style="color: blue;">Zephyr Workspace</a>
<br>

[6] <a href="https://docs.zephyrproject.org/latest/develop/application/index.html" style="color: blue;">Zephyr Application Development</a>
<br>

[7] <a href="https://docs.zephyrproject.org/latest/build/index.html" style="color: blue;">Zephyr Build and Configuration Systems</a>
<br>

[8] <a href="https://docs.zephyrproject.org/latest/build/cmake/index.html" style="color: blue;">Zephyr Build System (CMake)</a>
<br>

[9] <a href="https://docs.zephyrproject.org/latest/develop/west/manifest.html" style="color: blue;">West Manifests</a>
<br>

</p>


</div>



<br><br>
<a href="#top" style="font-size:20px; color: blue;">Back to top of the page</a>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8025</post-id>	</item>
		<item>
		<title>STM32 FreeRTOS: Heap Management</title>
		<link>https://hangpersonal.com/2026/07/28/stm32-freertos-heap/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Tue, 28 Jul 2026 15:52:12 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=7927</guid>

					<description><![CDATA[STM32 Microcontroller and FreeRTOS Development FreeRTOS Heap Implementation Compared Memory Fragmentation Process heap_1.c heap_1.c is the simplest FreeRTOS heap implementation and provides dynamic memory allocation through pvPortMalloc(). It manages a statically allocated heap defined by configTOTAL_HEAP_SIZE and allocates memory sequentially from the beginning of this heap. Once memory is allocated, it cannot be returned to...]]></description>
										<content:encoded><![CDATA[
<a href="https://hangpersonal.com/embedded-system/stm32-mcu/freertos-tutorials/" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
STM32 Microcontroller and FreeRTOS Development
</a>
<br><br>



<div class="article-text" style="margin-top:20px; margin-bottom:20px;">

<b style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:0px;">
FreeRTOS Heap Implementation Compared
</b>

</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode spbtbl-fullwidth" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS: Heap Implementations Compared"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">File</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">Frees Memory?</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">Memory Behavior</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">Typical Use Case</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#heap_1" style="font-size: 20px;color: blue">heap_1.c</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >No</td>                                    <td style="font-size:18px !important;" itemprop="description" >Never fragments</td>                                    <td style="font-size:18px !important;" itemprop="description" >Allocate-once (tasks/queues created at startup and never deleted)</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#heap_2" style="font-size: 20px;color: blue">heap_2.c</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Yes</td>                                    <td style="font-size:18px !important;" itemprop="description" >Can fragment (doesn't merge free blocks)</td>                                    <td style="font-size:18px !important;" itemprop="description" >Legacy designs only. Avoid for new projects</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#heap_3" style="font-size: 20px;color: blue">heap_3.c</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Yes</td>                                    <td style="font-size:18px !important;" itemprop="description" >Depends on compiler's C library</td>                                    <td style="font-size:18px !important;" itemprop="description" >When you specifically need the standard C malloc/free</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#heap_4" style="font-size: 20px;color: blue">heap_4.c</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Yes</td>                                    <td style="font-size:18px !important;" itemprop="description" >Merges adjacent free blocks to reduce fragmentation</td>                                    <td style="font-size:18px !important;" itemprop="description" >Default choice for most general-purpose RTOS projects</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#heap_5" style="font-size: 20px;color: blue">heap_5.c</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Yes</td>                                    <td style="font-size:18px !important;" itemprop="description" >Same as heap_4.c</td>                                    <td style="font-size:18px !important;" itemprop="description" >Systems with multiple, non-contiguous RAM banks</td>                            </tr>
                                            </tbody>
                </table>
                            </div>




<div class="article-text" style="margin-top:10px; margin-bottom:20px;">

<b style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Memory Fragmentation Process
</b>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="768" src="https://hangpersonal.com/wp-content/uploads/2026/07/freertos_fragmentation-1024x768.png" alt="" class="wp-image-7981" style="width:750px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/freertos_fragmentation-1024x768.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_fragmentation-300x225.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_fragmentation-768x576.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_fragmentation-850x638.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_fragmentation.png 1448w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<div class="article-text" style="margin-top:30px; margin-bottom:30px;">

<b id="heap_1" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
heap_1.c
</b>

<p>
<span class="highlight">heap_1.c</span> is the simplest FreeRTOS heap implementation and provides dynamic memory allocation through <span class="highlight">pvPortMalloc()</span>. It manages a statically allocated heap defined by <span class="highlight">configTOTAL_HEAP_SIZE</span> and allocates memory sequentially from the beginning of this heap. Once memory is allocated, it cannot be returned to the heap because <span class="highlight">heap_1.c</span> does not support <span class="highlight">vPortFree()</span>. This makes the implementation very small, fast, and deterministic, with no risk of heap fragmentation. It is most suitable for embedded applications in which all dynamic memory is allocated during system initialization and never released, such as systems that create all tasks, queues, semaphores, and other RTOS objects before starting normal operation.
</p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="432" src="https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap1-1024x432.png" alt="" class="wp-image-8001" style="width:650px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap1-1024x432.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap1-300x127.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap1-768x324.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap1-1536x648.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap1-850x359.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap1.png 1832w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<div class="article-text" style="margin-top:40px; margin-bottom:30px;">

<b id="heap_2" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
heap_2.c
</b>

<p>
<span class="highlight">heap_2.c</span> provides dynamic memory allocation through <span class="highlight">pvPortMalloc()</span> and supports releasing memory with <span class="highlight">vPortFree()</span>. It manages a statically allocated heap and reuses previously freed blocks when possible. However, adjacent free blocks are not combined, so repeated allocations and deallocations of different sizes can cause memory fragmentation over time. It is mainly suitable for applications that allocate and free blocks of the same or similar sizes, although <span class="highlight">heap_4.c</span> is generally preferred for most applications that require memory to be freed.
</p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="418" src="https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap2-1024x418.png" alt="" class="wp-image-8004" style="width:750px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap2-1024x418.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap2-300x123.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap2-768x314.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap2-1536x627.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap2-850x347.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap2.png 1873w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<div class="article-text" style="margin-top:40px; margin-bottom:30px;">

<b id="heap_3" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
heap_3.c
</b>

<p>
<span class="highlight">heap_3.c</span> implements the FreeRTOS memory allocation interface by wrapping the standard C library functions <span class="highlight">malloc()</span> and <span class="highlight">free()</span>. Unlike the other FreeRTOS heap implementations, it does not use the memory region defined by <span class="highlight">configTOTAL_HEAP_SIZE</span>; instead, memory management is handled by the C runtime library. This implementation is useful when an application already relies on the standard library heap, but its determinism, thread safety, fragmentation behavior, and memory usage depend on the specific C library and system configuration.
</p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="409" src="https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap3-1024x409.png" alt="" class="wp-image-8006" style="width:750px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap3-1024x409.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap3-300x120.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap3-768x307.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap3-1536x614.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap3-850x340.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap3.png 1890w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<div class="article-text" style="margin-top:40px; margin-bottom:30px;">

<b id="heap_4" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
heap_4.c
</b>

<p>
<span class="highlight">heap_4.c</span> is a commonly used FreeRTOS heap implementation that supports both dynamic allocation with <span class="highlight">pvPortMalloc()</span> and deallocation with <span class="highlight">vPortFree()</span>. It manages a statically allocated heap and automatically combines adjacent free memory blocks, which significantly reduces memory fragmentation compared with <span class="highlight">heap_2.c</span>. It provides a good balance between simplicity, efficiency, and flexibility, making it well suited for applications that dynamically create and delete tasks, queues, semaphores, and other RTOS objects during runtime.
</p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="411" src="https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap4-1024x411.png" alt="" class="wp-image-8008" style="width:750px;height:auto" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap4-1024x411.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap4-300x120.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap4-768x308.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap4-1536x616.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap4-850x341.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/freertos_heap4.png 1834w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<div class="article-text" style="margin-top:30px; margin-bottom:40px;">
</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>// ---------------------- Example ----------------------

uint8_t *buffer = NULL;
buffer = pvPortMalloc(32);
printf("Allocated memory at address: %p\r\n", (void *)buffer);

printf("Freeing memory at address: %p\r\n", (void *)buffer);
vPortFree(buffer);
buffer = NULL;

size_t freeMem;
freeMem = xPortGetFreeHeapSize();
printf("Free heap memory: %u bytes\r\n", (uint16_t)freeMem);</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">uint8_t</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9">buffer </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">NULL</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">buffer </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">pvPortMalloc</span><span style="color: #D5CED9">(</span><span style="color: #F39C12">32</span><span style="color: #D5CED9">);</span></span>
<span class="line"><span style="color: #FFE66D">printf</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot;Allocated memory at address: </span><span style="color: #EE5D43">%p\r\n</span><span style="color: #96E072">&quot;</span><span style="color: #D5CED9">, (</span><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9">)</span><span style="color: #00E8C6">buffer</span><span style="color: #D5CED9">);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #FFE66D">printf</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot;Freeing memory at address: </span><span style="color: #EE5D43">%p\r\n</span><span style="color: #96E072">&quot;</span><span style="color: #D5CED9">, (</span><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9">)</span><span style="color: #00E8C6">buffer</span><span style="color: #D5CED9">);</span></span>
<span class="line"><span style="color: #FFE66D">vPortFree</span><span style="color: #D5CED9">(buffer);</span></span>
<span class="line"><span style="color: #D5CED9">buffer </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">NULL</span><span style="color: #D5CED9">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">size_t</span><span style="color: #D5CED9"> freeMem;</span></span>
<span class="line"><span style="color: #D5CED9">freeMem </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xPortGetFreeHeapSize</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #FFE66D">printf</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot;Free heap memory: </span><span style="color: #EE5D43">%u</span><span style="color: #96E072"> bytes</span><span style="color: #EE5D43">\r\n</span><span style="color: #96E072">&quot;</span><span style="color: #D5CED9">, (</span><span style="color: #C74DED">uint16_t</span><span style="color: #D5CED9">)</span><span style="color: #00E8C6">freeMem</span><span style="color: #D5CED9">);</span></span></code></pre></div>



<div class="article-text" style="margin-top:40px; margin-bottom:30px;">

<b id="heap_5" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
heap_5.c
</b>

<p>
<span class="highlight">heap_5.c</span> provides the same allocation and deallocation behavior as <span class="highlight">heap_4.c</span>, including the ability to merge adjacent free blocks, but it can manage multiple separate memory regions instead of a single contiguous heap. The available regions are defined by the application using <span class="highlight">vPortDefineHeapRegions()</span>, allowing FreeRTOS to use memory located in different RAM banks or address ranges. It is particularly useful on microcontrollers with multiple RAM regions, such as internal SRAM, CCM RAM, or external memory, where the application needs to combine several non-contiguous areas into a single FreeRTOS heap.
</p>

</div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D5CED9;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D5CED9;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>typedef struct HeapRegion {
    uint8_t *pucStartAddress;  // Start address of the memory block
    size_t xSizeInBytes;       // Size of the memory region
} HeapRegion_t;

HeapRegion_t xHeapRegions[] = {
    { ( uint8_t * ) 0X10000000UL, 0x10000 },   // CCM memory, start address 0X10000000, size 64 KB
    { ( uint8_t * ) 0X20000000UL, 0x20000 },   // Internal SRAM, start address 0X20000000, size 128 KB
    { ( uint8_t * ) 0X68000000UL, 0x100000 },  // External SRAM, start address 0X68000000, size 1 MB
    { NULL, 0 }                                // End of the array
};

// Initialize the heap memory
vPortDefineHeapRegions((const HeapRegion_t *)xHeapRegions);</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki andromeda" style="background-color: #23262E" tabindex="0"><code><span class="line"><span style="color: #C74DED">typedef</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">struct</span><span style="color: #D5CED9"> HeapRegion {</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #C74DED">uint8_t</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9">pucStartAddress;</span><span style="color: #A0A1A7CC">  // Start address of the memory block</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #C74DED">size_t</span><span style="color: #D5CED9"> xSizeInBytes;</span><span style="color: #A0A1A7CC">       // Size of the memory region</span></span>
<span class="line"><span style="color: #D5CED9">} HeapRegion_t;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">HeapRegion_t xHeapRegions</span><span style="color: #C74DED">[]</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> {</span></span>
<span class="line"><span style="color: #D5CED9">    { ( </span><span style="color: #C74DED">uint8_t</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> ) </span><span style="color: #C74DED">0X</span><span style="color: #F39C12">10000000</span><span style="color: #C74DED">UL</span><span style="color: #D5CED9">, </span><span style="color: #C74DED">0x</span><span style="color: #F39C12">10000</span><span style="color: #D5CED9"> },</span><span style="color: #A0A1A7CC">   // CCM memory, start address 0X10000000, size 64 KB</span></span>
<span class="line"><span style="color: #D5CED9">    { ( </span><span style="color: #C74DED">uint8_t</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> ) </span><span style="color: #C74DED">0X</span><span style="color: #F39C12">20000000</span><span style="color: #C74DED">UL</span><span style="color: #D5CED9">, </span><span style="color: #C74DED">0x</span><span style="color: #F39C12">20000</span><span style="color: #D5CED9"> },</span><span style="color: #A0A1A7CC">   // Internal SRAM, start address 0X20000000, size 128 KB</span></span>
<span class="line"><span style="color: #D5CED9">    { ( </span><span style="color: #C74DED">uint8_t</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> ) </span><span style="color: #C74DED">0X</span><span style="color: #F39C12">68000000</span><span style="color: #C74DED">UL</span><span style="color: #D5CED9">, </span><span style="color: #C74DED">0x</span><span style="color: #F39C12">100000</span><span style="color: #D5CED9"> },</span><span style="color: #A0A1A7CC">  // External SRAM, start address 0X68000000, size 1 MB</span></span>
<span class="line"><span style="color: #D5CED9">    { </span><span style="color: #EE5D43">NULL</span><span style="color: #D5CED9">, </span><span style="color: #F39C12">0</span><span style="color: #D5CED9"> }</span><span style="color: #A0A1A7CC">                                // End of the array</span></span>
<span class="line"><span style="color: #D5CED9">};</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// Initialize the heap memory</span></span>
<span class="line"><span style="color: #FFE66D">vPortDefineHeapRegions</span><span style="color: #D5CED9">((</span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> HeapRegion_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9">)</span><span style="color: #00E8C6">xHeapRegions</span><span style="color: #D5CED9">);</span></span></code></pre></div>



<br><br>
<a href="#top" style="font-size:20px; color: blue;">Back to top of the page</a>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7927</post-id>	</item>
	</channel>
</rss>
