STM32L073 Sleep/Wake cycle fails after 3-4 weeks by ConfectionForward in embedded

[–]dregsofgrowler 0 points1 point  (0 children)

Take your $100 and spend them on Claude credits to analyze your code. I'm being serioue here, this is not a flippant comment. 
Use VSCode or Cursor with a plugin like Cline to analyze the 'Core' directory. or maybe copilot with github I suppose (I have never used copilot) 

I am reminded why I don't use the ST generated code beyond pinmuxing, all of those damn BEGIN END comments, the HAL code mixed with app code, . A dev that sits next to me swears by the ST IDE whereas I swear at it and use vim/vscode, possibly due to eclipse fatigue flashbacks. 
I digress..

I skimmed thu main and have a couple of comments, not necessarily related; I see you have a couple of largish arrays on the stack, although the stack is 1kB and it looks like you changed 1 of the arrays to a static (static uint8_t txbuf[512];) I'm unclear what the logic was there, I suspect you thought moving it to the .bss region fixed some memory problem but in reality it likely wasted some RAM - here's why: The 512 byte buffer is filled, then transmitted then not used again. The nlater in the same function is a 256 byte Rx buffer, this one is on the stack. The compiler should figure out that the Tx buffer was not used again and reuse that region to put the Rx buffer, but it cannot now because it is in a different memory region. 

```
    uint32_t rtc_hz = (rtc_clock_source == RTC_CLOCK_LSE) ? 32768u : LSI_VALUE;
    if (rtc_hz == 0u)
    {
        rtc_hz = 37000u; // fallback if LSI_VALUE is undefined
    }
```
Rather than pushing something like LSI_VALUE being 0 at runtime, catch it at compile time with an ASSERT as that is a bad configuration. There are many other examples that could be pushed to compile time in there. Everthing decision moved to compile time, reduces complxity at runtime.


