"But the address is cast as a ULONG*. "
size_t may be more appropriate, however that would fix the problem.
"1) Does the Kinetis have some protection or settings that may prevent execution from RAM?
2) Does the Kinetis have user/privilege modes that need to be manipulated? "
Varies with the part, in general no. Check data sheet.
"3) The K64 only has a thumb mode. How does that affect my memory addressing of instructions? "
Set bit-0 of the address.
This the code I use at startup to come items from Flash to RAM.
The linker script builds a table of the items.
/* ---------------------------------------------------------------------------------- */
static void __copy_rom_section_to_ram( uint8_t *dst_u8_ptr, uint8_t const *src_u8_ptr, uint32_t const size_to_copy );
static void __copy_rom_section_to_ram( uint8_t *dst_u8_ptr, uint8_t const *src_u8_ptr, uint32_t const size_to_copy )
{
if( dst_u8_ptr != src_u8_ptr )
{
uint32_t len = size_to_copy; /* MISRA deviation */
watchdog_service();
while( 0U != len--)
{
*dst_u8_ptr++ = *src_u8_ptr++;
}
}
watchdog_service();
}
/*
* Copy all sections of data and/or code that need to be in RAM
* from Flash at startup.
*
* flash_to_ram_tbl is automatically generated by the linker
* if it is referenced by the program. It is a table of
* flash_to_ram_data structures. The final entry in the table
* has all-zero fields.
*/
typedef struct flash_to_ram_data{
uint32_t src_u32; /* Source */
uint32_t dst_u32; /* Destination */
uint32_t size_u32; /* Number of bytes to copy */
}flash_to_ram_data;
extern flash_to_ram_data __flash_to_ram_tbl[];
static void __copy_rom_sections_to_ram( void );
static void __copy_rom_sections_to_ram( void )
{
flash_to_ram_data *flash_to_ram_entry;
/*
* Go through the entire table, copying sections from Flash to
* RAM, until find a zero marker in the size field:
*/
for( flash_to_ram_entry = __flash_to_ram_tbl; (0UL != flash_to_ram_entry->size_u32); ++flash_to_ram_entry )
{
__copy_rom_section_to_ram( (uint8_t *) flash_to_ram_entry->dst_u32, (uint8_t *) flash_to_ram_entry->src_u32, flash_to_ram_entry->size_u32 );
}
}
/* ---------------------------------------------------------------------------------- */