<?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>Sun, 16 Aug 2026 17:26:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</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>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 fetchpriority="high" 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="(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 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="(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[Work in Progress STM32 Microcontroller and Zephyr RTOS Development 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. Kernel: It manages threads, scheduling, interrupts, synchronization, timing, and other system...]]></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: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 style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
Zephyr Workspace
</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>zephyr-sdk-&lt;version>/

zephyr_workspace/
|--.venv/
|--.west/
     |--config
|--bootloader/
|--modules/
     |--hal/
         |--cmsis/ - CMSIS core headers    
         |--stm32/ - STM32 HAL and LL layers               
     |--lib/
         |--cmsis-dsp/
         |--cmsis-nn/
     |--fs/
         |--fatfs/
         |--littlefs/        
|--tools/
|--apps/
|--zephyr/
     |--arch/
     |--boards/
     |--cmake/
     |--drivers/
     |--include/
     |--kernel/
     |--samples/
     |--scripts/
     |--soc/
     |--subsys/
     |--tests/
     |--west.yml

arch/     - CPU architecture support  
boards/   - Board definitions, DeviceTree, Kconfig, and default settings
cmake/    - CMake build-system modules
drivers/  - Hardware drivers: GPIO, I2C, SPI, UART, ADC, sensors, etc
include/  - Public Zephyr API headers   
kernel/   - Kernel: scheduler, threads, synchronization, timers
samples/  - Example and reference applications
scripts/  - Build, configuration, flashing, testing, and helper tools  
soc/      - Vendor- and SoC-specific support
subsys/   - System services: logging, shell, networking, settings, etc
tests/    - Kernel, driver, subsystem, and API tests</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 style="color: #EE5D43">-</span><span style="color: #D5CED9">sdk</span><span style="color: #EE5D43">-&lt;</span><span style="color: #D5CED9">version</span><span style="color: #EE5D43">&gt;/</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">zephyr_workspace</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">.venv</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">.west</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">config</span></span>
<span class="line"><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">bootloader</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">modules</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">hal</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">         </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">cmsis</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> CMSIS core headers    </span></span>
<span class="line"><span style="color: #D5CED9">         </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">stm32</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> STM32 HAL and LL layers               </span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">lib</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">         </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">cmsis</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">dsp</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">         </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">cmsis</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">nn</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">fs</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">         </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">fatfs</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">         </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">littlefs</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">        </span></span>
<span class="line"><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">tools</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">apps</span><span style="color: #EE5D43">/</span></span>
<span class="line cbp-see-more-line "><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">zephyr</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">arch</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">boards</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">cmake</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">drivers</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">include</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">kernel</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">samples</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">scripts</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">soc</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">subsys</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">tests</span><span style="color: #EE5D43">/</span></span>
<span class="line"><span style="color: #D5CED9">     </span><span style="color: #EE5D43">|--</span><span style="color: #D5CED9">west.yml</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">arch</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">     </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> CPU architecture support  </span></span>
<span class="line"><span style="color: #D5CED9">boards</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">   </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> Board definitions, DeviceTree, Kconfig, and default settings</span></span>
<span class="line"><span style="color: #D5CED9">cmake</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">    </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> CMake build</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">system modules</span></span>
<span class="line"><span style="color: #D5CED9">drivers</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">  </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> Hardware drivers: GPIO, I2C, SPI, UART, ADC, sensors, etc</span></span>
<span class="line"><span style="color: #D5CED9">include</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">  </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> Public Zephyr API headers   </span></span>
<span class="line"><span style="color: #D5CED9">kernel</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">   </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> Kernel: scheduler, threads, synchronization, timers</span></span>
<span class="line"><span style="color: #D5CED9">samples</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">  </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> Example and reference applications</span></span>
<span class="line"><span style="color: #D5CED9">scripts</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">  </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> Build, configuration, flashing, testing, and helper tools  </span></span>
<span class="line"><span style="color: #D5CED9">soc</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">      </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> Vendor</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> and SoC</span><span style="color: #EE5D43">-</span><span style="color: #D5CED9">specific support</span></span>
<span class="line"><span style="color: #D5CED9">subsys</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">   </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> System services: logging, shell, networking, settings, etc</span></span>
<span class="line"><span style="color: #D5CED9">tests</span><span style="color: #EE5D43">/</span><span style="color: #D5CED9">    </span><span style="color: #EE5D43">-</span><span style="color: #D5CED9"> Kernel, driver, subsystem, and API tests</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>
</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 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" 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="(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" 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" 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" 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" 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>
		<item>
		<title>STM32 FreeRTOS: Hook Functions and Tickless Idle</title>
		<link>https://hangpersonal.com/2026/07/27/stm32-freertos-hook-tickless/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Mon, 27 Jul 2026 20:27:08 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=7896</guid>

					<description><![CDATA[STM32 Microcontroller and FreeRTOS Development vApplicationIdleHook() The idle task hook is a user-defined callback function that FreeRTOS executes repeatedly whenever no other task is ready to run. It is implemented as vApplicationIdleHook() and enabled by setting configUSE_IDLE_HOOK to 1 in FreeRTOSConfig.h. The hook can be used for low-priority background operations, such as entering a low-power...]]></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:30px; margin-bottom:40px;">
</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode spbtbl-fullwidth" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS: Hook Functions and Tickless Idle"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">Hook API Function</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">Description</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#task_idle_hook" style="font-size: 20px;color: blue">vApplicationIdleHook()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Runs user-defined background or low-power code during Idle task execution</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#application_tick" style="font-size: 20px;color: blue">vApplicationTickHook()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Runs from the RTOS tick interrupt</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#application_malloc_fail" style="font-size: 20px;color: blue">vApplicationMallocFailedHook()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Called when pvPortMalloc() cannot allocate memory</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#application_stack_overflow" style="font-size: 20px;color: blue">vApplicationStackOverflowHook()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Called when a task stack overflow is detected</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#application_daemon_task_startup" style="font-size: 20px;color: blue">vApplicationDaemonTaskStartupHook()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Runs once when the Timer Service/Daemon task starts</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#tickless_idle" style="font-size: 20px;color: blue">configUSE_TICKLESS_IDLE</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Enables tickless idle mode, allowing FreeRTOS to suppress unnecessary tick interrupts and reduce power consumption while the system is idle</td>                            </tr>
                                            </tbody>
                </table>
                            </div>




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

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

<p>
The idle task hook is a user-defined callback function that FreeRTOS executes repeatedly whenever no other task is ready to run. It is implemented as <span class="highlight">vApplicationIdleHook()</span> and enabled by setting <span class="highlight">configUSE_IDLE_HOOK</span> to 1 in <span class="highlight">FreeRTOSConfig.h</span>. The hook can be used for low-priority background operations, such as entering a low-power mode, collecting system statistics, or performing simple maintenance tasks. It must never block, call functions that may block, or perform lengthy processing, because doing so prevents the idle task from running normally and may delay the cleanup of deleted tasks.
</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>void vApplicationIdleHook(void)

// ---------------------- Example ----------------------

#define configUSE_TICKLESS_IDLE    0  
#define configUSE_IDLE_HOOK        1
#define configIDLE_SHOULD_YIELD    1 

void BeforeEnterSleep(void)
{
    __HAL_RCC_GPIOB_CLK_SLEEP_DISABLE();
    __HAL_RCC_GPIOC_CLK_SLEEP_DISABLE();
    __HAL_RCC_GPIOD_CLK_SLEEP_DISABLE();
    __HAL_RCC_GPIOE_CLK_SLEEP_DISABLE();
    __HAL_RCC_GPIOF_CLK_SLEEP_DISABLE();
    __HAL_RCC_GPIOG_CLK_SLEEP_DISABLE();
    __HAL_RCC_GPIOH_CLK_SLEEP_DISABLE();
}

void AfterExitSleep(void)
{
    __HAL_RCC_GPIOB_CLK_SLEEP_ENABLE();
    __HAL_RCC_GPIOC_CLK_SLEEP_ENABLE();
    __HAL_RCC_GPIOD_CLK_SLEEP_ENABLE();
    __HAL_RCC_GPIOE_CLK_SLEEP_ENABLE();
    __HAL_RCC_GPIOF_CLK_SLEEP_ENABLE();
    __HAL_RCC_GPIOG_CLK_SLEEP_ENABLE();
    __HAL_RCC_GPIOH_CLK_SLEEP_ENABLE();
}

void vApplicationIdleHook(void)
{
    BeforeEnterSleep();
    __DSB();  
    __WFI();  
    __ISB();  
    AfterExitSleep();
}</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">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vApplicationIdleHook</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configUSE_TICKLESS_IDLE</span><span style="color: #D5CED9">    </span><span style="color: #F39C12">0</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">configUSE_IDLE_HOOK</span><span style="color: #D5CED9">        </span><span style="color: #F39C12">1</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configIDLE_SHOULD_YIELD</span><span style="color: #D5CED9">    </span><span style="color: #F39C12">1</span><span style="color: #D5CED9"> </span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">BeforeEnterSleep</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</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: #FFE66D">__HAL_RCC_GPIOB_CLK_SLEEP_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOC_CLK_SLEEP_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOD_CLK_SLEEP_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOE_CLK_SLEEP_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOF_CLK_SLEEP_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOG_CLK_SLEEP_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOH_CLK_SLEEP_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">}</span></span>
<span class="line"></span>
<span class="line cbp-see-more-line "><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">AfterExitSleep</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</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: #FFE66D">__HAL_RCC_GPIOB_CLK_SLEEP_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOC_CLK_SLEEP_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOD_CLK_SLEEP_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOE_CLK_SLEEP_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOF_CLK_SLEEP_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOG_CLK_SLEEP_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOH_CLK_SLEEP_ENABLE</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: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vApplicationIdleHook</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</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: #FFE66D">BeforeEnterSleep</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__DSB</span><span style="color: #D5CED9">();  </span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__WFI</span><span style="color: #D5CED9">();  </span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__ISB</span><span style="color: #D5CED9">();  </span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">AfterExitSleep</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;">

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

<p>
<span class="highlight">vApplicationTickHook()</span> is a user-defined FreeRTOS hook function that is called from the RTOS tick interrupt each time the system tick occurs. To enable it, set <span class="highlight">configUSE_TICK_HOOK</span> to 1 in <span class="highlight">FreeRTOSConfig.h</span>. It is typically used for short, periodic operations such as incrementing counters, updating software timing variables, or triggering lightweight monitoring functions. Because it executes in interrupt context, the hook must run quickly, must not block, and may only call FreeRTOS API functions that are safe to use from an ISR.
</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>void vApplicationTickHook(void)

// ---------------------- Example ----------------------

#define configUSE_TICK_HOOK    1

volatile uint32_t ulTickHookCounter = 0;
volatile BaseType_t xOneSecondElapsed = pdFALSE;

void vApplicationTickHook(void) {
    ulTickHookCounter++;

    // Set a flag approximately once every second
    if (ulTickHookCounter >= configTICK_RATE_HZ)
    {
        ulTickHookCounter = 0;
        xOneSecondElapsed = pdTRUE;
    }
}</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">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vApplicationTickHook</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configUSE_TICK_HOOK</span><span style="color: #D5CED9">    </span><span style="color: #F39C12">1</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">volatile</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> ulTickHookCounter </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">0</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #C74DED">volatile</span><span style="color: #D5CED9"> BaseType_t xOneSecondElapsed </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> pdFALSE;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vApplicationTickHook</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</span><span style="color: #D5CED9">) {</span></span>
<span class="line"><span style="color: #D5CED9">    ulTickHookCounter</span><span style="color: #EE5D43">++</span><span style="color: #D5CED9">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #A0A1A7CC">// Set a flag approximately once every second</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #C74DED">if</span><span style="color: #D5CED9"> (ulTickHookCounter </span><span style="color: #EE5D43">&gt;=</span><span style="color: #D5CED9"> configTICK_RATE_HZ)</span></span>
<span class="line"><span style="color: #D5CED9">    {</span></span>
<span class="line"><span style="color: #D5CED9">        ulTickHookCounter </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">0</span><span style="color: #D5CED9">;</span></span>
<span class="line"><span style="color: #D5CED9">        xOneSecondElapsed </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> pdTRUE;</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;">

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

<p>
<span class="highlight">vApplicationMallocFailedHook()</span> is a user-defined FreeRTOS hook function that is called whenever a dynamic memory allocation request fails, such as when <span class="highlight">pvPortMalloc()</span>, <span class="highlight">xTaskCreate()</span>, or another kernel object creation function cannot obtain enough heap memory. To enable it, set <span class="highlight">configUSE_MALLOC_FAILED_HOOK</span> to 1 in <span class="highlight">FreeRTOSConfig.h</span>. The hook is commonly used to record diagnostic information, trigger an assertion, illuminate an error indicator, or halt execution for debugging. Because the system may have very little memory remaining, the hook should avoid performing additional dynamic memory allocations.
</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>void vApplicationMallocFailedHook(void)

// ---------------------- Example ----------------------

#define configUSE_MALLOC_FAILED_HOOK    1

void vApplicationMallocFailedHook(void) 
{
    taskDISABLE_INTERRUPTS();
    for (;;) {}
}</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">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vApplicationMallocFailedHook</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configUSE_MALLOC_FAILED_HOOK</span><span style="color: #D5CED9">    </span><span style="color: #F39C12">1</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vApplicationMallocFailedHook</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</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: #FFE66D">taskDISABLE_INTERRUPTS</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #C74DED">for</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;">

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

<p>
<span class="highlight">vApplicationStackOverflowHook()</span> is a user-defined FreeRTOS hook function that is called when the kernel detects that a task has exceeded its allocated stack space. To enable stack-overflow checking, set <span class="highlight">configCHECK_FOR_STACK_OVERFLOW</span> to 1 or 2 in <span class="highlight">FreeRTOSConfig.h</span>, with 2 providing more thorough checking. The hook receives the handle and name of the affected task, allowing the application to record diagnostic information, trigger an assertion, illuminate an error LED, or halt execution for debugging. Because stack corruption may already have occurred, the hook should avoid complex operations and should normally stop the system so the cause can be investigated.
</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>void vApplicationStackOverflowHook(TaskHandle_t xTask, 
                                   char *pcTaskName)

// ---------------------- Example ----------------------

#define INCLUDE_uxTaskGetStackHighWaterMark    1
#define configCHECK_FOR_STACK_OVERFLOW			   2    

volatile const char *g_overflow_task_name = NULL;
volatile TaskHandle_t g_overflow_task_handle = NULL;

void vApplicationStackOverflowHook(TaskHandle_t xTask, 
                                   char *pcTaskName) 
{
    g_overflow_task_handle = xTask;
    g_overflow_task_name = pcTaskName; // points to the task name string

    taskDISABLE_INTERRUPTS();
    for (;;) {
        __NOP(); // set breakpoint here and inspect g_overflow_task_name
                 // LED may also be turned on or toggled here
    }
}

TaskHandle_t taskHandler;
UBaseType_t uxRemainingWords;
uxRemainingWords = uxTaskGetStackHighWaterMark(taskHandler);
printf("Unused stack: %lu words (%lu bytes)\r\n",
       (unsigned long)uxRemainingWords,
       (unsigned long)uxRemainingWords * sizeof(StackType_t));</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">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vApplicationStackOverflowHook</span><span style="color: #D5CED9">(TaskHandle_t </span><span style="color: #00E8C6">xTask</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                                   </span><span style="color: #C74DED">char</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #00E8C6">pcTaskName</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">INCLUDE_uxTaskGetStackHighWaterMark</span><span style="color: #D5CED9">    </span><span style="color: #F39C12">1</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configCHECK_FOR_STACK_OVERFLOW</span><span style="color: #D5CED9">			   </span><span style="color: #F39C12">2</span><span style="color: #D5CED9">    </span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">volatile</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">char</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9">g_overflow_task_name </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: #C74DED">volatile</span><span style="color: #D5CED9"> TaskHandle_t g_overflow_task_handle </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">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vApplicationStackOverflowHook</span><span style="color: #D5CED9">(TaskHandle_t </span><span style="color: #00E8C6">xTask</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                                   </span><span style="color: #C74DED">char</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #00E8C6">pcTaskName</span><span style="color: #D5CED9">) </span></span>
<span class="line"><span style="color: #D5CED9">{</span></span>
<span class="line"><span style="color: #D5CED9">    g_overflow_task_handle </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> xTask;</span></span>
<span class="line"><span style="color: #D5CED9">    g_overflow_task_name </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> pcTaskName;</span><span style="color: #A0A1A7CC"> // points to the task name string</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">taskDISABLE_INTERRUPTS</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #C74DED">for</span><span style="color: #D5CED9"> (;;) {</span></span>
<span class="line cbp-see-more-line "><span style="color: #D5CED9">        </span><span style="color: #FFE66D">__NOP</span><span style="color: #D5CED9">();</span><span style="color: #A0A1A7CC"> // set breakpoint here and inspect g_overflow_task_name</span></span>
<span class="line"><span style="color: #D5CED9">                 </span><span style="color: #A0A1A7CC">// LED may also be turned on or toggled here</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: #D5CED9">TaskHandle_t taskHandler;</span></span>
<span class="line"><span style="color: #D5CED9">UBaseType_t uxRemainingWords;</span></span>
<span class="line"><span style="color: #D5CED9">uxRemainingWords </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">uxTaskGetStackHighWaterMark</span><span style="color: #D5CED9">(taskHandler);</span></span>
<span class="line"><span style="color: #FFE66D">printf</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot;Unused stack: </span><span style="color: #EE5D43">%lu</span><span style="color: #96E072"> words (</span><span style="color: #EE5D43">%lu</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>
<span class="line"><span style="color: #D5CED9">       (</span><span style="color: #C74DED">unsigned</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">long</span><span style="color: #D5CED9">)</span><span style="color: #00E8C6">uxRemainingWords</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">       (</span><span style="color: #C74DED">unsigned</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">long</span><span style="color: #D5CED9">)uxRemainingWords </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">sizeof</span><span style="color: #D5CED9">(StackType_t));</span></span></code></pre></div>



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

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

<p>
<span class="highlight">vApplicationDaemonTaskStartupHook()</span> is a user-defined FreeRTOS hook function that is called once when the daemon task, also known as the timer service task, begins running after the scheduler starts. To enable it, set <span class="highlight">configUSE_DAEMON_TASK_STARTUP_HOOK</span> to 1 in <span class="highlight">FreeRTOSConfig.h</span>. It is typically used to perform application initialization that must occur after the scheduler is active, such as creating synchronization objects, starting software timers, or initializing components that depend on FreeRTOS services. Because the hook executes in the context of the daemon task, lengthy or blocking operations should be avoided so that software timers and deferred callback processing are not delayed.
</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>void vApplicationDaemonTaskStartupHook(void)

// ---------------------- Example ----------------------

#define configUSE_DAEMON_TASK_STARTUP_HOOK    1
#define configUSE_TIMERS				              1

TimerHandle_t OneShotTimer_Handle;

OneShotTimer_Handle = 
  xTimerCreate((const char*			       ) "OneShotTimer",
			         (TickType_t			       ) 3000,
							 (UBaseType_t			       ) pdFALSE,
							 (void*				           ) 1,
							 (TimerCallbackFunction_t) OneShotTimerCallback);

void vApplicationDaemonTaskStartupHook(void) {
    BaseType_t xResult;
    xResult = xTimerStart(OneShotTimer_Handle, 0);
    configASSERT(xResult == pdPASS);
}

void OneShotTimerCallback(TimerHandle_t xTimer) {
	static TickType_t xTimeNow;
	xTimeNow = xTaskGetTickCount();
	printf("One-shot timer callback executing: %d\r\n", (int)xTimeNow);
}</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">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vApplicationDaemonTaskStartupHook</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configUSE_DAEMON_TASK_STARTUP_HOOK</span><span style="color: #D5CED9">    </span><span style="color: #F39C12">1</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configUSE_TIMERS</span><span style="color: #D5CED9">				              </span><span style="color: #F39C12">1</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">TimerHandle_t OneShotTimer_Handle;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">OneShotTimer_Handle </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span></span>
<span class="line"><span style="color: #D5CED9">  </span><span style="color: #FFE66D">xTimerCreate</span><span style="color: #D5CED9">((</span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">char</span><span style="color: #EE5D43">*</span><span style="color: #D5CED9">			       ) </span><span style="color: #96E072">&quot;OneShotTimer&quot;</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">			         (TickType_t			       ) </span><span style="color: #F39C12">3000</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">							 (UBaseType_t			       ) </span><span style="color: #00E8C6">pdFALSE</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">							 (</span><span style="color: #C74DED">void</span><span style="color: #EE5D43">*</span><span style="color: #D5CED9">				           ) </span><span style="color: #F39C12">1</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">							 (TimerCallbackFunction_t) </span><span style="color: #00E8C6">OneShotTimerCallback</span><span style="color: #D5CED9">);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vApplicationDaemonTaskStartupHook</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</span><span style="color: #D5CED9">) {</span></span>
<span class="line"><span style="color: #D5CED9">    BaseType_t xResult;</span></span>
<span class="line"><span style="color: #D5CED9">    xResult </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xTimerStart</span><span style="color: #D5CED9">(OneShotTimer_Handle, </span><span style="color: #F39C12">0</span><span style="color: #D5CED9">);</span></span>
<span class="line cbp-see-more-line "><span style="color: #D5CED9">    </span><span style="color: #FFE66D">configASSERT</span><span style="color: #D5CED9">(xResult </span><span style="color: #EE5D43">==</span><span style="color: #D5CED9"> pdPASS);</span></span>
<span class="line"><span style="color: #D5CED9">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">OneShotTimerCallback</span><span style="color: #D5CED9">(TimerHandle_t </span><span style="color: #00E8C6">xTimer</span><span style="color: #D5CED9">) {</span></span>
<span class="line"><span style="color: #D5CED9">	</span><span style="color: #C74DED">static</span><span style="color: #D5CED9"> TickType_t xTimeNow;</span></span>
<span class="line"><span style="color: #D5CED9">	xTimeNow </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xTaskGetTickCount</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">	</span><span style="color: #FFE66D">printf</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot;One-shot timer callback executing: </span><span style="color: #EE5D43">%d\r\n</span><span style="color: #96E072">&quot;</span><span style="color: #D5CED9">, (</span><span style="color: #C74DED">int</span><span style="color: #D5CED9">)xTimeNow);</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;">

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

<p>
<span class="highlight">configUSE_TICKLESS_IDLE</span> enables FreeRTOS tickless idle mode, which reduces power consumption when no application task is ready to run. Normally, the periodic RTOS tick interrupt continues waking the processor even while the Idle task is running. When tickless idle is enabled, FreeRTOS temporarily stops the tick interrupt, places the processor into a low-power state, and sleeps until an interrupt occurs or a blocked task is due to wake. After waking, the kernel adjusts its tick count to account for the elapsed time. Set it to 0 to disable tickless idle, 1 to use the port&#8217;s built-in implementation when supported, or 2 to provide a custom <span class="highlight">portSUPPRESS_TICKS_AND_SLEEP()</span> implementation.
</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>#define configUSE_TICKLESS_IDLE    1                       

// FreeRTOSConfig.h
extern void PreSleepProcessing(uint32_t ulExpectedIdleTime);
extern void PostSleepProcessing(uint32_t ulExpectedIdleTime);
#define configPRE_SLEEP_PROCESSING  PreSleepProcessing	 
#define configPOST_SLEEP_PROCESSING  PostSleepProcessing	 

// main.c
void PreSleepProcessing(uint32_t ulExpectedIdleTime)
{
    (void)ulExpectedIdleTime;

    // Disable GPIO clocks that are not needed during sleep
    __HAL_RCC_GPIOB_CLK_DISABLE();
    __HAL_RCC_GPIOC_CLK_DISABLE();
    __HAL_RCC_GPIOD_CLK_DISABLE();
    __HAL_RCC_GPIOE_CLK_DISABLE();
    __HAL_RCC_GPIOF_CLK_DISABLE();
    __HAL_RCC_GPIOG_CLK_DISABLE();
    __HAL_RCC_GPIOH_CLK_DISABLE();
}

void PostSleepProcessing(uint32_t ulExpectedIdleTime)
{
    (void)ulExpectedIdleTime;

    // Re-enable GPIO clocks after waking up
    __HAL_RCC_GPIOB_CLK_ENABLE();
    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOD_CLK_ENABLE();
    __HAL_RCC_GPIOE_CLK_ENABLE();
    __HAL_RCC_GPIOF_CLK_ENABLE();
    __HAL_RCC_GPIOG_CLK_ENABLE();
    __HAL_RCC_GPIOH_CLK_ENABLE();
}</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">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configUSE_TICKLESS_IDLE</span><span style="color: #D5CED9">    </span><span style="color: #F39C12">1</span><span style="color: #D5CED9">                       </span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// FreeRTOSConfig.h</span></span>
<span class="line"><span style="color: #C74DED">extern</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">PreSleepProcessing</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">ulExpectedIdleTime</span><span style="color: #D5CED9">);</span></span>
<span class="line"><span style="color: #C74DED">extern</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">PostSleepProcessing</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">ulExpectedIdleTime</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">configPRE_SLEEP_PROCESSING</span><span style="color: #D5CED9">  PreSleepProcessing	 </span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configPOST_SLEEP_PROCESSING</span><span style="color: #D5CED9">  PostSleepProcessing	 </span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// main.c</span></span>
<span class="line"><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">PreSleepProcessing</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">ulExpectedIdleTime</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: #C74DED">void</span><span style="color: #D5CED9">)ulExpectedIdleTime;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #A0A1A7CC">// Disable GPIO clocks that are not needed during sleep</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOB_CLK_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOC_CLK_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOD_CLK_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOE_CLK_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOF_CLK_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line cbp-see-more-line "><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOG_CLK_DISABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOH_CLK_DISABLE</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: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">PostSleepProcessing</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">ulExpectedIdleTime</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: #C74DED">void</span><span style="color: #D5CED9">)ulExpectedIdleTime;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #A0A1A7CC">// Re-enable GPIO clocks after waking up</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOB_CLK_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOC_CLK_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOD_CLK_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOE_CLK_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOF_CLK_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOG_CLK_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">__HAL_RCC_GPIOH_CLK_ENABLE</span><span style="color: #D5CED9">();</span></span>
<span class="line"><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">7896</post-id>	</item>
		<item>
		<title>STM32 FreeRTOS: Task Notifications</title>
		<link>https://hangpersonal.com/2026/07/22/stm32-freertos-task-notification/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Wed, 22 Jul 2026 23:55:35 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=7813</guid>

					<description><![CDATA[STM32 Microcontroller and FreeRTOS Development Task notifications enable direct communication between tasks without requiring separate kernel objects such as queues, semaphores, or event groups. Pending: When a task receives a notification, its notification state is set to pending. Not pending: When the task processes the notification, its notification state is cleared to not pending. Advantages:...]]></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:30px; margin-bottom:40px;">
</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS: Task Notification"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">Task Notification API Function</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">Description</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#task_notify" style="font-size: 20px;color: blue">xTaskNotify()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Sends a notification to a task and updates its notification value using the specified action</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#task_notify_from_isr" style="font-size: 20px;color: blue">xTaskNotifyFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Sends a task notification safely from an ISR</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#task_notify_give" style="font-size: 20px;color: blue">xTaskNotifyGive()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Increments a task's notification value and unblocks it if waiting</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#task_notify_give_from_isr" style="font-size: 20px;color: blue">vTaskNotifyGiveFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Increments a task’s notification value from an ISR</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#task_notify_query" style="font-size: 20px;color: blue">xTaskNotifyAndQuery()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Sends a notification and returns the task’s previous notification value</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#task_notify_query_from_isr" style="font-size: 20px;color: blue">xTaskNotifyAndQueryFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Performs notify-and-query safely from an ISR</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#task_notify_take" style="font-size: 20px;color: blue">ulTaskNotifyTake()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Waits for a notification count, then clears or decrements it</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#task_notify_wait" style="font-size: 20px;color: blue">xTaskNotifyWait()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Waits for a notification and optionally clears selected notification bits</td>                            </tr>
                                            </tbody>
                </table>
                            </div>




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

<p>
Task notifications enable direct communication between tasks without requiring separate kernel objects such as queues, semaphores, or event groups.
</p>

<ul>
<li> Pending: When a task receives a notification, its notification state is set to pending.
</li> 
<li> Not pending: When the task processes the notification, its notification state is cleared to not pending.
</li>
</ul>

<p></p>

<p>
<b>Advantages</b>: Faster than using queues, semaphore and event groups to perform an equivalent operation. Requires significantly less RAM than using a queue, semaphore or an event group.
</p>

<p>
<b>Limitations</b>: Unlike queues, semaphores and event groups, task notifications cannot be used to send events or data from a task to an ISR, although they can be used to send events or data from an ISR to a task. Unlike queues, semaphores and event groups, task notifications cannot be sent to multiple tasks.
</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>// FreeRTOSConfig.h
#define configUSE_TASK_NOTIFICATIONS   1 </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">configUSE_TASK_NOTIFICATIONS</span><span style="color: #D5CED9">   </span><span style="color: #F39C12">1</span><span style="color: #D5CED9"> </span></span></code></pre></div>



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

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

<p>
<span class="highlight">xTaskNotify()</span> sends a task notification to another task and updates the receiving task&#8217;s notification value according to the selected <span class="highlight">eNotifyAction</span>. It can set specific bits, increment the value, overwrite the existing value, update it only when no unread notification is pending, or generate a notification event without modifying the value. If the receiving task is blocked waiting for the notification, it is moved to the Ready state. The function normally returns <span class="highlight">pdPASS</span>; however, when <span class="highlight">eSetValueWithoutOverwrite</span> is used, it returns <span class="highlight">pdFAIL</span> if a previous notification is still pending.
</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>BaseType_t xTaskNotify(TaskHandle_t xTaskToNotify,
                       uint32_t ulValue,
                       eNotifyAction eAction)
                       
// ---------------------- Example ---------------------- 

TaskHandle_t ReceiverTask_Handler;
uint8_t keyState;
BaseType_t err;
err = xTaskNotify((TaskHandle_t	) ReceiverTask_Handler,
							    (uint32_t		  ) keyState,
							    (eNotifyAction) eSetValueWithOverwrite);</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">BaseType_t </span><span style="color: #FFE66D">xTaskNotify</span><span style="color: #D5CED9">(TaskHandle_t </span><span style="color: #00E8C6">xTaskToNotify</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                       </span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">ulValue</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                       eNotifyAction </span><span style="color: #00E8C6">eAction</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                       </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ---------------------- </span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">TaskHandle_t ReceiverTask_Handler;</span></span>
<span class="line"><span style="color: #C74DED">uint8_t</span><span style="color: #D5CED9"> keyState;</span></span>
<span class="line"><span style="color: #D5CED9">BaseType_t err;</span></span>
<span class="line"><span style="color: #D5CED9">err </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xTaskNotify</span><span style="color: #D5CED9">((TaskHandle_t	) </span><span style="color: #00E8C6">ReceiverTask_Handler</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">							    (</span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9">		  ) </span><span style="color: #00E8C6">keyState</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">							    (eNotifyAction) </span><span style="color: #00E8C6">eSetValueWithOverwrite</span><span style="color: #D5CED9">);</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xTaskNotifyFromISR()</span> is the interrupt-safe version of <span class="highlight">xTaskNotify()</span>. It supports the same notification actions and includes the <span class="highlight">pxHigherPriorityTaskWoken</span> parameter, which is set to <span class="highlight">pdTRUE</span> if the notification unblocks a task with a higher priority than the currently running task. This variable must be initialized to <span class="highlight">pdFALSE</span> before the function is called. If it is set to <span class="highlight">pdTRUE</span>, <span class="highlight">portYIELD_FROM_ISR()</span> should be called before exiting the ISR to request an immediate context switch.
</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>BaseType_t xTaskNotifyFromISR(TaskHandle_t xTaskToNotify, 
                              uint32_t ulValue, 
                              eNotifyAction eAction, 
                              BaseType_t * pxHigherPriorityTaskWoken)

TaskHandle_t EventGroupTask_Handler;
#define EVENTBIT_0	 (1 &lt;&lt; 0)

BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xTaskNotifyFromISR((TaskHandle_t ) EventGroupTask_Handler,
						       (uint32_t	   ) EVENTBIT_0,
						       (eNotifyAction) eSetBits,
						       (BaseType_t*	 ) &amp;xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);</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">BaseType_t </span><span style="color: #FFE66D">xTaskNotifyFromISR</span><span style="color: #D5CED9">(TaskHandle_t </span><span style="color: #00E8C6">xTaskToNotify</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                              </span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">ulValue</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                              eNotifyAction </span><span style="color: #00E8C6">eAction</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                              BaseType_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxHigherPriorityTaskWoken</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">TaskHandle_t EventGroupTask_Handler;</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">EVENTBIT_0</span><span style="color: #D5CED9">	 (</span><span style="color: #F39C12">1</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">&lt;&lt;</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">0</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">BaseType_t xHigherPriorityTaskWoken </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> pdFALSE;</span></span>
<span class="line"><span style="color: #FFE66D">xTaskNotifyFromISR</span><span style="color: #D5CED9">((TaskHandle_t ) </span><span style="color: #00E8C6">EventGroupTask_Handler</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">						       (</span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9">	   ) </span><span style="color: #00E8C6">EVENTBIT_0</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">						       (eNotifyAction) </span><span style="color: #00E8C6">eSetBits</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">						       (BaseType_t</span><span style="color: #EE5D43">*</span><span style="color: #D5CED9">	 ) </span><span style="color: #EE5D43">&amp;</span><span style="color: #00E8C6">xHigherPriorityTaskWoken</span><span style="color: #D5CED9">);</span></span>
<span class="line"><span style="color: #FFE66D">portYIELD_FROM_ISR</span><span style="color: #D5CED9">(xHigherPriorityTaskWoken);</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xTaskNotifyGive()</span> increments the target task&#8217;s notification value by one and marks the notification as pending. It is equivalent to calling <span class="highlight">xTaskNotify()</span> with the <span class="highlight">eIncrement</span> action and is typically paired with <span class="highlight">ulTaskNotifyTake()</span>. Together, these functions provide a lightweight alternative to a binary or counting semaphore when an event needs to be delivered to a single specific task. <span class="highlight">xTaskNotifyGive()</span> must be called from task context; use <span class="highlight">vTaskNotifyGiveFromISR()</span> when sending the notification from an ISR.
</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>BaseType_t xTaskNotifyGive(TaskHandle_t xTaskToNotify)

// ---------------------- Example ---------------------- 

TaskHandle_t SemapGiveTask_Handler;
xTaskNotifyGive(SemapTakeTask_Handler);
printf("TaskNotifyGive!\r\n");</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">BaseType_t </span><span style="color: #FFE66D">xTaskNotifyGive</span><span style="color: #D5CED9">(TaskHandle_t </span><span style="color: #00E8C6">xTaskToNotify</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ---------------------- </span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">TaskHandle_t SemapGiveTask_Handler;</span></span>
<span class="line"><span style="color: #FFE66D">xTaskNotifyGive</span><span style="color: #D5CED9">(SemapTakeTask_Handler);</span></span>
<span class="line"><span style="color: #FFE66D">printf</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot;TaskNotifyGive!</span><span style="color: #EE5D43">\r\n</span><span style="color: #96E072">&quot;</span><span style="color: #D5CED9">);</span></span></code></pre></div>



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

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

<p>
<span class="highlight">vTaskNotifyGiveFromISR()</span> safely increments a task&#8217;s notification value from an interrupt service routine and marks the notification as pending. It is commonly used to unblock a task responsible for deferred interrupt processing, such as handling received data or processing a completed DMA transfer. The <span class="highlight">pxHigherPriorityTaskWoken</span> parameter indicates whether the notification unblocked a task with a higher priority than the interrupted task. If it is set to <span class="highlight">pdTRUE</span>, <span class="highlight">portYIELD_FROM_ISR()</span> should be called before exiting the ISR to request an immediate context switch.
</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>void vTaskNotifyGiveFromISR(TaskHandle_t xTaskHandle, 
                            BaseType_t * pxHigherPriorityTaskWoken)
                            
// ---------------------- Example ----------------------

TaskHandle_t DataProcess_Handler;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(DataProcess_Handler, &amp;xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);</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">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vTaskNotifyGiveFromISR</span><span style="color: #D5CED9">(TaskHandle_t </span><span style="color: #00E8C6">xTaskHandle</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                            BaseType_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxHigherPriorityTaskWoken</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                            </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">TaskHandle_t DataProcess_Handler;</span></span>
<span class="line"><span style="color: #D5CED9">BaseType_t xHigherPriorityTaskWoken </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> pdFALSE;</span></span>
<span class="line"><span style="color: #FFE66D">vTaskNotifyGiveFromISR</span><span style="color: #D5CED9">(DataProcess_Handler, </span><span style="color: #EE5D43">&amp;</span><span style="color: #00E8C6">xHigherPriorityTaskWoken</span><span style="color: #D5CED9">);</span></span>
<span class="line"><span style="color: #FFE66D">portYIELD_FROM_ISR</span><span style="color: #D5CED9">(xHigherPriorityTaskWoken);</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xTaskNotifyAndQuery()</span> performs the same notification and value-update operation as <span class="highlight">xTaskNotify()</span>, while also returning the target task’s previous notification value through <span class="highlight">pulPreviousNotifyValue</span>. The previous value is captured atomically before the selected <span class="highlight">eNotifyAction</span> modifies it. This is useful when the sending task needs to inspect and update the notification value in a single operation, such as checking previously set event bits or reading a counter before incrementing or overwriting it. The function must be called from task context.
</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>BaseType_t xTaskNotifyAndQuery(TaskHandle_t xTaskToNotify,
                               uint32_t ulValue,
                               eNotifyAction eAction,
                               uint32_t * pulPreviousNotificationValue)</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">BaseType_t </span><span style="color: #FFE66D">xTaskNotifyAndQuery</span><span style="color: #D5CED9">(TaskHandle_t </span><span style="color: #00E8C6">xTaskToNotify</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                               </span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">ulValue</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                               eNotifyAction </span><span style="color: #00E8C6">eAction</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                               </span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pulPreviousNotificationValue</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xTaskNotifyAndQueryFromISR()</span> is the interrupt-safe version of <span class="highlight">xTaskNotifyAndQuery()</span>. It sends a notification to the target task, updates its notification value according to the selected <span class="highlight">eNotifyAction</span>, and returns the value that existed before the update through <span class="highlight">pulPreviousNotifyValue</span>. The <span class="highlight">pxHigherPriorityTaskWoken</span> parameter indicates whether the notification unblocked a higher-priority task, allowing the ISR to request an immediate context switch with <span class="highlight">portYIELD_FROM_ISR()</span>. The function normally returns <span class="highlight">pdPASS</span>; however, when <span class="highlight">eSetValueWithoutOverwrite</span> is used, it returns <span class="highlight">pdFAIL</span> if an unread notification is already pending.
</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>BaseType_t xTaskNotifyAndQueryFromISR(
    TaskHandle_t xTaskToNotify, 
    uint32_t ulValue, 
    eNotifyAction eAction, 
    uint32_t * pulPreviousNotificationValue
    BaseType_t * pxHigherPriorityTaskWoken)</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">BaseType_t </span><span style="color: #FFE66D">xTaskNotifyAndQueryFromISR</span><span style="color: #D5CED9">(</span></span>
<span class="line"><span style="color: #D5CED9">    TaskHandle_t </span><span style="color: #00E8C6">xTaskToNotify</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">ulValue</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">    eNotifyAction </span><span style="color: #00E8C6">eAction</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> pulPreviousNotificationValue</span></span>
<span class="line"><span style="color: #D5CED9">    BaseType_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxHigherPriorityTaskWoken</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
<span class="highlight">ulTaskNotifyTake()</span> allows the calling task to block until its notification value becomes nonzero or the specified timeout expires. When a notification is received, setting <span class="highlight">xClearCountOnExit</span> to <span class="highlight">pdTRUE</span> clears the notification value to zero, providing binary-semaphore behavior. Setting it to <span class="highlight">pdFALSE</span> decrements the value by one, providing counting-semaphore behavior. The function returns the notification value before it is cleared or decremented, or 0 if the wait period expires without a notification.
</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>uint32_t ulTaskNotifyTake(BaseType_t xClearCountOnExit, 
                          TickType_t xTicksToWait)
                          
// ---------------------- Example ----------------------

uint32_t NotifyValue;
NotifyValue = ulTaskNotifyTake(pdTRUE, portMAX_DELAY);</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">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">ulTaskNotifyTake</span><span style="color: #D5CED9">(BaseType_t </span><span style="color: #00E8C6">xClearCountOnExit</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                          TickType_t </span><span style="color: #00E8C6">xTicksToWait</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                          </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> NotifyValue;</span></span>
<span class="line"><span style="color: #D5CED9">NotifyValue </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">ulTaskNotifyTake</span><span style="color: #D5CED9">(pdTRUE, portMAX_DELAY);</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xTaskNotifyWait()</span> blocks the calling task until a notification becomes pending or the specified timeout expires. It can clear selected bits in the task&#8217;s notification value before waiting and clear additional bits after the received value has been copied to <span class="highlight">pulNotificationValue</span>. This makes it well suited for receiving event flags or a 32-bit mailbox value sent through <span class="highlight">xTaskNotify()</span>. The function returns <span class="highlight">pdTRUE</span> when a notification is received and <span class="highlight">pdFALSE</span> if the wait period expires without one.
</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>BaseType_t xTaskNotifyWait(uint32_t ulBitsToClearOnEntry,
                           uint32_t ulBitsToClearOnExit, 
                           uint32_t * pulNotificationValue, 
                           TickType_t xTicksToWait)
                           
// ---------------------- Example ----------------------

uint32_t NotifyValue;
BaseType_t err;
err = xTaskNotifyWait((uint32_t	 ) 0x00,		       // Clear no bits before waiting
							        (uint32_t	 ) ULONG_MAX,	     // Clear all bits after receiving
							        (uint32_t* ) &amp;NotifyValue,   // Store the received notification value  
							        (TickType_t) portMAX_DELAY); // Wait indefinitely                           </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">BaseType_t </span><span style="color: #FFE66D">xTaskNotifyWait</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">ulBitsToClearOnEntry</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                           </span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">ulBitsToClearOnExit</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                           </span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pulNotificationValue</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                           TickType_t </span><span style="color: #00E8C6">xTicksToWait</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                           </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9"> NotifyValue;</span></span>
<span class="line"><span style="color: #D5CED9">BaseType_t err;</span></span>
<span class="line"><span style="color: #D5CED9">err </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xTaskNotifyWait</span><span style="color: #D5CED9">((</span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9">	 ) </span><span style="color: #C74DED">0x</span><span style="color: #F39C12">00</span><span style="color: #D5CED9">,</span><span style="color: #A0A1A7CC">		       // Clear no bits before waiting</span></span>
<span class="line"><span style="color: #D5CED9">							        (</span><span style="color: #C74DED">uint32_t</span><span style="color: #D5CED9">	 ) </span><span style="color: #00E8C6">ULONG_MAX</span><span style="color: #D5CED9">,</span><span style="color: #A0A1A7CC">	     // Clear all bits after receiving</span></span>
<span class="line"><span style="color: #D5CED9">							        (</span><span style="color: #C74DED">uint32_t</span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> ) </span><span style="color: #EE5D43">&amp;</span><span style="color: #00E8C6">NotifyValue</span><span style="color: #D5CED9">,</span><span style="color: #A0A1A7CC">   // Store the received notification value  </span></span>
<span class="line"><span style="color: #D5CED9">							        (TickType_t) </span><span style="color: #00E8C6">portMAX_DELAY</span><span style="color: #D5CED9">);</span><span style="color: #A0A1A7CC"> // Wait indefinitely                           </span></span></code></pre></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">7813</post-id>	</item>
		<item>
		<title>FreeRTOS vs. Zephyr RTOS</title>
		<link>https://hangpersonal.com/2026/07/20/freertos-vs-zephyr/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Mon, 20 Jul 2026 16:40:47 +0000</pubDate>
				<category><![CDATA[Embedded System]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=7585</guid>

					<description><![CDATA[FreeRTOS is a lightweight, production-proven real-time kernel maintained by AWS under the MIT license. Built for resource-constrained microcontrollers, it delivers deterministic task scheduling, queues, semaphores, mutexes, and memory management with minimal flash and RAM usage. Its modular, vendor-neutral design integrates easily with custom toolchains, hardware platforms, and abstraction layers, making it a strong choice for...]]></description>
										<content:encoded><![CDATA[
<div class="article-text" style="margin-top:30px; margin-bottom:50px;">

<p>
<b>FreeRTOS</b> is a lightweight, production-proven real-time kernel maintained by AWS under the MIT license. Built for resource-constrained microcontrollers, it delivers deterministic task scheduling, queues, semaphores, mutexes, and memory management with minimal flash and RAM usage. Its modular, vendor-neutral design integrates easily with custom toolchains, hardware platforms, and abstraction layers, making it a strong choice for fast, predictable, low-level embedded systems.
</p>

<p>
<b>Zephyr</b> is a modern, full-featured RTOS hosted by the Linux Foundation under the Apache 2.0 license. Inspired by Linux, it combines standardized drivers, Devicetree and Kconfig configuration, built-in networking and wireless stacks, and security features such as MPU-based isolation. Its vendor-neutral, platform-oriented architecture enables developers to build secure, scalable IoT applications that can be ported across a wide range of hardware.
</p>


</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode spbtbl-fullwidth" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS vs Zephyr RTOS"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">Feature / Concept</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">FreeRTOS</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">Zephyr RTOS</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >License &amp; Sponsor</td>                                    <td style="font-size:18px !important;" itemprop="description" >Amazon Web Services (AWS) / MIT</td>                                    <td style="font-size:18px !important;" itemprop="description" >Linux Foundation / Apache 2.0</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Core Philosophy</td>                                    <td style="font-size:18px !important;" itemprop="description" >Minimalist kernel &amp; task scheduler</td>                                    <td style="font-size:18px !important;" itemprop="description" >Full-featured platform ecosystem</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Execution Primitives</td>                                    <td style="font-size:18px !important;" itemprop="description" >Tasks</td>                                    <td style="font-size:18px !important;" itemprop="description" >Threads, work queues, system work queue</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >System Options</td>                                    <td style="font-size:18px !important;" itemprop="description" >C Header file (FreeRTOSConfig.h)</td>                                    <td style="font-size:18px !important;" itemprop="description" >Kconfig (prj.conf)</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Hardware Description</td>                                    <td style="font-size:18px !important;" itemprop="description" >Vendor initialization code &amp; manual board support</td>                                    <td style="font-size:18px !important;" itemprop="description" >Devicetree (.dts), overlays, and bindings</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Abstraction Layer</td>                                    <td style="font-size:18px !important;" itemprop="description" >Vendor HALs (e.g., STM32 HAL, ESP-IDF)</td>                                    <td style="font-size:18px !important;" itemprop="description" >Universal, vendor-neutral driver APIs</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >App Portability</td>                                    <td style="font-size:18px !important;" itemprop="description" >Vendor/chip-specific projects</td>                                    <td style="font-size:18px !important;" itemprop="description" >Highly portable across boards and silicon vendors</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Networking &amp; Connectivity</td>                                    <td style="font-size:18px !important;" itemprop="description" >Manual integration (or AWS IoT / FreeRTOS-Plus-TCP)</td>                                    <td style="font-size:18px !important;" itemprop="description" >Built-in IPv4/IPv6, Ethernet, Wi-Fi, BLE, Mesh</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >System Services</td>                                    <td style="font-size:18px !important;" itemprop="description" >Custom logging, optional third-party components</td>                                    <td style="font-size:18px !important;" itemprop="description" >Built-in Logging subsystem, Shell CLI, USB, POSIX</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Memory Isolation</td>                                    <td style="font-size:18px !important;" itemprop="description" >Flat memory space (optional FreeRTOS-MPU)</td>                                    <td style="font-size:18px !important;" itemprop="description" >Native User/Kernel mode isolation &amp; MPU support</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Build System &amp; Tools</td>                                    <td style="font-size:18px !important;" itemprop="description" >Vendor IDEs (Keil, STM32CubeIDE), Make, CMake</td>                                    <td style="font-size:18px !important;" itemprop="description" >west meta-tool, CMake, and Zephyr SDK</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Flash / RAM Footprint</td>                                    <td style="font-size:18px !important;" itemprop="description" >Tiny (~5–10 KB Flash base)</td>                                    <td style="font-size:18px !important;" itemprop="description" >Scalable (~15–50+ KB Flash depending on modules)</td>                            </tr>
                                            </tbody>
                </table>
                            </div>




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

<p>
<b>FreeRTOS (Scheduler)</b>: FreeRTOS provides core RTOS primitives, tasks, semaphores, queues, and software timers. It leaves driver implementation, networking, and hardware configuration up to you or your target MCU&#8217;s vendor HAL.
</p>

<p>
<b>Zephyr (Platform)</b>: Zephyr takes a batteries-included approach. It includes unified driver models, a shell interface, power management, filesystems, and security modules built directly into the tree.
</p>

</div>



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

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

<p>
<b>FreeRTOS</b>: Configuration is managed through a single <span class="highlight">FreeRTOSConfig.h</span> file. You can easily integrate it into almost any vendor IDE (Keil, IAR, STM32CubeIDE) or custom Makefile/CMake environment.
</p>

<p>
<b>Zephyr</b>: Mimics the Linux kernel build process. Hardware is described using <span class="highlight">Devicetree (.dts)</span>, while software components are toggled using <span class="highlight">Kconfig (prj.conf)</span>. The meta-tool west manages repositories and builds, offering high cross-platform portability at the cost of a steeper initial learning curve.
</p>

</div>



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

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

<p>
<b>FreeRTOS</b>: Has lower context-switching and interrupt overhead because of its lean execution model. Tasks generally execute in a single shared memory space.
</p>

<p>
<b>Zephyr</b>: Emphasizes safety and isolation. On supported hardware, it separates kernel mode from user mode and enforces hardware stack protection and memory partitions using the Memory Protection Unit (MPU).
</p>

</div>



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

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

</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode spbtbl-fullwidth" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS API vs. Zephyr API"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">Concept</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">FreeRTOS API</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">Zephyr RTOS API</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Thread Creation</td>                                    <td style="font-size:18px !important;" itemprop="description" >xTaskCreate()</td>                                    <td style="font-size:18px !important;" itemprop="description" >k_thread_create()</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Thread Delay</td>                                    <td style="font-size:18px !important;" itemprop="description" >vTaskDelay()</td>                                    <td style="font-size:18px !important;" itemprop="description" >k_sleep()<br>k_msleep()</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Binary Semaphore</td>                                    <td style="font-size:18px !important;" itemprop="description" >xSemaphoreCreateBinary()<br>xSemaphoreTake()</td>                                    <td style="font-size:18px !important;" itemprop="description" >K_SEM_DEFINE(..., 0, 1)<br>k_sem_take()</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Mutex</td>                                    <td style="font-size:18px !important;" itemprop="description" >xSemaphoreCreateMutex()<br>xSemaphoreTake()</td>                                    <td style="font-size:18px !important;" itemprop="description" >K_MUTEX_DEFINE(...)<br>k_mutex_lock()</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Event Group</td>                                    <td style="font-size:18px !important;" itemprop="description" >xEventGroupCreate()</td>                                    <td style="font-size:18px !important;" itemprop="description" >k_event_init()</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Message Queue</td>                                    <td style="font-size:18px !important;" itemprop="description" >xQueueCreate()<br>xQueueSend()</td>                                    <td style="font-size:18px !important;" itemprop="description" >k_msgq_init()<br>k_msgq_put()</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Direct Notification</td>                                    <td style="font-size:18px !important;" itemprop="description" >Task Notification<br>xTaskNotify()</td>                                    <td style="font-size:18px !important;" itemprop="description" >Semaphore<br>k_event, or k_poll_signal</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Timers</td>                                    <td style="font-size:18px !important;" itemprop="description" >Software Timer<br>xTimerCreate()</td>                                    <td style="font-size:18px !important;" itemprop="description" >Kernel Timer<br>k_timer_init()</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Background Exec</td>                                    <td style="font-size:18px !important;" itemprop="description" >Daemon / Timer Task</td>                                    <td style="font-size:18px !important;" itemprop="description" >System Work Queue k_work_submit()</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" >Interrupt APIs</td>                                    <td style="font-size:18px !important;" itemprop="description" >Separate ...FromISR() APIs</td>                                    <td style="font-size:18px !important;" itemprop="description" >Unified APIs (e.g., k_sem_give() works in ISR)</td>                            </tr>
                                            </tbody>
                </table>
                            </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">7585</post-id>	</item>
		<item>
		<title>STM32 FreeRTOS: Event Groups</title>
		<link>https://hangpersonal.com/2026/07/17/stm32-freertos-event-group/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Sat, 18 Jul 2026 04:47:38 +0000</pubDate>
				<category><![CDATA[Embedded System]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=7579</guid>

					<description><![CDATA[STM32 Microcontroller and FreeRTOS Development Event Groups Event groups allow a task to wait in the blocked state for a combination of one of more events to occur. Event groups unblock all the tasks that were waiting for the same event, or combination of events, when the event occurs. Event groups reduce RAM usage by...]]></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:30px; margin-bottom:40px;">
</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode spbtbl-fullwidth" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS: Event Group"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">Event Group API Function</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">Description</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#event_group_create" style="font-size: 20px;color: blue">xEventGroupCreate()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Create an event group using dynamic memory allocation</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#event_group_create_static" style="font-size: 20px;color: blue">xEventGroupCreateStatic()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Create an event group using user-provided static memory</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#event_group_clear_bits" style="font-size: 20px;color: blue">xEventGroupClearBits()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Clear specified event bits from an event group</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#event_group_clear_bits_from_isr" style="font-size: 20px;color: blue">xEventGroupClearBitsFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Request specified event bits to be cleared from an ISR</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#event_group_set_bits" style="font-size: 20px;color: blue">xEventGroupSetBits()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Set specified event bits in an event group</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#event_group_set_bits_from_isr" style="font-size: 20px;color: blue">xEventGroupSetBitsFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Request specified event bits to be set from an ISR</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#event_group_get_bits" style="font-size: 20px;color: blue">xEventGroupGetBits()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Return the current event-bit value of an event group</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#event_group_get_bits_from_isr" style="font-size: 20px;color: blue">xEventGroupGetBitsFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Return the current event-bit value from an ISR</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#event_group_wait_bits" style="font-size: 20px;color: blue">xEventGroupWaitBits()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Block a task until specified event bits are set or a timeout occurs</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#event_group_sync" style="font-size: 20px;color: blue">xEventGroupSync()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Sets event bits and waits for all specified bits</td>                            </tr>
                                            </tbody>
                </table>
                            </div>




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

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

<p>
Event groups allow a task to wait in the blocked state for a combination of one of more events to occur. Event groups unblock all the tasks that were waiting for the same event, or combination of events, when the event occurs. Event groups reduce RAM usage by allowing us to replace multiple binary semaphores with a single event group.

<ul>
<li> Synchronizing tasks
</li>
<li>Broadcasting events to multiple tasks
</li>
</ul>

</p>

</div>



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

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

<p>
When <span class="highlight">configUSE_16_BIT_TICKS</span> is set to 0, <span class="highlight">TickType_t</span> is a 32-bit data type, so <span class="highlight">EventBits_t</span> is also a 32-bit data type. A variable of type <span class="highlight">EventBits_t</span> can store 24 event bits, while the upper 8 bits are reserved for internal use. Event bit 0 is stored in bit 0 of the variable, event bit 1 is stored in bit 1, and so on. For STM32 devices, an event group can therefore contain up to 24 usable event bits.
</p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="195" src="https://hangpersonal.com/wp-content/uploads/2026/07/event_group-1024x195.png" alt="" class="wp-image-7750" style="width:700px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/event_group-1024x195.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/event_group-300x57.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/event_group-768x146.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/event_group-1536x292.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/07/event_group-2048x389.png 2048w, https://hangpersonal.com/wp-content/uploads/2026/07/event_group-850x161.png 850w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


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

<p>
</p><ul>

<li>
An event group is a set of event flags
</li>

<li>An event flag is a boolean value (1 or 0) used to indicate whether an event has occurred or not
</li>

<li>An event flag is stored in a single bit and the state of all event flags can be stored in a single variable
</li>

</ul>
<p></p>

</div>



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

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

<p>
<span class="highlight">xEventGroupCreate()</span> dynamically allocates the required memory and creates a new event group. It returns an <span class="highlight">EventGroupHandle_t</span> for use with other event-group functions, or NULL if memory allocation fails. This function is available only when <span class="highlight">configSUPPORT_DYNAMIC_ALLOCATION</span> is enabled. When the event group is no longer needed, call <span class="highlight">vEventGroupDelete()</span> to free the allocated memory.
</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>EventGroupHandle_t xEventGroupCreate(void)

// ---------------------- Example ----------------------

EventGroupHandle_t xEventGroupHandler;
xEventGroupHandler = xEventGroupCreate();</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">EventGroupHandle_t </span><span style="color: #FFE66D">xEventGroupCreate</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">EventGroupHandle_t xEventGroupHandler;</span></span>
<span class="line"><span style="color: #D5CED9">xEventGroupHandler </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xEventGroupCreate</span><span style="color: #D5CED9">();</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xEventGroupCreateStatic()</span> creates an event group using memory supplied by the application rather than allocating memory from the FreeRTOS heap. The application must provide a <span class="highlight">StaticEventGroup_t</span> variable that remains valid for the entire lifetime of the event group. This function is useful in systems that require deterministic memory usage or do not permit dynamic allocation, and it is available only when <span class="highlight">configSUPPORT_STATIC_ALLOCATION</span> is enabled.
</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>EventGroupHandle_t xEventGroupCreateStatic(StaticEventGroup_t *pxEventGroupBuffer)</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">EventGroupHandle_t </span><span style="color: #FFE66D">xEventGroupCreateStatic</span><span style="color: #D5CED9">(StaticEventGroup_t </span><span style="color: #EE5D43">*</span><span style="color: #00E8C6">pxEventGroupBuffer</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xEventGroupClearBits()</span> clears one or more specified bits in an event group from task context. The bits are selected using a bit mask: each bit set to 1 in the mask is cleared, while all other bits remain unchanged. The function returns the event-group value before the bits were cleared, allowing the task to inspect the previous event state. It must not be called from an interrupt service routine.
</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>EventBits_t xEventGroupClearBits(EventGroupHandle_t xEventGroup, 
                                 const EventBits_t uxBitsToClear)</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">EventBits_t </span><span style="color: #FFE66D">xEventGroupClearBits</span><span style="color: #D5CED9">(EventGroupHandle_t </span><span style="color: #00E8C6">xEventGroup</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                                 </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> EventBits_t </span><span style="color: #00E8C6">uxBitsToClear</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xEventGroupClearBitsFromISR()</span> requests that one or more specified event bits be cleared from interrupt context. Because clearing event bits may unblock multiple waiting tasks, the operation is deferred to the FreeRTOS timer daemon task rather than performed directly within the ISR. The function returns <span class="highlight">pdPASS</span> if the request is successfully posted to the timer command queue, or <span class="highlight">pdFAIL</span> if the queue is full.
</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>BaseType_t xEventGroupClearBitsFromISR(EventGroupHandle_t xEventGroup, 
                                       const EventBits_t uxBitsToSet)</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">BaseType_t </span><span style="color: #FFE66D">xEventGroupClearBitsFromISR</span><span style="color: #D5CED9">(EventGroupHandle_t </span><span style="color: #00E8C6">xEventGroup</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                                       </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> EventBits_t </span><span style="color: #00E8C6">uxBitsToSet</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xEventGroupSetBits()</span> sets one or more specified bits in an event group from task context. Tasks waiting for those bits are then evaluated and may be moved from the Blocked state to the Ready state. Multiple bits can be set simultaneously by combining them with the bitwise OR operator. The function returns the event-group value after the bits have been set and any automatically cleared bits have been processed.
</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>EventBits_t xEventGroupSetBits(EventGroupHandle_t xEventGroup, 
                               const EventBits_t uxBitsToSet)

// ---------------------- Example ---------------------- 

#define EVENTBIT_0	 (1 &lt;&lt; 0)
#define EVENTBIT_1	 (1 &lt;&lt; 1)
#define EVENTBIT_2	 (1 &lt;&lt; 2)
#define EVENTBIT_ALL (EVENTBIT_0 | EVENTBIT_1 | EVENTBIT_2)
                              
xEventGroupSetBits(xEventGroupHandler, EVENTBIT_1);
xEventGroupSetBits(xEventGroupHandler, EVENTBIT_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">EventBits_t </span><span style="color: #FFE66D">xEventGroupSetBits</span><span style="color: #D5CED9">(EventGroupHandle_t </span><span style="color: #00E8C6">xEventGroup</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                               </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> EventBits_t </span><span style="color: #00E8C6">uxBitsToSet</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ---------------------- </span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">EVENTBIT_0</span><span style="color: #D5CED9">	 (</span><span style="color: #F39C12">1</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">&lt;&lt;</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">0</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">EVENTBIT_1</span><span style="color: #D5CED9">	 (</span><span style="color: #F39C12">1</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">&lt;&lt;</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">1</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">EVENTBIT_2</span><span style="color: #D5CED9">	 (</span><span style="color: #F39C12">1</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">&lt;&lt;</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">2</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">EVENTBIT_ALL</span><span style="color: #D5CED9"> (EVENTBIT_0 </span><span style="color: #EE5D43">|</span><span style="color: #D5CED9"> EVENTBIT_1 </span><span style="color: #EE5D43">|</span><span style="color: #D5CED9"> EVENTBIT_2)</span></span>
<span class="line"><span style="color: #D5CED9">                              </span></span>
<span class="line"><span style="color: #FFE66D">xEventGroupSetBits</span><span style="color: #D5CED9">(xEventGroupHandler, EVENTBIT_1);</span></span>
<span class="line"><span style="color: #FFE66D">xEventGroupSetBits</span><span style="color: #D5CED9">(xEventGroupHandler, EVENTBIT_2);                               </span></span></code></pre></div>



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

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

<p>
<span class="highlight">xEventGroupSetBitsFromISR()</span> requests that one or more event bits be set from an interrupt service routine. Because setting event bits may unblock multiple tasks and is not a constant-time operation, the request is deferred to the FreeRTOS timer daemon task. The <span class="highlight">xHigherPriorityTaskWoken</span> parameter indicates whether processing the request may make a higher-priority task ready to run. The function returns <span class="highlight">pdPASS</span> if the request is successfully posted to the timer command queue, or <span class="highlight">pdFAIL</span> if the queue is full.
</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>BaseType_t xEventGroupSetBitsFromISR(EventGroupHandle_t xEventGroup, 
                                     const EventBits_t uxBitsToSet, 
                                     BaseType_t * pxHigherPriorityTaskWoken)
                                     
// ---------------------- Example ----------------------

BaseType_t YieldRequired = pdFALSE;
BaseType_t xHigherPriorityTaskWoken;

YieldRequired = xEventGroupSetBitsFromISR(xEventGroupHandler,
    											                EVENTBIT_0,
												                  &amp;xHigherPriorityTaskWoken);	
												                  
if(YieldRequired != pdFAIL) {
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}                                      </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">BaseType_t </span><span style="color: #FFE66D">xEventGroupSetBitsFromISR</span><span style="color: #D5CED9">(EventGroupHandle_t </span><span style="color: #00E8C6">xEventGroup</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                                     </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> EventBits_t </span><span style="color: #00E8C6">uxBitsToSet</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                                     BaseType_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxHigherPriorityTaskWoken</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                                     </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">BaseType_t YieldRequired </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> pdFALSE;</span></span>
<span class="line"><span style="color: #D5CED9">BaseType_t xHigherPriorityTaskWoken;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">YieldRequired </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xEventGroupSetBitsFromISR</span><span style="color: #D5CED9">(xEventGroupHandler,</span></span>
<span class="line"><span style="color: #D5CED9">    											                EVENTBIT_0,</span></span>
<span class="line"><span style="color: #D5CED9">												                  </span><span style="color: #EE5D43">&amp;</span><span style="color: #00E8C6">xHigherPriorityTaskWoken</span><span style="color: #D5CED9">);	</span></span>
<span class="line"><span style="color: #D5CED9">												                  </span></span>
<span class="line"><span style="color: #C74DED">if</span><span style="color: #D5CED9">(YieldRequired </span><span style="color: #EE5D43">!=</span><span style="color: #D5CED9"> pdFAIL) {</span></span>
<span class="line"><span style="color: #D5CED9">    </span><span style="color: #FFE66D">portYIELD_FROM_ISR</span><span style="color: #D5CED9">(xHigherPriorityTaskWoken);</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;">

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

<p>
<span class="highlight">xEventGroupGetBits()</span> reads and returns the current value of an event group from task context without modifying any bits. The returned <span class="highlight">EventBits_t</span> value can be tested with bit masks to determine which events are currently set. Because another task or interrupt may change the event group immediately afterward, the returned value should be treated as a snapshot of its state at the time of the call.
</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>EventBits_t xEventGroupGetBits(EventGroupHandle_t xEventGroup)

// ---------------------- Example ----------------------

EventBits_t newValue;
newValue = xEventGroupGetBits(xEventGroupHandler);</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">EventBits_t </span><span style="color: #FFE66D">xEventGroupGetBits</span><span style="color: #D5CED9">(EventGroupHandle_t </span><span style="color: #00E8C6">xEventGroup</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">EventBits_t newValue;</span></span>
<span class="line"><span style="color: #D5CED9">newValue </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xEventGroupGetBits</span><span style="color: #D5CED9">(xEventGroupHandler);</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xEventGroupGetBitsFromISR()</span> reads and returns the current value of an event group from interrupt context without modifying any bits. It provides an ISR-safe way to check which event conditions are currently set. Like <span class="highlight">xEventGroupGetBits()</span>, the returned value is only a snapshot of the event group at the time of the call and may change immediately afterward.
</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>EventBits_t xEventGroupGetBitsFromISR(EventGroupHandle_t xEventGroup)</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">EventBits_t </span><span style="color: #FFE66D">xEventGroupGetBitsFromISR</span><span style="color: #D5CED9">(EventGroupHandle_t </span><span style="color: #00E8C6">xEventGroup</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
<span class="highlight">xEventGroupWaitBits()</span> allows a task to wait for one or more specified event bits. The task can be configured to unblock when either any requested bit is set or all requested bits are set. It can also automatically clear the matched bits before returning and wait indefinitely or for a specified timeout. The function returns the event-group value that caused the task to unblock, or the value present when the timeout expired.
</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>EventBits_t xEventGroupWaitBits(EventGroupHandle_t xEventGroup,
                                const EventBits_t uxBitsToWaitFor,
                                const BaseType_t xClearOnExit,
                                const BaseType_t xWaitForAllBits,
                                const TickType_t xTicksToWait)
                                
// ---------------------- Example ----------------------

EventBits_t EventValue;

// This code blocks the current FreeRTOS task until all event bits
// specified by EVENTBIT_ALL are set
EventValue = xEventGroupWaitBits((EventGroupHandle_t) xEventGroupHandler,
						     				         (EventBits_t		    ) EVENTBIT_ALL,
										             (BaseType_t		    ) pdTRUE,
										             (BaseType_t		    ) pdTRUE,
								                 (TickType_t		    ) portMAX_DELAY);   

// This call blocks the current task until any bit defined in EVENTBIT_ALL becomes set, 
// then clears the matched event bits and stores the previous event-group value in EventValue
EventValue = xEventGroupWaitBits((EventGroupHandle_t) xEventGroupHandler, // Event group to monitor
						     				         (EventBits_t		    ) EVENTBIT_ALL,       // Bit mask to wait for
										             (BaseType_t		    ) pdTRUE,             // Clear matched bits before returning
										             (BaseType_t		    ) pdFALSE,            // Wait for ANY bit, not all bits
								                 (TickType_t		    ) portMAX_DELAY);     // Wait indefinitely     								                                              </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">EventBits_t </span><span style="color: #FFE66D">xEventGroupWaitBits</span><span style="color: #D5CED9">(EventGroupHandle_t </span><span style="color: #00E8C6">xEventGroup</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                                </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> EventBits_t </span><span style="color: #00E8C6">uxBitsToWaitFor</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                                </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> BaseType_t </span><span style="color: #00E8C6">xClearOnExit</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                                </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> BaseType_t </span><span style="color: #00E8C6">xWaitForAllBits</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                                </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> TickType_t </span><span style="color: #00E8C6">xTicksToWait</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                                </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">EventBits_t EventValue;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// This code blocks the current FreeRTOS task until all event bits</span></span>
<span class="line"><span style="color: #A0A1A7CC">// specified by EVENTBIT_ALL are set</span></span>
<span class="line"><span style="color: #D5CED9">EventValue </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xEventGroupWaitBits</span><span style="color: #D5CED9">((EventGroupHandle_t) </span><span style="color: #00E8C6">xEventGroupHandler</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">						     				         (EventBits_t		    ) </span><span style="color: #00E8C6">EVENTBIT_ALL</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">										             (BaseType_t		    ) </span><span style="color: #00E8C6">pdTRUE</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">										             (BaseType_t		    ) </span><span style="color: #00E8C6">pdTRUE</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">								                 (TickType_t		    ) </span><span style="color: #00E8C6">portMAX_DELAY</span><span style="color: #D5CED9">);   </span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// This call blocks the current task until any bit defined in EVENTBIT_ALL becomes set, </span></span>
<span class="line"><span style="color: #A0A1A7CC">// then clears the matched event bits and stores the previous event-group value in EventValue</span></span>
<span class="line"><span style="color: #D5CED9">EventValue </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xEventGroupWaitBits</span><span style="color: #D5CED9">((EventGroupHandle_t) </span><span style="color: #00E8C6">xEventGroupHandler</span><span style="color: #D5CED9">,</span><span style="color: #A0A1A7CC"> // Event group to monitor</span></span>
<span class="line"><span style="color: #D5CED9">						     				         (EventBits_t		    ) </span><span style="color: #00E8C6">EVENTBIT_ALL</span><span style="color: #D5CED9">,</span><span style="color: #A0A1A7CC">       // Bit mask to wait for</span></span>
<span class="line"><span style="color: #D5CED9">										             (BaseType_t		    ) </span><span style="color: #00E8C6">pdTRUE</span><span style="color: #D5CED9">,</span><span style="color: #A0A1A7CC">             // Clear matched bits before returning</span></span>
<span class="line"><span style="color: #D5CED9">										             (BaseType_t		    ) </span><span style="color: #00E8C6">pdFALSE</span><span style="color: #D5CED9">,</span><span style="color: #A0A1A7CC">            // Wait for ANY bit, not all bits</span></span>
<span class="line"><span style="color: #D5CED9">								                 (TickType_t		    ) </span><span style="color: #00E8C6">portMAX_DELAY</span><span style="color: #D5CED9">);</span><span style="color: #A0A1A7CC">     // Wait indefinitely     								                                              </span></span></code></pre></div>



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

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

<p>
<span class="highlight">xEventGroupSync()</span> synchronizes multiple tasks at a common execution point. It atomically sets the event bits specified by <span class="highlight">uxBitsToSet</span>, then blocks the calling task until all bits in <span class="highlight">uxBitsToWaitFor</span> are set or the timeout expires. The function returns the event-group value that caused the task to unblock, allowing the task to determine whether synchronization was completed successfully.
</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>EventBits_t xEventGroupSync(EventGroupHandle_t xEventGroup, 
                            const EventBits_t uxBitsToSet, 
                            const EventBits_t uxBitsToWaitFor, 
                            TickType_t xTicksToWait)
                            
// ---------------------- Example ----------------------

#define TASK1_BIT (1UL &lt;&lt; 0UL)
#define TASK2_BIT (1UL &lt;&lt; 1UL)
#define TASK3_BIT (1UL &lt;&lt; 2UL)

EventGroupHandle_t xEventGroup;
EventBits_t uxAllSyncBits = (TASK1_BIT | TASK2_BIT | TASK3_BIT);

xEventGroup = xEventGroupCreate();

void vTask1Task(void *pvParameters) {
	EventBits_t uxReturn;
	while(1) {
		uxReturn = xEventGroupSync(xEventGroup, TASK1_BIT, uxAllSyncBits, portMAX_DELAY);
		if( uxAllSyncBits == (uxReturn &amp; uxAllSyncBits) ) {
			// Do something
		}
	}
}

void vTask2Task(void *pvParameters) {
	EventBits_t uxReturn;
	while(1) {
		uxReturn = xEventGroupSync(xEventGroup, TASK2_BIT, uxAllSyncBits, portMAX_DELAY);
		if( uxAllSyncBits == (uxReturn &amp; uxAllSyncBits) ) {
			// Do something
		}
	}
}

void vTask3Task(void *pvParameters) {
	EventBits_t uxReturn;
	while(1) {
		uxReturn = xEventGroupSync(xEventGroup, TASK3_BIT, uxAllSyncBits, portMAX_DELAY);
		if( uxAllSyncBits == (uxReturn &amp; uxAllSyncBits) ) {
			// Do something
			printf("All tasks set \r\n");
			vTaskDelay(_200ms);
		}
	}
}                            </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">EventBits_t </span><span style="color: #FFE66D">xEventGroupSync</span><span style="color: #D5CED9">(EventGroupHandle_t </span><span style="color: #00E8C6">xEventGroup</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                            </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> EventBits_t </span><span style="color: #00E8C6">uxBitsToSet</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                            </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> EventBits_t </span><span style="color: #00E8C6">uxBitsToWaitFor</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                            TickType_t </span><span style="color: #00E8C6">xTicksToWait</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                            </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">TASK1_BIT</span><span style="color: #D5CED9"> (</span><span style="color: #F39C12">1</span><span style="color: #C74DED">UL</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">&lt;&lt;</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">0</span><span style="color: #C74DED">UL</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">TASK2_BIT</span><span style="color: #D5CED9"> (</span><span style="color: #F39C12">1</span><span style="color: #C74DED">UL</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">&lt;&lt;</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">1</span><span style="color: #C74DED">UL</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">TASK3_BIT</span><span style="color: #D5CED9"> (</span><span style="color: #F39C12">1</span><span style="color: #C74DED">UL</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">&lt;&lt;</span><span style="color: #D5CED9"> </span><span style="color: #F39C12">2</span><span style="color: #C74DED">UL</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">EventGroupHandle_t xEventGroup;</span></span>
<span class="line"><span style="color: #D5CED9">EventBits_t uxAllSyncBits </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> (TASK1_BIT </span><span style="color: #EE5D43">|</span><span style="color: #D5CED9"> TASK2_BIT </span><span style="color: #EE5D43">|</span><span style="color: #D5CED9"> TASK3_BIT);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">xEventGroup </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xEventGroupCreate</span><span style="color: #D5CED9">();</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vTask1Task</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: #00E8C6">pvParameters</span><span style="color: #D5CED9">) {</span></span>
<span class="line"><span style="color: #D5CED9">	EventBits_t uxReturn;</span></span>
<span class="line"><span style="color: #D5CED9">	</span><span style="color: #C74DED">while</span><span style="color: #D5CED9">(</span><span style="color: #F39C12">1</span><span style="color: #D5CED9">) {</span></span>
<span class="line"><span style="color: #D5CED9">		uxReturn </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xEventGroupSync</span><span style="color: #D5CED9">(xEventGroup, TASK1_BIT, uxAllSyncBits, portMAX_DELAY);</span></span>
<span class="line"><span style="color: #D5CED9">		</span><span style="color: #C74DED">if</span><span style="color: #D5CED9">( uxAllSyncBits </span><span style="color: #EE5D43">==</span><span style="color: #D5CED9"> (uxReturn </span><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9"> uxAllSyncBits) ) {</span></span>
<span class="line"><span style="color: #D5CED9">			</span><span style="color: #A0A1A7CC">// Do something</span></span>
<span class="line"><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: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vTask2Task</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: #00E8C6">pvParameters</span><span style="color: #D5CED9">) {</span></span>
<span class="line"><span style="color: #D5CED9">	EventBits_t uxReturn;</span></span>
<span class="line"><span style="color: #D5CED9">	</span><span style="color: #C74DED">while</span><span style="color: #D5CED9">(</span><span style="color: #F39C12">1</span><span style="color: #D5CED9">) {</span></span>
<span class="line cbp-see-more-line "><span style="color: #D5CED9">		uxReturn </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xEventGroupSync</span><span style="color: #D5CED9">(xEventGroup, TASK2_BIT, uxAllSyncBits, portMAX_DELAY);</span></span>
<span class="line"><span style="color: #D5CED9">		</span><span style="color: #C74DED">if</span><span style="color: #D5CED9">( uxAllSyncBits </span><span style="color: #EE5D43">==</span><span style="color: #D5CED9"> (uxReturn </span><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9"> uxAllSyncBits) ) {</span></span>
<span class="line"><span style="color: #D5CED9">			</span><span style="color: #A0A1A7CC">// Do something</span></span>
<span class="line"><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: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">vTask3Task</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: #00E8C6">pvParameters</span><span style="color: #D5CED9">) {</span></span>
<span class="line"><span style="color: #D5CED9">	EventBits_t uxReturn;</span></span>
<span class="line"><span style="color: #D5CED9">	</span><span style="color: #C74DED">while</span><span style="color: #D5CED9">(</span><span style="color: #F39C12">1</span><span style="color: #D5CED9">) {</span></span>
<span class="line"><span style="color: #D5CED9">		uxReturn </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xEventGroupSync</span><span style="color: #D5CED9">(xEventGroup, TASK3_BIT, uxAllSyncBits, portMAX_DELAY);</span></span>
<span class="line"><span style="color: #D5CED9">		</span><span style="color: #C74DED">if</span><span style="color: #D5CED9">( uxAllSyncBits </span><span style="color: #EE5D43">==</span><span style="color: #D5CED9"> (uxReturn </span><span style="color: #EE5D43">&amp;</span><span style="color: #D5CED9"> uxAllSyncBits) ) {</span></span>
<span class="line"><span style="color: #D5CED9">			</span><span style="color: #A0A1A7CC">// Do something</span></span>
<span class="line"><span style="color: #D5CED9">			</span><span style="color: #FFE66D">printf</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot;All tasks set </span><span style="color: #EE5D43">\r\n</span><span style="color: #96E072">&quot;</span><span style="color: #D5CED9">);</span></span>
<span class="line"><span style="color: #D5CED9">			</span><span style="color: #FFE66D">vTaskDelay</span><span style="color: #D5CED9">(_200ms);</span></span>
<span class="line"><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>



<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">7579</post-id>	</item>
		<item>
		<title>STM32 FreeRTOS: Software Timers</title>
		<link>https://hangpersonal.com/2026/07/14/stm32-freertos-software-timer/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Tue, 14 Jul 2026 16:45:36 +0000</pubDate>
				<category><![CDATA[Embedded System]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=7488</guid>

					<description><![CDATA[STM32 Microcontroller and FreeRTOS Development One-shot timer: once started, it will execute its callback function once only. It can be restarted manually, but will not restart itself Auto-reload timer: once started, it will re-start itself each time it expires, resulting in periodic execution of its callback function xTimerCreate() Creates a FreeRTOS software timer using dynamically...]]></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:30px; margin-bottom:40px;">
</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode spbtbl-fullwidth" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS: Software Timer"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">Software Timer API Function</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">Description</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#timer_create" style="font-size: 20px;color: blue">xTimerCreate()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Creates a software timer using dynamic memory</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#timer_create_static" style="font-size: 20px;color: blue">xTimerCreateStatic()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Creates a software timer using user-provided memory</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#timer_start" style="font-size: 20px;color: blue">xTimerStart()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Starts or restarts a timer from a task</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#timer_start_from_isr" style="font-size: 20px;color: blue">xTimerStartFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Starts or restarts a timer from an ISR</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#timer_stop" style="font-size: 20px;color: blue">xTimerStop()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Stops a running timer from a task</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#timer_stop_from_isr" style="font-size: 20px;color: blue">xTimerStopFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Stops a running timer from an ISR</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#timer_reset" style="font-size: 20px;color: blue">xTimerReset()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Resets a timer and restarts its period from zero</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#timer_reset_from_isr" style="font-size: 20px;color: blue">xTimerResetFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Resets a timer from an ISR</td>                            </tr>
                                            </tbody>
                </table>
                            </div>




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

<p>
<b>One-shot timer</b>: once started, it will execute its callback function once only. It can be restarted manually, but will not restart itself
</p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="889" src="https://hangpersonal.com/wp-content/uploads/2026/07/one-shot-timer-1024x889.png" alt="" class="wp-image-7564" style="width:650px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/one-shot-timer-1024x889.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/one-shot-timer-300x260.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/one-shot-timer-768x666.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/one-shot-timer-850x738.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/one-shot-timer.png 1142w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


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

<p>
<b>Auto-reload timer</b>: once started, it will re-start itself each time it expires, resulting in periodic execution of its callback function
</p>

</div>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="686" src="https://hangpersonal.com/wp-content/uploads/2026/07/auto-reload-timer-1024x686.png" alt="" class="wp-image-7568" style="width:900px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/auto-reload-timer-1024x686.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/auto-reload-timer-300x201.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/auto-reload-timer-768x515.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/auto-reload-timer-850x570.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/auto-reload-timer.png 1532w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div class="article-text" style="margin-top:50px; 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>#define configUSE_TIMERS              1 
#define configTIMER_TASK_PRIORITY     (configMAX_PRIORITIES-1) 
#define configTIMER_QUEUE_LENGTH      5
#define configTIMER_TASK_STACK_DEPTH  (configMINIMAL_STACK_SIZE*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: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configUSE_TIMERS</span><span style="color: #D5CED9">              </span><span style="color: #F39C12">1</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">configTIMER_TASK_PRIORITY</span><span style="color: #D5CED9">     (configMAX_PRIORITIES</span><span style="color: #EE5D43">-</span><span style="color: #F39C12">1</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">configTIMER_QUEUE_LENGTH</span><span style="color: #D5CED9">      </span><span style="color: #F39C12">5</span></span>
<span class="line"><span style="color: #C74DED">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">configTIMER_TASK_STACK_DEPTH</span><span style="color: #D5CED9">  (configMINIMAL_STACK_SIZE</span><span style="color: #EE5D43">*</span><span style="color: #F39C12">2</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
Creates a FreeRTOS software timer using dynamically allocated memory from the FreeRTOS heap. It defines the timer name, period, one-shot or auto-reload mode, timer ID, and callback function. The newly created timer remains dormant until it is started.
</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>TimerHandle_t xTimerCreate(const char * const pcTimerName,
                           TickType_t xTimerPeriodInTicks,
                           UBaseType_t uxAutoReload,
                           void * pvTimerID,
                           TimerCallbackFunction_t pxCallbackFunction)
                           
// ---------------------- Example ----------------------

TimerHandle_t OneShotTimer_Handle;
TimerHandle_t AutoReloadTimer_Handle;

void OneShotTimerCallback(TimerHandle_t xTimer);    
void AutoReloadTimerCallback(TimerHandle_t xTimer); 

OneShotTimer_Handle = xTimerCreate("OneShotTimer",
			                     	       mainONE_SHOT_TIMER_PERIOD,
								                   pdFALSE,
								                   0,
								                   OneShotTimerCallback);
								                   
AutoReloadTimer_Handle = xTimerCreate("AutoReloadTimer",
									                    mainAUTO_RELOAD_TIMER_PERIOD,
									                    pdTRUE,
									                    0,
									                    AutoReloadTimerCallback);</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">TimerHandle_t </span><span style="color: #FFE66D">xTimerCreate</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">char</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pcTimerName</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                           TickType_t </span><span style="color: #00E8C6">xTimerPeriodInTicks</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                           UBaseType_t </span><span style="color: #00E8C6">uxAutoReload</span><span style="color: #D5CED9">,</span></span>
<span class="line"><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">pvTimerID</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                           TimerCallbackFunction_t </span><span style="color: #00E8C6">pxCallbackFunction</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                           </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">TimerHandle_t OneShotTimer_Handle;</span></span>
<span class="line"><span style="color: #D5CED9">TimerHandle_t AutoReloadTimer_Handle;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">OneShotTimerCallback</span><span style="color: #D5CED9">(TimerHandle_t </span><span style="color: #00E8C6">xTimer</span><span style="color: #D5CED9">);    </span></span>
<span class="line"><span style="color: #C74DED">void</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">AutoReloadTimerCallback</span><span style="color: #D5CED9">(TimerHandle_t </span><span style="color: #00E8C6">xTimer</span><span style="color: #D5CED9">); </span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">OneShotTimer_Handle </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xTimerCreate</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot;OneShotTimer&quot;</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">			                     	       mainONE_SHOT_TIMER_PERIOD,</span></span>
<span class="line"><span style="color: #D5CED9">								                   pdFALSE,</span></span>
<span class="line"><span style="color: #D5CED9">								                   </span><span style="color: #F39C12">0</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">								                   OneShotTimerCallback);</span></span>
<span class="line"><span style="color: #D5CED9">								                   </span></span>
<span class="line"><span style="color: #D5CED9">AutoReloadTimer_Handle </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xTimerCreate</span><span style="color: #D5CED9">(</span><span style="color: #96E072">&quot;AutoReloadTimer&quot;</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">									                    mainAUTO_RELOAD_TIMER_PERIOD,</span></span>
<span class="line"><span style="color: #D5CED9">									                    pdTRUE,</span></span>
<span class="line"><span style="color: #D5CED9">									                    </span><span style="color: #F39C12">0</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">									                    AutoReloadTimerCallback);</span></span></code></pre></div>



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

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

<p>
Creates a software timer using a StaticTimer_t memory buffer supplied by the application. Unlike xTimerCreate(), it does not allocate memory from the FreeRTOS heap, making memory usage predictable and suitable for systems that avoid dynamic allocation.
</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>TimerHandle_t xTimerCreateStatic(const char * const pcTimerName,
                                 TickType_t xTimerPeriodInTicks,
                                 UBaseType_t uxAutoReload,
                                 void * pvTimerID,
                                 TimerCallbackFunction_t pxCallbackFunction,
                                 StaticTimer_t * pxTimerBuffer)</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">TimerHandle_t </span><span style="color: #FFE66D">xTimerCreateStatic</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">char</span><span style="color: #D5CED9"> </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #C74DED">const</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pcTimerName</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                                 TickType_t </span><span style="color: #00E8C6">xTimerPeriodInTicks</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                                 UBaseType_t </span><span style="color: #00E8C6">uxAutoReload</span><span style="color: #D5CED9">,</span></span>
<span class="line"><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">pvTimerID</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                                 TimerCallbackFunction_t </span><span style="color: #00E8C6">pxCallbackFunction</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                                 StaticTimer_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxTimerBuffer</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
Starts a previously created software timer from normal task context. After the specified timer period expires, the timer&#8217;s callback function executes. For an auto-reload timer, this repeats periodically; for a one-shot timer, it occurs only once.
</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>BaseType_t xTimerStart(TimerHandle_t xTimer, 
                       TickType_t xTicksToWait)
                       
// ---------------------- Example ----------------------

TimerHandle_t OneShotTimer_Handle;
TimerHandle_t AutoReloadTimer_Handle;

xTimerStart(OneShotTimer_Handle, 0);
xTimerStart(AutoReloadTimer_Handle, 0);</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">BaseType_t </span><span style="color: #FFE66D">xTimerStart</span><span style="color: #D5CED9">(TimerHandle_t </span><span style="color: #00E8C6">xTimer</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                       TickType_t </span><span style="color: #00E8C6">xTicksToWait</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                       </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">TimerHandle_t OneShotTimer_Handle;</span></span>
<span class="line"><span style="color: #D5CED9">TimerHandle_t AutoReloadTimer_Handle;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #FFE66D">xTimerStart</span><span style="color: #D5CED9">(OneShotTimer_Handle, </span><span style="color: #F39C12">0</span><span style="color: #D5CED9">);</span></span>
<span class="line"><span style="color: #FFE66D">xTimerStart</span><span style="color: #D5CED9">(AutoReloadTimer_Handle, </span><span style="color: #F39C12">0</span><span style="color: #D5CED9">);</span></span></code></pre></div>



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

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

<p>
Starts or restarts a software timer from an interrupt service routine. It sends a start command to the timer command queue and uses pxHigherPriorityTaskWoken to indicate whether a context switch should occur when the ISR exits.
</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>BaseType_t xTimerStartFromISR(TimerHandle_t xTimer,
                              BaseType_t * pxHigherPriorityTaskWoken)</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">BaseType_t </span><span style="color: #FFE66D">xTimerStartFromISR</span><span style="color: #D5CED9">(TimerHandle_t </span><span style="color: #00E8C6">xTimer</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                              BaseType_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxHigherPriorityTaskWoken</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
Stops an active software timer from normal task context. Once stopped, the timer will not expire or execute its callback function, but the timer object remains valid and can be started again later.
</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>BaseType_t xTimerStop(TimerHandle_t xTimer, 
                      TickType_t xTicksToWait)

// ---------------------- Example ----------------------

TimerHandle_t AutoReloadTimer_Handle;
xTimerStop(AutoReloadTimer_Handle, 0);</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">BaseType_t </span><span style="color: #FFE66D">xTimerStop</span><span style="color: #D5CED9">(TimerHandle_t </span><span style="color: #00E8C6">xTimer</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                      TickType_t </span><span style="color: #00E8C6">xTicksToWait</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">TimerHandle_t AutoReloadTimer_Handle;</span></span>
<span class="line"><span style="color: #FFE66D">xTimerStop</span><span style="color: #D5CED9">(AutoReloadTimer_Handle, </span><span style="color: #F39C12">0</span><span style="color: #D5CED9">);</span></span></code></pre></div>



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

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

<p>
Stops an active software timer from an interrupt service routine. It is the interrupt-safe version of xTimerStop() and can request a context switch through the pxHigherPriorityTaskWoken parameter.
</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>BaseType_t xTimerStopFromISR(TimerHandle_t xTimer,
                             BaseType_t * pxHigherPriorityTaskWoken)</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">BaseType_t </span><span style="color: #FFE66D">xTimerStopFromISR</span><span style="color: #D5CED9">(TimerHandle_t </span><span style="color: #00E8C6">xTimer</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                             BaseType_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxHigherPriorityTaskWoken</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
Resets a timer&#8217;s expiration time from normal task context. If the timer is active, it restarts the full timer period from the moment the reset is requested; if it is dormant, the reset operation also starts it.
</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>BaseType_t xTimerReset(TimerHandle_t xTimer, 
                       TickType_t xTicksToWait)</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">BaseType_t </span><span style="color: #FFE66D">xTimerReset</span><span style="color: #D5CED9">(TimerHandle_t </span><span style="color: #00E8C6">xTimer</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                       TickType_t </span><span style="color: #00E8C6">xTicksToWait</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
Resets or starts a software timer from an interrupt service routine. It recalculates the expiration time from the moment it is called and uses pxHigherPriorityTaskWoken to indicate whether an ISR-level context switch is required.
</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>BaseType_t xTimerResetFromISR(TimerHandle_t xTimer,
                              BaseType_t * pxHigherPriorityTaskWoken)</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">BaseType_t </span><span style="color: #FFE66D">xTimerResetFromISR</span><span style="color: #D5CED9">(TimerHandle_t </span><span style="color: #00E8C6">xTimer</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                              BaseType_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxHigherPriorityTaskWoken</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">7488</post-id>	</item>
		<item>
		<title>TI C2000: External Memory Interface (EMIF)</title>
		<link>https://hangpersonal.com/2026/07/01/c2000-emif/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Thu, 02 Jul 2026 03:42:01 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=7387</guid>

					<description><![CDATA[TI C2000 Real-Time Microcontroller: Control, Sensing, and Communication External Memory Interface (EMIF) Interfacing to SDRAM Interfacing to Asynchronous Memory EMIF Performance External Memory Interface (EMIF) This EMIF memory controller is compliant with the JESD21-C SDR SDRAM memories utilizing a 32-bit/16-bit data bus. The purpose of this EMIF is to provide a means for the CPU...]]></description>
										<content:encoded><![CDATA[
<a href="https://hangpersonal.com/embedded-system/ti-mcu/c2000-tutorials/" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
TI C2000 Real-Time Microcontroller: Control, Sensing, and Communication
</a>

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



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

<li style="margin-bottom:16px;">
<a href="#c28x_emif" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
External Memory Interface (EMIF)
</a>
</li> 

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

<li style="margin-bottom:16px;">
<a href="#c28x_emif_async_memory" style="font-family: 'Inter', sans-serif; font-size: 22px; color: blue;">
Interfacing to Asynchronous Memory
</a>
</li> 

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


</ul>



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

<b id="c28_emif" style="display:block;
          font-family: 'Inter', sans-serif; 
          font-size: 22px; 
          color: black; 
          margin-top:0px; 
          margin-bottom:20px;">
External Memory Interface (EMIF)
</b>

<p>
This EMIF memory controller is compliant with the JESD21-C SDR SDRAM memories utilizing a 32-bit/16-bit data bus. The purpose of this EMIF is to provide a means for the CPU to connect to a variety of external devices including:

<ul>
<li> Single data rate (SDR) SDRAM
</li>
<li> Asynchronous devices including NOR Flash and SRAM
</li>
</ul>

A common use for the EMIF is to interface with both a flash device and an SDRAM device simultaneously.
</p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="772" src="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif-1024x772.png" alt="" class="wp-image-7396" style="width:800px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif-1024x772.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif-300x226.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif-768x579.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif-850x640.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif.png 1440w" 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-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="823" src="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_signal-1024x823.png" alt="" class="wp-image-7399" style="width:700px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_signal-1024x823.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_signal-300x241.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_signal-768x617.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_signal-850x683.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_signal.png 1239w" 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-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="772" src="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_config-1024x772.png" alt="" class="wp-image-7402" style="width:800px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_config-1024x772.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_config-300x226.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_config-768x579.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_config-850x640.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_config.png 1440w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


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

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

<p>
The EMIF supports a glueless interface to SDRAM devices with the following characteristics:
<ul>
<li> Pre-charge bit is A[10]
</li>
<li> The number of column address bits is 8, 9, 10, or 11
</li>
<li> The number of row address bits is 13, 14, 15, or 16
</li>
<li> The number of internal banks is 1, 2, or 4
</li>
</ul>
</p>

</div>



<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="603" src="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_512kpng-1024x603.png" alt="" class="wp-image-7448" style="width:600px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_512kpng-1024x603.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_512kpng-300x177.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_512kpng-768x452.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_512kpng-850x501.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_512kpng.png 1380w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">EMIF to 512K × 16 × 2 bank SDRAM<br></figcaption></figure>
</div>


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


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="604" src="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_2m-1024x604.png" alt="" class="wp-image-7449" style="width:600px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_2m-1024x604.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_2m-300x177.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_2m-768x453.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_2m-850x502.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_sdram_2m.png 1381w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">EMIF to 2M × 16 × 4 bank SDRAM</figcaption></figure>
</div>


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


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="331" src="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_16bit_address_pin-1024x331.png" alt="" class="wp-image-7453" style="width:900px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_16bit_address_pin-1024x331.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_16bit_address_pin-300x97.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_16bit_address_pin-768x248.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_16bit_address_pin-1536x496.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_16bit_address_pin-850x274.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_16bit_address_pin.png 1828w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">16-bit EMIF Address Pin Connections</figcaption></figure>
</div>


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

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

<p>
The EMIF easily interfaces to a variety of asynchronous devices including NOR Flash and SRAM. It can be operated in two major modes
</p><ul>
<li> Normal Mode
</li>
<li> Select Strobe Mode
</li>
</ul>
<p></p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="387" src="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_async_memory-1024x387.png" alt="" class="wp-image-7456" style="width:600px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_async_memory-1024x387.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_async_memory-300x113.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_async_memory-768x290.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_async_memory-850x321.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_async_memory.png 1441w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


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

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

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="769" src="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_performance-1024x769.png" alt="" class="wp-image-7404" style="width:800px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_performance-1024x769.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_performance-300x225.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_performance-768x577.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_performance-850x638.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_performance.png 1440w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


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


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="878" src="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_configuration_interface-1024x878.png" alt="" class="wp-image-7462" style="width:700px" srcset="https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_configuration_interface-1024x878.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_configuration_interface-300x257.png 300w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_configuration_interface-768x659.png 768w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_configuration_interface-850x729.png 850w, https://hangpersonal.com/wp-content/uploads/2026/07/c28_emif_configuration_interface.png 1364w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Example of Configuration Interface</figcaption></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://www.ti.com/video/series/c2000-f2837xd-microcontroller-one-day-workshop-series.html" style="color: blue;">
TMS320F2837xD Microcontroller Workshop</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">7387</post-id>	</item>
		<item>
		<title>STM32 FreeRTOS: Semaphores and Mutexes</title>
		<link>https://hangpersonal.com/2026/06/28/stm32-freertos-semaphore-mutex/</link>
		
		<dc:creator><![CDATA[hangcui1201]]></dc:creator>
		<pubDate>Mon, 29 Jun 2026 05:17:29 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://hangpersonal.com/?p=7308</guid>

					<description><![CDATA[STM32 Microcontroller and FreeRTOS Development (1) The task calls xSemaphoreTake() to acquire the semaphore. Since the semaphore is unavailable, Task is placed into the Blocked state until the semaphore becomes available. (2) An interrupt occurs, and the interrupt service routine (ISR) calls xSemaphoreGiveFromISR() to give the semaphore. As a result, the semaphore becomes available. (3)...]]></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:30px; margin-bottom:40px;">
</div>


            <div  class="spbtbl-wrapper spbtbl-blockmode spbtbl-fullwidth" >
                                <table class="spbtbl-style spbtbl-color-blue" title="FreeRTOS: Semaphore and Mutex"  itemscope itemtype="http://schema.org/Table" >
                    <!-- Superb Tables Plugin -->
                    <thead>
                        <tr>
                            <th style="font-size: 18px !important;"  itemprop="name"  align="left">Semaphore &amp; Mutex API Function</th><th style="font-size: 18px !important;"  itemprop="name"  align="left">Description</th>                        </tr>
                    </thead>
                    <tbody>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_create_binary" style="font-size: 20px;color: blue">xSemaphoreCreateBinary()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Creates a dynamically allocated binary semaphore</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_create_binary_static" style="font-size: 20px;color: blue">xSemaphoreCreateBinaryStatic()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Creates a binary semaphore using user-provided memory</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_create_counting" style="font-size: 20px;color: blue">xSemaphoreCreateCounting()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Creates a counting semaphore with an initial and maximum count</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_create_counting_static" style="font-size: 20px;color: blue">xSemaphoreCreateCountingStatic()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Creates a counting semaphore using user-provided memory</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_create_mutex" style="font-size: 20px;color: blue">xSemaphoreCreateMutex()</a>
</td>                                    <td style="font-size:18px !important;" itemprop="description" >Creates a dynamically allocated mutex with priority inheritance</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_create_mutex_static" style="font-size: 20px;color: blue">xSemaphoreCreateMutexStatic()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Creates a mutex using user-provided memory</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_give" style="font-size: 20px;color: blue">xSemaphoreGive()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Releases a semaphore from a task</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_give_from_isr" style="font-size: 20px;color: blue">xSemaphoreGiveFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Releases a semaphore from an interrupt handler</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_take" style="font-size: 20px;color: blue">xSemaphoreTake()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Waits for and obtains a semaphore from a task</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_take_from_isr" style="font-size: 20px;color: blue">xSemaphoreTakeFromISR()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Obtains a semaphore from an interrupt handler without blocking</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_create_mutex_recursive" style="font-size: 20px;color: blue">xSemaphoreCreateRecursiveMutex()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Creates a mutex that the owner can lock multiple times</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_create_mutex_recursive_static" style="font-size: 20px;color: blue">xSemaphoreCreateRecursiveMutexStatic()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Creates a static recursive mutex using user-provided memory</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_take_recursive" style="font-size: 20px;color: blue">xSemaphoreTakeRecursive()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Locks a recursive mutex; the owner may lock it multiple times</td>                            </tr>
                        <tr>                                    <td style="font-size:18px !important;" itemprop="description" ><a href="#semaph_give_recursive" style="font-size: 20px;color: blue">xSemaphoreGiveRecursive()</a></td>                                    <td style="font-size:18px !important;" itemprop="description" >Unlocks a recursive mutex; call once for each successful take</td>                            </tr>
                                            </tbody>
                </table>
                            </div>




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

<p>
(1) The task calls xSemaphoreTake() to acquire the semaphore. Since the semaphore is unavailable, Task is placed into the Blocked state until the semaphore becomes available.
</p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" width="955" height="233" src="https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_1.png" alt="" class="wp-image-7532" style="width:500px" srcset="https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_1.png 955w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_1-300x73.png 300w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_1-768x187.png 768w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_1-850x207.png 850w" sizes="auto, (max-width: 955px) 100vw, 955px" /></figure>
</div>


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

<p>
(2) An interrupt occurs, and the interrupt service routine (ISR) calls xSemaphoreGiveFromISR() to give the semaphore. As a result, the semaphore becomes available.
</p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="141" src="https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_2-1024x141.png" alt="" class="wp-image-7536" style="width:900px" srcset="https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_2-1024x141.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_2-300x41.png 300w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_2-768x106.png 768w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_2-1536x212.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_2-2048x282.png 2048w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_2-850x117.png 850w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


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

<p>
(3) Because the semaphore is now available, Task successfully acquires it using xSemaphoreTake(). The task transitions from the Blocked state to the Running (or Ready, depending on the scheduler) state and begins executing the associated processing.
</p>

</div>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="141" src="https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_3-1024x141.png" alt="" class="wp-image-7538" style="width:900px" srcset="https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_3-1024x141.png 1024w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_3-300x41.png 300w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_3-768x106.png 768w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_3-1536x212.png 1536w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_3-2048x282.png 2048w, https://hangpersonal.com/wp-content/uploads/2026/06/binary_semph_3-850x117.png 850w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


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

<p>
(4) Since a task function typically runs in an infinite loop, after completing the required processing it calls xSemaphoreTake() again to wait for the semaphore. Because the semaphore became unavailable after Step 3, the task enters the Blocked state once again, just as it did in Step 1. It remains blocked until another interrupt occurs and the interrupt service routine (ISR) calls xSemaphoreGiveFromISR() to give the semaphore.
</p>

</div>



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

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

<p>
Creates a binary semaphore using memory dynamically allocated from the FreeRTOS heap. A binary semaphore has only two states: available and unavailable, internally represented by a count of 1 or 0. The semaphore is created in the unavailable/empty state, so xSemaphoreGive() must normally be called before the first successful xSemaphoreTake(). It is commonly used for task-to-task or interrupt-to-task synchronization. The function returns a semaphore handle on success or NULL if memory allocation fails.
</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>SemaphoreHandle_t xSemaphoreCreateBinary(void)

// ---------------------- Example ----------------------

SemaphoreHandle_t xBinarySemaphore;
xBinarySemaphore = xSemaphoreCreateBinary();
xSemaphoreGive(xBinarySemaphore);

xSemaphoreTake(xBinarySemaphore, portMAX_DELAY);
xSemaphoreGive(xBinarySemaphore);</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">SemaphoreHandle_t </span><span style="color: #FFE66D">xSemaphoreCreateBinary</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">SemaphoreHandle_t xBinarySemaphore;</span></span>
<span class="line"><span style="color: #D5CED9">xBinarySemaphore </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xSemaphoreCreateBinary</span><span style="color: #D5CED9">();</span></span>
<span class="line"><span style="color: #FFE66D">xSemaphoreGive</span><span style="color: #D5CED9">(xBinarySemaphore);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #FFE66D">xSemaphoreTake</span><span style="color: #D5CED9">(xBinarySemaphore, portMAX_DELAY);</span></span>
<span class="line"><span style="color: #FFE66D">xSemaphoreGive</span><span style="color: #D5CED9">(xBinarySemaphore);</span></span></code></pre></div>



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

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

<p>
Creates a binary semaphore without using the FreeRTOS heap. The application provides a StaticSemaphore_t object that stores the semaphore’s internal control information. This buffer must remain valid for the entire lifetime of the semaphore, so it should normally be global or declared with static. Like the dynamically created version, the semaphore starts empty and must be given before it can be taken. Static creation is useful in safety-critical or memory-constrained systems where dynamic allocation is undesirable.
</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>SemaphoreHandle_t xSemaphoreCreateBinaryStatic(StaticSemaphore_t *pxSemaphoreBuffer)</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">SemaphoreHandle_t </span><span style="color: #FFE66D">xSemaphoreCreateBinaryStatic</span><span style="color: #D5CED9">(StaticSemaphore_t </span><span style="color: #EE5D43">*</span><span style="color: #00E8C6">pxSemaphoreBuffer</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
Creates a dynamically allocated counting semaphore. uxMaxCount specifies the largest value the semaphore count can reach, while uxInitialCount specifies its starting value and must not exceed the maximum. Every successful xSemaphoreGive() increases the count, and every successful xSemaphoreTake() decreases it. Counting semaphores are commonly used either to count pending events or to manage a pool of identical resources. The function returns a valid handle on success or NULL if allocation fails.
</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>SemaphoreHandle_t xSemaphoreCreateCounting(UBaseType_t uxMaxCount, 
                                           UBaseType_t uxInitialCount)
                                           
// ---------------------- Example ----------------------

SemaphoreHandle_t xCountSemaphore; 
xCountSemaphore = xSemaphoreCreateCounting(255, 0);</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">SemaphoreHandle_t </span><span style="color: #FFE66D">xSemaphoreCreateCounting</span><span style="color: #D5CED9">(UBaseType_t </span><span style="color: #00E8C6">uxMaxCount</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                                           UBaseType_t </span><span style="color: #00E8C6">uxInitialCount</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                                           </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">SemaphoreHandle_t xCountSemaphore; </span></span>
<span class="line"><span style="color: #D5CED9">xCountSemaphore </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xSemaphoreCreateCounting</span><span style="color: #D5CED9">(</span><span style="color: #F39C12">255</span><span style="color: #D5CED9">, </span><span style="color: #F39C12">0</span><span style="color: #D5CED9">);</span></span></code></pre></div>



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

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

<p>
Creates a counting semaphore using memory supplied by the application. It behaves like xSemaphoreCreateCounting(), but no FreeRTOS heap allocation is performed. The caller provides a persistent StaticSemaphore_t buffer that stores the semaphore’s control structure. The initial count must be less than or equal to the maximum count. This version is useful when all RTOS objects must have deterministic, statically allocated memory.
</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>SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount, 
                                                 UBaseType_t uxInitialCount, 
                                                 StaticSemaphore_t * pxSemaphoreBuffer)</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">SemaphoreHandle_t </span><span style="color: #FFE66D">xSemaphoreCreateCountingStatic</span><span style="color: #D5CED9">(UBaseType_t </span><span style="color: #00E8C6">uxMaxCount</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                                                 UBaseType_t </span><span style="color: #00E8C6">uxInitialCount</span><span style="color: #D5CED9">, </span></span>
<span class="line"><span style="color: #D5CED9">                                                 StaticSemaphore_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxSemaphoreBuffer</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
Creates a dynamically allocated mutex for protecting a shared resource, such as a UART, SPI peripheral, file system, or shared data structure. Unlike a newly created binary semaphore, a newly created mutex starts in the available state and can immediately be taken. A mutex records which task owns it and provides priority inheritance to reduce priority-inversion problems. The task that successfully takes the mutex must be the task that gives it back. Mutexes must not be used from interrupt service routines.
</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>SemaphoreHandle_t xSemaphoreCreateMutex(void)

// ---------------------- Example ----------------------

SemaphoreHandle_t xMutexSemaphore;
xMutexSemaphore = xSemaphoreCreateMutex();</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">SemaphoreHandle_t </span><span style="color: #FFE66D">xSemaphoreCreateMutex</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">SemaphoreHandle_t xMutexSemaphore;</span></span>
<span class="line"><span style="color: #D5CED9">xMutexSemaphore </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xSemaphoreCreateMutex</span><span style="color: #D5CED9">();</span></span></code></pre></div>



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

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

<p>
Creates a mutex using a user-provided StaticSemaphore_t buffer instead of dynamically allocating memory. It provides the same ownership tracking, mutual-exclusion behavior, and priority inheritance as xSemaphoreCreateMutex(). The buffer must remain allocated for as long as the mutex exists. The mutex is initially available, so no initial xSemaphoreGive() is required. This function is suitable for applications that prohibit heap allocation after startup.
</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>SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t *pxMutexBuffer)</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">SemaphoreHandle_t </span><span style="color: #FFE66D">xSemaphoreCreateMutexStatic</span><span style="color: #D5CED9">(StaticSemaphore_t </span><span style="color: #EE5D43">*</span><span style="color: #00E8C6">pxMutexBuffer</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
Releases a semaphore from task context. For a binary semaphore, it changes the state from unavailable to available. For a counting semaphore, it increases the current count by one, provided the maximum count has not already been reached. For a mutex, it releases ownership so another waiting task can acquire the protected resource. The function returns pdTRUE when successful and pdFALSE when the semaphore is already full or cannot be released. It must not be called from an interrupt; use xSemaphoreGiveFromISR() instead.
</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>BaseType_t xSemaphoreGive(xSemaphore)

// ---------------------- Example ----------------------

xSemaphoreGive(xBinarySemaphore);</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">BaseType_t </span><span style="color: #FFE66D">xSemaphoreGive</span><span style="color: #D5CED9">(xSemaphore)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #FFE66D">xSemaphoreGive</span><span style="color: #D5CED9">(xBinarySemaphore);</span></span></code></pre></div>



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

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

<p>
Releases a binary or counting semaphore from an interrupt service routine. If giving the semaphore unblocks a task whose priority is higher than that of the currently running task, *pxHigherPriorityTaskWoken is set to pdTRUE. The ISR should then request a context switch with the port-specific macro, commonly portYIELD_FROM_ISR(). The variable should normally be initialized to pdFALSE before the call. This function cannot be used with mutexes because mutex ownership and priority inheritance require task context.
</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>BaseType_t xSemaphoreGiveFromISR(SemaphoreHandle_t xSemaphore,
                                 BaseType_t * pxHigherPriorityTaskWoken)
                                 
// ---------------------- Example ----------------------

SemaphoreHandle_t xBinarySemaphore;
xBinarySemaphore = xSemaphoreCreateBinary();

BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(BinarySemaphore, &amp;xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);</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">BaseType_t </span><span style="color: #FFE66D">xSemaphoreGiveFromISR</span><span style="color: #D5CED9">(SemaphoreHandle_t </span><span style="color: #00E8C6">xSemaphore</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                                 BaseType_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxHigherPriorityTaskWoken</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">                                 </span></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">SemaphoreHandle_t xBinarySemaphore;</span></span>
<span class="line"><span style="color: #D5CED9">xBinarySemaphore </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xSemaphoreCreateBinary</span><span style="color: #D5CED9">();</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D5CED9">BaseType_t xHigherPriorityTaskWoken </span><span style="color: #EE5D43">=</span><span style="color: #D5CED9"> pdFALSE;</span></span>
<span class="line"><span style="color: #FFE66D">xSemaphoreGiveFromISR</span><span style="color: #D5CED9">(BinarySemaphore, </span><span style="color: #EE5D43">&amp;</span><span style="color: #00E8C6">xHigherPriorityTaskWoken</span><span style="color: #D5CED9">);</span></span>
<span class="line"><span style="color: #FFE66D">portYIELD_FROM_ISR</span><span style="color: #D5CED9">(xHigherPriorityTaskWoken);</span></span></code></pre></div>



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

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

<p>
Attempts to obtain a binary semaphore, counting semaphore, or standard mutex from task context. If the object is available, the operation succeeds immediately and its count is decreased. If it is unavailable, the calling task can enter the Blocked state for up to xTicksToWait ticks. A value of 0 performs a nonblocking check, while portMAX_DELAY can be used for an indefinite wait when the relevant FreeRTOS configuration permits it. The function returns pdTRUE when the semaphore is obtained and pdFALSE if the waiting time expires.
</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>BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore,
                          TickType_t xBlockTime)

// ---------------------- Example ----------------------

xSemaphoreTake(xBinarySemaphore, portMAX_DELAY);</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">BaseType_t </span><span style="color: #FFE66D">xSemaphoreTake</span><span style="color: #D5CED9">(SemaphoreHandle_t </span><span style="color: #00E8C6">xSemaphore</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                          TickType_t </span><span style="color: #00E8C6">xBlockTime</span><span style="color: #D5CED9">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A0A1A7CC">// ---------------------- Example ----------------------</span></span>
<span class="line"></span>
<span class="line"><span style="color: #FFE66D">xSemaphoreTake</span><span style="color: #D5CED9">(xBinarySemaphore, portMAX_DELAY);</span></span></code></pre></div>



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

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

<p>
Attempts to obtain a binary or counting semaphore from an interrupt service routine. It cannot wait or block, so it succeeds only if the semaphore count is already greater than zero. A successful operation decreases the semaphore count and returns pdTRUE; otherwise, it returns pdFALSE. It must not be used with mutexes or recursive mutexes. In most interrupt-to-task synchronization designs, the ISR gives the semaphore and the task takes it, so this function is used less frequently than xSemaphoreGiveFromISR().
</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>BaseType_t xSemaphoreTakeFromISR(SemaphoreHandle_t xSemaphore,
                                 BaseType_t * pxHigherPriorityTaskWoken)                         </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">BaseType_t </span><span style="color: #FFE66D">xSemaphoreTakeFromISR</span><span style="color: #D5CED9">(SemaphoreHandle_t </span><span style="color: #00E8C6">xSemaphore</span><span style="color: #D5CED9">,</span></span>
<span class="line"><span style="color: #D5CED9">                                 BaseType_t </span><span style="color: #EE5D43">*</span><span style="color: #D5CED9"> </span><span style="color: #00E8C6">pxHigherPriorityTaskWoken</span><span style="color: #D5CED9">)                         </span></span></code></pre></div>



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

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

<p>
Creates a dynamically allocated recursive mutex. A recursive mutex allows its owning task to take the same mutex multiple times without blocking itself. FreeRTOS maintains an internal recursion count that records how many times the owner has successfully taken it. The task must give the mutex exactly the same number of times before another task can acquire it. Recursive mutexes are useful when a protected function calls another function that needs the same lock. They must be used with xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive(), not the standard take and give functions.
</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>SemaphoreHandle_t xSemaphoreCreateRecursiveMutex(void)</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">SemaphoreHandle_t </span><span style="color: #FFE66D">xSemaphoreCreateRecursiveMutex</span><span style="color: #D5CED9">(</span><span style="color: #C74DED">void</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
Creates a recursive mutex using application-provided static memory. Its behavior is identical to the dynamically created recursive mutex, including ownership tracking, priority inheritance, and recursive nesting count. The supplied StaticSemaphore_t buffer must remain valid throughout the mutex’s lifetime. This function avoids heap allocation while still allowing the same task to lock a resource repeatedly. Recursive mutex support must be enabled in FreeRTOSConfig.h.
</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>SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic(StaticSemaphore_t *pxMutexBuffer)</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">SemaphoreHandle_t </span><span style="color: #FFE66D">xSemaphoreCreateRecursiveMutexStatic</span><span style="color: #D5CED9">(StaticSemaphore_t </span><span style="color: #EE5D43">*</span><span style="color: #00E8C6">pxMutexBuffer</span><span style="color: #D5CED9">)</span></span></code></pre></div>



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

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

<p>
Obtains a mutex created specifically as a recursive mutex. The first successful call assigns ownership to the calling task. Additional calls from the same task succeed immediately and increase the recursive nesting count. Calls from other tasks block for up to xTicksToWait while the mutex remains owned. The function returns pdTRUE when the mutex is obtained and pdFALSE if the waiting time expires. It must not be used with a standard mutex created by xSemaphoreCreateMutex().
</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>#define xSemaphoreTakeRecursive(xMutex, xBlockTime)
  xQueueTakeMutexRecursive(xMutex, xBlockTime)</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">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xSemaphoreTakeRecursive</span><span style="color: #D5CED9">(</span><span style="color: #00E8C6">xMutex</span><span style="color: #D5CED9">, </span><span style="color: #00E8C6">xBlockTime</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">  </span><span style="color: #FFE66D">xQueueTakeMutexRecursive</span><span style="color: #D5CED9">(xMutex, xBlockTime)</span></span></code></pre></div>



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

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

<p>
Releases one level of ownership of a recursive mutex. Each call decreases the mutex’s recursive nesting count by one. The mutex becomes available to other tasks only when the count reaches zero. Therefore, every successful call to xSemaphoreTakeRecursive() must eventually have a matching call to xSemaphoreGiveRecursive(). Only the task that owns the recursive mutex may give it, and the function must not be called from an ISR.
</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>#define xSemaphoreGiveRecursive(xMutex)
  xQueueGiveMutexRecursive(xMutex)</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">#define</span><span style="color: #D5CED9"> </span><span style="color: #FFE66D">xSemaphoreGiveRecursive</span><span style="color: #D5CED9">(</span><span style="color: #00E8C6">xMutex</span><span style="color: #D5CED9">)</span></span>
<span class="line"><span style="color: #D5CED9">  </span><span style="color: #FFE66D">xQueueGiveMutexRecursive</span><span style="color: #D5CED9">(xMutex)</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">7308</post-id>	</item>
	</channel>
</rss>
