Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post here first, or if you can't find a relevant section!
mustaq_ahm
Posts: 31
Joined: Tue Sep 14, 2021 11:08 am
Answers: 2

Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post by mustaq_ahm »

Hello all again :D

I am using Stm32f103c8t6 with Offical core with HID bootloader. I am working on Visual Studio Code IDE using Microsoft Arduino Extension.

I have a few PCBs with several Functional blocks mounted in Stm32f103c8t6. I will describe one of the boards with all functional blocks on it.

The board has 6 General Purpose Output (using built internal GPIO pins) with all necessary electronics to drive up to 24 volts. It also has 4 analogue industrial inputs (using external ADC pins via I2C1 communication (ADS1115 IC https://www.ti.com/lit/ds/symlink/ads1113.pdf)) with all necessary electronics to read the voltage up to 10 volts. Then, the board has 6 PWM using BTN8962TA https://www.infineon.com/dgdl/Infineon- ... 2d247a7bf5 to drive the motors using PWM frequency and Dutycycle using the outputs from PWM. To be noted for all the 6 PWMs, from the schematics of the board there are two external ADC pins(one for I sense, and V sense(using ADS1115 IC via I2C1)), one external GPIO pin(for Inhibit pin of PWM(using MCP23017 IC http://ww1.microchip.com/downloads/en/D ... 01952C.pdf via I2C1)), and an internal timer pin connected to PWM directly from the microcontroller. Then there are 5 thermocouple pins using MCP9600 IC http://ww1.microchip.com/downloads/en/D ... 02417A.pdf via I2C1. Then, the board has 3.3 to 5V I2C1 pins to use Sensirion SCD30 Sensor Module https://www.mouser.com/datasheet/2/682/ ... 510853.pdf. Also, it has a compatibility to support NeoPixel LED. Also SPI2 is also available for using SD card and touch screen to work it as HMI. Above all that it also has its I2C2, USART1, USART2, LIN.

When I created my own library for 6 General Purpose Output, 4 analogue industrial inputs, and 6 PWM with the help of all the available Arduino libraries for all electronic components. After creating it and I tried to check all the functionality I have made in my library in .ino file using my library. It worked pretty well.

Then I added more functionality in my library like just adding 5 thermocouples in my library with its available Arduino library and integrating into my library. Now, when I ran my .ino file, the program crashes the Stm32f103c8t6. Now, I had rebooted my Stm32f103c8t6 again to use it again.

After this, I noted that just adding functionalities till itself takes up almost 80% of the storage out of 64Kbytes.

I have some questions here!
Why my MCU is crashing when I upload a program?
Can I utilize the whole storage of my MCU?
I wanted to create a general-purpose Library to use the PCB as desired with minimal coding in .ino file. So, is that possible?
How maximize the storage in MCU?
How to use the storage efficiently?
Is it that true serial debug uses a lot of storage? but still, I did not use it much in my .ino file!


I have explained all my hardware things here, just give more clarity on what I am trying to achieve with what and how!

I hope to get your suggestions, opinions, guidance, directions, and references to achieve my task.

Thanks in advance.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post by ag123 »

u'd need a st-link and debug away, that is the only way to find out what may be wrong.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post by mrburnette »

mustaq_ahm wrote: Tue Oct 26, 2021 9:21 am ...
After this, I noted that just adding functionalities till itself takes up almost 80% of the storage out of 64Kbytes.

I have some questions here!
Why my MCU is crashing when I upload a program?
Can I utilize the whole storage of my MCU?
I wanted to create a general-purpose Library to use the PCB as desired with minimal coding in .ino file. So, is that possible?
How maximize the storage in MCU?
How to use the storage efficiently?
Is it that true serial debug uses a lot of storage? but still, I did not use it much in my .ino file!

...
Q) Why my MCU is crashing when I upload a program?
A) Unknown

Q) Can I utilize the whole storage of my MCU?
A) Yes, all of flash can be utilized

Q) minimal coding in .ino file. So, is that possible?
A) possible, yes, but somewhat counter-intuitive and could be inefficient depending on code granularity

