PolarFire® SoC 尝试移植 FreeRTOS (一)

 

1、 FreeRTOS 源码地址

  FreeRTOS/FreeRTOS-Kernel

2、尝试在 mpfs-mmuart-interrupt 工程上 增加 FreeRTOS  

   polarfire-soc-bare-metal-examples/driver-examples/mss/mss-mmuart/mpfs-mmuart-interrupt at main · polarfire-soc/polarfire-soc-bare-metal-examples

3、工程激活选项卡:eNVM-Scratchpad-Release-lcicleKit, 目的,更改链接文件,生成的固件,链接地址 位 eNVM 的地址, eNVM 只有 128KB , 因此要省着点用

image

 

4、确认 配置文件 /mpfs-mmuart-interrupt/src/boards/icicle-kit/platform_config/envm-scratchpad-release/mpfs_hal_config/mss_sw_config.h 文件中 

#define IMAGE_LOADED_BY_BOOTLOADER 0

  目的: 本身是 bootloader 功能

5、修改 DDR 初始化 状态机  , 测试5秒 太长, 关闭

/mpfs-mmuart-interrupt/src/platform/mpfs_hal/common/nwc/mss_ddr.c

static uint32_t ddr_setup(void) 函数中 

image

 

6、src 目录下 新建  FreeRTOS 文件夹 , 复制 FreeRTOS 源文件 / 和整个 include 文件夹, 记得复制  heap_4.c 文件

image

 

7、src/FreeRTOS 目录下新建 port 文件夹,复制 FreeRTOS-Kernel\portable\GCC\RISC-V 文件夹 到此目录

image

 

8、 将 FreeRTOS/FreeRTOS/Demo/RISC-V_RV64_PolarFire_SoftConsole/FreeRTOSConfig.h at main · FreeRTOS/FreeRTOS 

 FreeRTOSConfig.h 复制到  /mpfs-mmuart-interrupt/src/FreeRTOS/include/ 路径下

image

 

9、工程属性里 增加 头文件 路径 

image

 

编译 错误提示:

 ../src/FreeRTOS/port/RISC-V/portContext.h:52:10: fatal error: freertos_risc_v_chip_specific_extensions.h: No such file or directory

 

正在研究中 2025年9月8日 16点45分

 

10、增加 汇编 头文件路径,解决问题, 没错 汇编有专门的 头文件路径 

image

 11、编译结果:

17:45:18 Build Finished. 0 errors, 0 warnings. (took 15s.254ms)

 

12、 在 u54_1 函数中,创建一个 每秒打印一次log  的任务; 编译报错, 

image

 添加一下代码解决

void vApplicationMallocFailedHook( void )
{
    /* vApplicationMallocFailedHook() will only be called if
     * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
     * function that will get called if a call to pvPortMalloc() fails.
     * pvPortMalloc() is called internally by the kernel whenever a task, queue,
     * timer or semaphore is created.  It is also called by various parts of the
     * demo application.  If heap_1.c or heap_2.c are used, then the size of the
     * heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
     * FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
     * to query the size of free heap space that remains (although it does not
     * provide information on how the remaining heap might be fragmented). */
    taskDISABLE_INTERRUPTS();

    for( ; ; )
    {
    }
}

void vApplicationIdleHook( void )
{
    /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
     * to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle
     * task.  It is essential that code added to this hook function never attempts
     * to block in any way (for example, call xQueueReceive() with a block time
     * specified, or call vTaskDelay()).  If the application makes use of the
     * vTaskDelete() API function (as this demo application does) then it is also
     * important that vApplicationIdleHook() is permitted to return to its calling
     * function, because it is the responsibility of the idle task to clean up
     * memory allocated by the kernel to any task that has since been deleted. */
}


void vApplicationStackOverflowHook( TaskHandle_t pxTask,
                                    char * pcTaskName )
{
    ( void ) pcTaskName;
    ( void ) pxTask;

    /* Run time stack overflow checking is performed if
     * configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
     * function is called if a stack overflow is detected. */
    taskDISABLE_INTERRUPTS();

    for( ; ; )
    {
    }
}

void vApplicationTickHook( void )
{

}

/*-----------------------------------------------------------*/

void vAssertCalled( void )
{
    volatile uint32_t ul;
    const uint32_t ulNullLoopDelay = 0x1ffffUL;
    static volatile uint8_t value = 0u;

    taskDISABLE_INTERRUPTS();

    /* Flash the red LED to indicate that assert was hit - interrupts are off
     * here to prevent any further tick interrupts or context switches, so the
     * delay is implemented as a crude loop instead of a peripheral timer. */
    for( ; ; )
    {
        for( ul = 0; ul < ulNullLoopDelay; ul++ )
        {
            __asm volatile ( "nop" );
        }

        value = ( value == 0u ) ? 1u : 0u;
        // MSS_GPIO_set_output( GPIO2_LO, MSS_GPIO_16, value );
    }
}

13、编译 报错 :

Description Resource Path Location Type
undefined reference to `__freertos_irq_stack_top' port.c /mpfs-mmuart-interrupt/src/FreeRTOS/port/RISC-V line 154 C/C++ Problem

 

在链接文件中, 因为在 U5_1 内核中 调用的 TASK 创建 ,运行, 因此 mpfs-envm-lma-scratchpad-vma.ld 链接文件中 添加  PROVIDE(__freertos_irq_stack_top = .);

image

 再次编译 :

20:15:24 Build Finished. 0 errors, 1 warnings. (took 14s.369ms)

 

进行到这里, 程序烧录到板子里, 还是没有跑起来,……

现象是 ,程序最后 在 以下函数中循环:

image

 

继续查资料 

Using FreeRTOS on RISC-V Microcontrollers - FreeRTOS™

 预知后事如何:PolarFire® SoC 尝试移植 FreeRTOS (二) - 所长 - 博客园

posted on 2025-09-08 15:10  所长  阅读(35)  评论(0)    收藏  举报

导航