STM32DUINO – Architecture questions

Stecor
Sun Jan 29, 2017 8:00 pm
First of all, a Big Thank You! for the work done here. As a former AVR user, I recognize the significant jump in complexity between Cortex and 8-bit AVRs, and your making the Arduino platform work with STMs is pure wonder. Actually, the first tests I ran to comfirm the boards are working used std32duino.

You could say that my experience with Arduino is limited, and that is true, since I’ve mostly worked with WinAvr and Studio… I have always found Arduino to be lacking (masking accesss to peripherals, using the one-fits-all approach e.g. System timer using timer0) with simple controllers like the 8-bit avrs.

Coming to stm32duino, I would ask a few questions related to architecture:
1. What can one do to control what code is generated by default (a blinky sketch compiles to circa 12k whereas under Gcc-Arm–Eclipse it takes less than 2k). I understand that code supporting USB VCP must be included, and that the bootloader is also taking about 1k, but still, it seems too much. I spemt a bit of time trying to understand Wirish.h and Boards but the inclusions are so recursive that frankly, you lost me.

2. Can you suggest a different approach to using the arduino functions such as DigitalWrite, AnalogRead, etc without going down to register level? The SPL libraries by ST are more balanced in my opinion…

3. Are you planning a revamp to the editor? While the Arduino editor is adequate for simple projects, I find it’s lacking for more complex ones…

4. I believe warnings are suppressed during build time. Can they be enabled easily?

5. What about debug- within the IDE? Again, for a simple (avr based) debugging with leds and serial is probably adequate, but for mor complex projects it is really a good feature to have.

Thanks, and appologies if these are duplicated questions.
Stefan


Rick Kimball
Sun Jan 29, 2017 8:12 pm
All those questions have been asked and answered. You might use google:

for example:

http://bfy.tw/9lir


RogerClark
Sun Jan 29, 2017 9:40 pm
Re:1
This has been discussed many times on the forum. There are various reasons why the code size is larger than you might imagine.
This includes things like USB support, and the way the 32 bit compiler works.

Its not worth re-iterating here, what has been discussed at length in other threads

Re: 2

For SPL

See https://github.com/avikde/koduino

For HAL

See https://github.com/stm32duino

Re: Questions 3,4 and 5

We use the standard Arduino IDE, (normally at the latest release version); So..No, we don’t have any extra IDE features.

The codebase is just a “Third Party Core’ as defined by Arduino themselves. https://github.com/arduino/Arduino/wiki … cification


victor_pv
Mon Jan 30, 2017 6:21 pm
just to add that regarding 3 4 and 5, a search in the forums and the Wiki and you will find posts of some people is using Eclipse, you may want to try it.

I believe there are posts on using Visual Micro too.


sheepdoll
Mon Jan 30, 2017 10:49 pm
victor_pv wrote:just to add that regarding 3 4 and 5, a search in the forums and the Wiki and you will find posts of some people is using Eclipse, you may want to try it.

I believe there are posts on using Visual Micro too.


Stecor
Tue Jan 31, 2017 10:33 am
Thank you all for taking the time to read and provide feedback to my points.

Actually, the reason I posted initially was (is) that I think the amount of work put in thus far is appreciable, however, it looks to me like the overall approach could do with some re-assesment; personally, I moved over to an Eclipse-based solution because of the points made above.

Out of respect for the work you gentlemen and ladies put in to create and maintain the system, I wanted to provide some feedback, trying to point out what was an issue for me, hoping that you would see it as constructive criticism. Again, not trying to point out the obvious, but we’re now talking about embedded computers that exceed the processing power of my first computer (yep, I’m that old :) ) so (imo) the toolset could use some brushing up.

I also think it is not happenstance that, for instance, Nucleo boards adopt Arduino pinout headers, nor that some IDE providers (e.g Attolic) chose to open
up their systems free of charge…I think it is all happening because Arduino changed the way things are done &seen. All I am saying now is that, maybe, you could comsider adjusting the Arduino STM32 approach to suit…

Thanks again, and best wishes
Stefan


victor_pv
Tue Jan 31, 2017 2:57 pm
Stefan, we all agree debugging for example is necessary, but since this forum is not about the IDE itself, but supporting stm32 boards in the Arduino IDE, it results in different people use different IDEs when the Arduino one doesn’t cover the needs.

Personally I have just installed Eclipse with the Arduino plugin V4. Rick and other people posted some pretty good advice on how to set it up to use our core.

