‎2022-05-01 08:11 PM
Hello, i'm trying to execute a delay code from CCM memory but the MCU is frezing when enter to 'delay_ms' function. It is the first time that i try this and i don´t know if the linker file, and the startup file modifications are good implemented so i post there the modifications:
LD File:
/* Used by the startup to initialize ccm data */
_siccmdata = LOADADDR(.ccmdata);
...
/* Initialized data section into "CCM" Ram type memory */
.ccmdata :
{
. = ALIGN(4);
_sccmdata = .; /* create a global symbol at data start */
*(.ccmdata) /* .ccmdata sections */
*(.ccmdata*) /* .ccmdata* sections */
*(.ccmFunc) /* .ccmFunc sections */
*(.ccmFunc*) /* .ccmFunc* sections */
. = ALIGN(4);
_eccmdata = .; /* define a global symbol at data end */
} >CCMRAM AT> FLASH
/* Uninitialized data section into "CCM" Ram type memory */
. = ALIGN(4);
.ccmbss :
{
_sccmbss = .; /* create a global symbol at ccmram start */
*(.ccmbss)
*(.ccmbss*)
. = ALIGN(4);
_eccmbss = .; /* create a global symbol at ccmram end */
} >CCMRAM
...
Startup CCM Init:
...
FillZerobss:
str r3, [r2]
adds r2, r2, #4
LoopFillZerobss:
cmp r2, r4
bcc FillZerobss
/* CCM MODIFICATIONS */
/* Copy the data segment initializers from flash to SRAM */
ldr r0, =_sccmdata
ldr r1, =_eccmdata
ldr r2, =_siccmdata
movs r3, #0
b LoopCopyCCMDataInit
CopyCCMDataInit:
ldr r4, [r2, r3]
str r4, [r0, r3]
adds r3, r3, #4
LoopCopyCCMDataInit:
adds r4, r0, r3
cmp r4, r1
bcc CopyCCMDataInit
/* Zero fill the ccmbss segment. */
ldr r2, =_sccmbss
ldr r4, =_eccmbss
movs r3, #0
b LoopFillZeroCCMbss
FillZeroCCMbss:
str r3, [r2]
adds r2, r2, #4
LoopFillZeroCCMbss:
cmp r2, r4
bcc FillZeroCCMbss
/* END CCM MODIFICATIONS */
/* Call static constructors */
bl __libc_init_array
...
Delay function
__attribute__((optimize("-O0")))
__CCM_FUNC void delay_ms (uint16_t ms)
{
do {
int32_t cycles_to_ms = DELAY_CYCLES_MS;
do {
cycles_to_ms -= 12;
} while (cycles_to_ms > 0);
} while (--ms);
}
Where __CCM_FUNC macro expands to:
#define __CCM_FUNC __attribute__((section(".ccmFunc")))
Dump .elf file revelas that delay function is on CCM Memory (0x10000000):
...
__attribute__((optimize("-O0")))
__CCM_FUNC void delay_ms (uint16_t ms)
{
10000000: b480 push {r7}
10000002: b085 sub sp, #20
10000004: af00 add r7, sp, #0
10000006: 4603 mov r3, r0
10000008: 80fb strh r3, [r7, #6]
...
Debugging stops when delay_ms executes and MCU freezes
Solved! Go to Solution.
‎2022-05-01 09:19 PM
Short answer: CCM on STM32F4x is connected only to D-Bus, dont is posible execute code from CCM :expressionless_face:
‎2022-05-01 09:19 PM
Short answer: CCM on STM32F4x is connected only to D-Bus, dont is posible execute code from CCM :expressionless_face: