Skip to content

Commit 35ef00d

Browse files
Add concept-first teaching blocks to Phase2 topics
1 parent d3a3ab7 commit 35ef00d

13 files changed

+1322
-0
lines changed

Hardware_Fundamentals/Analog_IO.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ Analog I/O is essential for interfacing with real-world signals like temperature
3737

3838
## 🤔 What is Analog I/O?
3939

40+
### Concept: Sample and actuate with signal integrity
41+
42+
ADC/DAC performance depends on reference stability, input impedance, sampling time, and layout. Treat the analog front end as part of your software’s timing contract.
43+
44+
### Why it matters in embedded
45+
- Wrong sampling time or source impedance skews measurements.
46+
- Reference noise and grounding dominate effective resolution.
47+
- PWM+filter DACs need bandwidth/settling analysis like real DACs.
48+
49+
### Minimal example
50+
```c
51+
// Pseudo-code: configure ADC sample time to match source impedance
52+
// t_sample >= k * R_source * C_sample; consult datasheet constants
53+
void adc_config(uint32_t sample_cycles) { /* set SMPRx fields */ }
54+
```
55+
56+
### Try it
57+
1. Sweep sample time and measure a high-impedance source error vs a buffer driver.
58+
2. Capture multiple samples; compute ENOB; compare to datasheet under different Vref conditions.
59+
60+
### Takeaways
61+
- Match sample time to source impedance; buffer if needed.
62+
- Treat Vref as a signal; decouple and route carefully.
63+
- Average/oversample with thought; understand latency and bandwidth tradeoffs.
64+
4065
Analog I/O involves processing continuous voltage or current signals that can take on any value within a specified range. Unlike digital I/O which deals with discrete HIGH/LOW states, analog I/O handles the infinite range of values that represent real-world phenomena.
4166
4267
### **Core Concepts**

Hardware_Fundamentals/Clock_Management.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525

2626
Clock management is fundamental to embedded system design, affecting performance, power consumption, and system reliability. Proper clock configuration ensures optimal operation and efficient resource utilization.
2727

28+
### Concept: Frequency, sources, and stability drive everything
29+
30+
Clocks determine peripheral timing, serial baud, PWM resolution, and power. Choose sources (HSI, HSE, PLLs) that meet jitter/stability requirements and document the tree.
31+
32+
### Minimal example
33+
```c
34+
// Configure PLL for target SYSCLK; validate multiples for peripherals
35+
void clocks_init(void){ /* enable HSE, configure PLLM/N/P/Q; switch SYSCLK */ }
36+
```
37+
38+
### Takeaways
39+
- Changing clocks affects all derived timings; centralize and recompute dependents.
40+
- Validate startup delays and failure modes (HSE failure, PLL lock timeout).
41+
- Provide a single header/API with the current clock tree for other modules.
42+
2843
### **Key Concepts**
2944
- **Clock Sources** - Internal and external clock sources
3045
- **PLL Configuration** - Phase-locked loop setup and configuration

Hardware_Fundamentals/Digital_IO_Programming.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@
2727

2828
## 🎯 Overview
2929

30+
### Concept: Deterministic I/O with clear ownership of pins and timing
31+
32+
Digital I/O is about configuring pin direction, level, and timing deterministically. Treat each pin as a resource with explicit ownership and transitions.
33+
34+
### Why it matters in embedded
35+
- Prevents contention (two drivers on one net) and undefined levels.
36+
- Ensures edges meet external device timing (setup/hold, debounce).
37+
- Makes behavior predictable under interrupts and RTOS scheduling.
38+
39+
### Minimal example
40+
```c
41+
// Simple LED toggle with explicit initialization
42+
static inline void led_init(void){ /* configure GPIO port/pin mode */ }
43+
static inline void led_on(void){ /* set ODR bit */ }
44+
static inline void led_off(void){ /* clear ODR bit */ }
45+
static inline void led_toggle(void){ /* XOR ODR bit */ }
46+
```
47+
48+
### Try it
49+
1. Toggle a pin at a known period; measure with a logic analyzer to verify jitter.
50+
2. Add an ISR and observe jitter change; adjust priority or move work out of ISR.
51+
52+
### Takeaways
53+
- Initialize before use; document pull-ups/downs and default state.
54+
- Avoid read-modify-write races by using atomic set/reset registers when available.
55+
- Encapsulate pin control behind functions/macros for portability.
56+
3057
Digital I/O programming is the foundation of embedded system interaction with the physical world. It involves reading digital inputs (switches, sensors) and controlling digital outputs (LEDs, relays, displays).
3158
3259
**Key Concepts:**

