5 Replies Latest reply on Jun 27, 2014 1:03 PM by GregG_16

    I use STM32F103RD(64KB SRAM),But I can't use the last 4KB RAM?

    chch_2120956

      Dear,

       

          I use MCU STM32F103RD(64KB SRAM),when I have used 60KB  I call malloc(10) will fail ,can't get space ?

       

      Thanks a lot !!!

        • 1. Re: I use STM32F103RD(64KB SRAM),But I can't use the last 4KB RAM?

          I assume by

          I have used 60KB

          you mean that when it compiles, that is how much Static RAM the compiler has told you it is using.  That means that you have ~4KB of RAM to dynamically allocate using malloc().  I've found at least some functions in the SDK that use dynamic memory allocation, so it is likely that they are taking up those 4 KB (and probably trying to use more), which is why your malloc() call is failing.

          • 2. Re: I use STM32F103RD(64KB SRAM),But I can't use the last 4KB RAM?
            chch_2120956

            Thank you replying. complies use Staic Ram 36KB, SDK some functions use about 24KB ,then I call create thread that call malloc then will fail.

             

            I add DbgPrintf which put debug info to temp buf  at pvPortMalloc function.

            extern void DbgPrintf(const char *fmt,...);

            void *pvPortMalloc( size_t xWantedSize )

            {

                 void *pvReturn;

                 int a=(int)xWantedSize;

                 vTaskSuspendAll();

                 {

                          pvReturn = malloc( xWantedSize );

                         DbgPrintf("##size=%d,pv=0x%x\r\n",a,(unsigned int)pvReturn);

                 }

                 xTaskResumeAll();

             

                 ...

             

              return pvReturn;

            }

             

            Then I get debug message

             

            ##### task name =cloud_thread,stack_size=2048,pri=2
            ##size=80,pv=0x2000e8c8
            ##size=2048,pv=0

             

             

             

            Thank you

            1 of 1 people found this helpful
            • 3. Re: I use STM32F103RD(64KB SRAM),But I can't use the last 4KB RAM?
              chch_2120956

              Thank you replying. complies use Staic Ram 36KB, SDK some functions use about 24KB ,then I call create thread that call malloc then will fail.

               

              I add DbgPrintf which put debug info to temp buf  at pvPortMalloc function.

              extern void DbgPrintf(const char *fmt,...);

              void *pvPortMalloc( size_t xWantedSize )

              {

                   void *pvReturn;

                   int a=(int)xWantedSize;

                   vTaskSuspendAll();

                   {

                            pvReturn = malloc( xWantedSize );

                           DbgPrintf("##size=%d,pv=0x%x\r\n",a,(unsigned int)pvReturn);

                   }

                   xTaskResumeAll();

               

                   ...

               

                return pvReturn;

              }

               

              Then I get debug message

               

              ##### task name =cloud_thread,stack_size=2048,pri=2
              ##size=80,pv=0x2000e8c8
              ##size=2048,pv=0

               

               

               

              Thank you

              • 4. Re: I use STM32F103RD(64KB SRAM),But I can't use the last 4KB RAM?
                chch_2120956


                0x2000e8c8 +2048 -0x20000000=61460 >61440 =>get pv=0;

                the if highlight (61460) <=61424 malloc will success.


                • 5. Re: I use STM32F103RD(64KB SRAM),But I can't use the last 4KB RAM?
                  GregG_16

                  Hello,

                  Since MALLOC will allocate 4K blocks and runs in virtual memory, sometimes you can have fragments.  (Usually not an issue in systems with huge memory.)

                  Things like "scan results" and other functions rely on MALLOC, so it is best not to use every last bit or rely on it too heavily. 

                  Hope this helps.