But we don’t develop any IDE, so even though we would like things like debugging to be incorporated in the Arduino IDE, that is not our focus.
The focus of the forums is to keep developing a core which was created by leaflabs to be compatible with Arduino, so people can transition easily from one to the other.

If you dont need any compatibility with Arduino, as you mentioned Atollic is free, and Segger has an IDE that’s free for non-comercial use, and then there is Eclipse. The CubeMX is a great tool to generate configuration files and peripheral libraries.

But when you want the arduino simplicity to work, then all lwo level stuff needs to be abstracted, and that results in those 12KB of basic code. Setting up usb, 2x i2c, 2/3 spi, 8 timers, clocks for all those, flash settings, core frequency, etc.
There have been several discussions in the forum on reducing the amount of flash and ram used for basic stuff, and we made quite some progress, but there is a limit.
STM is developing a new Arduino core based on their HAL, and takes much more RAM and flash for just blinking a led. That’s the cost of abstracting.
You could of course modify your core, so if for example if you dont plan to use i2c and spi, the peripherals don’t get initialized.

Still using 12KB on an MCU with 128KB, leaves you over 100KB free for code, and if that’s not enought, you can buy an stm32f103RCT6 board with 256KB (actual 512KB on most cases). Taking that into acount, the cost of 12KB used to nicely initialize everything for you doesn’t seem like a big cost.


Ollie
Tue Jan 31, 2017 3:39 pm
My two favorite IDEs are Arduino and EmBitz. Arduino is for quick development of small projects for variety of boards – including ESP8266 and ESP32. The EmBitz is for STM32 development including F4xx and F7xx. The STM32 projects are larger and have more stringent timing requirements. A real debugger is essential for those.

Based on my experience with Eclipse, I do recommend EmBitz for it’s higher speed and debugging features, such as live view of variables, symbolic access of peripheral registers, and EB monitor. Like Eclipse, EmBitz is free.


stevestrong
Tue Jan 31, 2017 3:41 pm
victor_pv wrote: Eclipse with the Arduino plugin V4.

willfly1
Tue Jan 31, 2017 3:55 pm
I will throw in my choice of IDE – it is a text editor called Notepad++. With the NppExec plugin, one can compile sketches from within the editor itself, all while getting powerful text editor and syntax highlighting capabilities.

stevestrong
Tue Jan 31, 2017 3:57 pm
willfly1 wrote:With the NppExec plugin, one can compile sketches from within the editor itself, all while getting powerful text editor and syntax highlighting capabilities.

stevestrong
Tue Jan 31, 2017 3:58 pm
Ollie wrote:The EmBitz is for STM32 development including F4xx and F7xx. The STM32 projects are larger and have more stringent timing requirements. A real debugger is essential for those.

victor_pv
Tue Jan 31, 2017 5:28 pm
stevestrong wrote:willfly1 wrote:With the NppExec plugin, one can compile sketches from within the editor itself, all while getting powerful text editor and syntax highlighting capabilities.

BennehBoy
Tue Jan 31, 2017 7:31 pm
+2

RogerClark
Tue Jan 31, 2017 8:15 pm
stevestrong wrote:willfly1 wrote:With the NppExec plugin, one can compile sketches from within the editor itself, all while getting powerful text editor and syntax highlighting capabilities.

Stecor
Tue Jan 31, 2017 10:07 pm
victor_pv wrote:Stefan, we all agree debugging for example is necessary, but since this forum is not about the IDE itself, but supporting stm32 boards in the Arduino IDE, it results in different people use different IDEs when the Arduino one doesn’t cover the needs.

Yep, precisely – this is why I was chiming in. Lots of good code and examples, then you either port it or re-write because it’s too troublesome to build within the IDE’ s limitations imposed by the Arduino interface

[…]

If you dont need any compatibility with Arduino, as you mentioned Atollic is free, and Segger has an IDE that’s free for non-comercial use, and then there is Eclipse. The CubeMX is a great tool to generate configuration files and peripheral libraries.

Actually I use St-link v2 (and I’ve got two Nucleos which have their own st-link). Works a treat under AC6, gnu-arm-eclipse, Attolic. Maybe others too…

With Cube… Well, I use it for pinout planning and clock hints but otherwise, I shun HAL :mrgreen: I am the SPL kind of guy… Maybe I will switch to HAL sometime, not just yet tho.


But when you want the arduino simplicity to work, then all lwo level stuff needs to be abstracted, and that results in those 12KB of basic code. Setting up usb, 2x i2c, 2/3 spi, 8 timers, clocks for all those, flash settings, core frequency, etc.

