Skip to content
  • 0 Votes
    1 Posts
    128 Views
    A
    Half of firmware debugging is how you ask. A good report gets you an answer in an hour; "it doesn't work" gets you silence. Use this format every time: What I'm trying to do: one sentence β€” the goal, not the method. What I tried: the steps, in order. "Changed the baud rate, added a delay, swapped cables." What happened: exact text, not paraphrase. Paste the panic dump, the serial output, the wrong value. My setup: board (ESP32 DevKitC? which revision), IDE + version, relevant library versions. Minimal code: the smallest snippet that reproduces it β€” 20 lines beats 500. Use code blocks, never screenshots of code. Serial output: pasted as text, from boot to failure. Decode your own crash first A Guru Meditation Error print is a gift β€” it tells you the exception cause, the guilty program counter, and a backtrace. The fastest path: rebuild the exact same binary with symbols, feed the addresses to the decoder, and read the function names. Nine times out of ten it lands on one of these: Stack overflow β€” a task with a 1 KB stack calling deep library functions, or a large array declared inside a function. Symptom: crash inside random-looking code, corrupted backtrace. Fix: grow the stack, move big buffers to static/global. Watchdog bite β€” a task that never blocks. Any loop without a delay or blocking call starves the idle task and the watchdog resets the chip. Fix: yield every iteration. Null / wild pointer β€” dereferencing a queue handle or object that was never created, or used after deletion. Symptom: LoadProhibited on an address near zero. Fix: check every create call's return before use. Shared state without protection β€” a variable touched from a task and an ISR (or two tasks) with no guard. Symptom: works for hours, then corrupts once. Fix: qualifier or guard, depending on who shares it. The five gotchas that solve most posts here ADC reads garbage with WiFi on β†’ use ADC1 pins, never ADC2 under WiFi. Board resets randomly on USB β†’ weak cable or port; measure the rail under load, try a shorter cable and a powered hub. Serial shows garbage β†’ monitor baud must match Serial.begin() exactly. "Worked yesterday" β†’ something changed: code, wiring, power source, library update. Figure out what, then bisect it. Timing drift under WiFi β†’ never use blocking delays for cadence; sample on a stable timebase. Post with the format above and tag with firmware, freertos or esp32.
  • 0 Votes
    1 Posts
    99 Views
    A
    Most firmware projects hit a wall that only maths solves β€” a sensor reading too noisy to use, a frequency that must be detected, a filter that needs tuning, a calculation that loses precision on a microcontroller with no FPU. This post is the practical core: no academic DSP, just the techniques that come up with real sensors. Sample fast enough, or lie to yourself Nyquist: to represent bandwidth B you need fs > 2B; anything above fs/2 folds back as a phantom: f_alias = |f - k*fs|. Thermal logger at fs = 10 Hz with 60 Hz mains hum coupled into the wiring β†’ k=6 β†’ |60-60| = 0 Hz. Your "temperature drift" is mains hum pretending to be DC. 100 Hz sampler with 130 Hz motor PWM residue β†’ |130-100| = 30 Hz phantom. You chase a resonance that doesn't exist. The engineering rule (not the textbook 2x): sample at 5–10x the highest frequency you must resolve, so your filter has room to roll off. Averaging after aliasing can't help β€” the fold already happened at the sampling instant. Anti-alias in analog (RC before the ADC) or by oversampling-then-filtering at high fs. Smooth with the right tool Moving average (N): white noise drops by √N, lag β‰ˆ NΒ·T/2. General thermal and ADC cleanup (N = 16–64). Exponential (EMA): y += alpha*(x-y), O(1) RAM. Display smoothing and tight loops. Median (odd N): kills spikes (WiFi bursts, brush clicks), preserves edges. Put it before averaging in spiky environments. Oversample + decimate: 4x oversampling buys roughly 1 extra bit (16x β†’ +2 bits: sample 160 Hz, average 16, output 10 Hz). Needs real noise across 1 LSB to dither. Hysteresis/deadband: act only past Β±band. Stops relay and fan chatter around thresholds. β†’ Sampling and signal conditioning for industrial sensors Convert counts to units β€” with proof Two-point calibration: take two raw/reference pairs, fit T = aΒ·counts + b, then validate with a third point and record references, conditions, date, and stale-data behaviour (hold-last-good, never actuate on unvalidated samples). Sample on a stable timebase (millis() cadence with +=, not delay() drift under WiFi load). Takeaways: match the rate to the physics, filter in analog before digital, median-before-average for spikes, calibrate with numbers and an expiry date. Finish with Sampling, noise and calibration β€” the full treatment this primer is distilled from. Post your sensor, your rate, the filter you tried, and the numbers. Tag with signal-processing.
  • πŸ”’ How IoT devices get owned

    IoT Security Concepts security tls firmware
    1
    0 Votes
    1 Posts
    82 Views
    A
    Insecure firmware has taken down chunks of the internet β€” hundreds of thousands of cameras, routers and DVRs running default credentials, herded into a botnet overnight. Similar flaws have reached into industrial plants. Your device ships into an adversarial network, so security is a set of decisions from the first line of firmware, not a feature added at the end. Think like an attacker first Ask four questions about your own device: what is valuable here (data? compute? a foothold into the LAN?), who wants it, how do they reach it (open ports? UART header? cloud API?), and what happens if they succeed? That threat model decides everything else β€” a soil sensor and a door lock do not deserve the same budget, and the model tells you where the budget goes. β†’ Threat modelling and security foundations The transport layer: where most devices fail open TLS with both sides proving identity. Server-only TLS leaves devices talking to impostors; mutual auth means the device verifies the server and the server verifies the device. Two field gotchas: actually validate the CA chain (skipping verification "temporarily" becomes permanent), and sync the clock first β€” certificates look invalid on a device that thinks it's 1970. β†’ Device-side practice: TLS auth and secure boot Network posture. Close what you don't use, assume the local network is hostile, and treat every byte arriving over the air as untrusted input until validated. Most Mirai-class compromises weren't exotic crypto breaks β€” they were default passwords on open remote-access ports. β†’ Network and communication security Continue with the IoT security deep track β€” identity, firmware and incident response. Post your device, your threat model, and where you think you're exposed. Tag with security or tls. For identity, secure boot and updates, see the companion post below.
  • 0 Votes
    1 Posts
    86 Views
    A
    When a device fails in the field, the first question is: "what exact binary is on it, and can we rebuild it?" If your version control can't answer that, nothing else in your workflow matters. Checklist before you ask for help here Every shipped binary maps to a tag (git tag v1.2.3), not "final_final2". A tag is the only way to rebuild byte-identical firmware months later when a customer reports a bug on old hardware. β†’ Tags, releases and repository hygiene Build artefacts, secrets and calibration dumps are ignored. .pio/, build/, certificates, tokens and per-device calibration data never belong in history. Once a secret is committed, rotating it is the only fix β€” deleting the file later doesn't remove it from history. No credentials in the repo. Ever. Device tokens and WiFi passwords live in provisioning, environment, or a secrets store β€” not in a header file someone will push to GitHub. You can bisect back to the breakage. When a regression appears three weeks late, git bisect with small, honest commits finds the culprit in minutes. "Backup Friday" commits make that impossible. β†’ Advanced workflows and recovery Start at Git & Version Control and work through it in order. Share your workflows, ignore-file setups, or mistakes learned the hard way. Tag with git.
  • 0 Votes
    1 Posts
    84 Views
    A
    Desktop C forgives you. Firmware C doesn't. The same program that runs fine on a laptop can corrupt memory or miss an interrupt on a microcontroller β€” because of what the compiler and the hardware actually do with your code. The bugs that keep showing up here The missing volatile. A flag shared between main code and an interrupt handler works perfectly at -O0 and breaks at -O2, because the compiler cached it in a register. It never re-read memory β€” you never told it the value could change behind its back. The canonical shape looks like this: volatile bool data_ready = false; // set in ISR, polled in main loop void ADC_ISR(void) { data_ready = true; } void loop(void) { if (data_ready) { // re-read from memory every time data_ready = false; process_sample(); } } Drop the volatile and the compiler hoists the read out of the loop β€” the loop never sees the interrupt fire. Diagnosing it: if it works at -O0 but breaks at -O2, suspect a missing qualifier before suspecting hardware. Any variable touched both inside and outside an ISR gets volatile. No exceptions, no "but it works on my machine". β†’ Interrupts and ISR patterns Structs that don't match the hardware. You overlay a struct on a peripheral register map, but the compiler inserts padding where you didn't expect it, and now every field after the gap writes to the wrong address. On desktop this is a curiosity; on hardware it configures a peripheral into nonsense. Learn struct layout and padding, then verify with sizeof and offsetof instead of trusting the layout. β†’ Memory, pointers and data representation Read-modify-write that isn't atomic. GPIO_REG |= (1 << PIN) looks harmless until an interrupt fires between the read and the write and modifies a neighbouring pin β€” your write-back silently undoes it. On real firmware this shows up as a pin that "randomly" changes state once a week. Critical regions and atomic access exist for exactly this reason. Integer promotion adds a second trap: your uint8_t arithmetic quietly becomes int mid-expression, signed-vs-unsigned comparisons go sideways, and shifting into the sign bit is undefined behaviour the compiler is allowed to punish. β†’ Writing robust embedded C Start at the Embedded C track and work through it in order. Post the smallest reproducer plus your compiler flags and optimisation level. Tag with c-lang.