|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2025 MicroPython Contributors |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | + * THE SOFTWARE. |
| 25 | + */ |
| 26 | + |
| 27 | +/* |
| 28 | + * FreeRTOS Configuration for STM32 MicroPython port |
| 29 | + */ |
| 30 | + |
| 31 | +#ifndef FREERTOS_CONFIG_H |
| 32 | +#define FREERTOS_CONFIG_H |
| 33 | + |
| 34 | +#include <stdint.h> |
| 35 | + |
| 36 | +// Most STM32 have 4 NVIC priority bits |
| 37 | +// This will be overridden by CMSIS if included later |
| 38 | +#ifndef __NVIC_PRIO_BITS |
| 39 | +#define __NVIC_PRIO_BITS 4 |
| 40 | +#endif |
| 41 | + |
| 42 | +// Get clock frequency from HAL |
| 43 | +extern uint32_t SystemCoreClock; |
| 44 | +#define configCPU_CLOCK_HZ (SystemCoreClock) |
| 45 | + |
| 46 | +// Cortex-M interrupt priorities |
| 47 | +// STM32F4/F7 have 4 priority bits (0-15), lower number = higher priority |
| 48 | +// SysTick and PendSV should be at lowest priority for FreeRTOS |
| 49 | +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY (15) |
| 50 | +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY (5) |
| 51 | + |
| 52 | +// Derived values (shifted for NVIC registers) |
| 53 | +#define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - __NVIC_PRIO_BITS)) |
| 54 | +#define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - __NVIC_PRIO_BITS)) |
| 55 | + |
| 56 | +// ============================================================================ |
| 57 | +// MANDATORY for MicroPython threading backend |
| 58 | +// ============================================================================ |
| 59 | + |
| 60 | +#define configSUPPORT_STATIC_ALLOCATION (1) |
| 61 | +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS (1) |
| 62 | +#define configUSE_MUTEXES (1) |
| 63 | +#define configUSE_RECURSIVE_MUTEXES (1) |
| 64 | +#define INCLUDE_vTaskDelete (1) |
| 65 | +#define INCLUDE_xTaskGetCurrentTaskHandle (1) |
| 66 | + |
| 67 | +// ============================================================================ |
| 68 | +// Scheduler configuration |
| 69 | +// ============================================================================ |
| 70 | + |
| 71 | +#define configTICK_RATE_HZ (1000) |
| 72 | +#define configUSE_PREEMPTION (1) |
| 73 | +#define configUSE_16_BIT_TICKS (0) |
| 74 | +#define configMAX_PRIORITIES (8) |
| 75 | +#define configMINIMAL_STACK_SIZE (128) |
| 76 | +#define configMAX_TASK_NAME_LEN (16) |
| 77 | +#define configUSE_TICK_HOOK (1) |
| 78 | +#define configUSE_IDLE_HOOK (0) |
| 79 | +#define configUSE_TIME_SLICING (1) |
| 80 | + |
| 81 | +// ============================================================================ |
| 82 | +// Memory configuration |
| 83 | +// ============================================================================ |
| 84 | + |
| 85 | +// Dynamic allocation enabled for idle/timer tasks |
| 86 | +// Python threads use static allocation with GC memory |
| 87 | +#define configSUPPORT_DYNAMIC_ALLOCATION (1) |
| 88 | +#define configTOTAL_HEAP_SIZE (4096) |
| 89 | + |
| 90 | +// ============================================================================ |
| 91 | +// Optional features |
| 92 | +// ============================================================================ |
| 93 | + |
| 94 | +#define configCHECK_FOR_STACK_OVERFLOW (2) |
| 95 | +#define INCLUDE_uxTaskGetStackHighWaterMark (1) |
| 96 | +#define configUSE_TASK_NOTIFICATIONS (1) |
| 97 | +#define configUSE_COUNTING_SEMAPHORES (1) |
| 98 | +#define configUSE_QUEUE_SETS (0) |
| 99 | + |
| 100 | +// Timers disabled to save space (enable if needed) |
| 101 | +#define configUSE_TIMERS (0) |
| 102 | + |
| 103 | +// ============================================================================ |
| 104 | +// Include optional function APIs |
| 105 | +// ============================================================================ |
| 106 | + |
| 107 | +#define INCLUDE_vTaskPrioritySet (1) |
| 108 | +#define INCLUDE_uxTaskPriorityGet (1) |
| 109 | +#define INCLUDE_vTaskDelay (1) |
| 110 | +#define INCLUDE_vTaskDelayUntil (1) |
| 111 | +#define INCLUDE_vTaskSuspend (1) |
| 112 | +#define INCLUDE_xTaskGetSchedulerState (1) |
| 113 | +#define INCLUDE_xTaskResumeFromISR (1) |
| 114 | +#define INCLUDE_eTaskGetState (1) |
| 115 | + |
| 116 | +// ============================================================================ |
| 117 | +// Assert configuration |
| 118 | +// ============================================================================ |
| 119 | + |
| 120 | +#define configASSERT(x) do { if (!(x)) { __asm volatile ("cpsid i"); for (;;) {} } } while (0) |
| 121 | + |
| 122 | +// ============================================================================ |
| 123 | +// Cortex-M specific |
| 124 | +// ============================================================================ |
| 125 | + |
| 126 | +#define configUSE_PORT_OPTIMISED_TASK_SELECTION (1) |
| 127 | + |
| 128 | +// Disable handler installation check - our SVC/PendSV handlers wrap the |
| 129 | +// FreeRTOS handlers, so the vector table addresses won't match exactly. |
| 130 | +// The wrappers correctly forward to vPortSVCHandler/xPortPendSVHandler. |
| 131 | +#define configCHECK_HANDLER_INSTALLATION (0) |
| 132 | + |
| 133 | +// Handler integration note: |
| 134 | +// DO NOT define xPortPendSVHandler, xPortSysTickHandler, vPortSVCHandler here. |
| 135 | +// The STM32 port keeps its own handlers and calls FreeRTOS functions as needed. |
| 136 | +// This preserves existing port functionality (pendsv_dispatch, systick_dispatch, etc). |
| 137 | + |
| 138 | +#endif // FREERTOS_CONFIG_H |
0 commit comments