如题,我想在编译的时候将一段数据放入自定义的flash空间,如下,其中第14-26行是我自己添加的,想在_shell_command_start和_shell_command_end之间开辟一段空间,用于存储我的自定义的一段数据,这段数据的大小由KEEP (*(shellCommand))计算,其中shellCommand是在C的源代码中定义的一个结构体类型(共16个字节),可能会在这段空间添加多个(数量不定)。但是编译的时候KEEP (*(shellCommand))这一行报错。而在stm32CubeIDE(也是基于eclipse开发的一款IDE)中,这个语法是可以正常执行的
SECTIONS { .intvecs : > FLASH_START .text : >> FLASH | FLASH_LAST_PAGE .const : >> FLASH | FLASH_LAST_PAGE .constdata : >> FLASH | FLASH_LAST_PAGE .rodata : >> FLASH | FLASH_LAST_PAGE .cinit : > FLASH | FLASH_LAST_PAGE .pinit : >> FLASH | FLASH_LAST_PAGE .init_array : > FLASH | FLASH_LAST_PAGE .emb_text : >> FLASH | FLASH_LAST_PAGE .ccfg : > FLASH_LAST_PAGE (HIGH) /* Constant data goes into FLASH */ .rodata : { . = ALIGN(4); *(.rodata) /* .rodata sections (constants, strings, etc.) */ . = ALIGN(4); . = ALIGN(4); _shell_command_start = .; KEEP (*(shellCommand)) _shell_command_end = .; . = ALIGN(4); } >FLASH ... ... }
shellCommand的类型定义如下:
typedef struct shell_command
{
int value;
struct
{
const char *name; /**< 命令名 */
int (*function)(); /**< 命令执行函数 */
const char *desc; /**< 命令描述 */
} cmd; /**< 命令定义 */
} ShellCommand;
通过调用如下宏定义添加自定义数据
#define SHELL_EXPORT_CMD(_attr, _name, _func, _desc, ...) \
const char shellCmd##_name[] = #_name; \
const char shellDesc##_name[] = #_desc; \
SHELL_USED const ShellCommand \
shellCommand##_name SHELL_SECTION("shellCommand") = \
{ \
.value = _attr, \
.cmd.name = shellCmd##_name, \
.cmd.function = (int (*)())_func, \
.cmd.desc = shellDesc##_name, \
##__VA_ARGS__ \
}