This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

IWRL6432: 如何在不同时刻将不同程序加载到同一块RAM上运行程序?

Part Number: IWRL6432

有2段程序:分别是hello_world_main 和hello_world_main_test,这2段程序放在不同的Section

void __attribute__ ((section("TC"))) hello_world_main(void *args)
{
/* Open drivers to open the UART driver for console */
Drivers_open();
Board_driversOpen();

DebugP_log("Hello World!\r\n");
DebugP_log("This is new HW!\r\n");

Board_driversClose();
Drivers_close();
}

void __attribute__ ((section("TC1"))) hello_world_main_test(void *args)
{
/* Open drivers to open the UART driver for console */
Drivers_open();
Board_driversOpen();

DebugP_log("Hello World Test!\r\n");
DebugP_log("This is new HW!\r\n");

Board_driversClose();
Drivers_close();
}

以下是Linker.cmd文件中关于TC和TC1的说明。
SECTIONS
{
/* This has the M4F entry point and vector table, this MUST be at 0x0 */
.vectors:{} palign(8) > M4F_VECS
.bss: {} palign(8) > M4F_RAM12 /* This is where uninitialized globals go */
RUN_START(__BSS_START)
RUN_END(__BSS_END)
.text: {} align(8) >> M4F_RAM12 | M4F_RAM3 /* This is where code resides */
.data: {} align(8) >> M4F_RAM12 | M4F_RAM3 /* This is where initialized globals and static go */
.rodata: {} align(8) >> M4F_RAM12 | M4F_RAM3 /* This is where const's go */
.sysmem: {} palign(8) > M4F_RBL /* This is where the malloc heap goes */
.stack: {} palign(8) > M4F_RBL /* This is where the main() stack goes */
.l3: {} palign(8) > HWASS_SHM_MEM /* This is where L3 data goes */

TC: {} align(8) LOAD = 0x00440000, RUN = 0x00420000
TC1: {} align(8) LOAD = 0x00441000, RUN = 0x00420000
}

MEMORY
{
M4F_VECS : ORIGIN = 0x00400000 , LENGTH = 0x00000200
M4F_RAM12 : ORIGIN = 0x00400200 , LENGTH = (0x00058000 - 0x200) /* 32KB of RAM2 is being used by RBL */
M4F_RBL : ORIGIN = 0x00458000 , LENGTH = 0x8000 /* 32KB of RAM2 is being used by RBL */
M4F_RAM3 : ORIGIN = 0x00460000 , LENGTH = 0x00020000

HWASS_SHM_MEM : ORIGIN = 0x60000000, LENGTH = 0x00068000 /* 256KB in APPSS PD and 160KB in HWA PD */
}

在编译时提示错误:

请问这个要如何解决不同程序在不同时刻在同一块RAM上运行?

  • 您好,

    hello_world_main和hello_world_main_test两个函数被分别放在名为"TC"和"TC1"的两个不同的Section中。在链接脚本中,这两个Section的LOAD地址分别为0x00440000和0x00441000,而RUN地址都为0x00420000。这意味着这两个Section都被加载到了同一块RAM上,但是在不同的地址空间中运行。

    如果这两个函数需要在不同时刻运行,您需要确保它们不会相互干扰,即它们使用的变量和资源不会冲突。如果这两个函数需要共享某些变量或资源,您需要使用同步机制(例如信号量、互斥量等)来确保它们的正确性。

    如果这两个函数需要在同时刻运行,您需要将它们放在不同的RAM中,以避免它们之间的干扰。您可以在链接脚本中定义另一个RAM Section,并将其中一个函数放在该Section中。例如,您可以在链接脚本中添加以下内容:

    TC: {} align(8) LOAD = 0x00440000, RUN = 0x00420000
    TC1: {} align(8) LOAD = 0x00441000, RUN = 0x00420000
    TC2: {} align(8) LOAD = 0x00442000, RUN = 0x00420000

    然后将其中一个函数放在TC2 Section中,例如:

    void __attribute__ ((section("TC2"))) hello_world_main_test(void *args)
    {
    /* Open drivers to open the UART driver for console */
    Drivers_open();
    Board_driversOpen();
    
    DebugP_log("Hello World Test!\r\n");
    DebugP_log("This is new HW!\r\n");
    
    Board_driversClose();
    Drivers_close();
    }

    这样,hello_world_main和hello_world_main_test两个函数将被加载到不同的RAM Section中,以避免它们之间的干扰。

    但是还请注意,您还需要确保这两个RAM Section不会重叠,以避免地址冲突。在链接脚本中,您可以使用ORIGIN和LENGTH定义RAM Section的起始地址和长度。

  • 你好!

    如您所说hello_world_main和hello_world_main_test两个函数被分别放在名为"TC"和"TC1"的两个不同的Section中,程序在调用其中一个时会确保另外一个函数不会执行(或已经执行完成并退出)。
    目前是想不同时刻在0x0042000运行这2个函数,有没有相关的demo或文档介绍IWRL6432如何在同一个RAM上重载不同的程序并允许?

  • 根据您提供的信息,可以使用以下步骤来实现在0x0042000运行这两个函数:
    1. 首先,需要在程序中创建一个新的Section,命名为"TC2",并将其地址设置为0x0042000。
    2. 然后,将hello_world_main和hello_world_main_test两个函数分别放入"TC"和"TC1" Section中。
    3. 接下来,需要在程序中添加一些代码来确保在0x0042000运行这两个函数。可以使用以下代码片段来实现这一点:

    // 将TC Section中的hello_world_main函数复制到TC2 Section中
    memcpy((void*)0x0042000, (void*)hello_world_main, (size_t)hello_world_main_size);
    
    // 调用hello_world_main函数
    ((void(*)())0x0042000)();
    
    // 将TC1 Section中的hello_world_main_test函数复制到TC2 Section中
    memcpy((void*)0x0042000, (void*)hello_world_main_test, (size_t)hello_world_main_test_size);
    
    // 调用hello_world_main_test函数
    ((void(*)())0x0042000)();

    这段代码将hello_world_main和hello_world_main_test函数分别复制到TC2 Section中,并在0x0042000处调用它们。由于这两个函数被放置在不同的Section中,因此在调用其中一个函数时,另一个函数不会被执行。