Correct usage of HAL functions in Arduino code

Post here all questions related to STM32 core if you can't find a relevant section!
kvv213
Posts: 38
Joined: Thu Dec 26, 2019 10:58 pm

Re: Correct usage of HAL functions in Arduino code

Post by kvv213 »

mrburnette wrote: Sat Jan 18, 2020 6:17 pm
kvv213 wrote: Sat Jan 18, 2020 7:46 am @mrburnette
Don't agree with your option, here are my thoughts:
...
At my current development I have to move from AVR platform (two different chips, not ATMEGA328) to STM32 (and here I had to switch to more advanced chip during development).

PS. Sorry for the flame :)
My final, thoughts: STM32duino is not Arduino in that it will not provision Arduino.cc official hardware. It is a software wrapper service that hides STM code and creates an API to mimic Arduino sketch capability (syntax) on many evaluation boards that utilize a STM microcontroller. Not all of the uC hardware capabilities may be available to the programmer and some adjustment may be required to 3rd party libraries.
I'm very glad that you spent your best years working for 10Fortune companies and have experience with high availability and high load systems. And I fully agree with you that Duino is just a wrapper over HAL&CMSIS. And it is great because me as a developer can use the framework that I know and I have access instantly to a such a great amount of libraries most of them work just perfectly without any additional tuning with STM32.

Following your position to its xtreme all the developers should use assembler or better write in machine codes. But it is nonsense because:
a. Developers work costs a lot. It is more expensive than hardware.
b. All the companies need to get their software as soon as possible. Because waiting costs even more than the labour of developers.

So, in the modern world you need to get your software as soon as possible because any other ways are non-profit. And in such environment frameworks (or even wrappers) like Duino are the golden solution. Remember that we are speaking about embedded systems not Google Search engine or Cellular operator billing system. The size here does matter.

Imagine a situation when you are a firmware developer at a company that develops custom electronic devices for IoT or something similar. And today your boss signed a contact with a new customer. And you need to develop a firmware for a board that will be ready the next monday. And it uses a chip you haven't ever heard and it is from Albania. All the specs are in Albanian :)

What will you use for development? Albanian analogue of LL? Or Arduino that is happily is available for the chip?

PS. I was a software developer, I was an IT-manager of a 3rd Top world financial structures, I know what are the high load systems and high availability systems. But we are speaking about embedded systems. F103RE costs twice cheaper than ATMEGA328 but it is better 100x times. Why I should spend my precious time for studying of very complicated architecture of STM32 (especially comparing to AVR)? Arduino (in terms of Duino) covers my demands in 90%. The remaining 10% can be closed diving into HAL or CMSIS.
kvv213
Posts: 38
Joined: Thu Dec 26, 2019 10:58 pm

Re: Correct usage of HAL functions in Arduino code

Post by kvv213 »

mrburnette wrote: Sat Jan 18, 2020 6:17 pm
kvv213 wrote: Sat Jan 18, 2020 7:46 am @mrburnette
Don't agree with your option, here are my thoughts:
...
At my current development I have to move from AVR platform (two different chips, not ATMEGA328) to STM32 (and here I had to switch to more advanced chip during development).

PS. Sorry for the flame :)
6. Arduino code is lighter for development and further supporting. The code is much easy reading and after a year or two after development is finished I don't need to break my brain trying to understand what exactly a concrete piece of code is doing.
This statement is simply incorrect ... if true, we would all be using BASIC.
What should be said is that all IDE's provide mechanisms for including programmer comments and that capability will easily provide for documentation needed in code sections.
BTW we still use basic and very widely and it fits the tasks where it is used. Hint: Visual Basic for Application. Is very powerful thing.

PS. I'd be glad to see C# at MCUs. With its garbage collector and simplicity when complex types are passed with a "link" and comply by value.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Correct usage of HAL functions in Arduino code

Post by mrburnette »

kvv213 wrote: Sat Jan 18, 2020 7:14 pm ...

... And it is great because me as a developer can use the framework that I know and I have access instantly to a such a great amount of libraries most of them work just perfectly without any additional tuning with STM32.
&
... Imagine a situation when you are a firmware developer at a company that develops custom electronic devices for IoT or something similar. And today your boss signed a contact with a new customer. And you need to develop a firmware for a board that will be ready the next monday. And it uses a chip you haven't ever heard and it is from Albania. All the specs are in Albanian :)

