Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post here all questions related to LibMaple core if you can't find a relevant section!
User avatar
Mangy_Dog
Posts: 92
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post by Mangy_Dog »

Hi sorry for making a single thread for a few issues im having...

Im working on a fairly complex project, The hardware is locked down...

Firstly Ive discovered even on an empty program with stlink being the uploader (so i assume no boot loader is being sent) Im getting 14KB of flash being used.

When i upload my display init test code it takes up 24KB, the display init test code in arudino Uno only takes 8kb roughly...

A guy I know checked the .elf and said that the USB stack is being installed (even though im not using USB) and some flash handling code.

So firstly how do I disable USB stack getting installed to save space and anything else im not using........

Also I tested LTO. And while this did indeed shrink the output significantly, it also didnt work and seemed to brick my mcu. I wasnt able to reflash the chip with stlink through normal SWD reset, I had to hotwire a wire to the reset pin and manually pull to ground and catch it Stlink utility to erase the chip.
Anyone know why LTO would break the chip? Is LTO more experimental?


Finally because in tight on flash space and I need an RTOS, I cant use freertos as it has a rather large headroom... Chibi is the obvious next choice but I cant find any guides on installing it into rogers core? Im assuming it needs a library install, the download for chibi seems to be for coreless builds.

Oh and all this is on rogers core...

I cant use stm32s new core as the graphics library im using relies on rogers core to work.

So umm :D Any ideas?
Just a dogs body developer, mostly making props and stuff...
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post by fpiSTM »

Well the only thing I can tell is that you can consider LTO as experimental.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post by mrburnette »

Mangy_Dog wrote: Wed Sep 23, 2020 2:11 pm ...
Firstly Ive discovered even on an empty program with stlink being the uploader (so i assume no boot loader is being sent) Im getting 14KB of flash being used.
There is NO such thing in Arduino as an empty .bin file from an empty sketch. There is quite a bit of C initialization code.
When i upload my display init test code it takes up 24KB, the display init test code in arudino Uno only takes 8kb roughly...
Think ... AVR is 8-bit and STM32 is 32-bit, so the core code is significantly fatter. But you get a more powerful and more capable system.
A guy I know checked the .elf and said that the USB stack is being installed (even though im not using USB) and some flash handling code.
Yes. The board definitions like Maple Mini and Bluepill do load the USB stack to support USB IDE console debugging. It is somewhere in one of the WiKis. I thing "Generic" does not load the USB code.
So firstly how do I disable USB stack getting installed to save space and anything else im not using........


Select a board definition that does not append the USB support code ... Or, edit the current definition to create a new def.
Finally because in tight on flash space and I need an RTOS, I cant use freertos as it has a rather large headroom... Chibi is the obvious next choice but I cant find any guides on installing it into rogers core? Im assuming it needs a library install, the download for chibi seems to be for coreless builds.
Obvious? I know of no rationale to support this claim, in fact you provide only your confirmation that an RTOS is needed. In my experience, proper code structure and artfully crafted (callback) functions often negate the RTOS requirement and associated overhead.

My friend westfw started an discussion 12 years ago:
https://forum.arduino.cc/index.php?topic=46766.0

Take a look at how big offending blocking functions can be reworked:
https://www.google.com/search?q=Arduino ... t+blocking

and, just to round out the discussion:
https://arduino.stackexchange.com/quest ... ing-timers


Ray
User avatar
Mangy_Dog
Posts: 92
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post by Mangy_Dog »

Of course i realise theres no such thing as a truely empty sketch....

I still wouldnt have expected the code take up multiples of the same code just going from 8 bit to 32bit architecture.

I am using the generic f103c8 option, as Im working on a custom board ive made.

And yes I usually work in non blocking code. But while an earlier version of this project worked ok in this non blocking style, now that im adding an entire graphics processing set of functions, its now making it more and more difficult to keep it non blocking. So having thread control that just runs, solves a lot of headaches.
Just a dogs body developer, mostly making props and stuff...
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post by stevestrong »

