Executing code in RAM causes MbedOS crash

I want to run code in RAM, declared:

RAMFUNC uint8_t MyCode[CODESIZE] WORDALIGNED;

The compiler accepts this, but when I try to execute code in this area I get an MbedOS crash (red flashing LED).

The same code works on other ARM boards (ATSAMD51, Teensy 4.0). Any suggestions?

I should have added: RAMFUNC is defined as:

#define RAMFUNC __attribute__ ((section (".ramfunctions")))

Here's a program to demonstrate:

/* RAM Function Test */

#define WORDALIGNED __attribute__((aligned (4)))
#define RAMFUNC __attribute__ ((section (".ramfunctions")))

RAMFUNC uint8_t MyCode[256] WORDALIGNED;
typedef int (*intfn_ptr_type)(int x);

int test (void) {
  int i = 0;
  MyCode[i++] = 0x0d; MyCode[i++] = 0x21; // mov r1, #13
  MyCode[i++] = 0x48; MyCode[i++] = 0x43; // mul r0, r1  
  MyCode[i++] = 0x70; MyCode[i++] = 0x47; // bx lr
  int x = 10;
  int y = ((intfn_ptr_type)&MyCode[1])(x);
  return y;
}

void setup() {
  Serial.begin(9600);
  delay(5000);
  Serial.println(test());
}

void loop() { }

It creates an array MyCode[] in RAM, and puts the ARM machine code into it for:

mov r1, #13
mul r0, r1
bx lr

which simply multiplies r0 by 13.

The program jumps to the entry point of the function with 21 in r0, so the program should print 273.

This works on all ARM platforms I've tested it on (ATSAMD21, ATSAMD51, RP2040, etc). On the GIGA it flashes the red MbedOS error light. It would be nice if I could get it to work on the GIGA too.

In reply to "why would you want to do this?" see ARM assembler overview.