What will you use for development? Albanian analogue of LL? Or Arduino that is happily is available for the chip?
Ethically, I really need a reality-check! If new s/w failed is there any property or life a consequence? If only blinky-LED or maybe something arcane like counting visitors entering through a doorway, then maybe OK.

But if your real-world scenario really means your boss has insane expectations and is committing same to contracts, then another job you should find ASAP. Sooner or later calamity (mayhem) will catch your boss and they are likely to be sued, possibly you too. Engineers (professionals in their respective fields) must act responsibly.

Example of bad: Hacking a wheel-chair controller over the weekend using unfamiliar microcontroller and 3rd party Arduino libraries.

But, to answer your question, IF my name is on the software approval document, I would be using the uC manufacturer's products. Yes, I have walked away from lucrative jobs because I was expected to quietly act inappropriately.
PS. I was a software developer, I was an IT-manager of a 3rd Top world financial structures, I know what are the high load systems and high availability systems. But we are speaking about embedded systems.
Funny how people consider microcontrollers to be lowly little computers.
At what size does a computer become sophisticated enough to warrant standard management and engineering oversight?
When does liability for product design matter?
If one exits the "hobby programmer" world, when are they playing with the Big Boys and Girls? Like, is there some DMZ where rules do not apply between "hobby" and "commercial"?

I'm old, the world has changed, but in my university course curriculum over 50 years ago, there was a required Engineering Ethics class series: applicable to all engineering students.

I believe it is still improper to throw together a bunch of custom & 3rd party code, call it my own, and release same without a through test plan that includes requirement break & fix. (Plus a full license review on the 3rd party code.) Worst is if the software engineer releases it on an Arduino core they have virtually no hardware experience. Were such a programmer working for me, they would have been escorted by security to the nearest exit and no letter of recommendation would ever have been provided.

Engineering Big Iron or little postage-stamp sized circuit boards, basic business practices are applicable.

F103RE costs twice cheaper than ATMEGA328 but it is better 100x times.
But, it really is not totally about SRAM, gates, clock cycles: it is about selecting the best product for the requirements, understanding "economics" are always a concern.
Why I should spend my precious time for studying of very complicated architecture of STM32 (especially comparing to AVR)? Arduino (in terms of Duino) covers my demands in 90%. The remaining 10% can be closed diving into HAL or CMSIS.
Because when you "punch through" the Arduino language and interact with the hidden lower level(s) you take full responsibility for your actions. So far, you indicate you want to play at the Arduino levels but have someone else show you how to call the extra 10% you need to complete your project... Not sustainable, imho. Digging in and spending your precious time is far better than having to ask every time.

Ray
kvv213
Posts: 38
Joined: Thu Dec 26, 2019 10:58 pm

Re: Correct usage of HAL functions in Arduino code

Post by kvv213 »

mrburnette wrote: Sat Jan 18, 2020 10:10 pm
kvv213 wrote: Sat Jan 18, 2020 7:14 pm ...

... And it is great because me as a developer can use the framework that I know and I have access instantly to a such a great amount of libraries most of them work just perfectly without any additional tuning with STM32.
&
... Imagine a situation when you are a firmware developer at a company that develops custom electronic devices for IoT or something similar. And today your boss signed a contact with a new customer. And you need to develop a firmware for a board that will be ready the next monday. And it uses a chip you haven't ever heard and it is from Albania. All the specs are in Albanian :)

What will you use for development? Albanian analogue of LL? Or Arduino that is happily is available for the chip?
Why I should spend my precious time for studying of very complicated architecture of STM32 (especially comparing to AVR)? Arduino (in terms of Duino) covers my demands in 90%. The remaining 10% can be closed diving into HAL or CMSIS.
Because when you "punch through" the Arduino language and interact with the hidden lower level(s) you take full responsibility for your actions. So far, you indicate you want to play at the Arduino levels but have someone else show you how to call the extra 10% you need to complete your project... Not sustainable, imho. Digging in and spending your precious time is far better than having to ask every time.