In order to get rid of USB you have to remove from boards.txt the following directive:

Code: Select all

-DSERIAL_USB
So search for the line corresponding to your upload method and delete it.
User avatar
Mangy_Dog
Posts: 92
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post by Mangy_Dog »

Thanks steve, that clawed back 3kb :D

I tried removing generic bootloader as well but that made no difference. Any other options or stuff to strip off?
Just a dogs body developer, mostly making props and stuff...
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post by stevestrong »

The default -Os compiler directive should give best result to save code.
As the F103C8 chip has actually 128kB flash (at least most of them, even if officially only 64 is given ;) ) I see no reason to worry about code size.
If it is still an issue, then I recomend to switch to F4 family (more flash, higher execution speed).
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post by mrburnette »

Mangy_Dog wrote: Wed Sep 23, 2020 7:50 pm Of course i realise theres no such thing as a truely empty sketch....

I still wouldnt have expected the code take up multiples of the same code just going from 8 bit to 32bit architecture.

I am using the generic f103c8 option, as Im working on a custom board ive made.

And yes I usually work in non blocking code. But while an earlier version of this project worked ok in this non blocking style, now that im adding an entire graphics processing set of functions, its now making it more and more difficult to keep it non blocking. So having thread control that just runs, solves a lot of headaches.
In my professional days I heard hundred of concerns such as yours and it all fell into the giant category of "Scope Creep." Designs were made, prototypes constructed, hardware ordered, commitment dates and prices set, and then something unexpected changed: such as your graphic processing functions.

You are not going to like my answer, but go back to your customer and negotiate a reasonable solution: a phased approach with the introduction not including graphics or a different microcontroller (and release date) that will easily accommodate the additional code. Last year I had a customer that at the last moment they wanted graphic gauges instead of LCD readings: He did not get it in phase 1 and the "low-cost" solution for phase 2 was to take my (existing) development diagnostic serial stream and send it over BlueTooth to a Raspberry Pi running NodeRED (free) and hosting the graphics on the webserver there. Note, absolutely no code or hardware changes were made on the Arduino side. Now the customer has graphic gauges on the rPi touch screen, his WiFi tablet, and his cellphone.

Here is my simple Arduino ASCII to NodeRED graphic solution:
https://www.hackster.io/rayburne/arduin ... asy-28882d

This query results will explain a bit more about GCC flash use:
https://www.google.com/search?q=GCC+fla ... artup+code



Ray

PS: Don't allow a problem to wag the entire project architecture and never use more than 80% of your flash or RAM resources.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post by mrburnette »

As for the USB stack, here is the correct answer:
https://stm32duinoforum.com/forum/viewt ... tml#p52022
Roger long ago made the assumption that if you wanted to use the USART Serial uploader, you probably didn't want to use the native USB. Native USB is enabled or disabled by defines passed to the compiler.
Good luck,

Ray
User avatar
Mangy_Dog
Posts: 92
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Multiple problems - LTO killing MCU, USB stack issues, How to install chibios?

Post by Mangy_Dog »

Ohh no scope creep going on, and luckily this is my project, no client so much. Though I am selling a couple of finished pieces...
I concepted this idea over a year ago.... and started developing the hardware at the beginning of the year. I just assumed as the first prototype without the graphics side fit on an atmega, that same code shouldnt be much different in size on the stm32. But that doesnt look to be the case soooo, its got me a little worried. It would probebly be fine, but I am going to be super careful how i write the code now.

Also i tried compiling with LTO and while my 30kb sketch came down to 3KB, i guess something broke in the compile as that also bricked the MCU.
Is LTO and -S0 two different things?
If so how do i set S0 so i can try it?

And yes in all likely hood my c8 is a CB, but I got the chips from Ali, who knows i might just have a bunch of real 64KB chips :p Sure if i really do have 128KB i should have no issues at all... But if i am stuck with 64KB im certainly a tinsy bit worried ill go past that.
Just a dogs body developer, mostly making props and stuff...
Post Reply

Return to “General discussion”