Program runs out of memory after one too many objects created

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

oszfather
Posts: 11
Joined: Tue Jun 14, 2022 5:27 pm
Has thanked: 2 times

Program runs out of memory after one too many objects created

Postby oszfather » Mon Jun 19, 2023 7:22 pm

Using STM32H7A3QI, which has around 2MB of flash memory and 1.4MB of RAM. Program uses C++ with g++ compiler and makes use of the Eigen library. which is pretty compact. I have a class that contains a few matrix variables from the eigen libary like so: (They range from 4x4, 6x6, 6x1 in size)

Code: Select all

class Joint {
    public:
        // Constants / Inputs
            Vector3f LINK_LENGTH;
            Vector3f AXIS;
            Vector3f HOME_POS;

        // Constants / Derived
            Screw SCREW_AXIS_SPACE;
            Screw SCREW_AXIS_EE;

        // Variables
            float          JOINT_POS;
            Transformation HOME_CONFIG = Matrix4f::Identity();
            Transformation SPACE_CONFIG;
            Transformation SCREW_SPACE_EXP_CONFIG;
            Transformation SCREW_EE_EXP_CONFIG;
            Jacobian       JACOBIAN = MatrixXf::Zero(6,6);
            Jacobian       PINV_JACOBIAN = MatrixXf::Zero(6, 6);

        /*
        *  METHODS ------------------------------------------------------
        */

        // Constructor
            Joint(Vector3f linklength, Vector3f axis);
        // Methods
            void                JOINT_INIT(Vector3f displacem);
        // Destructor
        ~Joint();
};


Im trying to create 7 objects of this class however I'm only able to create two until the stm32 stops working. Main function looks as:

Code: Select all

int main(void) {
    /*
     --------------------------------------------|||    HARDWARE SETUP STAGE     |||--------------------------------------------
    */

     /*
       * System initializations.
       * - HAL initialization, this also initializes the configured device drivers
       *   and performs the board-specific initializations.
       * - Kernel initialization, the main() function becomes a thread and the
       *   RTOS is active.
     */

      halInit();
      chSysInit();

      palSetPadMode(GPIOA, 2U, PAL_MODE_ALTERNATE(7) | PAL_STM32_OSPEED_HIGHEST |
                               PAL_STM32_OTYPE_PUSHPULL);
      palSetPadMode(GPIOA, 3U, PAL_MODE_ALTERNATE(7) | PAL_STM32_OSPEED_HIGHEST |
                               PAL_STM32_OTYPE_PUSHPULL);
      PeripheralInit();


//      /*
//       --------------------------------------------|||     SETUP STAGE     |||---------------------------------------------
//      */


        // 1. Joint Definitions -------------------------------------------------------------------------------------------
        Joint A(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(0.0f, 0.0f, 1.0f));
        Joint B(Vector3f(0.0f, 0.0f, 1.7f), Vector3f(1.0f, 0.0f, 0.0f));
   //     Joint C(Vector3f(0.0f, 0.0f, 1.8f), Vector3f(1.0f, 0.0f, 0.0f));

//        Joint D(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(0.0f, 0.0f, 1.0f));
//        Joint E(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(1.0f, 0.0f, 0.0f));
//        Joint F(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(1.0f, 0.0f, 0.0f));

       // Joint END_EFFECTOR(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(0.0f, 0.0f, 0.0f));


  while (1) {

    palSetLine(LINE_LED1);
    chThdSleepMilliseconds(50);
    palSetLine(LINE_LED2);
    chThdSleepMilliseconds(50);
    palSetLine(LINE_LED3);
    chThdSleepMilliseconds(200);
    palClearLine(LINE_LED1);
    chThdSleepMilliseconds(50);
    palClearLine(LINE_LED2);
    chThdSleepMilliseconds(50);
    palClearLine(LINE_LED3);
    chThdSleepMilliseconds(200);

  }
}


I've commented out the 'Joint' declerations after 'Joint B' as the leds blink up until this point as per the while loop. When I uncomment the 'Joint C' decleration the program gets stuck. Debugging line by line with openOCD (When there are 3 or more 'Joints' declared) causes the debugger to get stuck at random lines mainly during 'halInit()'.

I know this an issue to do with memory however the H7A3 is pretty beefy and should easily be able to handle this. Is this an issue to do with chibiOS not allocating more memory?
What is causing this and how do i fix it ?

User avatar
Giovanni
Site Admin
Posts: 14458
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Program runs out of memory after one too many objects created

Postby Giovanni » Mon Jun 19, 2023 8:40 pm

Hi,

Are you including syscalls.c in your makefile? the G++ library is probably using malloc() for allocation.

What compiler options are you using?

Giovanni

oszfather
Posts: 11
Joined: Tue Jun 14, 2022 5:27 pm
Has thanked: 2 times

Re: Program runs out of memory after one too many objects created

Postby oszfather » Mon Jun 19, 2023 8:47 pm

Giovanni wrote:Hi,

Are you including syscalls.c in your makefile? the G++ library is probably using malloc() for allocation.

What compiler options are you using?

Giovanni


Hi, no i dont have any mention of syscalls.c in the makefile. These are the options from the makefile:

Code: Select all

##############################################################################
# Build global options
# NOTE: Can be overridden externally.
#

# Compiler options here.
ifeq ($(USE_OPT),)
  USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
endif

# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
  USE_COPT =
endif

# C++ specific options here (added to USE_OPT).
ifeq ($(USE_CPPOPT),)
  USE_CPPOPT = -std=gnu++11 -fno-exceptions -fno-rtti
endif

# Enable this if you want the linker to remove unused code and data.
ifeq ($(USE_LINK_GC),)
  USE_LINK_GC = yes
endif

# Linker extra options here.
ifeq ($(USE_LDOPT),)
  USE_LDOPT = -lstdc++
endif

# Enable this if you want link time optimizations (LTO).
ifeq ($(USE_LTO),)
  USE_LTO = yes
endif

# Enable this if you want to see the full log while compiling.
ifeq ($(USE_VERBOSE_COMPILE),)
  USE_VERBOSE_COMPILE = no
endif

# If enabled, this option makes the build process faster by not compiling
# modules not used in the current configuration.
ifeq ($(USE_SMART_BUILD),)
  USE_SMART_BUILD = yes
endif

#
# Build global options
##############################################################################

##############################################################################
# Architecture or project specific options
#

# Stack size to be allocated to the Cortex-M process stack. This stack is
# the stack used by the main() thread.
ifeq ($(USE_PROCESS_STACKSIZE),)
  USE_PROCESS_STACKSIZE = 0x400
endif

# Stack size to the allocated to the Cortex-M main/exceptions stack. This
# stack is used for processing interrupts and exceptions.
ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
  USE_EXCEPTIONS_STACKSIZE = 0x400
endif

# Enables the use of FPU (no, softfp, hard).
ifeq ($(USE_FPU),)
  USE_FPU = no
endif

# FPU-related options.
ifeq ($(USE_FPU_OPT),)
  USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv5-d16
endif

User avatar
Giovanni
Site Admin
Posts: 14458
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Program runs out of memory after one too many objects created

Postby Giovanni » Mon Jun 19, 2023 9:06 pm

Try adding $(CHIBIOS)/os/various/syscalls.c to CSRC.

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: Bing [Bot] and 7 guests