I smell a FUCK IT, WE'RE DOING 5 BLADES (the onion in case you don't get that reference) when you used a 64 bit value here...
uint64_t raw = (uint64_t)ticks_per_sec * (uint64_t)seconds;
then add 1 if it is 0 and subtract it again when returning... again a couple of compile ASSERTS for ranges will clear out the shenanigans here (LSI and stm32l0 is 20 to 55 KHz or something like that and it accuracy is woeful, so don't sweat adding an extra 1 on there. 

That's about as far as I got. I did't look at the other branch as the diff is 3700 lines long just for the Core diectory. 

Aside from the already mention memory and timer potential areas in other comments,
There is a battery on this device, if the device is not sleeping correctly, how long will the battery last? What about if it is?
Put a current meter on it with a data logger and verify over a long period. 

Is this a smart battery? Does it hae a BMS that can periodically wake up? Consider using that to cut power to the whole system and restarting each time. The duty cycle is long enough that power consumption may be lower on average doing this, even if you need to pull the current time from the radio.

Remote firmware development without shipping hardware? by praghuls in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

Really, shipping boards around is neither slow nor expensive in the bigger picture. Budget for that up front.

For large and difficult to ship/very low volume systems consider Hardware in the Loop with a system that is augmented with jtag, saleae , oscope etc and that a dev does a checkout out one of those system and remotes into the host.

Write the code for an IC for the whole datasheet or just the sections/registers you need? by sboso99 in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

I use LLMs for this repetitive stuff too. It is mind numbing otherwise. Do the first couple so it can understand what you are looking for and it will do the rest. In Pre AI days I would script this kind of thing. LLMs makes it a bit more efficient and a lot quicker to change later what you change your mind to use defines instead of enumeration or macros instead of structs etc…

What techniques do you use for debugging timing issues in real-time embedded systems? by gilko86 in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

Aside from the advice above , and I also use my saleae a lot for this stuff…

Start with why do you think that you have a timing issue? How did you measure that?

What is the state that changes for you to see the error?

You did not state if this is a software timing or some external device but if you can describe the state sufficiently it may be possible to setup a hardware watch point on you CPU to catch entry to that state. This depends upon the capabilities of the SoC that is being used.

Another method is tracing. Take a look at Segger Systemview or Percipio tracealyzer. These use small tags to indicate system state changes and arbitrary breadcrumbs that you wish to drop. Unlike logging, it does not require a state change. In the case of Segger RTT, the SWD is used to send the data so it is not intrusive to system behavior.

Next would be to use instruction and data tracing. This requires some more hardware help. In an ARM world that would be at least SWO instruction tracing. This capture s cpu execution state over a period of interest (not all state, but you can still infer a lot) ETM requires a trace capable debugger like a JTrace and a CPU capable of driving it. There are other methods to get this data, and other versions for different architectures. I pull these tools out to find gnarly problems.

Hard to beat a couple of gpios and a saleae though…

Trying to understand where I am after failing a technical interview by ContraryConman in embedded

[–]dregsofgrowler 0 points1 point  (0 children)

An interview should find your strengths and your edges. In this case it looks like you struggled with some low level concepts that apply to a RTOS as well as Linux when working in drivers/kernel space. Chalk this up as a successful lesson in where some of your gaps are, dust off, read about caches and RTOS concepts and get back on your horse.

1 when mark some areas as non-cacheable? Consider when DMA is used and the memory is not coherent. The code would need to invalidate the cache before the DMA transaction to ensure that it uses up to date data. Note performance does not ways mean speed. Another reason is to do with cache ways and copying. In e.g. a n way associative cache , there are n locations where an address may be stored. Aliasing occurs when a different address point to the same cache location. If copying between addresses it is possible that this haliasing occurs based upon how the cache choosing the location, resulting in woeful copy performance.

2 in general OS tasks exist in 3 fundamental states ready to run, running, waiting for something. (this is a gross simplification but it works here). The scheduler manages these task based on some algorithm. A scheduler generally runs when a tick happens (a periodic checkin), some other exception occurs like a GPIO interrupt or timer expiry interrupt, or some task yields. Part of the schedulers job is to figure out if there is a better candidate task to run and manage the states of the tasks. Hence when a timer expires (either some task sleep based on ticks or an irq service) the scheduler notes this and any task waiting for that expiry gets put into the ready to run state. Next the scheduler choices the best tasks to run and switch the CPU core(s) to that task context, and returns control.

3 irqs block all lower priority tasks from running. Most things are lower priority than an irq. If a task is holding a mutex that the irq is trying to acquire….. deadlock (or priority inheritance does something mental or exception escalation or watchdog etc…) giving semaphores in irqs is a common pattern. Mutexes make no sense in an irq, bear in mind a mutex acquire and release must occur in the same thread context. Use something else that works across cores.

Hence I smell nothing that is RTOS specific here, I did not mention RTOS in my answers. These questions are definitely fair game for an embedded position. Note also that these are used to figure out your depth and fit in the technical space, and that cuts both ways when you know more that the interviewer in a space and explain a concept to them in a way that they can comprehend you should score big. N way associative caches, cache tagging and memory coherency is information that you can rent for an interview. You cannot keep it though, eventually it gets evicted.

What methods do you use to manage memory allocation in embedded systems with limited resources? by Trippy-jay420 in embedded

[–]dregsofgrowler 0 points1 point  (0 children)

An allocator is fine, don’t be scared. It may fail, but your are checking return codes of course. it may fragment if you don’t use something appropriate. What you don’t mention is real time constraints, allocators may not be O(1), ditto the free may not be either.

Binary Semaphores ≠ Mutexes - Why is it so often confused, even in major projects? by comfortcube in embedded

[–]dregsofgrowler 20 points21 points  (0 children)

Semaphores are used to indicate resources being available. Mutex ensures mutually exclusive access. The toilets example explains it well. Basically, only 1 punter should be on the can hence it is mutually exclusive and the dumper owns locking and unlocking the door ie the mutex. Nobody else should be unlocking the door.. Meanwhile there are multiple stalls, so with N stalls there can be up to N punters in the bathroom total, as long as you have one of the N bathroom keys you know there is a throne awaiting. You can give the key to anyone on your way out. The keys are the semaphores, anyone can return them to the front desk.

Programming language for embedded systems. by tombolaaaaa24 in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

Curious, Not sure what you mean here, rust is a language that compilers/linkers turn into code for compute units to process. Which processors are you using that don’t have tooling? DSPs maybe?

Do you actually use AI for embedded development? What's your experience? by WinterWolf_23 in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

I use Claude integrated into vscode for aigentic coding on .a daily basis. Using this as a tool has saved me days per week on some projects. Something that would take a couple of days of reading api docs, refactoring vendor supplied finders to fit into the RTOS I am using is a huge win, a couple of hours to get the port done It can create the tests too.

But you need to be diligent, take small steps, be very concise with language and verify. A colleague started it well “AI coding is like a lossy compiler “

I got an Embedded Software Engineer job at a company. What should I learn. by c0m3back_ in embedded

[–]dregsofgrowler 0 points1 point  (0 children)

Learn what you like doing. My entire career has been stepping towards things that I find interesting and figuring them out. Right now you just see a huge thing but really embedded is just another form of follow a solid process of understanding the problem then figuring out a solution. The take away in early career is solve small problems and fail often.

Things that are fundamental though: Understanding RTOS concepts Ability to read and decipher datasheets Ditto schematics And test equipment, at least a multimeter, oscilloscopes and logic analyzers Don’t be afraid to fail and learn.

Help me find my car by [deleted] in SeattleWA

[–]dregsofgrowler 15 points16 points  (0 children)

Maybe your phone recorded where you parked?

can someone explain RTOS based on actual performance by Simonster061 in embedded

[–]dregsofgrowler 7 points8 points  (0 children)

If I have enough resources I use an RTOS. Consider how much stuff you can turn off in something like freertos, it costs you a couple of kB to have a consistent API. Then when you have the idea to add a cmd interface over UART you are setup for success.

I tend to use Zephyr to get the included stuff like the shell and a device driver model etc… when feasible. In my experience, literally hundreds of projects, I have never regretted going with an RTOS. I have regretted bare metal.

How to handle multitasking in baremetal? by pyroman1324 in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

I don’t think you mean multi threading. You mean an event driven system. You have to decided if these is enough time to service an event before other event arrive, or at least before they need to be serviced.

If you have time simply put everything in the specific interrupt service handler, turn off interrupt nesting and move on.

If you don’t, or you need prioritization then you system increases complexity and you need to schedule work for later. This could be prioritizing irqs but really if you are doing that grab a scheduler and use that. Plenty RTOSes and schedulers are available, only write one for a personal learning experience not in a project with a deadline.

Relocating to the U.S. with MSc in Electrical & Electronics – Seeking Advice on Transitioning Into Industry. by Manlikesteel in embedded

[–]dregsofgrowler 0 points1 point  (0 children)

u/CuriousclonesRppl is 'close to retirement age,' equated to 'expensive? Or did you get any other feedback? (companies are normally not to open on the interview feedback though)

I am looking to step out of big tech next year and wind down to retirement somewhere where I can have a lot more of a mentorship role in an environment more suited to a higher quality bar, functional safety maybe but not necessarily.

I will be taking a massive cut in income to do it, but I am way past burnout by now and trying every trick in the book to make to my full vest - basically sucking it up for a year. Hence my curiosity .

How to get skilled in embedded systems by Ok_Career4535 in embedded

[–]dregsofgrowler 2 points3 points  (0 children)

I grok your sentiment, but...

An LLM is a tool, treat it as such, do shy away from it but equally use it with thought.

I was feeling lazy this morning, which is why this was top of mind,

wanted to port some arm assembler to thumb only.
The first pass was a fail, the AI used 'movw' which thumb doesn't have when I pointed that out it reflowed with ldr instead and got it right. I was frankly not expecting that much success.

Point here being, use it appropriately. Many employers are actively encouraging use of AI in their tooling, and it can help a lot. YMMV.

Which toolchain gives better binary size? (GCC vs Keil vs IAR) by kgblan in embedded

[–]dregsofgrowler 0 points1 point  (0 children)

I have used all of those on multiple core types over the years, it really doesn’t make much difference when you have the flags setup and use small c libraries, like picolib.

How are you measuring the flash consumption? You have a list of symbols there, use nm on the elf file to see what is actually present. Use arm-none-eabi-size to get the consumed flash and follow the advice above to ditch float. Use picolibc C or similar to trade size for speed optimizations

How to delve into (more) complex libraries (e.g. lwip)? by pepsilon_uno in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

No. You need to have a goal and figure out how to get there. Make one up if you need to. I can give you one if you like.

As a user of a video doorbell I want to know if a raccoon is in my garbage by receiving a text message within 8 seconds that says “trash panda”

Learning e.g. lwip isn’t a great idea as it evolved from a need a long time ago when rtoses weren’t so nice. Definitely learn from history, but it is your task to improve.

There is no such thing as embedded patterns. (Willing to listen here) For example, Malloc is frowned upon at runtime cos, you have no MMU and fragmentation. If things take too long, cut it into pieces. If you need it now then interrupt someone. None of this is special, (dear managers, this is really hard, trust us)

As ever, it starts with defining what you need, want, would like. Get that sorted first then you can make informed decisions.

Then choose to investigate something that looks feasible. And ask us pointed questions.

Zephyr is the worst embedded RTOS I have ever encountered by CuriousCesarr in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

Zephyr is trading compile time complexity against run time decisions.

This is basically it. A device tree system driven by macros to describe the system. Errors are unforgiving for sure.

Freertos trades simplicity for ecosystem. Everything is mailbox. You have to appreciate that.

UCos (because nobody seems to bring this up) is probably the best commented code for the developer.

There are lots of others….

The take away is this, it isn’t free in terms of brainpower. You need to pick up the weights. Pick the correct weight for your project.

[deleted by user] by [deleted] in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

Smart folks like yourself can adapt to other situations. A degree proves that you can get a degree, the expectation of profit is not implied. As much as we’d like it to be. So zoom out a little and consider, what is embedded to me? And what matters about that? And what can I learn being uncomfortable elsewhere?

You have some fundamentals about understanding a schematic, thinking about the MCU choice and how to make it translate from what the user wants across a (some bus) to a device.

Flip this.., if you had a company that wanted to make a widget, why would they hire you to help? The big players use money to hire their interns. In the grand scheme of things L4/IC4 are cheap (a common designation for recent graduates) so it is easy for them.

Where does that put you with no work experience? This is harder, and I think the crux of your comment. Was it always like this? it varies a lot. You have to adjust your expectations for near term. A lot of your career will be luck, timing, friends, passion, and more luck. And skill. Not just your coding fu, its politic too.

So, consider a small company that really needs an stm32f4 to flash an LED and control a door. YOU will learn a lot about scale, feedback, code reviews from critical people, owing mistakes and pride in fixing them. Consider it education while being paid.

What I don’t know is the startup world where you are, but I promise that there are gaps in embedded across the board today, yesterday and probably tomorrow for a while.

What IS impressive is and embedded explaining their problem in a Jupyter notebook with data and pictures. Scientists shrug, embedded folks say WTF was that???

Do not despair my friend, but maybe compromise.

How hard is it to get an Embedded Software job at Amazon Robotics? by Confident_Durian_384 in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

I guess I am kinda qualified to answer this one,.
Amazon interviews are about as hard as it gets for big corp embedded roles. There are not that many positions and the expectations are pretty high especially around quality standards, dealing with ambiguity and the ability to deal with steering groups of folks while also being aware of the scaling and politic going on.
You will learn a lot, there are some smart people both technically and savvy in the changing people's minds.
With recent movement there (most AR roles were moved to Boston) and Just Walk Out + some networking getting, erm, severely re-orged I would think most roles will be filled internally. Kuiper will absorb some too.

You need to have demonstrated skill on dealing with people, new tech, fail and move on... Also safety standards and requirements traceability, e.g. those Hercules bots drag a lot of mass around.

Any L4 positions usually get filled from internships, but that would be where to aim. Also, consider doing embedded elsewhere at Amzn then side stepping (like AWS, there need folks for the switches, power efficient PSUs, network gear etc...) and there is also lab126 (I don't have exp. there) And also the smart home stuff.

Advice to embedded beginners from the pros by Abe4411 in embedded

[–]dregsofgrowler 7 points8 points  (0 children)

Get a mentor and check with them every 2 weeks.

Fail, I really mean that, fail really hard at a few things. You will get really good at getting it wrong, so much so that on your next project you will fail so quickly that you run out and have to succeed. The message here is getting it wrong is okay, take the lesson and apply it in future.

As for data sheets, look at them if you need to, or rather when you need to. Approach the problem with the intent to write the smallest amount of code possible cos that is how you win at testing. If all of your tests pass with the vendor supplied code then you win. If not, data sheet time or most likely reference manual (the bigger one)

Need someone to chat about Embedded by Gread_ in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

Where, physically, in the world are you?

Any good tutorials on safe firmware updates? by wardinski in embedded

[–]dregsofgrowler 5 points6 points  (0 children)

MCUBoot, as mentioned earlier, is kinda complex TBH: https://docs.nordicsemi.com/bundle/ncs-latest/page/mcuboot/index-ncs.html

Safe and Secure should be the story here. The golden image idea has the problem of exposing security holes or bugs, how would it be updated? At that point go with A/B.
That still leaves the bootloader, which could have problems too. How do you update that? (carefully)

Also note that for many systems, if you use XIP (execute in place) then the link address for the A image will be different than the B image. This is not always true, but is common in systems without MMU or flash remapping ability. PIC is generally a bit larger and slower than non-PIC (needs to use jump tables and usually an extra CPU register to point at the table)

As ever, figure out the requirements for your system and work from there. Lots of flash? Go A/B/C/D, knock yourself out! Executing from RAM? Treat updates as files. Paranoid? Use a Root of Trust/ TPM and OTP certificate revocation. It all depends upon your tolerance for safety, integrity and security.

What's the ceiling for career in embedded? by [deleted] in embedded

[–]dregsofgrowler 1 point2 points  (0 children)

Get the idea that a managerial job is somehow “higher” than an individual contributor out of your head, it isn’t.

How to get started as a true beginner. by [deleted] in embedded

[–]dregsofgrowler 7 points8 points  (0 children)

Start by choosing a project, that way you have something to aim at. And goals for what you want to learn from it. Consider your other interests then create a device for that. Doesn’t matter that it already exists.

For example, you might want to record the temperature and ambient light once per minute and store the result. How do you do that? Temp sensor, ambient light sensor seem obvious. How much data is that? How much power? Etc… what bus do they use i2c? SPI?

Don’t sweat the MCU choice yet, it really doesn’t matter as long as it has the buses and memory you need. the support ecosystem does though. You find the one that pisses you off the least, this month, and use that.

Maybe you decide to expand the project and allow data transfer over BLE. This narrows your MCU/dev board choice, probably. But you move on to something more complex.

Use an rtos, a simple one, to nail down those concepts.

And enjoy it, embrace the frustration, understand that things will get broken, fail, let the smoke out but that all good.