|
Does anyone use C++ for embedded? I've done C since the dawn of time, working in embedded systems at small companies for a while now. I'm starting to look at larger companies for a change, and it looks like they're much more into C++, which makes sense when you're working in larger teams with more power. How deep into C++ do embedded systems go? It sounds like elements of boost and, I assume, many other libraries are available. I've always heard templates are inherently unsafe in memory limited environments, but looking into it that might just apply to making things arguably worse in unstable memory environments, and writing C++ correctly (compared to C) has essentially the same execution parameters and is faster to write. Or does it really depend on the size of the system, so a Pixel runs C++ and a fit bit runs essentially C?
|
# ¿ May 11, 2022 00:59 |
|
|
# ¿ May 3, 2024 02:17 |
|
Thanks for the answers, this all makes a ton of sense. Foxfire_ posted:(I don't know what you mean by "unstable memory environment") It's not a huge thing for me, but I've heard that C++ is not appreciated in high radiation environments ranging including space and some medical/aerospace. I've heard a few rationales, one being that a memory error that changes the location of a function pointer is the worst type of disaster, and C++ uses function pointers in hidden ways, like virtual functions. I had assumed that templates would also do some kind of dynamic typing, because that's how the code makes it look, but generating extra functions makes more sense.
|
# ¿ May 11, 2022 13:25 |
|
Rust is a great language, and I think getting into it made me a better programmer. But I had to drop it for C++ when I realized it was really not going to be used in a job. Folks I talk to agree that it would be great for someone else to move their giant code base to Rust, but nobody wants to be that someone else
|
# ¿ May 11, 2022 18:31 |
|
qsvui posted:I've worked on devices sent into space that were all running on C++. Is there any data backing up this rationale? I'd really like to read it because right now, this just sounds like hand waving. I'm looking for real data on it too, and not finding anything. I think it's just ancient tradition.
|
# ¿ May 13, 2022 02:09 |
|
Does anyone have a good recommendation for writing optimized C code? I work on microcontrollers, and we're working on efficiency vs clarity. My memory on optimization, which seems to be true from testing, is that C will optimize code in a file but not really code between files. So, if you're calling a function using a constant input, the call will only be optimized if it is inline. This gets frustrating when we're calling vendor provided DMA setup code, so the way to speed things up seems to be to copy the vendor code and strip out everything that doesn't apply because the optimizer doesn't see that we're always running the same way, just with 2 parameters out of 10 being different.
|
# ¿ Aug 7, 2022 00:35 |
|
pseudorandom name posted:Modern C compilers support link-time optimization. The DMA setup happens in an interrupt and seems to be taking a surprisingly long time, so it would definitely be nice to speed up. I'll look into the link-time optimization, that may be the keyword I needed. ExcessBLarg! posted:I'd say the problem is that the vendor is providing an omnibus function with 10 parameters. If they're not breaking the interface down into something more digestible then you may just have to. Yeah, this is definitely part of the problem. DMAs are such flexible features that its hard to make an interface that is simple, efficient, and flexible.
|
# ¿ Aug 7, 2022 04:59 |
|
More descriptive variable names and initializing values are important. Couple of other small things that matter for larger, longer lived programs: - You should indent the putchar line since it follows the if statement. The indents make the execution flow easier to read, and it is just a universal standard. I prefer to also always have braces, even for one line if statements, because it makes the code clearer and easier to expand. - c and pc are ints, seems like they should be char, I assume that's the type that get_char returns.
|
# ¿ Jan 1, 2023 19:28 |
|
There are situations where it's a nice note for how many bytes an output parameter will return, likecode posted:bool read_2_bytes(uint8_t bytes[2]);
|
# ¿ Jan 10, 2023 15:14 |
|
Does internet of mud have a lot of bugs, still, or are frogs the bigger problem?
|
# ¿ Feb 3, 2023 14:33 |
|
Someone I know was working with a professor who wrote their own FFT function in Python. It had an error, and he now uses that as proof that folks should just use MatLab. Test your poo poo or everyone suffers.
|
# ¿ Feb 19, 2023 19:16 |
|
roomforthetuna posted:If you write it in python it's called a slow fourier transform. The poo poo I need to test ... is my own posts
|
# ¿ Feb 20, 2023 00:32 |
|
I have some time to work on or find some tools to help debug our embedded ARM code. The code is all base metal, no OS, very linked to communicating with external sensors, so we have SWV debug traces, print statements, and stepping through code. We use the STM32 with their Eclipse based STM32CubeIDE, and I've been getting a lot of use out of the SWV logs that let us monitor specific registers and when they were accessed, it lets us insert ID values into a volatile variable and we can see when certain points in the code were hit, which is a huge help for checking out function execution time, especially when it involves interfacing with the external hardware. I'd like some tools to make it easier to insert these checkpoints into different spots in the code, and then process the debug log and make it easier to read what is going on instead of needing to remember the 0x0100 is when we entered the GPIO7 interrupt, and 0x0101 is when we exited. My first instinct is to write something up in Python, but I feel like this must be a common issue and I'm reinventing the wheel. I know there are some full execution trace tools available through Segger, but I think the advanced features all require more than the one SWD line we're using. My plan right now is to: - Write up a Python script that will tokenize C (probably using pycparser?) to help identify where the volatile variables are set, what values they use, and basic housekeeping like making sure values are not repeated. Eventually maybe this can help add or enable/disable the debug signals - Either get an OpenOCD-Python interface to our debugger working, or copy the debug data from the window in the IDE and paste it into a file, parse the output data with Python. The core need is I want to see interrupts and function call durations. I think the info is all available in the ARM debug interface but I feel like there's got to be a better tool for accessing this data. Any advice?
|
# ¿ Aug 12, 2023 17:25 |
|
yippee cahier posted:Check out https://orbcode.org/orbuculum/ and their blog for examples. I haven’t personally used it, but it looks cool and is on my list when I next need to do some deep introspection.
|
# ¿ Aug 12, 2023 20:20 |
|
Very inspired by the planning committee that designed the C language that they included this intuitive syntax for such common situations.
|
# ¿ Nov 1, 2023 20:27 |
|
Plorkyeran posted:Are you suggesting that Kernigham and Ritchie made some bad decisions when creating C? The post above you did not end in a semicolon, so I am reporting this post; I am a C compiler;
|
# ¿ Nov 1, 2023 22:09 |
|
There is a non zero chance I am getting ghosted because I added brackets to an if statement in a coding exercise. The point here is people who don't use brackets are cowards at heart.
|
# ¿ Nov 3, 2023 21:41 |
|
Sweeper posted:If true you wouldn’t want to work there anyway
|
# ¿ Nov 3, 2023 23:00 |
|
PDP-1 posted:Weird question: does the first function called in a C++ program absolutely have to be called main, or can we rename it to something else?
|
# ¿ Dec 13, 2023 03:53 |
|
|
# ¿ May 3, 2024 02:17 |
|
That question got me thinking: Do colleges today have assignments along the lines of "Find available libraries that implement X, discuss some details about how to use them and conceptually how they work"? The idea being that sometimes you need to write it, sometimes you need to find it, and focusing too much on either part is dangerous.
|
# ¿ Mar 23, 2024 19:54 |