Arduino code sources?

+1
Reply to
Cursitor Doom
Loading thread data ...

I've not used it yet, and have a report of endian problems, and perhaps others. Please report issues if you find them :). But I'm proud of the documentation and testing structure (it took several days studying the data sheet to design!), and will hopefully get to test it myself soon.

Clifford Heath

Reply to
Clifford Heath

You should see his soldering!

Reply to
Cursitor Doom

That's actually an excellent tip. I must try to remember that for future use.

-- This message may be freely reproduced without limit or charge only via the Usenet protocol. Reproduction in whole or part through other protocols, whether for profit or not, is conditional upon a charge of GBP10.00 per reproduction. Publication in this manner via non-Usenet protocols constitutes acceptance of this condition.

Reply to
Cursitor Doom

there are plug-ins for other IDEs you can develop Arduino code with that will show you the optimized asm your C/C++ code generates for AVR, ARM, MSP430, MIPS, etc on the fly, in real-time as you type

Reply to
bitrex

Or for longer programs close enough to real-time. Modern C/C++ compiler running on a core i-something class processor are perfectly capable of compiling and optimizing a 5,000 or 10,000 line small to medium-size uP project codebase in under a second or two.

You can look thru the steps of the optimization process as it parses the code down and optimizes it thru multiple passes, in 2019 "multi-pass compilation" often means dozens or hundreds of passes.

Reply to
bitrex

I've just hand-built a Makefile for a client's SAMD Arduino project that allows it to be compiled inside an Atmel Studio project so we can debug USB re-enumeration issues. Contrary to what it says on the tin, Atmel Studio cannot create such a Makefile for an Arduino project automatically - it doesn't even get close, I tried.

I have no idea why the original author thought it was reasonable to attempt to develop a 10KLOC commercial product using Arduino. Least of all a SAMD product - the BOSSA code loader is the biggest load of s**te I've come across in years, and the author doesn't seem to even care, so I'll name-and-shame him:

Clifford Heath.

Reply to
Clifford Heath

I would never try to develop a commercial product that size within the Arduino IDE/environment, hell no. It's fine for little jobs and proofs-of-concept.

Large projects I write, prototype and debug all the algorithms and classes and components, in portable C++, as if I'm writing an application for a desktop x86 machine.

Then port it over. I often use tools like Compiler Explorer to look at the generated ASM for the AVR or ARM for some functional component if I'm unsure of what kind of code will be generated.

Most code even for uPs is processor-agnostic and will comprise only a tiny fraction of the execution time of a given program so there's no point to try to heavily optimize it for execution speed. The uP-specific or Arduino-specific stuff like manipulating pins and reading/writing from the serial port, and optimizing those parts if necessary, is the last part I work on, once everything else is debugged, checked for errors by a static analyzer (as configured by default the Arduino IDE SUCKS at reporting potentially catastrophic mistakes), and working as near perfect as possible in a test-driven development situation. And avr-gcc and arm-gcc tend to generate very compact code, even from template-heavy C++11.

Obviously keeping in mind the resource limitations of the processor it will end up running on. that's not very hard to do. You can't just use dynamically-allocated memory except in certain cases, but sometimes it's just fine and helpful. Dynamically allocating a small object that's destroyed/deleted at the end of a function call, where ownership of the resource-holding pointer isn't transferred anywhere else, isn't really any more dangerous than a stack allocation even on an 8 bit machine.

A use case is iterators that allow you to iterate over lists of things of arbitrary size without having to hardcode the list size into the function call. The dynamically allocated object within a function call is the Iterator object. C++ doesn't support variable-length arrays. It's good programming practice to never touch raw storage like C-style arrays when you just need to look at what is contained, and in C++ it's very straightforward to write an iterable List class that can hold lists of arbitrary stuff (use a template) of arbitrary size and is very efficient, even on 8 bit.

Reply to
bitrex

So would I, but that would cover less than a third of the code in this case, since it's all about hardware access (I2S links to feed audio to a

3G modem, etc) and that's where the bugs are. It probably should have better device driver testing, but it is what it is, not by my choice.

Absolutely no need for that in this case.

Yes, exactly.

Plenty of grunt here. This processor was chosen for its peripherals.

Please, save your programming advice for someone who needs it :) The OP is trying to climb the hill of his first embedded C. More advanced lessons can come later, but I wanted him to know that Arduino has definite downsides! Atmel Studio is a much better option.

Clifford Heath.

Reply to
Clifford Heath

A "modern C++" feature that would be very helpful for uP based projects is a smart pointer. You can't really do dynamic memory allocation/de-allocation at will on a processor with 2k of RAM. But you still often need to hold and transfer resources around.

