Libero PolarFire® SoC ICICLE 开发板 新建一个简单的工程(四) 串口控制和LED控制 C代码 移植 FreeRTOS

Libero PolarFire® SoC ICICLE 开发板 新建一个简单的工程(一) MSS 配置 - 所长 - 博客园

Libero PolarFire® SoC ICICLE 开发板 新建一个简单的工程(二) libero 工程 - 所长 - 博客园

Libero PolarFire® SoC ICICLE 开发板 新建一个简单的工程(三) softconsole 2022 工程创建 - 所长 - 博客园

 Libero PolarFire® SoC ICICLE 开发板 新建一个简单的工程(四) 串口控制和LED控制 C代码 移植 FreeRTOS - 所长 - 博客园

 

PolarFire® SoC 尝试移植 FreeRTOS (一) - 所长 - 博客园

PolarFire® SoC 尝试移植 FreeRTOS (二) - 所长 - 博客园

 PolarFire® SoC FreeRTOS RISC-V 'systick' 定时器 mtime - 所长 - 博客园

PolarFire® SoC 移植 xprintf - 所长 - 博客园

PolarFire® SoC SoftConsole 烧录 程序到 eNVM - 所长 - 博客园

 

修改链接文件 到  这样 下载 程序就可以掉电保存了!

 

image

 

void e51(void)
{
    volatile uint32_t icount = 0U;
    uint64_t hartid = read_csr(mhartid);

    (void) mss_config_clk_rst(MSS_PERIPH_MMUART_E51, (uint8_t) 1, PERIPHERAL_ON);

    MSS_UART_init(p_uartmap_e51,
    MSS_UART_115200_BAUD,
    MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT);

    /* Message on uart0 */
    MSS_UART_polled_tx(p_uartmap_e51, g_message3,
            sizeof(g_message3));

#if (IMAGE_LOADED_BY_BOOTLOADER == 0)

    /* Clear pending software interrupt in case there was any. */

    clear_soft_interrupt();
    set_csr(mie, MIP_MSIP);

    /* Raise software interrupt to wake hart 1 */
    raise_soft_interrupt(1U);

    /* Raise software interrupt to wake hart 2 */
    raise_soft_interrupt(2U);

    __enable_irq();

#endif

    // mtime clk init 1Mhz
    #define BIT_SET 0x00010000U
    SYSREG->RTC_CLOCK_CR &= ~BIT_SET;
    SYSREG->RTC_CLOCK_CR = LIBERO_SETTING_MSS_EXT_SGMII_REF_CLK / LIBERO_SETTING_MSS_RTC_TOGGLE_CLK;
    SYSREG->RTC_CLOCK_CR |= BIT_SET;

    #if ( mainVECTOR_MODE_DIRECT == 1 )
    {
        __asm__ volatile ( "csrw mtvec, %0" : : "r" ( freertos_risc_v_trap_handler ) );
    }
    #else
    {
        __asm__ volatile ( "csrw mtvec, %0" : : "r" ( ( uintptr_t ) freertos_vector_table | 0x1 ) );
    }
    #endif

    xTaskCreate( x_system_task, "system", configMINIMAL_STACK_SIZE, NULL, 2, NULL );

    /* Start the tasks and timer running. */
    vTaskStartScheduler();

    while (1U);

    /* never return */
}
/* Kernel includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

#include "xprintf.h"

extern void freertos_vector_table( void );

void xprintf_output_c( uint8_t ch )
{
    MSS_UART_polled_tx(p_uartmap_e51, &ch, 1 );
}

void x_system_task( void * arg )
{

    // xprintf 移植
    xdev_out(xprintf_output_c);

    for(;;)
    {
        xprintf( "system version:%d.\n", 2 );

        vTaskDelay(1000);
    }
}

 

测试结果:

image

 

 

下面控制 LED 灯, 首先解除  GPIO  编译的 问题

image

 

void fsm_led( void )
{

    static uint8_t init_flag = 0;
    static uint8_t led_flag = 0;

    if( init_flag == 0 )
    {

        (void) mss_config_clk_rst(MSS_PERIPH_GPIO2, (uint8_t) 0, PERIPHERAL_ON);

        MSS_GPIO_init(GPIO2_LO);
        MSS_GPIO_config(GPIO2_LO, MSS_GPIO_0, MSS_GPIO_OUTPUT_MODE);

        init_flag = 1;

    }

    if( led_flag == 0 )
    {   // 点亮 LED
        MSS_GPIO_set_output(GPIO2_LO, MSS_GPIO_0, 1);
        led_flag = 1;
    }
    else
    {   // 关闭 LED
        MSS_GPIO_set_output(GPIO2_LO, MSS_GPIO_0, 0);
        led_flag = 0;
    }

}

 

10:58:53 INFO - mpfsBootmodeProgrammer v3.7 started.
10:58:53 INFO - "C:\Users\zydz\Desktop\polarfire_code\icicle_software\mpfs-mmuart-interrupt\eNVM-Scratchpad-Release-IcicleKit\bootmode1" is the output folder and the previous contents of this folder will be deleted.
10:58:53 INFO - Selected boot mode "1 - non-secure boot from eNVM" and working in directory "C:\Users\zydz\Desktop\polarfire_code\icicle_software\mpfs-mmuart-interrupt\eNVM-Scratchpad-Release-IcicleKit".
10:58:53 INFO - Generating BIN file...
10:58:53 INFO - Generating header...
10:58:53 INFO - Generating HEX file...
10:58:53 INFO - Preparing for bitstream generation...
10:58:53 INFO - Generating bitstream...
10:59:00 INFO - Programming the target...
10:59:07 INFO - mpfsBootmodeProgrammer completed successfully.

 

断电 上电 

image

 

posted on 2026-02-06 18:07  所长  阅读(2)  评论(0)    收藏  举报

导航