Varible static link during compile time

Hi, all

I’m having this strange problem using freertos. So basically in main.c I use the following code to statically assign xQueue to address 0x0820F000.

static QueueHandle_t xQueue __attribute__ ((section("0x0820F000"))) = NULL;

Using objdump -t shows that xQueue was exactly at 0x0820F000. However, after I boot the kernel using qemu-system-riscv32 and use gdb to debug it, I found that somehow during runtime the xQueue was in somewhere else, not at 0x0820F000 anymore. I checked that both in runtime and using objdump the initial address for kernel was the same, so how can xQueue goes to somewhere else.

Also, I know it is not exactly a FreeRTOS question (I’ve checked some related questions on the forums), but I’m wondering if there is a way that can make a variable assigned at a specific address in the FreeRTOS kernel?

Best regards,

A non const variable can not be assigned to flash memory but must reside in RAM. You didn’t specify which POD you are using, but the address looks like a Cortex Flash address. Or does your POD map 0x820f000 to RAM?

The section syntax looks unusual to me. What compiler/linker are you using?

Hi,

Thanks for your responses!

The xQueue might change somewhere else, so I do not want to make it const.

Sorry, I’m still new to FreeRTOS, the POD here means…? Of course, I’m using the Risc-V-qemu-virt Demo on the git repository. I’m not sure how to check if it successfully maps 0x820f000 to RAM.

I’m using riscv32-unknown-elf- provide in the makefile as compiler/linker.

Best,

That’s the point. Your variable is a variable, meaning it is subject to manipulation, thus it can’t reside in flash memory, but the address your are using to me looks like a flash address.

Sorry, I should have asked what MCU you are using. POD is an older term for “Processor or Derivative.” It’s not a FreeRTOS specific term. Again, the question aims at what kind of memory is behind the address 0x820f000. Is it a RAM or Flash address on your target?

Sorting variables into specific memory locations is a fairly elementary task for all RTOSs. Query the internet for “linker command files” for specifics; there is no point in giving you a crash course here as the understanding of linker command files and map files is crucial for understanding embedded systems, so it’s a good idea to thoroughly familarize yourself with the issue. Lots of good tutorials on the net.

So basically all I need to do is to determine have I located this variable in RAM instead of the flash address.

Yes, I did a lot of research beforehand, but the more I read, the more I got confused, especially on the embedded scenario, so I turn to you. Sorry for bothering your time again, I will look deeper into it.

Best,

No problem. I once posted a link to a site I found reasonably good here (see embedded link in that post):

Thanks! I will look into it!

Is:

valid syntax to place a variable at a known address? If so, I’ve never seen it done this way and can’t find any documentation that says this can be done. I think this line is saying to place the variable in a section called “0x0820F000”, which would then require your linker script to declare a section with that name at the address you want the variable to reside. If you want to then initialise a non const variable placed at a certain address you will probably also have to update your start up code.

…why you would ever want to place a queue handle at a fixed address would be another question.