のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

prvPortStartFirstTaskのあと、HardFault

prvPortStartFirstTaskで、svc 0のあと、HardFaultになる。

f:id:none53:20190718035425p:plain
prvPortStartFirstTask

static void prvPortStartFirstTask( void )
{
    __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"
                );
}
/*-----------------------------------------------------------*/

vPortSVCHandlerに、ブレークを設定したが、止まらなかった。

www.freertos.org

inc/FreeRTOSConfig.h:136

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler    SVC_Handler
#define xPortPendSVHandler PendSV_Handler

startup_stm32f429zitx.s

g_pfnVectors:
0  .word  _estack 
1 .word  Reset_Handler
2  .word  NMI_Handler
3  .word  HardFault_Handler

4  .word  MemManage_Handler
5  .word  BusFault_Handler
6  .word  UsageFault_Handler
7  .word  0

8  .word  0
9  .word  0
A  .word  0
B  .word  SVC_Handler

C  .word  DebugMon_Handler
D  .word  0
E  .word  PendSV_Handler
F  .word  SysTick_Handler

f:id:none53:20190718040612p:plain
nvic

Timebase SourceをTIM14に変更

Timebase SourceをTIM14

f:id:none53:20190717085503p:plain
Timebase SourceをTIM14

f:id:none53:20190717085620p:plain
Timebase

f:id:none53:20190717085645p:plain
code generation

xPortSysTickHandlerが呼ばれるようになった。

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. */
    portDISABLE_INTERRUPTS();
    {
        /* Increment the RTOS tick. */
        if( xTaskIncrementTick() != pdFALSE )
        {
            /* A context switch is required.  Context switching is performed in
           the PendSV interrupt.  Pend the PendSV interrupt. */
            portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
        }
    }
    portENABLE_INTERRUPTS();
}
/*-----------------------------------------------------------*/

myTask01とmyTask02が切り替わるようになった。

f:id:none53:20190718032303p:plain
systickからtimer14