You know, I always wondered what’s wrong with using #includes and a PeripheralInit() instead of having it pre-defined And hidden away… Who uses *all* periphs on a chip anyway? Not to mention that, for instance with SPI (which is quite handy nowadays) having multiple ports open – or communicating with different slaves at different speeds and settings – could do with improvements, especially under the pre-defined setup… Just my opinion, of course ;)


STM is developing a new Arduino core based on their HAL, and takes much more RAM and flash for just blinking a led. That’s the cost of abstracting.

Not so sure about the Ram, but one difference with HAL that I could see is that HAL perform more “complete” functions (e.g. inits) when compared to SPL. For instance, an SPL USART init requires clock enabling, GPIO setup, peripheral setup, maybe pin remapping. Under HAL it’s just one function. However I prefer the SPL way, and for time-critical sections, direct register access… Performance Improvements are quite pronounced there.

If you ask me, the main driver for HAL is implementing best practices when it comes to exception management. Also, makes it easier for the programmer to get by without reading the extensive chip documentation… Which all comes with the cost of unnecessary wasted cycles… I still remember the “old days” when assembly programmers where downtalking high-level code monkeys because of wasted resources. We all know how that one ended, but I feel that HAL is a bit over the top for my needs – at least for now…


You could of course modify your core, so if for example if you dont plan to use i2c and spi, the peripherals don’t get initialized.

That I tried, and found to be too involved and it’s IMHO the wrong approach – it should go – i need it, i enable it rather than the other way round… Too much hw, you see… :)

Still using 12KB on an MCU with 128KB, leaves you over 100KB free for code, and if that’s not enought, you can buy an stm32f103RCT6 board with 256KB (actual 512KB on most cases). Taking that into acount, the cost of 12KB used to nicely initialize everything for you doesn’t seem like a big cost.


victor_pv
Wed Feb 01, 2017 12:25 am
You know, I always wondered what’s wrong with using #includes and a PeripheralInit() instead of having it pre-defined And hidden away… Who uses *all* periphs on a chip anyway? Not to mention that, for instance with SPI (which is quite handy nowadays) having multiple ports open – or communicating with different slaves at different speeds and settings – could do with improvements, especially under the pre-defined setup… Just my opinion, of course ;)

There is nothing wrong for you, and for a lot of other people. But Arduino mainly appeals to the people that doesn’t necessarily needs to know how to initialize an SPI port, a few timers, cpu clocks, etc. That is the whole target or Arduino, and that is what this core is mainly about, although you still can have low level access to anything you want.


Ollie
Wed Feb 01, 2017 2:08 am
stevestrong wrote:Ollie wrote:The EmBitz is for STM32 development including F4xx and F7xx. The STM32 projects are larger and have more stringent timing requirements. A real debugger is essential for those.

stevestrong
Wed Feb 01, 2017 9:37 am
Ollie wrote:The applications cannot be ported between these two IDEs due to different libraries.

racemaniac
Wed Feb 01, 2017 10:22 am
As we’re talking architecture: i would love to see some more attention to offering some async DMA libraries :). that’s where the true IO power of these little guys is, and by sticking to the arduino API we’re completely missing it >_<.

Also for many of the reasons mentioned in this thread, i’m currently working in visual studio with visualgdb & the cubemx code generator. i got great debugging, can create code for any stm32, far better IDE, …
But i’m very grateful this arduino port a IDE exists for doing the simple stuff, and it was also what allowed me to get started with all of this withouth a huge learning curve upfront :).


GrumpyOldPizza
Wed Feb 01, 2017 12:25 pm
racemaniac wrote:As we’re talking architecture: i would love to see some more attention to offering some async DMA libraries :). that’s where the true IO power of these little guys is, and by sticking to the arduino API we’re completely missing it >_<.

Also for many of the reasons mentioned in this thread, i’m currently working in visual studio with visualgdb & the cubemx code generator. i got great debugging, can create code for any stm32, far better IDE, …
But i’m very grateful this arduino port a IDE exists for doing the simple stuff, and it was also what allowed me to get started with all of this withouth a huge learning curve upfront :).


Ollie
Wed Feb 01, 2017 5:09 pm
stevestrong wrote:Ollie wrote:The applications cannot be ported between these two IDEs due to different libraries.

Ollie
Wed Feb 01, 2017 5:11 pm
GrumpyOldPizza wrote:
Some folks I know use “Visual Micro” which integrates openocd/gdb. So debugging should be possible there as well. Haven’t tried it myself though, I’m a Unix guy …

