CubeMX freeRTOS V9 вылетает на STM32F4

У меня особая проблема с freeRTOS на STM32F4 с использованием cubeMX. Когда я использую старую версию CubeMX (с поддержкой пакетов, например, STM32Cube_FW_F4_V1.14.0), которая поддерживает freeRTOSv8, она работает нормально, без проблем. Когда я обновил CubeMX до последней версии, которая поддерживает freeRTOSv9, он вылетает при запуске планировщика RTOS.

    BaseType_t xPortStartScheduler( void )
{
    /* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.
    See http://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. */
    configASSERT( portCPUID != portCORTEX_M7_r0p1_ID );
    configASSERT( portCPUID != portCORTEX_M7_r0p0_ID );

    #if( configASSERT_DEFINED == 1 )
    {
        volatile uint32_t ulOriginalPriority;
        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
        functions can be called.  ISR safe functions are those that end in
        "FromISR".  FreeRTOS maintains separate thread and ISR API functions to
        ensure interrupt entry is as fast and simple as possible.

        Save the interrupt priority value that is about to be clobbered. */
        ulOriginalPriority = *pucFirstUserPriorityRegister;

        /* Determine the number of priority bits available.  First write to all
        possible bits. */
        *pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE;

        /* Read the value back to see how many bits stuck. */
        ucMaxPriorityValue = *pucFirstUserPriorityRegister;

        /* Use the same mask on the maximum system call priority. */
        ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue;

        /* Calculate the maximum acceptable priority group value for the number
        of bits read back. */
        ulMaxPRIGROUPValue = portMAX_PRIGROUP_BITS;
        while( ( ucMaxPriorityValue & portTOP_BIT_OF_BYTE ) == portTOP_BIT_OF_BYTE )
        {
            ulMaxPRIGROUPValue--;
            ucMaxPriorityValue <<= ( uint8_t ) 0x01;
        }

        /* Shift the priority group value back to its position within the AIRCR
        register. */
        ulMaxPRIGROUPValue <<= portPRIGROUP_SHIFT;
        ulMaxPRIGROUPValue &= portPRIORITY_GROUP_MASK;

        /* Restore the clobbered interrupt priority register to its original
        value. */
        *pucFirstUserPriorityRegister = ulOriginalPriority;
    }
    #endif /* conifgASSERT_DEFINED */

    /* Make PendSV and SysTick the lowest priority interrupts. */
    portNVIC_SYSPRI2_REG |= portNVIC_PENDSV_PRI;
    portNVIC_SYSPRI2_REG |= portNVIC_SYSTICK_PRI;

    /* Start the timer that generates the tick ISR.  Interrupts are disabled
    here already. */
    vPortSetupTimerInterrupt();

    /* Initialise the critical nesting count ready for the first task. */
    uxCriticalNesting = 0;

    /* Ensure the VFP is enabled - it should be anyway. */
    vPortEnableVFP();

    /* Lazy save always. */
    *( portFPCCR ) |= portASPEN_AND_LSPEN_BITS;

    /* Start the first task. */
    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. */
    prvTaskExitError();

    /* Should not get here! */
    return 0;
}
/*-----------------------------------------------------------*/

происходит сбой при первом запуске задачи prvPortStartFirstTask ();


person Marcin Gajewski    schedule 21.08.2018    source источник
comment
После обновления я воссоздал новый проект CubeMx с нуля. SVC_Handler и PendSV_Handler были объявлены в двух разных местах, и они будут появляться каждый раз, когда я регенерирую код. Если вам ничего не нужно из новой версии, вернитесь к старой.   -  person MasterRem    schedule 23.08.2018


Ответы (3)


Похоже, что PendSV_Handler, SVC_Handler или SysTick_Handler обработчики прерываний не реализованы. Пожалуйста, проверьте файлы stm32f4xx_it.c и FreeRTOSConfig.h. Обычно прерывания, связанные с помощью, определяют:

#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
person denis krasutski    schedule 23.08.2018

Поскольку вы работали с платой STM32F4, это MCU Cortex-M4, было бы намного проще отладить, если бы вы могли предоставить значение регистров Cortex-M4, когда программа перестает работать, значение регистров, такое как control, xPSR, sp, lr, pc, и CFSR и выгрузите кадр стека исключений, затем проверьте, имеют ли эти значения смысл, с помощью кода дизассемблирования RTOS.

В порту FreeRTOS для Cortex-M4 последним шагом prvPortStartFirstTask() является создание исключения SVC, после чего ЦП переходит к процедуре обработчика SVC. До исключения SVC FreeRTOS даже не запускал первую задачу.

Таким образом, в вашем случае ЦП вряд ли остановится в PendSV_Handler и SysTick_Handler. Более вероятно, что он застрянет в подпрограмме обработчика сбоев (например, сбой HardFault или MemManage, если вы включите MPU на своей плате STM32F4). Если вы используете GDB, вы можете добавить точки останова в эту подпрограмму обработчика ошибок HardFault_Handler, MemManage_Handler, чтобы выяснить проблему.

person Han    schedule 23.05.2019

Как указано в этом сообщении, это известная проблема на пластине STM32F401 при использовании инструмента конфигурации устройства STM32CubeMX или STM32CubeIDE.

Решение

В своем проекте STMCubeMX найдите файл stm32f4xx_hal_msp.c. Затем замените строку HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0); на HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);

person fofolevrai    schedule 15.12.2020