0

I want to create an array at specific address with fixed size to access some physical memory in an embedded system using RISC-V. I have already used pointers to access memory regions, like

volatile int* mem1 = (volatile int*) SOME_ADDRESS ; 
mem1[0] = 1;

However, as I am accessing memory that is used also by core for its own local data I want it to avoid using that region of memory without modifying any linker script or starup code. I tried to use malloc, but that does not seem to be supported yet.

Is there a way in C code to make this work?

11
  • In Standard C? There is no way. In POSIX? mmap() might be an option.
    – CPlus
    May 15 at 6:13
  • This is baremetal, not possible to use that
    – AlaBek
    May 15 at 6:16
  • "as I am accessing memory that is used also by core for its own local data" What do you mean with that, a RTOS?
    – Lundin
    May 15 at 6:56
  • 2
    You cannot align your memory usage with other parts of the code, without actually aligning it. Just randomly pick some address won't work as you already know. Tell the linker who is supposed to use what memory.
    – Gerhardh
    May 15 at 7:35
  • 2
    I want it to avoid ... modifying any linker script. Why? That is the most obvious way of doing it. A pointer as you showed in your example is also fine.
    – Gerhard
    May 15 at 8:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.