Hello,
I am using Keil uVision 5.15 compiler. copying a routine to ram(FLASH_eraseOneBlock) and try to runit, the code crashes (hardware Fault). I have looked at Keil's ram function example and it does not work either. my code is:
typedef void (*FunctionPointer_t)(uint32_t ); FunctionPointer_t ramFunc; uint32_t executableRam[100]; void TxfrToRam(void) { uint32_t source,source_end; uint32_t *dest,addr; source = (uint32_t)&FLASH_eraseOneBlock; source_end = (uint32_t)source + 80; dest = (uint32_t *)executableRam; ramFunc = (FunctionPointer_t)dest; while (source < source_end) { *dest++ = *(uint32_t *)source++; } for (addr = 0x2000; addr < 0x20000; addr += FLASH_PAGE_SIZE) { ramFunc(addr); } }
Any help will be highly appreciated.
Thanks
Yash
Note that the scatter file specifies two addresses for al regions.
One address range where to store the variables/code in flash. One address range where to run the variables/code.
So the linker can link a function to store in flash, but with addresses adjusted for running in RAM. That's the officially sanctioned way of getting correct binary code for use in RAM.