Ray
I understand and support your opinion and point of view. Responsibility should be presented at any level, speaking about a controller of a wheel chair or a NASA spacecraft. The same with respect of authors rights for libraries etc. And at the same time you need to consider the time of implementation of a project and resources that you need to spend to reach the goals. The ages when yuo can spend years for engineering gone. Everything is processing faster and faster. If you are slow - you are out of your business. That is why developers use more and more high level of development. And that is why waterfall is used only at the construction yards. Agile, CI/CD etc conquered the world. And fast development and fast implementation is not a synonym to low quality.

In your case you should became a pro with this albanian chip. You should program it only at the lowest level because if not, there can be limitations at a higher level. And you should spend 3 human-months for developing of the ordered device. And this will be your last project at this company because this work has been done by an indian guy who spend one day with high-level approach (not forgetting about testing obviously). I have to repeat - fast development doesn't mean poor quality or disrespect of others IP.

Returning back to the software level, Arduino eco-system, STM32Duino and the rest. Ardunio was the most successful step to microelectronics for broad mass of people. Before it was a club where only very well educated engineers could work (with the full stack of moral responsibility and scheduled lunches). Arduino opened the door and it appeared that programming a tiny controller can be done with just a number of lines and closing the hassle with programmers, compilers, linkers and toolchains from a developer. This developer can focus on solving his particular business problem instead of digging in tons of datasheets. Solving his business problem not his technical ignorance. And this developer is happy with his ignorance. Because for him it doesn't matter how exactly a chip turn its light on with help or register A or register B.

I met a number of times when snobs claimed that the arduino was a homemade toy. But it's not. It is enough mature to help to solve problems. And Arduino now not an eco-system for AVR only. It works in the same way with a great amount of platforms. Learning once how to work with Arduino you can program a twenty platforms and three hundred of devices. As well as you use Java and expect that it will work everywhere where a JVM is. And you don't need to write or recompile your program for every platform. But, if you need something specific then you have to find a way how to reach this specific thing for your Java implementation. The same with STM32Duino or AVR Arduino, both of them have specific chip tuning in code. That is not good and not bad. That is.

In my case I'd like to use chip specific functions that are not implemented in Arduino because it is too chip specific (some of chips has this feature but some of them none). But I didn't know the way how to do this. With help of this forum now I understand how to do this. And asking is not a shame. Asking is a good habbit when you communicate with other people and people learn something new and help each other. Isn't it great? And DAC processing is not the 10% of the code that is not covered by Arduino :) BTW such kind of communication is helpful not only for the asker. @ag123 can prove that my asking were helping to fix mistakes in duino code. They were in but nobody indicated that because a question wasn't asked.

Repeating once more the core idea. Developing at Arduino (as high level with support of a number less amount of libraries) is faster than developing at low level playing with registers especially because 85% of the code or maybe even more is not connected directly with the chip peripherals at all. This is internal data processing and user communication.

PS. Time of OS/360 gone. May be it is not good, mey be it is not bad. But it is true. Even IBM and Microsoft changed their attitude to software development under pressure of Linux, Amazon, Google. People are changing, life is changing, world also is changing.
PSS. My original question wasn't sound like "What university should I attend in order to understand the best practise of programming mcu's". It was about a different thing. Anyway - peace!
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Correct usage of HAL functions in Arduino code

Post by mrburnette »

kvv213 wrote: Sun Jan 19, 2020 12:09 am ...
The ages when you can spend years for engineering gone. Everything is processing faster and faster. If you are slow - you are out of your business. That is why developers use more and more high level of development. And that is why waterfall is used only at the construction yards. Agile, CI/CD etc conquered the world. And fast development and fast implementation is not a synonym to low quality.
...
Returning back to the software level, Arduino eco-system, STM32Duino and the rest. Ardunio was the most successful step to microelectronics for broad mass of people.

Anyway - peace!
Peace 2. I am sure you must view my criticism of using Arduino as one of those "snobs" shouting 'toy, toy, toy...' but rather I stand on my soapbox and shout "gateway ecosystem." A fine learning tool, a wonderful product to incorporate programming logic into projects. According to Wikipedia,
The Arduino project started in 2005 as a program for students at the Interaction Design Institute Ivrea in Ivrea, Italy,[2] aiming to provide a low-cost and easy way for novices and professionals to create devices that interact with their environment using sensors and actuators. Common examples of such devices intended for beginner hobbyists include simple robots, thermostats and motion detectors.
I believe my old-school stance on using Arduino (IDE, libraries, cores) has rather annoyed you. It is obvious that your specific needs are driven by what I view as "shaky ground foundation"; however, other than what you have stated in this thread, I am ignorant of your quality process(es.)