Q) How maximize the storage in MCU? How to use the storage efficiently?
A) Stm32f103c8t6 is a "general purpose" microcontroller and full of useful hardware: SPI, I2C, USART, A/D, DMA ... all for a low-price to consumer. While the engineers provide lots of modules, designs often use a subset of capabilities. By providing lots of peripherals and protocol, the uC offers a decent mid-range 32-bit system, with SRAM and FLASH limitations that are a major component of the uC silicon footprint: the larger the silicon die, the more costly the end product.

Your intent to create "one" library to rule the Stm32f103c8t6 is interesting but is just not how most coders would approach this chip. Separate libraries would parallel the "core" components. This is software granularity. Written correctly, the library would present 1 C++ object for every chip component/peripheral such that Serial #1, Serial #2, Serial #3 all use the same object code for efficiency. This concept extends to other internal uC building blocks. Libraries can be constructed with parameter overloading to create robustness. Extend this thought to provision external hardware sensors... or like general, just incorporate the two needs into a separate library; example: BMP280 library.

IMO, you need to drop back and spend a few days with a good C++ book. Concepts such as polymorphism, overloading, inheritance, etc.

Once the above is digested, then a trip through C++ linker land for an understanding of how code is linked: http://www.cplusplus.com/forum/general/121815/

... and remember there are many "under the hood" software components that provision the STM32 Arduino environment:
viewtopic.php?p=4322#p4322
mustaq_ahm
Posts: 31
Joined: Tue Sep 14, 2021 11:08 am
Answers: 2

Re: Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post by mustaq_ahm »

ag123 wrote: Tue Oct 26, 2021 11:30 am u'd need a st-link and debug away, that is the only way to find out what may be wrong.
could you please explain to me a little bit more, please? and How?

I use STM32cubeprogrammer to boot my stm32f103c8t6 MCU via STlink having connected SWDIO and SWCLK with Nucleo-F103RB (0x410). Using Nucleo-F103RB as a STlinker to my MCU to boot HID bootloader in the start address of 0x08000000.
mustaq_ahm
Posts: 31
Joined: Tue Sep 14, 2021 11:08 am
Answers: 2

Re: Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post by mustaq_ahm »

mrburnette wrote: Tue Oct 26, 2021 1:12 pm
Q) Why my MCU is crashing when I upload a program?
A) Unknown

Thank you so much. I will follow your opinion.

By the way, In my point of view. Everything, I have written in the library is efficiently programmed and error free. Could you think of possibilities of crashing my MCU?
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post by ag123 »

mustaq_ahm wrote: Wed Oct 27, 2021 7:31 am
ag123 wrote: Tue Oct 26, 2021 11:30 am u'd need a st-link and debug away, that is the only way to find out what may be wrong.
could you please explain to me a little bit more, please? and How?

I use STM32cubeprogrammer to boot my stm32f103c8t6 MCU via STlink having connected SWDIO and SWCLK with Nucleo-F103RB (0x410). Using Nucleo-F103RB as a STlinker to my MCU to boot HID bootloader in the start address of 0x08000000.
normally if the firmware doesn't fit in flash, i'd think u'd know it during compile phase. unless you have a .ld file that's different from the spec of your mcu.
and if the ld file is after all correct, and if the app crashes after it is installed, this has to mean that something else is wrong.

I've tried building a hid bootloader written for stm32f407 and re-building it for stm32f401/f411, the hid boot loader installs, but that it crashes on start / reset.
viewtopic.php?p=8267#p8267
While I debug that, i found that it hardfault in various places in main(). I did not attempt to further fix it for now, i may try to figure it out again.

But if this is the symptom you observe, then I'm afraid debug is about the only way to figure out what is wrong.

as to whether your firmware fits in flash, you'd need to review the spec sheets for your mcu and check in there e.g.
https://www.st.com/resource/en/datashee ... f103c8.pdf
and in your .ld file you would need to specify it based on those specs.
These things are in the variant directory of your board, it is done for you as part of stm32duino(s) in the variants. you can take a look at the core codes in particular the variant relevant to your board.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post by ag123 »