willfly1
Sat Feb 04, 2017 3:58 pm
Sorry for late reply – here is how I build using Npp. Essentially it invokes arduino_debug.exe and pass in command line parameters just like compiling a Java program etc.

1. Install NppExec plugin
2. Add following commands:
Compile Sketch
//save current file
NPP_SAVE
cd "$(CURRENT_DIRECTORY)"
"c:\Program Files (x86)\Arduino\arduino_debug.exe" --pref build.path="$(CURRENT_DIRECTORY)/build" --verify "$(FULL_CURRENT_PATH)"


BennehBoy
Sat Feb 04, 2017 5:31 pm
Brilliant, thanks, got it working.

Need to figure out how to switch the IDE between target device types now though :D


RogerClark
Sat Feb 04, 2017 8:04 pm
BennehBoy wrote:Brilliant, thanks, got it working.

Need to figure out how to switch the IDE between target device types now though :D


sheepdoll
Sat Feb 04, 2017 8:08 pm
I just posted my makefile script in this thread viewtopic.php?f=42&t=337&start=10#p23322

BennehBoy
Sat Feb 04, 2017 9:04 pm
RogerClark wrote:
Probably overkill, but there is a scripable automation system for Windows called AutoIt, which you could use to change menu options in the IDE, and could run those scripts from NPP.

RogerClark
Sat Feb 04, 2017 9:09 pm
BennehBoy wrote:RogerClark wrote:
Probably overkill, but there is a scripable automation system for Windows called AutoIt, which you could use to change menu options in the IDE, and could run those scripts from NPP.

BennehBoy
Sat Feb 04, 2017 9:16 pm
And com port setting:

"c:\Program Files (x86)\Arduino\arduino_debug.exe" --pref serial.port="COM9" --pref serial.port.file="COM9"


BennehBoy
Sat Feb 04, 2017 9:20 pm
Don’t thank me too fast, sketch upload fails for maple,

java.io.IOException: Cannot run program “{runtime.hardware.path}/tools/win/maple_upload.bat”: CreateProcess error=2, The system cannot find the file specified

Some more tinkering and should hopefully sort it.


willfly1
Sat Feb 04, 2017 9:45 pm
RogerClark wrote:
Is anyone using any of the C tools for NPP that allow you to look up where a function is defined and view it etc.

BennehBoy
Sat Feb 04, 2017 9:52 pm
It only works if you tell npp the language is C++ first

I’ve not figured out yet how to tell NPP that .ino should be treated as c++, if anyone has then please let me know


RogerClark
Sat Feb 04, 2017 10:02 pm
willfly1 wrote:RogerClark wrote:
Is anyone using any of the C tools for NPP that allow you to look up where a function is defined and view it etc.

BennehBoy
Sat Feb 04, 2017 10:07 pm
autocompletion is built in, you just have to turn it on…

Go to 'Settings'->'Preferences'

Click on 'Auto-Completion' in the left hand list

Tick 'Enable auto-completion on each input'

Select 'Function and word completion'

Tick 'Ignore numbers' (if you wish)

Click 'Close'


RogerClark
Sun Feb 05, 2017 1:14 am
BennehBoy wrote:autocompletion is built in, you just have to turn it on…

Go to 'Settings'->'Preferences'

Click on 'Auto-Completion' in the left hand list

Tick 'Enable auto-completion on each input'

Select 'Function and word completion'

Tick 'Ignore numbers' (if you wish)

Click 'Close'


BennehBoy
Sun Feb 05, 2017 1:11 pm
BennehBoy wrote:java.io.IOException: Cannot run program “{runtime.hardware.path}/tools/win/maple_upload.bat”: CreateProcess error=2, The system cannot find the file specified

BennehBoy
Sun Feb 05, 2017 3:03 pm
Another useful command:

Clean

cd "$(CURRENT_DIRECTORY)"
cmd /c del "$(CURRENT_DIRECTORY)/build" /F /S /Q


BennehBoy
Sun Feb 05, 2017 3:27 pm
I realise I’ve taken this thread way off topic, apologies.

I’ll create a NPP config thread and move everything over.


RogerClark
Sun Feb 05, 2017 8:01 pm
BennehBoy wrote:I realise I’ve taken this thread way off topic, apologies.

I’ll create a NPP config thread and move everything over.


Leave a Reply

Your email address will not be published. Required fields are marked *