Hardware_Fundamentals/External_Interrupts.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
External interrupts allow embedded systems to respond immediately to external events without polling. They are essential for real-time applications, user interfaces, and efficient system design.
2727

28+
### Concept: Edges vs levels, and clearing the source
29+
30+
Choose edges to capture transitions; levels to detect sustained conditions. Always clear the source appropriately and consider masking during long handlers.
31+
2832
### **Key Concepts**
2933
- **Interrupt Vector Table** - Maps interrupt sources to handler functions
3034
- **Interrupt Priority** - Determines which interrupt takes precedence

Hardware_Fundamentals/Hardware_Abstraction_Layer.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@
2525

2626
A Hardware Abstraction Layer (HAL) provides a standardized interface between application software and hardware, enabling code portability across different microcontrollers and hardware platforms. A well-designed HAL simplifies development, testing, and maintenance of embedded systems.
2727

28+
### Concept: Thin, stable interfaces over volatile hardware
29+
30+
Design the HAL as a narrow API that hides registers but exposes timing and error behavior. Keep it minimal to avoid lock-in and ease testing.
31+
32+
### Minimal example
33+
```c
34+
typedef struct {
35+
int (*init)(void);
36+
int (*write)(const void*, size_t, uint32_t timeout_ms);
37+
int (*read)(void*, size_t, uint32_t timeout_ms);
38+
} uart_hal_t;
39+
```
40+
41+
### Takeaways
42+
- Separate interface (headers) from implementation (per MCU).
43+
- Don’t leak register-level terms through the API.
44+
- Provide non-blocking and timeout variants for RTOS compatibility.
45+
2846
### **Key Concepts**
2947
- **Abstraction** - Hiding hardware-specific details behind a common interface
3048
- **Portability** - Ability to run code on different hardware platforms

Hardware_Fundamentals/Interrupts_Exceptions.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424

2525
## 🎯 **Overview**
2626

27+
### Concept: Bound latency, classify priorities, and clear sources
28+
29+
Design ISRs to be minimal and deterministic. Classify priorities by urgency, not feature importance. Always clear the source and hand off work to threads/tasks.
30+
31+
### Minimal example
32+
```c
33+
void EXTIx_IRQHandler(void){
34+
if (EXTI->PR & LINE){ EXTI->PR = LINE; xTaskNotifyFromISR(...); }
35+
}
36+
```
37+
38+
### Takeaways
39+
- Keep critical sections short; avoid calling into slow drivers.
40+
- Validate NVIC priority grouping and rules for RTOS API calls.
41+
- Measure entry/exit with GPIO toggles or cycle counters.
42+
2743
Interrupts and exceptions are fundamental mechanisms that allow embedded systems to respond to external events and handle errors efficiently. Understanding interrupt handling is crucial for real-time system design and reliable embedded applications.
2844
2945
### **Key Concepts**

Hardware_Fundamentals/Power_Management.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@
2727

2828
Power management is critical for battery-powered embedded systems and energy-efficient applications. Effective power management extends battery life, reduces heat generation, and enables portable and IoT devices.
2929

30+
### Concept: Budget power per state and per wakeup
31+
32+
Power is owned by your state machine: define active/idle/sleep states with known currents and wakeup sources. Measure, don’t guess.
33+
34+
### Minimal example
35+
```c
36+
typedef enum { RUN, IDLE, SLEEP } pm_state_t;
37+
void enter_idle(void){ /* reduce clocks, gate peripherals */ }
38+
void enter_sleep(void){ /* tickless idle, stop clocks, enable wakeups */ }
39+
```
40+
41+
### Takeaways
42+
- Use tickless idle when latency budget allows; verify wake sources.
43+
- Gate unused clocks/peripherals; disable pull-ups that leak.
44+
- Quantify energy/event (uC per sensor read) to compare designs.
45+
3046
### **Key Concepts**
3147
- **Sleep Modes** - Different power states for energy conservation
3248
- **Wake-up Sources** - Events that bring system out of sleep