What's a pointer? A pointer holds the address of a _resource_. The ownership status of a resource must always be well-defined. A "unique pointer" object defines ownership of a resource - the object that holds that unique pointer object, which wraps a dumb pointer, "owns" that resource. Unique pointers cant be copied, only moved. If an object holds a unique pointer it cannot be copied, either, or else two owners would exist. Nuh uh.

Sometimes other code needs to hold a reference to a resource. Some logic would like to see what a data buffer contains, but shouldn't "own" the buffer. So there can be an "observer pointer". It can only be used for read-only access to the resource but cannot modify the actual resource's state in any way. The observer container can be both copied and moved. They can be passed to functions, even plain-C functions, taking a const-qualified raw pointer seamlessly but cannot be passed to functions taking a non-const qualified pointer as that would allow write access to the resource.

An advantage of C++ is you can write code to define rule-enforcing data structures like that to, by design, self-enforce safer further design decisions. Along the same lines raw data types like "int" should never be used and passed around to represent something like dollars in a bank account, or velocity. They should be wrapped in an object that enforces assumptions like class Dollars, or class Velocity. A function that computes an output velocity from an input velocity should return a Velocity and take a Velocity argument e.g. Velocity calc_new_velocity(Velocity v) not int calc_new_velocity(int v).

And no, this almost never "bloats the code" if done intelligently the compiler and optimizer will figure out that in almost all cases it can compute a velocity under the hood by just manipulating the raw ints like it would when compiling C. all the boilerplate is mostly for your benefit so it can warn you if you try to do something stupid.

Reply to
bitrex

"Arduino" is just an API. The Arduino-provided IDE sux balls. But you can use the processor-specific API with an IDE of your choice though, with a little work, just so you can use e.g. digitalWrite, analogRead, Serial.begin etc. and not have to muck with setting up all the registers and interrupts yourself. For many (even "professional") projects they're fine. So maybe digitalWrite sometimes takes 100 clock cycles. BFD. Fix it if/when you know you need to flip the pins faster.

Reply to
bitrex

BTW the purpose of the mini-rant isn't to be super-useful advice to a total beginner, but I think it's worth thinking about when beginning any endeavor to consider "where do I want to be in two years time." I think it's worth thinking about how "real code" is written in the 21st century, or should be, and ideally things will go well and one won't want to stay in the sandbox forever.

A lot of Arduino-environment code is bad. but the tools are available so it doesn't have to be that way, so I think it's worth thinking about how to be at a place where one is writing _good_ code in two years time simultaneously, code that can earn money, and not just rote-learning the syntax. and I think that also means learning a bit about software _engineering_ practices simultaneously and not just code-writing.

Reply to
bitrex

The anti-pattern is formally called "blog-driven development."

Reply to
bitrex

The only thing scarier than hardware engineers designing software is software engineers designing hardware. Leave designing hardware to physicists. Then the hardware engineers will be free to write software and the software engineers can do the physics.

Reply to
bitrex

Atmel Studio has a much better and more complete API (the ASF), much better implemented. It's a no-contest if you're on a supported MCU.

Reply to
Clifford Heath

On a sunny day (Mon, 3 Jun 2019 00:00:56 -0400) it happened bitrex wrote in :

Although I agree with many other things you tweeted here, the problem these days, and has perhaps always been, is draw lines between fields. I hove worked in many different fields from high power to physics to medical to broadcast to repair to hardware design software design, documentation writing, so much more translation, always curious about the next field. Applying what you learned in one field to the other is where the real strength is, invention. We need more of that, Not the limited responsibility closed horizons do what the boss says servitude that for example did lead to that recent Boeing disaster. There ARE no separation lines, those only exist in illusion.

Reply to
Jan Panteltje

And peripherals / shields. And ecosystem including libraries and users. (And operating system)

Beginners use arduino to glue bits together in simple ways. It is /sufficient/ for that.

Apart from that, I'm not going to defend arduinos.

Reply to
Tom Gardner

One of the games I play in pub conversations is to try to get people to come up with a simple definition of what's hardware and what's software. Almost all fail around the boundary, because they have insufficient understanding of both.

One of the best engineers I knew had taken a 1 year MSc conversion course after his first degree in biochemistry.

He was an exception, not least because two of his ancestors had Nobel prizes.

Reply to
Tom Gardner

... and can be seen in all walks of software and hardware :(

Reply to
Tom Gardner

Tom Gardner wrote in news:Ze4JE.561232$ snipped-for-privacy@fx38.am:

Get REAL work done...

Reply to
DecadentLinuxUserNumeroUno

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.