Flash Driver Stack Usage

Hi,

Suddenly my program started to corrupt some variables.

I took a look at my threads stacks in the RTOS Resouces and discovered that one of my threads is always at the maximum stack size.

I tried to increase the stack size, but it always uses the whole stack.

 

I started putting some breakpoint and discovered that the problem occurs when calling "if(flash.p_api->open(flash.p_ctrl, flash.p_cfg) != SSP_SUCCESS)".

Before this call, the MaxStackUsage is 836, after this call it goes to 8192 (which is the StackSize).

 

Is it expected?

  • Hi Mad River,

    Unfortunately I cannot reproduce the issue. Did you have Data Flash Background Operation enabled? Are you sure the issue occurred right after calling the open API?

    Regards,
    adboc
  • In reply to adboc:

    adboc

    Did you have Data Flash Background Operation enabled?

    Yes, it is enabled.

    adboc

    Are you sure the issue occurred right after calling the open API? 

    Yes, I am sure. One breakpoint just before it and one breakpoint just after.

     

    May it be a wrong information from the debugger? I am using a 5-pin SWD (reset, vcc, gnd, swclk and swdio).

  • In reply to Mad River:

    I don't know if this issue is related, but what may be causing the program to triggers the following code inside NMI_Handler()?

    if (1 == R_ICU->NMISR_b.SPEST)
    {
    /** MPU Stack Error interrupt is requested. */
    bsp_group_irq_call(BSP_GRP_IRQ_MPU_STACK);

    /** Clear MPU Stack error flag. */
    R_ICU->NMICLR_b.SPECLR = 1U;
    }
  • In reply to Mad River:

    Hi Mad River,

    This indicates a stack pointer error, which might be a stack overflow (run out of the stack memory). Does your application use a recurrence (even indirect such like: A calls B, B calls C, etc., X calls A, and again, A calls B, ...)?

    Regards,
    adboc
  • In reply to adboc:

    Hi adboc,


    if (1 == R_ICU->NMISR_b.SPEST)
    {
    /** MPU Stack Error interrupt is requested. */
    bsp_group_irq_call(BSP_GRP_IRQ_MPU_STACK);

    /** Clear MPU Stack error flag. */
    R_ICU->NMICLR_b.SPECLR = 1U;
    }


    More information about the problem:
    It happens a few seconds after the memory stick be inserted.
    And it only happens when I have two programs stored in the flash memory (bootloader + application). When I only store the application in the address 0x000000 the problem stops.
  • In reply to Mad River:

    Hi Mad River,

    Do you use USBX Host Mass Storage module? How much memory did you assign to USBX memory pool (configuration settings of the USBX on ux module)? Please, try using 65536 bytes.

    Regards,
    adboc
  • In reply to adboc:

    Hi adboc,

    Yes, I am using USBX Host Mass Storage module. The memory pool have 48K bytes.
    I don't have much more RAM avaible to increase it.
    The documentation says that it needs "Pre-built library: 45KB".

    The afirmation I made above, about it only happen when I have the bootloader is not true. It happens also when I have only one programm.
  • In reply to Mad River:

    Hi Mad River,

    Could you check which thread is marked as 'running' in RTOS Resources tab when the error occurs?

    To enable this tab, you should suspend the application, select Renesas Views > Partner OS > RTOS Resources. Then confirm the OS (ThreadX) and resume the application. Next time the application is suspened (for example due to the above error), it will contain some useful information. In Threads tab you should see which thread is marked as 'running'.

    Regards,
    adboc
  • In reply to Mad River:

    Hi, Mad River I have same problem with you. Do you have any solution for this stack problem when application is placed beside bootloader ?