Hardware_Fundamentals/Pulse_Width_Modulation.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@
2222

2323
## 🎯 Overview
2424

25+
### Concept: Duty, frequency, and resolution are coupled
26+
27+
PWM is timer compare hardware. Your choice of period (ARR) and clock prescaler sets frequency and duty resolution. Match these to actuator needs and EMC constraints.
28+
29+
### Minimal example
30+
```c
31+
// Set PWM to 20 kHz with 10-bit resolution if clock allows
32+
void pwm_init(void){ /* set PSC/ARR; configure CCx mode; enable output */ }
33+
void pwm_set_duty(uint16_t duty){ /* write CCRx, clamp to ARR */ }
34+
```
35+
36+
### Try it
37+
1. Sweep frequency to move switching noise out of sensitive bands.
38+
2. Evaluate linearity vs dead-time/driver delays on motors/LEDs.
39+
40+
### Takeaways
41+
- Frequency vs resolution tradeoff is dictated by timer clock.
42+
- Use complementary outputs and dead-time for half-bridges.
43+
- Filtered PWM (RC) behaves like a DAC; design the filter.
44+
2545
Pulse Width Modulation (PWM) is a technique used to control power delivery to electrical devices by rapidly switching between on and off states. It's widely used in motor control, LED dimming, power supplies, and audio applications.
2646
2747
**Key Concepts:**

Hardware_Fundamentals/Reset_Management.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525

2626
Reset management is crucial for embedded systems to ensure reliable startup, handle system failures, and maintain system integrity. Understanding reset mechanisms helps design robust systems that can recover from various failure conditions.
2727

28+
### Concept: Know every reset cause and make resets informative
29+
30+
Track POR, BOR, watchdog, software reset, and pin reset. Preserve reset reason across boot and expose it for diagnostics.
31+
32+
### Minimal example
33+
```c
34+
uint32_t reset_reason_read(void){ return RCC->CSR & REASON_MASK; }
35+
void reset_reason_clear(void){ RCC->CSR |= RCC_CSR_RMVF; }
36+
```
37+
38+
### Takeaways
39+
- Clear flags early; log to non-volatile memory if needed.
40+
- Define a boot flow that handles partial initialization after soft resets.
41+
- Provide a user-visible diagnostic (LED pattern, log) of reset cause.
42+
2843
### **Key Concepts**
2944
- **Reset Sources** - Different conditions that trigger system reset
3045
- **Reset Configuration** - Setting up reset behavior and timing

Hardware_Fundamentals/Timer_Counter_Programming.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@
2222

2323
## 🎯 Overview
2424

25+
### Concept: Timers are schedulers and timestampers
26+
27+
Use timers to measure, schedule, and generate pulses with bounded jitter. Configure prescalers and auto‑reload to match your required resolution and range.
28+
29+
### Why it matters in embedded
30+
- Wrong prescaler causes drift or overflow.
31+
- Input capture/compare enables precise measurements and pulse generation.
32+
- Deterministic timing underpins PWM, communication timeouts, and RTOS ticks.
33+
34+
### Minimal example
35+
```c
36+
// Configure a periodic interrupt at 1 kHz
37+
void tim_init_1khz(void){ /* enable clock, set PSC/ARR, enable IRQ */ }
38+
void TIMx_IRQHandler(void){ /* clear flag; do bounded work; defer heavy work */ }
39+
```
40+
41+
### Try it
42+
1. Measure timer ISR jitter with a logic analyzer; vary IRQ priority.
43+
2. Use input capture to time an external signal; compare to scope measurement.
44+
45+
### Takeaways
46+
- Choose PSC/ARR from required frequency and clock.
47+
- Keep ISRs short; use compare events for precise edges instead of software loops.
48+
- Document time bases centrally to avoid drift errors.
49+
2550
Timers and counters are essential peripherals in embedded systems for precise timing, frequency measurement, PWM generation, and event counting. Understanding timer programming is crucial for real-time applications.
2651
2752
**Key Concepts:**

0 commit comments

Comments
 (0)