cancel
Showing results for 
Search instead for 
Did you mean: 

modify startup_stm32f769xx.s so that newly added memory range is initialized ?

arnold_w
Senior II

I'm working with the STM32F769 microcontroller and I've defined a new section in the linker script using instructions from https://www.openstm32.org/Using%2BCCM%2BMemory :

 

/* Emulated RAM in the JPEG peripheral */
HACK_RAM_JPEG_HUFFENC_AC0 (rwx): ORIGIN = 0x40024000, LENGTH = 352 /* JPEG->HUFFENC_AC0 */

.hackRamJpegHuffencAc0 :
{
    . = ALIGN(4);
    KEEP(*(.hackRamJpegHuffencAc0))
    *(.hackRamJpegHuffencAc0 .hackRamJpegHuffencAc0.*)
} >HACK_RAM_JPEG_HUFFENC_AC0

/* Used by the startup to initialize data */
_sidata_HACK_RAM_JPEG_HUFFENC_AC0 = LOADADDR(.data_HACK_RAM_JPEG_HUFFENC_AC0);

/* Initialized HACK_RAM_JPEG_HUFFENC section 
* 
* IMPORTANT NOTE! 
* If initialized variables will be placed in this section, 
* the startup code needs to be modified to copy the init-values.  
*/
.data_HACK_RAM_JPEG_HUFFENC_AC0 : 
{
  . = ALIGN(4);
  _sdata_HACK_RAM_JPEG_HUFFENC_AC0 = .;        /* create a global symbol at data start */
  *(.data_HACK_RAM_JPEG_HUFFENC_AC0)           /* .data sections */
  *(.data_HACK_RAM_JPEG_HUFFENC_AC0*)          /* .data* sections */
      
  . = ALIGN(4);
  _edata_HACK_RAM_JPEG_HUFFENC_AC0 = .;        /* define a global symbol at data end */
} >HACK_RAM_JPEG_HUFFENC_AC0 AT> FLASH

/* Uninitialized (bss-like) section in HACK_RAM_JPEG_HUFFENC_AC0 */
.bss_HACK_RAM_JPEG_HUFFENC_AC0 :
{
  . = ALIGN(4);
  _sbss_HACK_RAM_JPEG_HUFFENC_AC0 = .;  /* Define the start of bss */
  *(.bss.HACK_RAM_JPEG_HUFFENC_AC0)   /* Uninitialized section */
  *(.bss.HACK_RAM_JPEG_HUFFENC_AC0.*)
  . = ALIGN(4);
  _ebss_HACK_RAM_JPEG_HUFFENC_AC0 = .;  /* Define the end of bss */
} >HACK_RAM_JPEG_HUFFENC_AC0

 

I have absolutely no knowledge of assembler programming and ChatGPT was just hallucinating when I asked him, so I don't know how to change the assembler code in startup_stm32f769xx.s. Unlike in the example (https://www.openstm32.org/Using%2BCCM%2BMemory ), I'm adding a section, not replacing a section. So, can somebody please help me to modify startup_stm32f769xx.s so that __HAL_RCC_JPEG_CLK_ENABLE() is called and then the HACK_RAM_JPEG_HUFFENC_AC0 area is initialized?

1 ACCEPTED SOLUTION

Accepted Solutions
arnold_w
Senior II

I solved it by calling a regular C-function (placed inside a C-file) from the assembler code:

.extern InitHackMemory  /* Declare external C function */

LoopFillZerobss:
  ldr  r3, = _ebss
  cmp  r2, r3
  bcc  FillZerobss

/* Call the clock system intitialization function.*/
  bl  SystemInit   
/* Call static constructors */
  bl __libc_init_array
/* Call the external C function to initialize hack memory */
  bl  InitHackMemory
/* Call the application's entry point.*/
  bl  main
  bx  lr    
.size  Reset_Handler, .-Reset_Handler

 

// External symbols from linker script
extern uint32_t _sidata_HACK_RAM_JPEG_HUFFENC_AC0;
extern uint32_t _sdata_HACK_RAM_JPEG_HUFFENC_AC0;
extern uint32_t _edata_HACK_RAM_JPEG_HUFFENC_AC0;

extern uint32_t _sbss_HACK_RAM_JPEG_HUFFENC_AC0;
extern uint32_t _ebss_HACK_RAM_JPEG_HUFFENC_AC0;

void InitHackMemory(void) {
    __HAL_RCC_JPEG_CLK_ENABLE();
    uint32_t *src=&_sidata_HACK_RAM_JPEG_HUFFENC_AC0;
    uint32_t *dst = &_sdata_HACK_RAM_JPEG_HUFFENC_AC0;

    // Copy initialized data from Flash to RAM
    while (dst < &_edata_HACK_RAM_JPEG_HUFFENC_AC0) {
        *dst++ = *src++;
    }

    // Zero initialize the .bss section
    while (dst < &_ebss_HACK_RAM_JPEG_HUFFENC_AC0) {
        *dst++ = 0;
    }
}

 

View solution in original post

1 REPLY 1
arnold_w
Senior II

I solved it by calling a regular C-function (placed inside a C-file) from the assembler code:

.extern InitHackMemory  /* Declare external C function */

LoopFillZerobss:
  ldr  r3, = _ebss
  cmp  r2, r3
  bcc  FillZerobss

/* Call the clock system intitialization function.*/
  bl  SystemInit   
/* Call static constructors */
  bl __libc_init_array
/* Call the external C function to initialize hack memory */
  bl  InitHackMemory
/* Call the application's entry point.*/
  bl  main
  bx  lr    
.size  Reset_Handler, .-Reset_Handler

 

// External symbols from linker script
extern uint32_t _sidata_HACK_RAM_JPEG_HUFFENC_AC0;
extern uint32_t _sdata_HACK_RAM_JPEG_HUFFENC_AC0;
extern uint32_t _edata_HACK_RAM_JPEG_HUFFENC_AC0;

extern uint32_t _sbss_HACK_RAM_JPEG_HUFFENC_AC0;
extern uint32_t _ebss_HACK_RAM_JPEG_HUFFENC_AC0;

void InitHackMemory(void) {
    __HAL_RCC_JPEG_CLK_ENABLE();
    uint32_t *src=&_sidata_HACK_RAM_JPEG_HUFFENC_AC0;
    uint32_t *dst = &_sdata_HACK_RAM_JPEG_HUFFENC_AC0;

    // Copy initialized data from Flash to RAM
    while (dst < &_edata_HACK_RAM_JPEG_HUFFENC_AC0) {
        *dst++ = *src++;
    }

    // Zero initialize the .bss section
    while (dst < &_ebss_HACK_RAM_JPEG_HUFFENC_AC0) {
        *dst++ = 0;
    }
}