Page 2 of 2
Re: How to execute code from RAM (STM32F3 CCM RAM)
Posted: Wed Sep 09, 2015 2:34 pm
by Critek
I already browsed through many doscussions in order to find what I ma looking for. I think your idea is sensible and will work but I don't have any file named vectors.c
and the only place where I find my vector is in a startup_stm32f3303xc.s. How do you think, is it a good idea to invoke the memcpy function on the begining of the SytemInit() function?
Re: How to execute code from RAM (STM32F3 CCM RAM)
Posted: Wed Sep 09, 2015 3:14 pm
by mobyfab
I should work, but you can do a manual copy in the init file, ie:
Code: Select all
#if CRT0_INIT_CCM
/* CCM segment initialization.*/
{
uint32_t *tp, *dp, *end;
extern vectors_t _vectors_CCM;
tp = &_siccm;
dp = &_sccm;
while (dp < &_eccm)
*dp++ = *tp++;
tp = (uint32_t*)&_vectors;
dp = (uint32_t*)&_vectors_CCM;
end = (uint32_t*)((&_vectors_CCM)+sizeof(vectors_t));
while (dp < end)
*dp++ = *tp++;
SCB->VTOR = (uint32_t)&_vectors_CCM;
}
#endif
I think now the init file is in assembly, but that works as well if you know how to do it.
The vector file is here: os/common/ports/ARMCMx/compilers/GCC/vectors.c
I will test this code tonight but it compiles

Re: How to execute code from RAM (STM32F3 CCM RAM)
Posted: Thu Sep 10, 2015 5:41 pm
by mobyfab
I tried to make it a bit cleaner.
Code: Select all
/*
* init.c
*/
#include "ch.h"
#include "vectors.h"
/**
* @brief CCM segment initialization switch.
*/
#if !defined(CRT0_INIT_CCM) || defined(__DOXYGEN__)
#define CRT0_INIT_CCM TRUE
#endif
/**
* @brief ROM image of the CCM segment start.
* @pre The symbol must be aligned to a 32 bits boundary.
*/
extern uint32_t _siccm;
/**
* @brief CCM segment start.
* @pre The symbol must be aligned to a 32 bits boundary.
*/
extern uint32_t _sccm;
/**
* @brief CCM segment end.
* @pre The symbol must be aligned to a 32 bits boundary.
*/
extern uint32_t _eccm;
/**
* @brief ISR Vector table.
* @pre The symbol must be aligned to a 32 bits boundary.
*/
extern vectors_t _vectors;
/**
* @brief STM32 CCM vectors table.
*/
vectors_t _vectors_CCM;
void __late_init(void)
{
#if CRT0_INIT_CCM
/* CCM segment initialization.*/
{
uint32_t *tp, *dp, *end;
tp = &_siccm;
dp = &_sccm;
while (dp < &_eccm)
*dp++ = *tp++;
tp = (uint32_t*)&_vectors;
dp = (uint32_t*)&_vectors_CCM;
end = (uint32_t*)((&_vectors_CCM)+sizeof(vectors_t));
while (dp < end)
*dp++ = *tp++;
SCB->VTOR = (uint32_t)&_vectors_CCM;
}
#endif
}
Code: Select all
File: bootloader/build/bootloader.elf
65: 10000000 416 OBJECT LOCAL DEFAULT 3 _vectors_CCM.5062
425: 08000000 416 OBJECT GLOBAL DEFAULT 1 _vectors
You will have to have a vector.h file with the vector_t typedef from vectors.c
What I did is split the definition out of the c file.
That would be nice if giovanni could do that. (move the vector typedefs to a header file or put some kind of hook/helper fuction to copy/move the table)
Re: How to execute code from RAM (STM32F3 CCM RAM)
Posted: Thu Sep 10, 2015 6:00 pm
by Giovanni
I will look into it when I return on startup files.
Giovanni
Re: How to execute code from RAM (STM32F3 CCM RAM)
Posted: Fri Sep 11, 2015 12:03 am
by mobyfab
Awesome

There is probably some noticeable performance gains here.
Even for devices without CCM, putting the vectors in ram would help.
I tested the code and it works fine, I just had to fix a cast.
Code: Select all
void __late_init(void)
{
#if CRT0_INIT_CCM
/* CCM segment initialization.*/
{
uint32_t *tp, *dp, *end;
tp = &_siccm;
dp = &_sccm;
while (dp < &_eccm)
*dp++ = *tp++;
tp = (uint32_t*)&_vectors;
dp = (uint32_t*)&_vectors_CCM;
end = ((uint32_t*)(&_vectors_CCM)+sizeof(vectors_t));
while (dp < end)
*dp++ = *tp++;
SCB->VTOR = (uint32_t)&_vectors_CCM;
}
#endif
}