From 850fc671388a9bae9eabd572fbf3b670bbe32b4a Mon Sep 17 00:00:00 2001 From: Guanxi Tong Date: Wed, 18 Nov 2026 14:07:14 +0800 Subject: [PATCH] =?UTF-8?q?build(rtos):=20=E9=80=82=E9=85=8D=20AC6=20?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 工程已参考 COD 战队《Keil 使用 FreeRTOS 后 AC6 编译器适配指南》,将 FreeRTOS 的 armcc 端口替换为 GCC 端口:portable/GCC/ARM_CM4F 的 port.c 与 portmacro.h 覆盖到 portable/RVDS/ARM_CM4F。 工程克隆后可直接用 AC6 编译,无需再改动工程文件。 但维护者若需要运行 CubeMX GENERATE,必须先按照文章在自己本机的固件包中做同样替换, 否则生成时会把 AC5 端口拷回工程,编译时重新出现 armcc 语法错误(`__forceinline` 等)。 详见 docs/ac6-migration.md。 --- MDK-ARM/Simba-Titan.uvprojx | 4 +- .../portable/RVDS/ARM_CM4F/PORT-SOURCE.txt | 10 + .../Source/portable/RVDS/ARM_CM4F/port.c | 391 ++++++++---------- .../Source/portable/RVDS/ARM_CM4F/portmacro.h | 181 ++++---- 4 files changed, 279 insertions(+), 307 deletions(-) create mode 100644 Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/PORT-SOURCE.txt diff --git a/MDK-ARM/Simba-Titan.uvprojx b/MDK-ARM/Simba-Titan.uvprojx index 53fa9ef..a386122 100644 --- a/MDK-ARM/Simba-Titan.uvprojx +++ b/MDK-ARM/Simba-Titan.uvprojx @@ -11,7 +11,7 @@ 0x4 ARM-ADS 6240000::V6.24::ARMCLANG - 0 + 1 STM32H723VGTx @@ -323,7 +323,7 @@ 0 0 0 - 2 + 3 0 0 1 diff --git a/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/PORT-SOURCE.txt b/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/PORT-SOURCE.txt new file mode 100644 index 0000000..b9f098b --- /dev/null +++ b/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/PORT-SOURCE.txt @@ -0,0 +1,10 @@ +本目录内容不是 ST 原版的 armcc(RVDS) 端口。 + +来源:STM32Cube_FW_H7_V1.13.0/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F + (port.c、portmacro.h) + +原因:原版端口使用 armcc 专有语法(__forceinline、__asm void、preserve8), + 在 Arm Compiler 6 下无法编译;替换为 GCC 写法后可同时支持 AC6。 + +注意:目录名仍保留 RVDS,是为了不改动 uvprojx 中的 include 路径。 + 替换步骤与本机固件包需要同步修改的原因,见 /docs/ac6-migration.md。 diff --git a/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c b/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c index 05ef20c..73430b5 100644 --- a/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c +++ b/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c @@ -34,23 +34,10 @@ #include "FreeRTOS.h" #include "task.h" -#ifndef __TARGET_FPU_VFP +#ifndef __VFP_FP__ #error This port can only be used when the project options are configured to enable hardware floating point support. #endif -#if configMAX_SYSCALL_INTERRUPT_PRIORITY == 0 - #error configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0. See http: /*www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ -#endif - -/* Legacy macro for backward compatibility only. This macro used to be used to - * replace the function that configures the clock used to generate the tick - * interrupt (prvSetupTimerInterrupt()), but now the function is declared weak so - * the application writer can override it by simply defining a function of the - * same name (vApplicationSetupTickInterrupt()). */ -#ifndef configOVERRIDE_DEFAULT_TICK_CONFIGURATION - #define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 0 -#endif - /* Constants required to manipulate the core. Registers first... */ #define portNVIC_SYSTICK_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000e010 ) ) #define portNVIC_SYSTICK_LOAD_REG ( *( ( volatile uint32_t * ) 0xe000e014 ) ) @@ -99,15 +86,15 @@ /* The systick is a 24-bit counter. */ #define portMAX_24_BIT_NUMBER ( 0xffffffUL ) +/* For strict compliance with the Cortex-M spec the task start address should + * have bit-0 clear, as it is loaded into the PC on exit from an ISR. */ +#define portSTART_ADDRESS_MASK ( ( StackType_t ) 0xfffffffeUL ) + /* A fiddle factor to estimate the number of SysTick counts that would have * occurred while the SysTick counter is stopped during tickless idle * calculations. */ #define portMISSED_COUNTS_FACTOR ( 94UL ) -/* For strict compliance with the Cortex-M spec the task start address should - * have bit-0 clear, as it is loaded into the PC on exit from an ISR. */ -#define portSTART_ADDRESS_MASK ( ( StackType_t ) 0xfffffffeUL ) - /* Let the user override the default SysTick clock rate. If defined by the * user, this symbol must equal the SysTick clock rate when the CLK bit is 0 in the * configuration register. */ @@ -120,6 +107,15 @@ #define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 ) #endif +/* Let the user override the pre-loading of the initial LR with the address of + * prvTaskExitError() in case it messes up unwinding of the stack in the + * debugger. */ +#ifdef configTASK_RETURN_ADDRESS + #define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS +#else + #define portTASK_RETURN_ADDRESS prvTaskExitError +#endif + /* * Setup the timer to generate the tick interrupts. The implementation in this * file is weak to allow application writers to change the timer used to @@ -130,19 +126,19 @@ void vPortSetupTimerInterrupt( void ); /* * Exception handlers. */ -void xPortPendSVHandler( void ); +void xPortPendSVHandler( void ) __attribute__( ( naked ) ); void xPortSysTickHandler( void ); -void vPortSVCHandler( void ); +void vPortSVCHandler( void ) __attribute__( ( naked ) ); /* * Start first task is a separate function so it can be tested in isolation. */ -static void prvStartFirstTask( void ); +static void prvPortStartFirstTask( void ) __attribute__( ( naked ) ); /* - * Functions defined in portasm.s to enable the VFP. + * Function to enable the VFP. */ -static void prvEnableVFP( void ); +static void vPortEnableVFP( void ) __attribute__( ( naked ) ); /* * Used to catch tasks that attempt to return from their implementing function. @@ -186,7 +182,7 @@ static UBaseType_t uxCriticalNesting = 0xaaaaaaaa; #if ( configASSERT_DEFINED == 1 ) static uint8_t ucMaxSysCallPriority = 0; static uint32_t ulMaxPRIGROUPValue = 0; - static const volatile uint8_t * const pcInterruptPriorityRegisters = ( uint8_t * ) portNVIC_IP_REGISTERS_OFFSET_16; + static const volatile uint8_t * const pcInterruptPriorityRegisters = ( const volatile uint8_t * const ) portNVIC_IP_REGISTERS_OFFSET_16; #endif /* configASSERT_DEFINED */ /*-----------------------------------------------------------*/ @@ -209,7 +205,7 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, pxTopOfStack--; *pxTopOfStack = ( ( StackType_t ) pxCode ) & portSTART_ADDRESS_MASK; /* PC */ pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) prvTaskExitError; /* LR */ + *pxTopOfStack = ( StackType_t ) portTASK_RETURN_ADDRESS; /* LR */ /* Save code space by skipping register initialisation. */ pxTopOfStack -= 5; /* R12, R3, R2 and R1. */ @@ -228,6 +224,8 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, static void prvTaskExitError( void ) { + volatile uint32_t ulDummy = 0; + /* A function that implements a task must not exit or attempt to return to * its caller as there is nothing to return to. If a task wants to exit it * should instead call vTaskDelete( NULL ). @@ -237,78 +235,59 @@ static void prvTaskExitError( void ) configASSERT( uxCriticalNesting == ~0UL ); portDISABLE_INTERRUPTS(); - for( ; ; ) + while( ulDummy == 0 ) { + /* This file calls prvTaskExitError() after the scheduler has been + * started to remove a compiler warning about the function being defined + * but never called. ulDummy is used purely to quieten other warnings + * about code appearing after this function is called - making ulDummy + * volatile makes the compiler think the function could return and + * therefore not output an 'unreachable code' warning for code that appears + * after it. */ } } /*-----------------------------------------------------------*/ -__asm void vPortSVCHandler( void ) +void vPortSVCHandler( void ) { -/* *INDENT-OFF* */ - PRESERVE8 - - /* Get the location of the current TCB. */ - ldr r3, =pxCurrentTCB - ldr r1, [ r3 ] - ldr r0, [ r1 ] - /* Pop the core registers. */ - ldmia r0!, {r4-r11,r14} - msr psp, r0 - isb - mov r0, #0 - msr basepri, r0 - bx r14 -/* *INDENT-ON* */ + __asm volatile ( + " ldr r3, pxCurrentTCBConst2 \n" /* Restore the context. */ + " ldr r1, [r3] \n" /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */ + " ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */ + " ldmia r0!, {r4-r11, r14} \n" /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */ + " msr psp, r0 \n" /* Restore the task stack pointer. */ + " isb \n" + " mov r0, #0 \n" + " msr basepri, r0 \n" + " bx r14 \n" + " \n" + " .align 4 \n" + "pxCurrentTCBConst2: .word pxCurrentTCB \n" + ); } /*-----------------------------------------------------------*/ -__asm void prvStartFirstTask( void ) +static void prvPortStartFirstTask( void ) { -/* *INDENT-OFF* */ - PRESERVE8 - - /* Use the NVIC offset register to locate the stack. */ - ldr r0, =0xE000ED08 - ldr r0, [ r0 ] - ldr r0, [ r0 ] - /* Set the msp back to the start of the stack. */ - msr msp, r0 - - /* Clear the bit that indicates the FPU is in use in case the FPU was used - * before the scheduler was started - which would otherwise result in the - * unnecessary leaving of space in the SVC stack for lazy saving of FPU - * registers. */ - mov r0, #0 - msr control, r0 - /* Globally enable interrupts. */ - cpsie i - cpsie f - dsb - isb - /* Call SVC to start the first task. */ - svc 0 - nop - nop -/* *INDENT-ON* */ -} -/*-----------------------------------------------------------*/ - -__asm void prvEnableVFP( void ) -{ -/* *INDENT-OFF* */ - PRESERVE8 - - /* The FPU enable bits are in the CPACR. */ - ldr.w r0, =0xE000ED88 - ldr r1, [ r0 ] - - /* Enable CP10 and CP11 coprocessors, then save back. */ - orr r1, r1, #( 0xf << 20 ) - str r1, [ r0 ] - bx r14 - nop -/* *INDENT-ON* */ + /* Start the first task. This also clears the bit that indicates the FPU is + * in use in case the FPU was used before the scheduler was started - which + * would otherwise result in the unnecessary leaving of space in the SVC stack + * for lazy saving of FPU registers. */ + __asm volatile ( + " ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */ + " ldr r0, [r0] \n" + " ldr r0, [r0] \n" + " msr msp, r0 \n" /* Set the msp back to the start of the stack. */ + " mov r0, #0 \n" /* Clear the bit that indicates the FPU is in use, see comment above. */ + " msr control, r0 \n" + " cpsie i \n" /* Globally enable interrupts. */ + " cpsie f \n" + " dsb \n" + " isb \n" + " svc 0 \n" /* System call to start first task. */ + " nop \n" + " .ltorg \n" + ); } /*-----------------------------------------------------------*/ @@ -317,10 +296,6 @@ __asm void prvEnableVFP( void ) */ BaseType_t xPortStartScheduler( void ) { - /* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0. - * See https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ - configASSERT( configMAX_SYSCALL_INTERRUPT_PRIORITY ); - /* This port can be used on all revisions of the Cortex-M7 core other than * the r0p1 parts. r0p1 parts should use the port from the * /source/portable/GCC/ARM_CM7/r0p1 directory. */ @@ -331,7 +306,7 @@ BaseType_t xPortStartScheduler( void ) { volatile uint8_t ucOriginalPriority; volatile uint32_t ulImplementedPrioBits = 0; - volatile uint8_t * const pucFirstUserPriorityRegister = ( uint8_t * ) ( portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER ); + volatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER ); volatile uint8_t ucMaxPriorityValue; /* Determine the maximum priority from which ISR safe FreeRTOS API @@ -423,13 +398,22 @@ BaseType_t xPortStartScheduler( void ) uxCriticalNesting = 0; /* Ensure the VFP is enabled - it should be anyway. */ - prvEnableVFP(); + vPortEnableVFP(); /* Lazy save always. */ *( portFPCCR ) |= portASPEN_AND_LSPEN_BITS; /* Start the first task. */ - prvStartFirstTask(); + prvPortStartFirstTask(); + + /* Should never get here as the tasks will now be executing! Call the task + * exit error function to prevent compiler warnings about a static function + * not being called in the case that the application writer overrides this + * functionality by defining configTASK_RETURN_ADDRESS. Call + * vTaskSwitchContext() so link time optimisation does not remove the + * symbol. */ + vTaskSwitchContext(); + prvTaskExitError(); /* Should not get here! */ return 0; @@ -473,67 +457,60 @@ void vPortExitCritical( void ) } /*-----------------------------------------------------------*/ -__asm void xPortPendSVHandler( void ) +void xPortPendSVHandler( void ) { - extern uxCriticalNesting; - extern pxCurrentTCB; - extern vTaskSwitchContext; + /* This is a naked function. */ -/* *INDENT-OFF* */ - PRESERVE8 - - mrs r0, psp - isb - /* Get the location of the current TCB. */ - ldr r3, =pxCurrentTCB - ldr r2, [ r3 ] - - /* Is the task using the FPU context? If so, push high vfp registers. */ - tst r14, #0x10 - it eq - vstmdbeq r0!, {s16-s31} - - /* Save the core registers. */ - stmdb r0!, {r4-r11, r14} - - /* Save the new top of stack into the first member of the TCB. */ - str r0, [ r2 ] - - stmdb sp!, {r0, r3} - mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY - msr basepri, r0 - dsb - isb - bl vTaskSwitchContext - mov r0, #0 - msr basepri, r0 - ldmia sp!, {r0, r3} - - /* The first item in pxCurrentTCB is the task top of stack. */ - ldr r1, [ r3 ] - ldr r0, [ r1 ] - - /* Pop the core registers. */ - ldmia r0!, {r4-r11, r14} - - /* Is the task using the FPU context? If so, pop the high vfp registers - * too. */ - tst r14, #0x10 - it eq - vldmiaeq r0!, {s16-s31} - - msr psp, r0 - isb - #ifdef WORKAROUND_PMU_CM001 /* XMC4000 specific errata */ - #if WORKAROUND_PMU_CM001 == 1 - push { r14 } - pop { pc } - nop + __asm volatile + ( + " mrs r0, psp \n" + " isb \n" + " \n" + " ldr r3, pxCurrentTCBConst \n" /* Get the location of the current TCB. */ + " ldr r2, [r3] \n" + " \n" + " tst r14, #0x10 \n" /* Is the task using the FPU context? If so, push high vfp registers. */ + " it eq \n" + " vstmdbeq r0!, {s16-s31} \n" + " \n" + " stmdb r0!, {r4-r11, r14} \n" /* Save the core registers. */ + " str r0, [r2] \n" /* Save the new top of stack into the first member of the TCB. */ + " \n" + " stmdb sp!, {r0, r3} \n" + " mov r0, %0 \n" + " msr basepri, r0 \n" + " dsb \n" + " isb \n" + " bl vTaskSwitchContext \n" + " mov r0, #0 \n" + " msr basepri, r0 \n" + " ldmia sp!, {r0, r3} \n" + " \n" + " ldr r1, [r3] \n" /* The first item in pxCurrentTCB is the task top of stack. */ + " ldr r0, [r1] \n" + " \n" + " ldmia r0!, {r4-r11, r14} \n" /* Pop the core registers. */ + " \n" + " tst r14, #0x10 \n" /* Is the task using the FPU context? If so, pop the high vfp registers too. */ + " it eq \n" + " vldmiaeq r0!, {s16-s31} \n" + " \n" + " msr psp, r0 \n" + " isb \n" + " \n" + #ifdef WORKAROUND_PMU_CM001 /* XMC4000 specific errata workaround. */ + #if WORKAROUND_PMU_CM001 == 1 + " push { r14 } \n" + " pop { pc } \n" + #endif #endif - #endif - - bx r14 -/* *INDENT-ON* */ + " \n" + " bx r14 \n" + " \n" + " .align 4 \n" + "pxCurrentTCBConst: .word pxCurrentTCB \n" + ::"i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) + ); } /*-----------------------------------------------------------*/ @@ -542,9 +519,8 @@ void xPortSysTickHandler( void ) /* The SysTick runs at the lowest interrupt priority, so when this interrupt * executes all interrupts must be unmasked. There is therefore no need to * save and then restore the interrupt mask value as its value is already - * known - therefore the slightly faster vPortRaiseBASEPRI() function is used - * in place of portSET_INTERRUPT_MASK_FROM_ISR(). */ - vPortRaiseBASEPRI(); + * known. */ + portDISABLE_INTERRUPTS(); { /* Increment the RTOS tick. */ if( xTaskIncrementTick() != pdFALSE ) @@ -554,14 +530,13 @@ void xPortSysTickHandler( void ) portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } } - - vPortClearBASEPRIFromISR(); + portENABLE_INTERRUPTS(); } /*-----------------------------------------------------------*/ #if ( configUSE_TICKLESS_IDLE == 1 ) - __weak void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) + __attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) { uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft; TickType_t xModifiableIdleTime; @@ -574,17 +549,17 @@ void xPortSysTickHandler( void ) /* Enter a critical section but don't use the taskENTER_CRITICAL() * method as that will mask interrupts that should exit sleep mode. */ - __disable_irq(); - __dsb( portSY_FULL_READ_WRITE ); - __isb( portSY_FULL_READ_WRITE ); + __asm volatile ( "cpsid i" ::: "memory" ); + __asm volatile ( "dsb" ); + __asm volatile ( "isb" ); /* If a context switch is pending or a task is waiting for the scheduler * to be unsuspended then abandon the low power entry. */ if( eTaskConfirmSleepModeStatus() == eAbortSleep ) { - /* Re-enable interrupts - see comments above the __disable_irq() - * call above. */ - __enable_irq(); + /* Re-enable interrupts - see comments above the cpsid instruction + * above. */ + __asm volatile ( "cpsie i" ::: "memory" ); } else { @@ -645,27 +620,27 @@ void xPortSysTickHandler( void ) if( xModifiableIdleTime > 0 ) { - __dsb( portSY_FULL_READ_WRITE ); - __wfi(); - __isb( portSY_FULL_READ_WRITE ); + __asm volatile ( "dsb" ::: "memory" ); + __asm volatile ( "wfi" ); + __asm volatile ( "isb" ); } configPOST_SLEEP_PROCESSING( xExpectedIdleTime ); /* Re-enable interrupts to allow the interrupt that brought the MCU * out of sleep mode to execute immediately. See comments above - * the __disable_irq() call above. */ - __enable_irq(); - __dsb( portSY_FULL_READ_WRITE ); - __isb( portSY_FULL_READ_WRITE ); + * the cpsid instruction above. */ + __asm volatile ( "cpsie i" ::: "memory" ); + __asm volatile ( "dsb" ); + __asm volatile ( "isb" ); /* Disable interrupts again because the clock is about to be stopped * and interrupts that execute while the clock is stopped will increase * any slippage between the time maintained by the RTOS and calendar * time. */ - __disable_irq(); - __dsb( portSY_FULL_READ_WRITE ); - __isb( portSY_FULL_READ_WRITE ); + __asm volatile ( "cpsid i" ::: "memory" ); + __asm volatile ( "dsb" ); + __asm volatile ( "isb" ); /* Disable the SysTick clock without reading the * portNVIC_SYSTICK_CTRL_REG register to ensure the @@ -773,51 +748,51 @@ void xPortSysTickHandler( void ) vTaskStepTick( ulCompleteTickPeriods ); /* Exit with interrupts enabled. */ - __enable_irq(); + __asm volatile ( "cpsie i" ::: "memory" ); } } #endif /* #if configUSE_TICKLESS_IDLE */ - /*-----------------------------------------------------------*/ /* - * Setup the SysTick timer to generate the tick interrupts at the required + * Setup the systick timer to generate the tick interrupts at the required * frequency. */ -#if ( configOVERRIDE_DEFAULT_TICK_CONFIGURATION == 0 ) - - __weak void vPortSetupTimerInterrupt( void ) +__attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) +{ + /* Calculate the constants required to configure the tick interrupt. */ + #if ( configUSE_TICKLESS_IDLE == 1 ) { - /* Calculate the constants required to configure the tick interrupt. */ - #if ( configUSE_TICKLESS_IDLE == 1 ) - { - ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ); - xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick; - ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ ); - } - #endif /* configUSE_TICKLESS_IDLE */ - - /* Stop and clear the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; - portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; - - /* Configure SysTick to interrupt at the requested rate. */ - portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL; - portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT ); + ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ); + xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick; + ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ ); } + #endif /* configUSE_TICKLESS_IDLE */ -#endif /* configOVERRIDE_DEFAULT_TICK_CONFIGURATION */ + /* Stop and clear the SysTick. */ + portNVIC_SYSTICK_CTRL_REG = 0UL; + portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; + + /* Configure SysTick to interrupt at the requested rate. */ + portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL; + portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT ); +} /*-----------------------------------------------------------*/ -__asm uint32_t vPortGetIPSR( void ) +/* This is a naked function. */ +static void vPortEnableVFP( void ) { -/* *INDENT-OFF* */ - PRESERVE8 - - mrs r0, ipsr - bx r14 -/* *INDENT-ON* */ + __asm volatile + ( + " ldr.w r0, =0xE000ED88 \n" /* The FPU enable bits are in the CPACR. */ + " ldr r1, [r0] \n" + " \n" + " orr r1, r1, #( 0xf << 20 ) \n" /* Enable CP10 and CP11 coprocessors, then save back. */ + " str r1, [r0] \n" + " bx r14 \n" + " .ltorg \n" + ); } /*-----------------------------------------------------------*/ @@ -829,7 +804,7 @@ __asm uint32_t vPortGetIPSR( void ) uint8_t ucCurrentPriority; /* Obtain the number of the currently executing interrupt. */ - ulCurrentInterrupt = vPortGetIPSR(); + __asm volatile ( "mrs %0, ipsr" : "=r" ( ulCurrentInterrupt )::"memory" ); /* Is the interrupt number a user defined interrupt? */ if( ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER ) @@ -849,10 +824,10 @@ __asm uint32_t vPortGetIPSR( void ) * be set to a value equal to or numerically *higher* than * configMAX_SYSCALL_INTERRUPT_PRIORITY. * - * Interrupts that use the FreeRTOS API must not be left at their - * default priority of zero as that is the highest possible priority, + * Interrupts that use the FreeRTOS API must not be left at their + * default priority of zero as that is the highest possible priority, * which is guaranteed to be above configMAX_SYSCALL_INTERRUPT_PRIORITY, - * and therefore also guaranteed to be invalid. + * and therefore also guaranteed to be invalid. * * FreeRTOS maintains separate thread and ISR API functions to ensure * interrupt entry is as fast and simple as possible. diff --git a/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/portmacro.h b/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/portmacro.h index d79c9b4..ec9cfc9 100644 --- a/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/portmacro.h +++ b/Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F/portmacro.h @@ -28,7 +28,7 @@ #ifndef PORTMACRO_H -#define PORTMACRO_H + #define PORTMACRO_H /* *INDENT-OFF* */ #ifdef __cplusplus @@ -69,19 +69,19 @@ /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do * not need to be guarded with a critical section. */ #define portTICK_TYPE_IS_ATOMIC 1 + #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS ) + typedef uint64_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffffffffffffffffULL #else #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width. #endif /*-----------------------------------------------------------*/ /* Architecture specifics. */ - #define portSTACK_GROWTH ( -1 ) - #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) - #define portBYTE_ALIGNMENT 8 - -/* Constants used with memory barrier intrinsics. */ - #define portSY_FULL_READ_WRITE ( 15 ) - + #define portSTACK_GROWTH ( -1 ) + #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) + #define portBYTE_ALIGNMENT 8 + #define portDONT_DISCARD __attribute__( ( used ) ) /*-----------------------------------------------------------*/ /* Scheduler utilities. */ @@ -92,10 +92,9 @@ \ /* Barriers are normally not required but do ensure the code is completely \ * within the specified behaviour for the architecture. */ \ - __dsb( portSY_FULL_READ_WRITE ); \ - __isb( portSY_FULL_READ_WRITE ); \ + __asm volatile ( "dsb" ::: "memory" ); \ + __asm volatile ( "isb" ); \ } -/*-----------------------------------------------------------*/ #define portNVIC_INT_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000ed04 ) ) #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) @@ -106,16 +105,22 @@ /* Critical section management. */ extern void vPortEnterCritical( void ); extern void vPortExitCritical( void ); - + #define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI() + #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vPortSetBASEPRI( x ) #define portDISABLE_INTERRUPTS() vPortRaiseBASEPRI() #define portENABLE_INTERRUPTS() vPortSetBASEPRI( 0 ) #define portENTER_CRITICAL() vPortEnterCritical() #define portEXIT_CRITICAL() vPortExitCritical() - #define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI() - #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vPortSetBASEPRI( x ) /*-----------------------------------------------------------*/ +/* Task function macros as described on the FreeRTOS.org WEB site. These are + * not necessary for to use this port. They are defined so the common demo files + * (which build with all the ports) will build. */ + #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) + #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) +/*-----------------------------------------------------------*/ + /* Tickless idle/low power functionality. */ #ifndef portSUPPRESS_TICKS_AND_SLEEP extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ); @@ -123,13 +128,23 @@ #endif /*-----------------------------------------------------------*/ -/* Port specific optimisations. */ +/* Architecture specific optimisations. */ #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 #endif #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 +/* Generic helper function. */ + __attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap ) + { + uint8_t ucReturn; + + __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" ); + + return ucReturn; + } + /* Check the configuration. */ #if ( configMAX_PRIORITIES > 32 ) #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice. @@ -141,16 +156,10 @@ /*-----------------------------------------------------------*/ - #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __clz( ( uxReadyPriorities ) ) ) + #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) ucPortCountLeadingZeros( ( uxReadyPriorities ) ) ) - #endif /* taskRECORD_READY_PRIORITY */ -/*-----------------------------------------------------------*/ + #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ -/* Task function macros as described on the FreeRTOS.org WEB site. These are - * not necessary for to use this port. They are defined so the common demo files - * (which build with all the ports) will build. */ - #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) - #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) /*-----------------------------------------------------------*/ #ifdef configASSERT @@ -164,87 +173,16 @@ #define portINLINE __inline #ifndef portFORCE_INLINE - #define portFORCE_INLINE __forceinline + #define portFORCE_INLINE inline __attribute__( ( always_inline ) ) #endif -/*-----------------------------------------------------------*/ - - static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI ) - { - __asm - { - /* Barrier instructions are not used as this function is only used to - * lower the BASEPRI value. */ -/* *INDENT-OFF* */ - msr basepri, ulBASEPRI -/* *INDENT-ON* */ - } - } -/*-----------------------------------------------------------*/ - - static portFORCE_INLINE void vPortRaiseBASEPRI( void ) - { - uint32_t ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY; - - __asm - { - /* Set BASEPRI to the max syscall priority to effect a critical - * section. */ -/* *INDENT-OFF* */ - msr basepri, ulNewBASEPRI - dsb - isb -/* *INDENT-ON* */ - } - } -/*-----------------------------------------------------------*/ - - static portFORCE_INLINE void vPortClearBASEPRIFromISR( void ) - { - __asm - { - /* Set BASEPRI to 0 so no interrupts are masked. This function is only - * used to lower the mask in an interrupt, so memory barriers are not - * used. */ -/* *INDENT-OFF* */ - msr basepri, # 0 -/* *INDENT-ON* */ - } - } -/*-----------------------------------------------------------*/ - - static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void ) - { - uint32_t ulReturn, ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY; - - __asm - { - /* Set BASEPRI to the max syscall priority to effect a critical - * section. */ -/* *INDENT-OFF* */ - mrs ulReturn, basepri - msr basepri, ulNewBASEPRI - dsb - isb -/* *INDENT-ON* */ - } - - return ulReturn; - } -/*-----------------------------------------------------------*/ - - static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void ) + portFORCE_INLINE static BaseType_t xPortIsInsideInterrupt( void ) { uint32_t ulCurrentInterrupt; BaseType_t xReturn; /* Obtain the number of the currently executing interrupt. */ - __asm - { -/* *INDENT-OFF* */ - mrs ulCurrentInterrupt, ipsr -/* *INDENT-ON* */ - } + __asm volatile ( "mrs %0, ipsr" : "=r" ( ulCurrentInterrupt )::"memory" ); if( ulCurrentInterrupt == 0 ) { @@ -258,6 +196,55 @@ return xReturn; } +/*-----------------------------------------------------------*/ + + portFORCE_INLINE static void vPortRaiseBASEPRI( void ) + { + uint32_t ulNewBASEPRI; + + __asm volatile + ( + " mov %0, %1 \n"\ + " msr basepri, %0 \n"\ + " isb \n"\ + " dsb \n"\ + : "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory" + ); + } + +/*-----------------------------------------------------------*/ + + portFORCE_INLINE static uint32_t ulPortRaiseBASEPRI( void ) + { + uint32_t ulOriginalBASEPRI, ulNewBASEPRI; + + __asm volatile + ( + " mrs %0, basepri \n"\ + " mov %1, %2 \n"\ + " msr basepri, %1 \n"\ + " isb \n"\ + " dsb \n"\ + : "=r" ( ulOriginalBASEPRI ), "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory" + ); + + /* This return will not be reached but is necessary to prevent compiler + * warnings. */ + return ulOriginalBASEPRI; + } +/*-----------------------------------------------------------*/ + + portFORCE_INLINE static void vPortSetBASEPRI( uint32_t ulNewMaskValue ) + { + __asm volatile + ( + " msr basepri, %0 "::"r" ( ulNewMaskValue ) : "memory" + ); + } +/*-----------------------------------------------------------*/ + + #define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" ) + /* *INDENT-OFF* */ #ifdef __cplusplus }