My strong reactions come from years of working both Arduino.cc and the original STM32duino.com forums. Not applicable to you, many forum questions have a theme of creating projects around automobiles, hooking CAN-bus, motorcycle this-n-that, personal medical device modificatons, and numerous home projects involving AC main attachments. I am regretful if I was overly cautious of your uses of Arduino, but few forum readers actually read the entire thread to gain a context of the dialog.

If you and your boss and company lawyers have no concerns, then I will respect your selection as appropriate for your business case. While I believe the world is changing, I simply cannot recommend Arduino & 3rd party code as a proper foundation to build commercial products ...unless you are building boards to sell to Arduino users. The requirements, design, prototyping, programming, testing, assurance, production, and distribution periods are definitely shorter these days than in the past ... however that trend has been going on as long as electric computers have existed.

The trend that concerns me most is that a majority of makers that can blink a LED with an Arduino board considers themself a programmer. It is useless to attempt to cast their enthusiasm into the role of beginner, intermediate, and expert... the bulk of readers only read the 'expert' response.

Good wishes,

Ray
kvv213
Posts: 38
Joined: Thu Dec 26, 2019 10:58 pm

Re: Correct usage of HAL functions in Arduino code

Post by kvv213 »

mrburnette wrote: Sun Jan 19, 2020 3:28 am If you and your boss and company lawyers have no concerns, then I will respect your selection as appropriate for your business case. While I believe the world is changing, I simply cannot recommend Arduino & 3rd party code as a proper foundation to build commercial products ...unless you are building boards to sell to Arduino users. The requirements, design, prototyping, programming, testing, assurance, production, and distribution periods are definitely shorter these days than in the past ... however that trend has been going on as long as electric computers have existed.
I understood your position towards this even at the beginning. The "old" way of step-by-step processing (taks -> requirements -> design -> ...) was great. Modern days requires in the most cases a different approach. We have to use repetitive processes, we have to change requirements at development stage. But it doesn't mean that we don't have requirements, design stage, prototyping and the rest. It is done in a different way. And this soil is weak for shure but it is weak because it should be flexible.
Next, Arduino is a tool as well as HAL. It is also a tool. What is better - depends on the task. If I need to create a simple but very efficient automat (press button, read value, send value but do it as fast as possible) I'd prefer HAL because it is easier to do using it. If I need tons of communication with user and define wired algos of measurements readings then I prefer Arduino just because it is easier to do it with Arduino. And the final result will depend not on the used tool but on the the qualification of the developer who used it.
There are a lot of beginners at Arduino eco-system just because guys at Arduino did a great thing they reduced the entry-level. And it is fantastic. Many companies tried to do so but Arduino did it with all my respect. And they created a great framework that hides not necessary in the most cases stuff from the users. Instead of bury oneself into chip specification and finding some tricky ways how to overcame mistakes in this chip (and the more complex chip is the more likely it has mistakes in design, in its internal processing - remember mistakes that have Intel processors). They just can use a standard tool.

And a pro programmer can use Arduino framework too. He has reasons to do that for sure. He may be a pro programmer with diplomas and certificates but a novice with AVR or STM32 or ESP32. And you consider all of Arduino users as novices in everything and think that Arduino framework shouldn't be used at a commercial usage (with the same result of 3rd party libs) because novices uses it... Well this position is understood.

PS. Pros also can do strange things and not using Arduino. The latest hustle with Toyota firmwares https://www.edn.com/toyotas-killer-firm ... sequences/

The conclusion of the article is as you wrote before - the culture of development.
"It all starts with the engineering culture. If you have to fight to implement quality, or conversely, if others let you get away with shoddy work, quality cannot flourish. The culture must support proper peer review, documented rule enforcement, use of code-quality tools and metrics, etc."
But I'd like to add - car firmware is a very complex thing and a human can be lost in its complexity. If a tool can reduce this complexity it will reduce the probability of a human mistake.
tschrama
Posts: 4
Joined: Wed Sep 09, 2020 1:57 pm

Re: Correct usage of HAL functions in Arduino code

Post by tschrama »

Old thread, but very educative to read both your viewpoints. Thanks guys.
Post Reply

Return to “General discussion”