Skip to content

Tags

#c

Posts tagged #c on Dynamo Geeks: 17 posts from the community, most useful first.

17 posts

Posts tagged #c

  1. Question

    IWDG vs WWDG on STM32: which one you actually use in production, and how do you feed it?

    Discussion in our team this week, I want outside opinions. Today: IWDG only, ~100 ms timeout, kicked from a low priority FreeRTOS task. Colleague says this is useless, because a stuck high priority task will block the low priority one and we reset, fine, but a runaway loop that still lets the kicking task run will never reset. He wants WWDG with a window, so kicking too early also resets. Constraints: motor control…

    Karthikeyan S10likes6comments

  2. Question

    Recursion confusion: why does my function print the numbers in reverse order?

    Assalam o Alaikum all. I am a 2nd year CS student. I am having a confusion in recursion. Here is my code: #include <stdio.h> void print(int n) { if (n == 0) return; print(n - 1); printf("%d ", n); } int main() { print(5); return 0; } I expected 5 4 3 2 1 but it prints 1 2 3 4 5 . When I move the printf above the recursive call, it prints 5 4 3 2 1 . Why is the position of one line changing the whole order? Our…

    Zainab Malik7likes8comments

  3. Question

    do i actually need to learn C first?? frank keeps telling me to 😭

    ok so im 16, been making minecraft mods in java for like a year and i lowkey love it. but every time i post something frank_cpp98 replies "learn C first, kid" and now im scared im doing it wrong lol questions (sorry theres a lot) do i need C to get a job later or is java fine should i learn c++ instead since its closer to java?? will AI take all the jobs before i graduate anyway (fr asking) i just put linux on my…

    Max Petrosyan12likes10comments

  4. Experience

    The BOR level nobody set: why our controllers reset when the farmer's motor starts

    Field returns from farms in Tiruppur district. Controllers resetting at random, and some of them came back with the settings corrupted: pressure set point became 0, or the pump type changed by itself. Bench test: perfect, 2 weeks, zero resets. "Lab bench power supply never shows this. Farm shows it on day one only." I say this sentence to every new engineer now. Going to site One farm, 200 m of cable from the…

    Karthikeyan S12likes6comments

  5. Question

    How do you unit test firmware? We test almost nothing on host

    Honest question. In my team all the testing is on the target hardware: flash, run, look at the logs and the scope. We have some integration tests on a HIL bench but zero unit tests. When I propose unit tests, the people say is impossible because the code touch registers everywhere. Is a codebase of around 60k lines of C, STM32, FreeRTOS. The drivers call the HAL directly from the application logic in many places.…

    Diego Ramírez3likes3comments

  6. Article

    volatile is not a mutex: sharing data between an ISR and your main loop

    Every few months a junior in my team come with the same bug: a counter updated in an interrupt, read in the main loop, and sometimes the value is garbage. And the first answer is always "but I put volatile". So here is the explanation I give them, maybe is useful for someone else. What volatile does volatile tells the compiler: this variable can change outside of the normal program flow, so read it from memory every…

    Diego Ramírez3likes3comments

  7. Article

    volatile is not a lock: 4 ISR bugs I have personally shipped to pump controllers

    All four of these went to the field in products with my name in the git blame. All four passed bench testing. Sharing so you can ship different bugs. Bug 1: the missing volatile bool adc_done = false; /* BUG: not volatile */ void ADC_IRQHandler(void) { adc_value = ADC1->DR; adc_done = true; } void read_adc(void) { start_conversion(); while (!adc_done) { } /* at -O2 this becomes while(1) */ adc_done = false; } The…

    Karthikeyan S19likes10comments

  8. Article

    I maintain something you depend on. I am done pretending that is sustainable.

    skerry is a small C library that parses JSON. it is maybe four thousand lines. it is also, as far as I can tell from the download numbers and the angry emails, inside a lot of things you use: routers, a payment terminal, at least two cars, and the backend of companies whose quarterly profit is larger than the GDP of the town I live in. I have maintained it for fourteen years. I have two co-maintainers who help when…

    Karl Lindqvist102likes22comments

  9. Experience

    someone forked skerry, renamed it, stripped my name, and sold support for it

    a story from a few years back that still annoys me in a specific, instructive way. skerry is permissively licensed on purpose, you can do almost anything with it, including fork it. I knew that when I chose the license. so this is not a legal complaint. it is a story about the difference between what you are allowed to do and what you should do. a consultancy took skerry, forked it, renamed it something close enough…

    Karl Lindqvist34likes5comments

  10. Experience

    the heap overflow I reported to skerry, and why @kernel_karl is the gold standard

    since this topic is usually about maintainers behaving badly or companies being awful, here is the opposite, because it deserves saying out loud. last year I was fuzzing C JSON parsers for fun (yes, that is my idea of fun) and I found a heap buffer overflow in skerry, the little parser Karl maintains and that, as his bio says, half your companies vendor and never thank. a malformed deeply nested input could write…

    Nadia Benali28likes8comments

  11. Experience

    The pump that stopped every 40 minutes: a FreeRTOS priority inversion story

    Field complaint: a pressure booster pump in an apartment building stops for 2 seconds roughly every 40 minutes. Water pressure drops, people on the 9th floor shout, the building manager calls our service guy, the service guy calls me. On the bench: nothing. Ran it for 3 days, no stop. The system STM32F4, FreeRTOS, three tasks that matter: MotorControl , priority 5, runs every 1 ms, kicks the watchdog through a…

    Karthikeyan S14likes9comments

  12. Article

    I2C debugging with a ₹650 logic analyser: the 5 bugs I find every month

    Every month somebody at work or on WhatsApp says "the sensor is not detecting". Nine times out of ten it is one of these five. Before you change the library or the sensor, look at the bus. The tool The cheap 24 MHz 8 channel "Saleae compatible" clone, ₹650 online. With sigrok PulseView (free) it works very well: sudo apt install pulseview sigrok-firmware-fx2lafw Sample at least 4× the bus speed, I use 8 MHz for 400…

    Karthikeyan S26likes8comments

  13. Article

    ESP32 battery sensor: from 4 days to about a year on one 18650. Real numbers, real mistakes

    My uncle has a coconut farm near Pollachi. He wanted soil moisture and temperature from 6 spots, every 10 minutes, on his phone. Easy, I said. ESP32, WiFi to the pump shed, MQTT, done. First version battery died in 4 days . This post is how it became about a year, with numbers, because "use deep sleep" is not an answer. Step 0: measure, don't guess You need two tools: A multimeter in series for the sleep current (µA…

    Karthikeyan S37likes12comments

Get the best of Dynamo Geeks weekly

One email each Monday with the most useful posts. No spam; unsubscribe in one click.