Hey Lukas, thank you very much for answering! I definitely overlooked this.
However, this still didn't solve my problem. The remap is still not working, I'm simply always accessing the original location and not the remapped one.
In the meantime, I made a small test program in S32 Design Studio for Power Architecture, for MPC5748G, which has two functions that blink different LEDs, and are placed at two distinct memory locations.
Here's the source code:
#include "derivative.h" /* include peripheral declarations */
#define PA10 10
#define PA7 7
extern void xcptn_xmpl(void);
__attribute__ ((section(".text1"))) void blink1()
{
uint32_t i;
// Initialize DS4 LED.
SIUL2.MSCR[PA10].B.SSS = 0;
SIUL2.MSCR[PA10].B.OBE = 1;
SIUL2.MSCR[PA10].B.IBE = 0;
SIUL2.GPDO[PA10].B.PDO_4n = 1;
while (1)
{
for (i = 0; i < 100000; i++);
// Blink DS4 LED.
SIUL2.GPDO[PA10].B.PDO_4n = !SIUL2.GPDO[PA10].B.PDO_4n;
}
}
__attribute__ ((section(".text2"))) void blink2()
{
uint32_t i;
// Initialize DS5 LED.
SIUL2.MSCR[PA7].B.SSS = 0;
SIUL2.MSCR[PA7].B.OBE = 1;
SIUL2.MSCR[PA7].B.IBE = 0;
SIUL2.GPDO[PA7].B.PDO_4n = 1;
while (1)
{
for (i = 0; i < 100000; i++);
// Blink DS5 LED.
SIUL2.GPDO[PA7].B.PDO_4n = !SIUL2.GPDO[PA7].B.PDO_4n;
}
}
int main(void)
{
// Configure and enable interrupts.
xcptn_xmpl();
// Setup the remap logic and physical addresses,
// per-master enable, and region size.
PFLASH.PFCRD[0].Word0.R = 0x09100000; // logical address
PFLASH.PFCRD[0].Word1.R = 0x01200000; // physical address
PFLASH.PFCRD[0].Word2.R = 0xffff0012; // 256KB region
// Enable remap descriptor 0.
PFLASH.PFCRDE.R = 0xffff0000;
// Enable instruction remap.
PFLASH.PFCRCR.B.IRMEN = 1;
// Enable flash remap.
PFLASH.PFCRCR.B.GRMEN = 1;
blink1();
blink2(); // Won't be called but placed here so it would be included in the output file.
while (1);
}
I also added the needed program sections to the flash linker file
...
MEMORY
{
flash_rchw : org = 0x00FA0000, len = 0x4
cpu0_reset_vec : org = 0x00FA0000+0x10, len = 0x4
cpu1_reset_vec : org = 0x00FA0000+0x14, len = 0x4
cpu2_reset_vec : org = 0x00FA0000+0x04, len = 0x4
m_text : org = 0x01000000, len = 256K
m_text1 : org = 0x01100000, len = 256K
m_text2 : org = 0x01200000, len = 256K
m_data : org = 0x40000000, len = 768K
}
...
.text1 :
{
*(.text1)
} > m_text1
.text2 :
{
*(.text2)
} > m_text2
...
I've checked the generated .srec file, and the functions are indeed placed at the desired locations.
If I've understood it correctly, this code should call the blink2 function instead of blink1, since the memory has been remapped so that logical address 0x01100000 will point to the physical address 0x01200000. It still doesn't work, and always calls the blink1 function. I've tried setting the 27th bit (e.g. 0x09100000) in both the logical and physical addresses on or off, but none of the combinations work. And it's not that the execution will jump to an unprogrammed area in the flash memory, it just always accesses the original, unmapped location of 0x01100000.
Can you see any problems in this example? Maybe something else I forgot to initialize?
Thank you very much for your time.