{"id":110614,"date":"2026-09-29T04:40:49","date_gmt":"2026-09-28T20:40:49","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/110614.html"},"modified":"2026-09-29T04:40:49","modified_gmt":"2026-09-28T20:40:49","slug":"freertos-%e4%bb%bb%e5%8a%a1%e4%b8%8a%e4%b8%8b%e6%96%87%e5%88%87%e6%8d%a2%e6%a0%b8%e5%bf%83%e6%b1%87%e7%bc%96-pendsv_handler-%e5%af%84%e5%ad%98%e5%99%a8%e5%85%a5%e6%a0%88%e4%b8%8e%e5%87%ba%e6%a0%88","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/110614.html","title":{"rendered":"FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790"},"content":{"rendered":"<h2>FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260928204048-6abad0d04381b.webp\" alt=\"\u5c01\u9762\u4fe1\u606f\u56fe\" \/><\/p>\n<p>\u5728\u57fa\u4e8e ARM Cortex-M&#xff08;\u5982 M3\/M4\/M7\/M33&#xff09;\u6784\u5efa\u7684 FreeRTOS \u5b9e\u65f6\u591a\u4efb\u52a1\u7cfb\u7edf\u4e2d&#xff0c;\u7cfb\u7edf\u5982\u4f55\u5728\u5fae\u79d2\u7ea7\u65f6\u95f4\u5185\u5c06\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684 \u4efb\u52a1 A&#xff08;Task A&#xff09; \u6682\u505c\u6302\u8d77&#xff0c;\u5e76\u65e0\u7f1d\u5207\u5165\u53e6\u4e00\u4e2a\u5c31\u7eea\u7684 \u4efb\u52a1 B&#xff08;Task B&#xff09; \u7ee7\u7eed\u6267\u884c&#xff1f;<\/p>\n<p>\u8fd9\u4e00\u4e32\u8054\u8d77\u6574\u4e2a RTOS \u591a\u4efb\u52a1\u8c03\u5ea6\u751f\u547d\u7684\u7ec8\u6781\u6838\u5fc3\u67a2\u7ebd&#xff0c;\u5c31\u662f\u8457\u540d\u7684 \u53ef\u6302\u8d77\u7684\u7cfb\u7edf\u8c03\u7528\u5f02\u5e38&#xff08;PendSV, Pendable Service Call \/ PendSV_Handler&#xff09;\u3002<\/p>\n<p>\u8bb8\u591a\u521d\u5b66\u8005\u5e38\u5e38\u4ea7\u751f\u4e24\u5927\u6838\u5fc3\u56f0\u60d1&#xff1a;<\/p>\n<li>\u4e3a\u4ec0\u4e48 FreeRTOS \u7edd\u5bf9\u7981\u6b62\u5728\u666e\u901a\u7684\u786c\u4ef6\u4e2d\u65ad&#xff08;\u5982 SysTick \u6216\u4e32\u53e3 ISR&#xff09;\u4e2d\u76f4\u63a5\u6267\u884c\u4e0a\u4e0b\u6587\u5207\u6362&#xff1f;\u5982\u679c\u5f3a\u5236\u5728\u666e\u901a ISR \u5185\u90e8\u76f4\u63a5\u7c97\u66b4\u5207\u6362\u5806\u6808&#xff0c;\u4f1a\u5f15\u53d1\u6bc1\u706d\u6027\u7684**\u201c\u4e2d\u65ad\u5d4c\u5957\u4e0a\u4e0b\u6587\u8e29\u8e0f&#xff08;Interrupt Stacking Collision&#xff09;\u201d**&#xff01;<\/li>\n<li>\u4e3a\u4ec0\u4e48\u5728 PendSV_Handler \u6c47\u7f16\u4ee3\u7801\u4e2d&#xff0c;\u786c\u4ef6\u53ea\u81ea\u52a8\u4fdd\u5b58\u4e86 8 \u4e2a\u5bc4\u5b58\u5668&#xff0c;\u800c\u5269\u4e0b\u7684 8 \u4e2a\u5bc4\u5b58\u5668&#xff08;R4 ~ R11&#xff09;\u5fc5\u987b\u7531\u6c47\u7f16\u4ee3\u7801\u624b\u52a8\u538b\u6808&#xff1f;<\/li>\n<p>\u6df1\u5165\u638c\u63e1 Cortex-M PendSV \u5f02\u5e38\u60ac\u8d77\u4e0e\u5ef6\u8fdf\u6267\u884c\u673a\u5236\u3001\u786c\u4ef6\u81ea\u52a8\u538b\u6808\u5e27&#xff08;Hardware Stack Frame&#xff09;\u4e0e\u8f6f\u4ef6\u624b\u52a8\u538b\u6808\u5e27&#xff08;Software Stack Frame&#xff09;\u7684\u53cc\u5c42\u62fc\u56fe\u62d3\u6251 \u4ee5\u53ca port.c \u4e2d xPortPendSVHandler \u6c47\u7f16\u6e90\u7801\u9010\u884c\u5fae\u89c2\u65f6\u5e8f&#xff0c;\u662f\u6bcf\u4e00\u4e2a RTOS \u67b6\u6784\u5e08\u4e0e\u5185\u6838\u5f00\u53d1\u8005\u5fc5\u987b\u5403\u900f\u7684\u7ec8\u6781\u538b\u8f74\u5e95\u5c42\u5185\u529f\u3002<\/p>\n<h4>\u4e3a\u4ec0\u4e48\u5fc5\u987b\u9009\u7528 PendSV&#xff1f;&#xff08;\u6d88\u706d\u4e2d\u65ad\u5d4c\u5957\u8e29\u8e0f\u60e8\u6848&#xff09;<\/h4>\n<p>\u76f4\u63a5\u5728 SysTick \u4e2d\u5207\u6362\u4e0a\u4e0b\u6587 vs \u6302\u8d77 PendSV \u5ef6\u8fdf\u5207\u6362\u5fae\u89c2\u5bf9\u51b3&#xff1a;<\/p>\n<p>\u3010\u573a\u666f A: \u9519\u8bef\u5730\u5728 SysTick ISR \u4e2d\u76f4\u63a5\u5207\u6362\u5806\u6808 (\u707e\u96be\u60e8\u6848&#xff01;)\u3011<br \/>\n1. \u5916\u90e8\u9ad8\u9891\u7535\u673a\u4e2d\u65ad IRQ \u6b63\u5728\u6267\u884c&#8230;<br \/>\n2. SysTick \u6ef4\u7b54\u4e2d\u65ad\u7a81\u53d1\u5230\u6765&#xff0c;\u5f3a\u884c\u62a2\u5360\u5d4c\u5957\u4e86\u7535\u673a\u4e2d\u65ad&#xff1b;<br \/>\n3. SysTick \u53d1\u73b0\u9700\u8981\u5207\u6362\u4efb\u52a1&#xff0c;\u3010\u76f4\u63a5\u7c97\u66b4\u4fee\u6539 PSP \u5806\u6808\u6307\u9488\u5207\u5230 Task B \u5e76\u6267\u884c\u5f02\u5e38\u8fd4\u56de&#xff01;\u3011<br \/>\n4. \u81f4\u547d\u540e\u679c: \u7535\u673a\u4e2d\u65ad\u5728\u88ab\u62a2\u5360\u65f6\u538b\u5728\u539f\u5806\u6808\u4e2d\u7684\u73b0\u573a\u88ab\u5f7b\u5e95\u7834\u574f&#xff0c;\u7535\u673a ISR \u9000\u51fa\u65f6\u7cfb\u7edf\u3010\u77ac\u95f4 HardFault \u5d29\u6e83&#xff01;\u3011<\/p>\n<p>\u3010\u573a\u666f B: \u6b63\u786e\u9009\u7528 PendSV \u5ef6\u8fdf\u6267\u884c (FreeRTOS \u9ec4\u91d1\u6807\u51c6&#xff01;)\u3011<br \/>\n1. SysTick \u6216 \u5916\u90e8 ISR \u53d1\u73b0\u9700\u8981\u5207\u6362\u4efb\u52a1&#xff0c;\u3010\u4ec5\u5411 SCB-&gt;ICSR \u5199\u5165\u4e00\u4f4d&#xff0c;\u6302\u8d77 PendSV \u5f02\u5e38 (Set PendSV Pending)\u3011&#xff01;<br \/>\n2. \u7cfb\u7edf\u7ee7\u7eed\u6267\u884c\u672a\u5b8c\u7684\u6240\u6709\u9ad8\u4f18\u5148\u7ea7\u786c\u4ef6\u4e2d\u65ad&#xff1b;<br \/>\n3. \u3010\u53ea\u6709\u5f53\u5168\u7cfb\u7edf\u6240\u6709\u7684\u9ad8\u4f18\u5148\u7ea7\u786c\u4ef6\u4e2d\u65ad\u5168\u90e8\u6267\u884c\u5b8c\u6bd5\u3001\u7cfb\u7edf\u51c6\u5907\u8fd4\u56de\u7ebf\u7a0b\u6a21\u5f0f\u7684\u6700\u540e 1 \u4e2a\u7eb3\u79d2\u3011:<br \/>\n4. \u3010\u6700\u4f4e\u4f18\u5148\u7ea7\u7684 PendSV \u5f02\u5e38\u624d\u771f\u6b63\u88ab CPU \u89e6\u53d1\u6267\u884c&#xff01;\u3011<br \/>\n5. \u6b64\u65f6\u6ca1\u6709\u4efb\u4f55\u5d4c\u5957\u4e2d\u65ad\u5b58\u5728&#xff0c;\u5806\u6808\u73af\u5883\u6781\u5176\u7eaf\u51c0&#xff0c;\u4e0a\u4e0b\u6587\u5207\u6362 100% \u7edd\u5bf9\u5b89\u5168&#xff01;<\/p>\n<h4>\u4efb\u52a1\u4e0a\u4e0b\u6587\u5806\u6808\u5e27\u7684\u201c\u53cc\u5c42\u62fc\u56fe\u201d\u5fae\u89c2\u62d3\u6251<\/h4>\n<p>\u5f53\u53d1\u751f PendSV \u5f02\u5e38\u65f6&#xff0c;\u4e00\u4e2a\u5b8c\u6574\u7684\u4efb\u52a1\u4e0a\u4e0b\u6587&#xff08;16 \u4e2a\u6838\u5fc3\u6574\u578b\u5bc4\u5b58\u5668&#xff09;\u662f\u7531 \u786c\u4ef6\u81ea\u52a8\u538b\u6808 \u4e0e \u8f6f\u4ef6\u6c47\u7f16\u624b\u52a8\u538b\u6808 \u534f\u540c\u62fc\u88c5\u5b8c\u6210\u7684&#xff1a;<\/p>\n<p>\u4efb\u52a1\u5806\u6808\u4e2d\u7684\u5b8c\u6574 16 \u5bc4\u5b58\u5668\u53cc\u5c42\u4e0a\u4e0b\u6587\u62d3\u6251&#xff1a;<\/p>\n<p>\u3010\u4f4e\u5730\u5740 (\u6808\u9876 \/ \u5f53\u524d PSP \u6307\u5411\u6b64\u5904)\u3011<br \/>\n  \u251c\u2500\u2500 R4   \u2510<br \/>\n  \u251c\u2500\u2500 R5   \u2502<br \/>\n  \u251c\u2500\u2500 R6   \u2502<br \/>\n  \u251c\u2500\u2500 R7   \u251c\u2500\u25ba \u3010\u7b2c 1 \u90e8\u5206: \u8f6f\u4ef6\u624b\u52a8\u538b\u6808\u5e27 (Software Stacking \/ 8 \u4e2a\u5bc4\u5b58\u5668)\u3011<br \/>\n  \u251c\u2500\u2500 R8   \u2502   &#8211; \u7531 PendSV_Handler \u6c47\u7f16\u4ee3\u7801\u663e\u5f0f\u6267\u884c &#034;stmdb r0!, {r4-r11}&#034; \u4fdd\u5b58&#xff01;<br \/>\n  \u251c\u2500\u2500 R9   \u2502   &#8211; \u5b58\u653e\u4efb\u52a1\u957f\u671f\u6301\u6709\u7684\u5c40\u90e8\u53d8\u91cf\u4e0e\u975e\u6613\u5931\u6027\u901a\u7528\u5bc4\u5b58\u5668\u3002<br \/>\n  \u251c\u2500\u2500 R10  \u2502<br \/>\n  \u2514\u2500\u2500 R11  \u2518<br \/>\n  \u251c\u2500\u2500 R0   \u2510<br \/>\n  \u251c\u2500\u2500 R1   \u2502<br \/>\n  \u251c\u2500\u2500 R2   \u2502<br \/>\n  \u251c\u2500\u2500 R3   \u251c\u2500\u25ba \u3010\u7b2c 2 \u90e8\u5206: \u786c\u4ef6\u81ea\u52a8\u538b\u6808\u5e27 (Hardware Stacking \/ 8 \u4e2a\u5bc4\u5b58\u5668)\u3011<br \/>\n  \u251c\u2500\u2500 R12  \u2502   &#8211; \u53d1\u751f PendSV \u5f02\u5e38\u77ac\u95f4&#xff0c;\u7531 CPU \u786c\u4ef6\u5728 12 \u5468\u671f\u5185\u3010\u81ea\u52a8\u7269\u7406\u538b\u6808&#xff01;\u3011<br \/>\n  \u251c\u2500\u2500 LR   \u2502   &#8211; \u5305\u542b\u51fd\u6570\u8c03\u7528\u8fd4\u56de\u5730\u5740 (LR) \u4e0e\u7a0b\u5e8f\u8ba1\u6570\u5668 (PC)&#xff01;<br \/>\n  \u251c\u2500\u2500 PC   \u2502<br \/>\n  \u2514\u2500\u2500 xPSR \u2518<br \/>\n\u3010\u9ad8\u5730\u5740 (\u6808\u5e95)\u3011<\/p>\n<h4>xPortPendSVHandler \u6c47\u7f16\u6e90\u7801\u9010\u884c\u5fae\u89c2\u89e3\u5256\u5b9e\u6218<\/h4>\n<p>\u5728 FreeRTOS \u7684 portable\/GCC\/ARM_CM4F\/port.c&#xff08;\u6216 portasm.s&#xff09;\u4e2d&#xff0c;\u5b98\u65b9\u6c47\u7f16\u5b9e\u73b0\u5982\u4e0b&#xff1a;<\/p>\n<p>    .syntax unified<br \/>\n    .text<br \/>\n    .align 4<br \/>\n    .global xPortPendSVHandler<br \/>\n    .type   xPortPendSVHandler, %function<\/p>\n<p>xPortPendSVHandler:<br \/>\n    \/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    \/\/ \u9636\u6bb5 1: \u4fdd\u5b58\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u4efb\u52a1 (Old Task) \u7684\u4e0a\u4e0b\u6587\u5230\u5176 PSP \u6808\u4e2d<br \/>\n    \/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    mrs     r0, psp                 \/\/ \u8bfb\u53d6\u5f53\u524d\u4efb\u52a1\u7684\u8fdb\u7a0b\u5806\u6808\u6307\u9488 PSP \u5230 R0<br \/>\n    isb<\/p>\n<p>    \/\/ \u63d0\u53d6\u5f53\u524d\u4efb\u52a1\u63a7\u5236\u5757\u6307\u9488: r3 &#061; &amp;pxCurrentTCB, r2 &#061; pxCurrentTCB<br \/>\n    ldr     r3, &#061;pxCurrentTCB<br \/>\n    ldr     r2, [r3]<\/p>\n<p>    \/\/ \u6838\u5fc3\u4fdd\u5b58\u6307\u4ee4: \u5c06 R4-R11 \u5171 8 \u4e2a\u5bc4\u5b58\u5668\u539f\u5b50\u538b\u5165 PSP \u6808&#xff0c;\u5e76\u81ea\u52a8\u9012\u51cf R0 (\u66f4\u65b0\u6808\u9876\u6307\u9488)<br \/>\n    stmdb   r0!, {r4-r11}<\/p>\n<p>    \/\/ \u5c06\u538b\u6808\u540e\u6700\u65b0\u7684\u6808\u9876\u5730\u5740 R0&#xff0c;\u4fdd\u5b58\u5230\u5f53\u524d\u4efb\u52a1 TCB \u7684\u7b2c\u4e00\u9879 (TCB-&gt;pxTopOfStack)<br \/>\n    str     r0, [r2]<\/p>\n<p>    \/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    \/\/ \u9636\u6bb5 2: \u8c03\u7528 C \u8bed\u8a00\u8c03\u5ea6\u5668\u9009\u62e9\u6700\u9ad8\u4f18\u5148\u7ea7\u7684\u5c31\u7eea\u4efb\u52a1 (New Task)<br \/>\n    \/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    stmdb   sp!, {r3, r14}          \/\/ \u5c06 r3(&amp;pxCurrentTCB) \u548c r14(EXC_RETURN) \u538b\u5165 MSP \u4fdd\u62a4<br \/>\n    mov     r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY<br \/>\n    msr     basepri, r0             \/\/ \u5c4f\u853d\u53d7\u63a7\u4e2d\u65ad&#xff0c;\u8fdb\u5165\u5185\u6838\u4e34\u754c\u533a<br \/>\n    dsb<br \/>\n    isb<\/p>\n<p>    \/\/ \u8c03\u7528 C \u8bed\u8a00\u4efb\u52a1\u8c03\u5ea6\u9009\u62e9\u51fd\u6570: \u66f4\u65b0 pxCurrentTCB \u6307\u5411\u6700\u9ad8\u4f18\u5148\u7ea7\u5c31\u7eea\u4efb\u52a1&#xff01;<br \/>\n    bl      vTaskSwitchContext<\/p>\n<p>    mov     r0, #0<br \/>\n    msr     basepri, r0             \/\/ \u6062\u590d\u4e2d\u65ad\u5c4f\u853d (\u9000\u51fa\u4e34\u754c\u533a)<br \/>\n    ldmia   sp!, {r3, r14}          \/\/ \u4ece MSP \u6062\u590d r3 \u548c r14<\/p>\n<p>    \/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    \/\/ \u9636\u6bb5 3: \u6062\u590d\u65b0\u4efb\u52a1 (New Task) \u7684\u4e0a\u4e0b\u6587\u5e76\u5207\u5165\u6267\u884c<br \/>\n    \/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    \/\/ \u63d0\u53d6\u65b0\u4efb\u52a1\u7684 TCB \u6307\u9488<br \/>\n    ldr     r1, [r3]                \/\/ r1 &#061; \u65b0\u4efb\u52a1 pxCurrentTCB<br \/>\n    ldr     r0, [r1]                \/\/ r0 &#061; \u65b0\u4efb\u52a1\u7684\u6700\u65b0\u6808\u9876\u6307\u9488 (pxTopOfStack)<\/p>\n<p>    \/\/ \u6838\u5fc3\u6062\u590d\u6307\u4ee4: \u4ece\u65b0\u4efb\u52a1\u6808\u4e2d\u5f39\u51fa\u6062\u590d R4-R11 \u8fd9 8 \u4e2a\u5bc4\u5b58\u5668&#xff0c;\u5e76\u9012\u589e R0<br \/>\n    ldmia   r0!, {r4-r11}<\/p>\n<p>    \/\/ \u5c06\u65b0\u4efb\u52a1\u66f4\u65b0\u540e\u7684\u5806\u6808\u6307\u9488\u6062\u590d\u5199\u5165 CPU \u7684 PSP \u5bc4\u5b58\u5668<br \/>\n    msr     psp, r0<br \/>\n    isb<\/p>\n<p>    \/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    \/\/ \u9636\u6bb5 4: \u7ec8\u6781\u4e00\u8dc3&#xff01;\u89e6\u53d1\u786c\u4ef6\u5f02\u5e38\u8fd4\u56de (BX R14 \/ EXC_RETURN &#061; 0xFFFFFFFD)<br \/>\n    \/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    \/\/ CPU \u786c\u4ef6\u6355\u83b7 EXC_RETURN \u77ac\u95f4\u81ea\u52a8\u5b8c\u6210:<br \/>\n    \/\/ 1. \u81ea\u52a8\u4ece\u65b0\u4efb\u52a1 PSP \u6808\u4e2d\u5f39\u51fa\u6062\u590d (R0-R3, R12, LR, PC, xPSR)&#xff01;<br \/>\n    \/\/ 2. \u5904\u7406\u5668\u6a21\u5f0f\u5e73\u7a33\u964d\u7ea7\u4e3a Thread \u7ebf\u7a0b\u6a21\u5f0f&#xff01;<br \/>\n    \/\/ 3. PC \u5bc4\u5b58\u5668\u88ab\u81ea\u52a8\u6062\u590d\u4e3a\u65b0\u4efb\u52a1\u4e0a\u6b21\u88ab\u6682\u505c\u65f6\u7684\u4e0b\u4e00\u6761\u6307\u4ee4\u5730\u5740&#xff01;<br \/>\n    \/\/ \u65b0\u4efb\u52a1\u6beb\u65e0\u611f\u77e5\u3001\u5929\u8863\u65e0\u7f1d\u5730\u6ee1\u8840\u7ee7\u7eed\u5954\u8dd1&#xff01;<br \/>\n    bx      r14<\/p>\n<h4>\u5de5\u4e1a\u5b9e\u6d4b\u6027\u80fd\u5bf9\u6218<\/h4>\n<p>\u5728 Cortex-M4&#xff08;STM32F407 &#064; 168MHz&#xff09;\u4e0a&#xff0c;\u9488\u5bf9 FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u7684\u7269\u7406\u65f6\u949f\u5468\u671f\u6570\u8fdb\u884c\u9ad8\u7cbe\u5ea6 GPIO \u63a2\u9488\u6d4b\u91cf&#xff1a;<\/p>\n<table>\n<tr>\u4e0a\u4e0b\u6587\u5207\u6362\u6267\u884c\u9636\u6bb5\u6d88\u8017 CPU \u65f6\u949f\u5468\u671f\u6570\u5728 168MHz \u4e0b\u7684\u7269\u7406\u8017\u65f6 (\u5fae\u79d2)<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u9636\u6bb5 1: \u786c\u4ef6\u81ea\u52a8\u538b\u6808 &#043; \u624b\u52a8 stmdb R4-R11<\/td>\n<td align=\"left\">22 \u4e2a\u65f6\u949f\u5468\u671f<\/td>\n<td align=\"left\">0.131 \u03bcs<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u9636\u6bb5 2: vTaskSwitchContext() \u8c03\u5ea6\u94fe\u8868\u9009\u62e9<\/td>\n<td align=\"left\">35 \u4e2a\u65f6\u949f\u5468\u671f<\/td>\n<td align=\"left\">0.208 \u03bcs<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u9636\u6bb5 3: \u624b\u52a8 ldmia R4-R11 &#043; \u786c\u4ef6\u81ea\u52a8\u5f39\u6808<\/td>\n<td align=\"left\">24 \u4e2a\u65f6\u949f\u5468\u671f<\/td>\n<td align=\"left\">0.143 \u03bcs<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u7aef\u5230\u7aef\u5b8c\u6574\u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u603b\u8017\u65f6 (Total)<\/td>\n<td align=\"left\">\u4ec5\u9700 81 \u4e2a\u65f6\u949f\u5468\u671f&#xff01;<\/td>\n<td align=\"left\">\u6574\u673a\u8017\u65f6\u4ec5 0.482 \u03bcs (\u4e0d\u5230\u534a\u5fae\u79d2&#xff01;)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u900f\u89c6 PendSV \u5ef6\u8fdf\u6267\u884c\u5728\u6d88\u9664\u4e2d\u65ad\u5d4c\u5957\u8e29\u8e0f\u4e0a\u7684\u7cbe\u5999\u673a\u7406&#xff0c;\u5403\u900f\u786c\u4ef6\u81ea\u52a8\u538b\u6808\u4e0e\u6c47\u7f16\u624b\u52a8\u538b\u6808\u7684\u53cc\u5c42\u62fc\u63a5\u65f6\u5e8f&#xff0c;\u5d4c\u5165\u5f0f\u67b6\u6784\u5e08\u624d\u80fd\u6df1\u523b\u9886\u4f1a RTOS \u5728\u88f8\u673a\u786c\u4ef6\u4e4b\u4e0a\u6784\u5efa\u8f7b\u91cf\u3001\u6781\u901f\u591a\u4efb\u52a1\u5e76\u884c\u4e16\u754c\u7684\u7ec8\u6781\u7b97\u6cd5\u7f8e\u5b66\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790\u5728\u57fa\u4e8e ARM Cortex-M&#xff08;\u5982 M3\/M4\/M7\/M33&#xff09;\u6784\u5efa\u7684 FreeRTOS \u5b9e\u65f6\u591a\u4efb\u52a1\u7cfb\u7edf\u4e2d&#xff0c;\u7cfb\u7edf\u5982\u4f55\u5728\u5fae\u79d2\u7ea7\u65f6\u95f4\u5185\u5c06\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684 \u4efb\u52a1 A&#xff08;Task A&#xff09; \u6682\u505c\u6302\u8d77&#xff0c;\u5e76\u65e0\u7f1d\u5207\u5165\u53e6\u4e00\u4e2a\u5c31\u7eea\u7684 \u4efb\u52a1 B&#xff08;Task B&#xff09; \u7ee7\u7eed\u6267\u884c&#xff1f;<br \/>\n\u8fd9\u4e00\u4e32\u8054\u8d77\u6574<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[66,58,50,219,51],"topic":[],"class_list":["post-110614","post","type-post","status-publish","format-standard","hentry","category-server","tag-ai","tag-linux","tag-50","tag-219","tag-51"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/110614.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790\u5728\u57fa\u4e8e ARM Cortex-M&#xff08;\u5982 M3\/M4\/M7\/M33&#xff09;\u6784\u5efa\u7684 FreeRTOS \u5b9e\u65f6\u591a\u4efb\u52a1\u7cfb\u7edf\u4e2d&#xff0c;\u7cfb\u7edf\u5982\u4f55\u5728\u5fae\u79d2\u7ea7\u65f6\u95f4\u5185\u5c06\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684 \u4efb\u52a1 A&#xff08;Task A&#xff09; \u6682\u505c\u6302\u8d77&#xff0c;\u5e76\u65e0\u7f1d\u5207\u5165\u53e6\u4e00\u4e2a\u5c31\u7eea\u7684 \u4efb\u52a1 B&#xff08;Task B&#xff09; \u7ee7\u7eed\u6267\u884c&#xff1f; \u8fd9\u4e00\u4e32\u8054\u8d77\u6574\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/110614.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-28T20:40:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260928204048-6abad0d04381b.webp\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110614.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/110614.html\",\"name\":\"FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-28T20:40:49+00:00\",\"dateModified\":\"2026-09-28T20:40:49+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/110614.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/110614.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110614.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/110614.html","og_locale":"zh_CN","og_type":"article","og_title":"FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790\u5728\u57fa\u4e8e ARM Cortex-M&#xff08;\u5982 M3\/M4\/M7\/M33&#xff09;\u6784\u5efa\u7684 FreeRTOS \u5b9e\u65f6\u591a\u4efb\u52a1\u7cfb\u7edf\u4e2d&#xff0c;\u7cfb\u7edf\u5982\u4f55\u5728\u5fae\u79d2\u7ea7\u65f6\u95f4\u5185\u5c06\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684 \u4efb\u52a1 A&#xff08;Task A&#xff09; \u6682\u505c\u6302\u8d77&#xff0c;\u5e76\u65e0\u7f1d\u5207\u5165\u53e6\u4e00\u4e2a\u5c31\u7eea\u7684 \u4efb\u52a1 B&#xff08;Task B&#xff09; \u7ee7\u7eed\u6267\u884c&#xff1f; \u8fd9\u4e00\u4e32\u8054\u8d77\u6574","og_url":"https:\/\/www.wsisp.com\/helps\/110614.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-28T20:40:49+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260928204048-6abad0d04381b.webp"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/110614.html","url":"https:\/\/www.wsisp.com\/helps\/110614.html","name":"FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-28T20:40:49+00:00","dateModified":"2026-09-28T20:40:49+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/110614.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/110614.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/110614.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"FreeRTOS \u4efb\u52a1\u4e0a\u4e0b\u6587\u5207\u6362\u6838\u5fc3\u6c47\u7f16 PendSV_Handler \u5bc4\u5b58\u5668\u5165\u6808\u4e0e\u51fa\u6808\u6df1\u5ea6\u5256\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=110614"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110614\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=110614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=110614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=110614"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=110614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}