上图是incbin.s的内容,实现把M0+内核的代码导入ram。
在hello_world_core0.c是(m4内核的main函数)增加如下代码
/* Address of RAM, where the image for core1 should be copied */
#define CORE1_BOOT_ADDRESS (void *)0x20010000
这个宏定义是M0+内核烧录到rom的首地址
#if defined(__CC_ARM)
extern uint32_t Image$$CORE1_REGION$$Base;
extern uint32_t Image$$CORE1_REGION$$Length;
#define CORE1_IMAGE_START &Image$$CORE1_REGION$$Base
#elif defined(__ICCARM__)
extern unsigned char core1_image_start[];
#define CORE1_IMAGE_START core1_image_start
#endif
#ifdef CORE1_IMAGE_COPY_TO_RAM
uint32_t get_core1_image_size()//读取m0+内核代码的大小
{
uint32_t core1_image_size;
#if defined(__CC_ARM)
core1_image_size = (uint32_t)&Image$$CORE1_REGION$$Length;
#elif defined(__ICCARM__)
#pragma section = "__sec_core"
core1_image_size = (uint32_t)__section_end("__sec_core") - (uint32_t)&core1_image_start;
#endif
return core1_image_size;
}
#endif
然后在main函数中增加拷贝m0+代码的代码
#ifdef CORE1_IMAGE_COPY_TO_RAM
/* Calculate size of the image - not required on LPCExpresso. LPCExpresso copies image to RAM during startup
* automatically */
uint32_t core1_image_size;
core1_image_size = get_core1_image_size();
PRINTF("Copy Secondary core image to address: 0x%x, size: %d\n", CORE1_BOOT_ADDRESS, core1_image_size);
/* Copy Secondary core application from FLASH to RAM. Primary core code is executed from FLASH, Secondary from RAM
* for maximal effectivity.*/
memcpy(CORE1_BOOT_ADDRESS, (void *)CORE1_IMAGE_START, core1_image_size);
#endif
编译,下载,即可运行,下面是串口助手的截图,说明运行正常,同时,M0+内核控制的led(4个红色一组,4个绿色一组)也在交替闪烁。