There are stm32 mcus with plenty more flash (most have a fraction more sram as well), all it takes is to look them up on ST's web.
you can try things like an RC suffix chip which is more than c8.
Actually, sram memory is a bigger limitation, for 'small microcontroller apps', one'd likely live with 20k sram, but you can try writing a full fledge web server. you'd have a hard time doing a fraction of that except for the simplest web server.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post by mrburnette »

mustaq_ahm wrote: Wed Oct 27, 2021 7:34 am ...
By the way, In my point of view. Everything, I have written in the library is efficiently programmed and error free. Could you think of possibilities of crashing my MCU?
You are going to drive yourself mad!

Take your library and extract every hardware driver (SPI, Serial, I2C, etc.) into a separate, smaller library you can more easily test. If you like, you can keep a common .h header file for all versions.

- Write simple test code for each mini-lib.
-Test.
- Move to next module...
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post by ag123 »

Typically, with stm32f103c8t6, a 'library' is pretty difficult, unless you release it open sourced, just as with many out there on github.
the limited sram and flash pretty much means that binary libraries is 'quite impossible'. For open sourced libraries, actually users should review the codes rather than just use them directly. Many of them may not work even if it is for the same mcu, there are often factors that makes the boards and other electronics and circumstances different from on the board it is developed and tested.
StevenD
Posts: 3
Joined: Fri Jun 25, 2021 8:38 am

Re: Insufficient Storage. Efficient Memory. Stm32f103c8t6.

Post by StevenD »

mrburnette wrote: Tue Oct 26, 2021 1:12 pm
mustaq_ahm wrote: Tue Oct 26, 2021 9:21 am ...
After this, I noted that just adding functionalities till itself takes up almost 80% of the storage out of 64Kbytes.

I have some questions here!
Why my MCU is crashing when I upload a program?
Can I utilize the whole storage of my MCU?
I wanted to create a general-purpose Library to use the PCB as desired with minimal coding in .ino file. So, is that possible?
How maximize the storage in MCU?
How to use the storage efficiently?
Is it that true serial debug uses a lot of storage? but still, I did not use it much in my .ino file!

...
Q) Why my MCU is crashing when I upload a program?
A) Unknown

Q) Can I utilize the whole storage of my MCU?
A) Yes, all of flash can be utilized

Q) minimal coding in .ino file. So, is that possible?
A) possible, yes, but somewhat counter-intuitive and could be inefficient depending on code granularity

Q) How maximize the storage in MCU? How to use the storage efficiently?
A) Stm32f103c8t6 is a "general purpose" microcontroller and full of useful hardware: SPI, I2C, USART, A/D, DMA ... all for a low-price to consumer. While the engineers provide lots of modules, designs often use a subset of capabilities. By providing lots of peripherals and protocol, the uC offers a decent mid-range 32-bit system, with SRAM and FLASH limitations that are a major component of the uC silicon footprint: the larger the silicon die, the more costly the end product.

Your intent to create "one" library to rule the Stm32f103c8t6 is interesting but is just not how most coders would approach this chip. Separate libraries would parallel the "core" components. This is software granularity. Written correctly, the library would present 1 C++ object for every chip component/peripheral such that Serial #1, Serial #2, Serial #3 all use the same object code for efficiency. This concept extends to other internal uC building blocks. Libraries can be constructed with parameter overloading to create robustness. Extend this thought to provision external hardware sensors... or like general, just incorporate the two needs into a separate library; example: BMP280 library.

IMO, you need to drop back and spend a few days with a good C++ book. Concepts such as polymorphism, overloading, inheritance, etc.

Once the above is digested, then a trip through C++ linker land for an understanding of how code is linked: http://www.cplusplus.com/forum/general/121815/

... and remember there are many "under the hood" software components that provision the STM32 Arduino environment:
viewtopic.php?p=4322#p4322
thank you so much for the info...
Post Reply

Return to “General discussion”