This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Hercules memoryInit function

Other Parts Discussed in Thread: HALCOGEN

Hello all,

we did change the memoryInit function generated by HalcoGen (don't aks why ;-) )

The generated function is the following

/** @fn void memoryInit(uint32 ram)
*   @brief Memory Initialization Driver
*
*   This function is called to perform Memory initialization of selected RAM's.
*/
/* SourceId : SELFTEST_SourceId_002 */
/* DesignId : SELFTEST_DesignId_004 */
/* Requirements : HL_SR396 */
void memoryInit(uint32 ram)
{
/* USER CODE BEGIN (6) */
/* USER CODE END */

    /* Enable Memory Hardware Initialization */
    systemREG1->MINITGCR = 0xAU;

    /* Enable Memory Hardware Initialization for selected RAM's */
    systemREG1->MSINENA  = ram;

    /* Wait until Memory Hardware Initialization complete */
    /*SAFETYMCUSW 28 D MR:NA <APPROVED> "Hardware status bit read check" */
    while((systemREG1->MSTCGSTAT & 0x00000100U) != 0x00000100U)
    {
Timer_Delay_sw(1000); // THIS LINE IS ADDED FROM US!!! }/* Wait */ /* Disable Memory Hardware Initialization */ systemREG1->MINITGCR = 0x5U; /* USER CODE BEGIN (7) */ /* USER CODE END */ }

The Timer_delay_sw function is the following:

void Timer_delay_sw(TIME_T countNops)
{
    for(; countNops > 0U; countNops--)
    {
        __asm__("nop");
    }
}

With this function call included, the processor got somehow "confused". Depending on the project I have strange behavior like a reset (PC jumping to 0) after the memoryInit is executed or I got stuck in some self test endless loop. Does anybody have a hint why such a change could have such an influence? I also have my own theory: The systemREG1->MSINENA = ram does delete the stack hence the return address of the memoryInit function has to be stored in some register. Maybe after calling the Timer_delay_sw function this return address does get changed?

Any other ideas would be very appreciated.

Matthias

  • Hi Matthias,

      I think you need to remove the call to the delay while you are waiting for the memoryInit to complete. I think the reason why you have erratic behavior is because the memoryInit is trying to clear out the SRAM contents. While it is doing so, you also make the call to  Timer_delay_sw() function. This means there will be some context switch by saving the CPU registers to the stack. The stack is stored in the SRAM. You are trying to push data onto the stack while the SRAM is being initialized. 

  • Hi,

    yes, that's something I had in mind. But good to hear it from experts.

    best
    Matthias