Variable/array at fixed memory address Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
alex4d1
Member++
Posts: 26
Joined: Mon May 13, 2024 11:38 pm

Variable/array at fixed memory address

Post by alex4d1 »

Hi all,

I'd like to store a variable/array at a fixed memory address within the firmware image.
The idea is to create an firmware image with the variable/array at a fixed location so that I can manipulate these variables/array without having to recompile.

With GCC I'd do this by creating a new section within the linker file:

Code: Select all

MEMORY
{
  m_interrupts  (rx) : ORIGIN = 0x00000000, LENGTH = 0xC0
  m_cfmprotrom  (rx) : ORIGIN = 0x00000400, LENGTH = 0x10
  m_text        (rx) : ORIGIN = 0x00000800, LENGTH = 128K - 0x800
  m_data       (rwx) : ORIGIN = 0x1FFFF000, LENGTH = 16K
}

Code: Select all

SECTIONS
{
  /* placing my named section at given address: */
  .myBufBlock 0x20000000 :
  {
    KEEP(*(.myBufSection)) /* keep my variable even if not referenced */
  } > m_data
 
  /* other placements follow here... */
}
then I'd use something like this:

Code: Select all

unsigned char __attribute__((section (".myBufSection"))) buf[128];
to place the variable/array inside this section.

How do I do this when using the XTC toolchain?

Thanks
Alex
View Solution
User avatar
xhuw
Verified
Active Member
Posts: 41
Joined: Wed May 22, 2024 2:36 pm

Post by xhuw »

Hey this is not possible with XTC.

There is an alternative however that I think works. you can hardcode a pointer to this address:

Code: Select all

#include <xs1.h>

const char* buf = (char*)(XS1_RAM_BASE + XS1_RAM_SIZE - (XS1_DBG_BUFFER_WORDS * 4));
the top XS1_DBG_BUFFER_WORDS should be preserved through resets. This is macro expands to 32 on an xs3a chip. which is precisely 128 bytes so maybe this will work for you.

Docs aren't super clear on this though so let me know if it works :)
XMOS Software Engineer

Image
alex4d1
Member++
Posts: 26
Joined: Mon May 13, 2024 11:38 pm

Post by alex4d1 »

Thanks. Creating a pointer to a fixed address does generally work, but I'm not quite sure how I would locate the array in the XE file.
The linker won't add the array to the firmware image, just the pointer. Or am I missing something here?

For example:
In my application I create a pointer as you suggested:

Code: Select all

const char* buf = (char*)(XS1_RAM_BASE + XS1_RAM_SIZE - (XS1_DBG_BUFFER_WORDS * 4));
Then I read the content of the buffer and print it via xscope.

Now I want to manipulate the compiled XE file manually to change this buffer. Where in the XE file would I need to make edits to make this happen?
User avatar
xhuw
Verified
Active Member
Posts: 41
Joined: Wed May 22, 2024 2:36 pm

Post by xhuw »

What you are describing is not possible without hacking stuff. (e.g. manually finding the data in the xe file and editing with a hex editor or similar)

You must keep the data in the C file and recompile your application. What are you hoping to achieve by doing this? we might be able to satisfy your requirement by some other means?

Alternatively, you could use my solution above and use xgdb to overwrite the contents of the memory. I think recompiling will be much simpler though.
XMOS Software Engineer

Image
alex4d1
Member++
Posts: 26
Joined: Mon May 13, 2024 11:38 pm

Post by alex4d1 »

This use case I am after is not a application firmware, it is a configuration/commission firmware.
And the data I try to manipulate is modified by the xcore_math library and then written into the QSPI flash.

I should be able to get xcore_math to compile under windows.
Otherwise I can always use xscope to transfer data from the host to the target.

There are many solutions to this, just tried to find the quickest.

Thanks for the clarification.
RitchRock
XCore Addict
Posts: 224
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

Could you use a data partition separate from the firmware image(s)?