How to execute code from RAM (STM32F3 CCM RAM)

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

tecnologic
Posts: 124
Joined: Tue Jan 10, 2012 8:42 am
Has thanked: 21 times
Been thanked: 5 times

How to execute code from RAM (STM32F3 CCM RAM)

Post by tecnologic »

Hi guys,

i want to run a control interrupt from RAM. As i see it current RT V3 in the master branch has no support for executing code from ram or have i missed something?

So if there is no support for this, what do u think is the best approach?

I thougt of creating 2 sections in rules.ld, .fast and .fast_run. With the functions placed in .fast . Next thing would be a _late_init function copying .fast to .fast_run.

i have only done this in crossworks before, so i'am quite unsure i do not miss something. Am i right that the linker understands End of section with } ram4 AT > flash

any hints?

Thanks in andvance

Tec
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How to execute code from RAM (STM32F3 CCM RAM)

Post by Giovanni »

Hi,

The linker scripts define the extra memory areas but there is no support for copying the code there automatically, allocation in those regions is always NOLOAD.

Introducing some kind of loading support would require a much more complex startup file.

Giovanni
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: How to execute code from RAM (STM32F3 CCM RAM)

Post by mobyfab »

Hey,

This is my linker script to use CCM on a F303 device:
https://github.com/fpoussin/MotoLink/bl ... er/link.ld
https://github.com/fpoussin/MotoLink/bl ... on/link.ld

It is separated in 2 files.

The modified init code: (to init CCM memory)
https://github.com/fpoussin/MotoLink/bl ... mon/crt0.c

Just append "_CCM" to the function or variables names to place them in the CCM area.
tecnologic
Posts: 124
Joined: Tue Jan 10, 2012 8:42 am
Has thanked: 21 times
Been thanked: 5 times

Re: How to execute code from RAM (STM32F3 CCM RAM)

Post by tecnologic »

Thanks Moby,

i changed ur code a bit to fit in V3 structure. But thanks for the base. But where du u provide "_CCM" i do not see the definition?
I think i'am working with __attribute__(section(.ccm)).

The next question is "*(.text.*_CCM*)" means text code with attribute _CCM is placed in ccm OK? But will the linker automaticly place the code at the ccm load address _siccm? An also data ? (*(.data.*_CCM*))

If i understand the linker script correctly u have no need auf .ccm section. every thing ist just placed right an u only need to copy CCM from loadaddr to ram from startup code.

regards

Tec

@edit: u also placed Vectors in CCM ram, but to do this u need to change the vector table start addres, can u provide the code for this?
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: How to execute code from RAM (STM32F3 CCM RAM)

Post by mobyfab »

It was already working with V3.
It's all done by the linker. You don't need any special attributes.

As long as there is _CCM in the name, the linker will put it in the CCM area. functions or variables.

text.Vector* are the interrupt routines, not the vector table.
Critek
Posts: 4
Joined: Tue Sep 08, 2015 8:30 am

Re: How to execute code from RAM (STM32F3 CCM RAM)

Post by Critek »

Hello,
this will be the first time for me to try this so I have many doubts. First question is about correct placing those linker files. Where should
I put them so that during a debbug proccess everything would be fine. Second question is about moving ISR vector to RAM.
I guess it is not as simple as: just uncommenting one line in system_stm32f3xx.c file. It probably just enables the possibility
of moving (mapping) ISR vector. I went through the manual and tried looking the solution on the internet but with no success.
This operation is probably also not supported. Can u please help me in this matter? I'm also using F3 discovery board
and I'm programming using CubeMX & System Workbench for stm32 (eclipse).




Okey, sorry for the trouble, I've finally found the linker script.
Last edited by Critek on Tue Sep 08, 2015 9:05 am, edited 1 time in total.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How to execute code from RAM (STM32F3 CCM RAM)

Post by Giovanni »

Critek wrote:Can u please help me in this matter? I'm also using F3 discovery board
and I'm programming using CubeMX & System Workbench for stm32 (eclipse).


Hi,

I think you should ask on the ST forum or AC6 forum. Here we use different things and our solution would not apply to your setup.

In general you need a customized .ld file for the linker and a customized startup file that copies code in CCM RAM.

Giovanni
Critek
Posts: 4
Joined: Tue Sep 08, 2015 8:30 am

Re: How to execute code from RAM (STM32F3 CCM RAM)

Post by Critek »

I have such files in my project, I have also asked on stm32 forum but the only thing I got was that I have to write or change my linker script file.
So the result is the same. There are no ready, supported functions which do map code and ISR vector to RAM
Critek
Posts: 4
Joined: Tue Sep 08, 2015 8:30 am

Re: How to execute code from RAM (STM32F3 CCM RAM)

Post by Critek »

Okey, I think I found something useful in here:
http://www.st.com/web/en/resource/technical/document/application_note/DM00083249.pdf

but Im still trying to find how to map the entire ISR vector
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: How to execute code from RAM (STM32F3 CCM RAM)

Post by mobyfab »

This is probably what you are looking for:

http://infocenter.arm.com/help/index.js ... HDGBC.html

This is how I do it with my apps using a bootloader:

Code: Select all

MEMORY
{
    boot_flash (rx) : org = 0x08000000, len = 20k
    flash (rx) : org = 0x08005000, len = 128k
    eeprom (rwx) : org = 0x8025000, len = 108k
    ram (rwx) : org = 0x20000000, len = 40k
    ccmram (rwx) : org = 0x10000000, len = 8k
}

__user_flash_address__ = ORIGIN(flash);
__user_flash_length__   = LENGTH(flash);

Code: Select all

#if defined(_FROM_ASM_)
  .extern uint32_t __user_flash_address__
#else
  extern uint32_t __user_flash_address__;
#endif

#define CORTEX_VTOR_INIT ((uint32_t)&__user_flash_address__)


My bootloader "jumps" to the vector address so I can't put it in CCM before jumping since I already use it. (well I could but that would be complicated)
Without a bootloader you would have to copy it to CCM first, then copy it's new address.

basically, using my linker scripts previously posted: (untested)

Code: Select all

extern vectors_t _vectors;
vectors_t _vectors_CCM;

memcpy(&_vectors, &_vectors_CCM, sizeof(vectors_t));
SCB->VTOR = (uint32_t)&_vectors_CCM;

You get the idea :) You need to do this in vectors.c, where vectors_t is defined, or replace it with you own.
Post Reply