cancel
Showing results for 
Search instead for 
Did you mean: 

execute code from RAM

arunl4g
Associate II
Posted on April 25, 2016 at 16:26

Hi 

My task is to execute a code from RAM instead of Flash but i dont know how can i able to do it . i am using f429 discovery.

Could anyone help me ?

Thanks 
4 REPLIES 4
Posted on April 25, 2016 at 18:00

Who assigns these tasks?

So what are your choices here? Copy some amount of code the RAM and call it, or specify load regions within the linker script or scatter file to place specific functions into RAM when building the image?

typedef int (*pFunction)(void);
void RamCode(void)
{
static const uint16_t Code[] = { 0xF04F, 0x007B, 0x4770 }; // payload
uint8_t Buffer[16]; // as big as required
pFunction RunCode;
memcpy(Buffer, Code, sizeof(Code)); // Copy code
RunCode = (pFunction)&Buffer[1]; // +1 for Thumb code
printf(''%d
'',RunCode());
}

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on April 25, 2016 at 18:03

/**
* @brief Enable or disable the power down mode during RUN mode .
* @param NewState: new state of the power down mode during RUN mode.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
__ramfunc void RAM_FLASH_RUNPowerDownCmd(FunctionalState NewState)
{
if (NewState != DISABLE)
{
/* Unlock the RUN_PD bit */
FLASH->PDKEYR = FLASH_PDKEY1;
FLASH->PDKEYR = FLASH_PDKEY2;
/* Set the RUN_PD bit in FLASH_ACR register to put Flash in power down mode */
FLASH->ACR |= (uint32_t)FLASH_ACR_RUN_PD;
}
else
{
/* Clear the RUN_PD bit in FLASH_ACR register to put Flash in idle mode */
FLASH->ACR &= (uint32_t)(~(uint32_t)FLASH_ACR_RUN_PD);
}
}

You can do this sort of thing in IAR, and perhaps similar things in Keil or GNU/GCC by using #pragma or attribute type things to direct a subset of the code into RAM sections/segments.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
arunl4g
Associate II
Posted on April 25, 2016 at 19:54

Hi clive, 

Its about specify ta region in linker scipt for a specific functions into RAM when building the image.

i am not using Keil or IAR. i am using eclipse to develop project.

 kindly help me how can i specify a location in liker scirpt.

Thank you for the code.
Radosław
Senior
Posted on April 25, 2016 at 21:37

Which eclipse? AC6? Or clean distribution? With or without ARM plugin?

Open linker script Find definition data section, copy it, change names for your purpose for example  ram_func  main section name and elemens, adresses, 

In startup or in source code write code for ram_func section.

Freddie Chopin provide very good startup for this (multiple copy loop). check example for LPC4XXX.