All Contents
| Lean Embedded | Embedded Interface | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Microcontrollers
4004 Microprocessor
- Getting Started with 4004 MicroProcessor : Datasheet serach in http://www.intel.com/
- Reference : https://en.wikipedia.org/wiki/Intel_4004
- Intel 4004 Instructions Set : http://e4004.szyc.org/iset.html
- https://www.4004.com/
STM8S003 MCU
- STM8S003 Datasheet: STM8S003 datasheet
STM8S003 Controller Pinout ( STM8S003 TSSOP2)
STM Programmer
You can buy this USB programmer from eBay The ST-LINK/V2 is an in-circuit debugger and programmer for the STM8 and STM32 microcontroller families. The
single wire interface module (SWIM) and JTAG/serial wire debugging (SWD) interfaces are used to communicate with any STM8 or STM32 microcontroller located on an application board. for more details about the ST-LINK V2 programmer click here. SWIM is Single-WireInterface Module, See SWIM protocol details.
ST-LINK V2 Pinout
Example: Hello World
In the hello world example will see the LED Blink Program in STM8S003 Controller. Usually the first program of everything (Controller) in electronics we start from blink example.
- Required Development Tool: IAR Embedded Work Bench includes ST-LINK V2 USB drivers (Download Free Trial Version for STM8S003 controller)
- Alternatively, you can download the full standard library for STM8 from ST website.
- https://my.st.com/content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm8-embedded-software/stsw-stm8069.license%3d1470738771420.html
- Refer Links: http://embedonix.com/articles/embedded-projects/getting-started-with-stm8-development-part-1-blinking-a-led/
- Reference: http://www.emcu.it
Required? Infinite loop in Embedded system
Yes โ in most embedded systems, an infinite loop is required at the end of main() or in the main task.
Why?
- No Operating System Exit
- Unlike desktop programs, thereโs usually no โreturn to OSโ in bare-metal embedded systems.
- If
main()finishes, the CPU may jump to an undefined location and execute garbage instructions, causing unpredictable behavior.
- Continuous Operation
- Embedded systems often run indefinitely (controllers, sensors, appliances).
- The infinite loop keeps the device active, continuously handling tasks, checking inputs, and controlling outputs.
- Low-Power & Idle Handling
- The loop can contain sleep or low-power mode instructions to save energy while waiting for interrupts.
Typical example:
int main(void) {
init_peripherals();
while (1) { // Infinite loop
process_tasks();
}
}
Exception:
In embedded code is running under an RTOS, main() might just create tasks and let the scheduler run; in that case, the infinite loop may be inside the task, not main() itself.
Timers in Embedded system
In embedded systems, timers are hardware or software components used to measure time intervals, generate delays, or trigger events at precise intervals.
1. Types of Timers
- Hardware Timers
- Built into the microcontroller.
- More accurate and independent of CPU execution speed.
- Can work even when the CPU is in low-power mode.
- Examples: 8-bit timers, 16-bit timers, watchdog timers.
- Software Timers
- Implemented in code using counters and delays.
- Less accurate (depends on CPU and OS scheduling).
- Useful when hardware timers are already occupied.
2. Timer Modes
- One-shot mode โ Runs once for the set duration, then stops.
- Periodic mode โ Repeats at a fixed interval.
- Capture mode โ Records the time when an event occurs.
- Compare mode โ Generates an interrupt when the counter matches a set value.
- PWM mode โ Produces Pulse Width Modulated signals.
3. Common Uses
- Generating delays without blocking the CPU.
- Measuring time intervals (e.g., speed calculation in sensors).
- Creating precise clock signals.
- Scheduling tasks in real-time systems.
- Driving PWM for motor control or dimming LEDs.
- Timeout detection (e.g., watchdog timer to reset system on hang).
4. Example (C – AVR/ARM)
// Example: Configure Timer0 for 1ms interrupt
void Timer0_Init(void) {
TCCR0A = (1 << WGM01); // CTC mode
OCR0A = 249; // Compare value for 1ms at 16MHz with prescaler 64
TIMSK0 = (1 << OCIE0A); // Enable compare match interrupt
TCCR0B = (1 << CS01) | (1 << CS00); // Start timer with prescaler 64
}
ISR(TIMER0_COMPA_vect) {
// This code runs every 1ms
}
Key point: In embedded systems, timers are essential for real-time control because they allow precise event scheduling without wasting CPU cycles.
Watchdog timer
A Watchdog Timer (WDT) in embedded systems is a hardware or software timer used to detect and recover from malfunctions.
Purpose
The WDT ensures that if your program gets stuck (e.g., infinite loop, deadlock, or crash), the system can reset itself automatically to resume normal operation.
How it works
- Enable the WDT in your microcontroller.
- The WDT counts down from a preset value.
- Your code must periodically โkickโ or โfeedโ the WDT before it times out.
- If the WDT is not fed in time, it assumes the system is stuck and resets the MCU.
Example scenario
- In normal operation:
The main loop updates sensors, processes data, and callsfeed_watchdog(). - If a bug causes the loop to hang:
The watchdog is not fed โ WDT expires โ MCU resets โ System recovers.
Benefits
- Increases system reliability.
- Reduces need for manual resets.
- Essential for unattended or remote systems.
Example (C for STM32)
#include "stm32f4xx.h"
void WDT_Init(void) {
IWDG->KR = 0x5555; // Enable write access
IWDG->PR = 0x06; // Prescaler
IWDG->RLR = 4095; // Reload value
IWDG->KR = 0xAAAA; // Reload counter
IWDG->KR = 0xCCCC; // Start WDT
}
void Feed_WDT(void) {
IWDG->KR = 0xAAAA; // Reload counter
}
int main(void) {
WDT_Init();
while(1) {
// Application code
Feed_WDT(); // Reset watchdog timer
}
}
Memories in Microcontrollers
Volatile and Non-volatile memory
Generally, memory are two categories
- Non Volatile Memory – The contents of the memory are not permanently deleted while power is on and Off. It is often found in USB flash drives, MP3 players, digital cameras, and solid-state drives.
- Volatile Memory – The contents of the memory are permanently deleted while power is on and Off.
which means that when the power is shut off, the contents of the memory are NOT lost
The main categories in Microcontroller are three type
- Flash memory
- RAM
- EEPROM memory
Flash memory
Flash memory is used to store the program. It can be electronically reprogrammed and erased. Flash memory is a type of electronically erasable programmable read-only memory (EEPROM), but may also be a standalone memory storage device such as a USB drive. It is Non-volatile memory.
RAM Memory
The abbreviation of RAM is Random Access Memory. RAM is used to store the local variables during program execution time. RAM memory is helping to fast read access during the execution time. It is volatile memory.
Many type of RAM is available
- SRAM,
- DRAM and etc.
EEPROM
The Abbreviation of EEPROM is Electrically Erasable Programmable Read-Only Memory. Itโs used to permanently store data like device Parameters, Errors, Timestamps, Sensor data, etc (As per project required). When compare to FLASH and RAM, the EEPROM is a slow response while accessing when execution. It’s non-volatile memory same as FLASH.
Memory Swapping Concept
In modern ARM cortex R series (TMS570LC4357- ARM Cortex R5F) have feature like swapping of the CPU instruction memory (flash) and data memory (RAM).
For example : controller flash memeory start from 0x00000000 and RAM start from 0x08000000. By default, CPU starts RAM memory from 0x08000000. But After swapping, the data RAM is accessed starting from 0x00000000, and flash memory is now accessed starting from 0x08000000. For this need to properly configure the settings in the respective register.
Difference between 8 bit, 16 Bit, 32 Bit, 64 Bit Microcontrollers
| Controllers | Internal Bus | ALU Operations | Family | Precision |
|---|---|---|---|---|
| 8 Bit | 8 Bits | 8 Bits | 8051, AVR, PIC, HSC12 | 1Byte |
| 16 Bit | 16 Bits | 16 Bits | Extended 8051XA, Intel 8096, MC68HC12, PIC16F | 2Bytes or Half word Its greater precision than 8 bits |
| 32 Bit | 32 Bits | 32 Bits | ARM, PIC32, Intel 80960, Intel/Atmel 251 Family, TMS570LC43570, ESP32 and ESP8266. | 4Bytes or Word Its greater precision than 16 bits |
| 64 Bit | 64 Bits | 64 Bits | ARM Cortex-R82 (Launched at 2020) | 8Bytes Its greater precision than 32 bits |
Bootloader
The bootloader is a piece of code that runs before, any operating system is running. Bootloaders are used to boot other operating systems, usually, each operating system has a set of bootloaders specific for it. Bootloaders usually contain several ways to boot the OS kernel and also contain commands for debugging and/or modifying the kernel environment. Bootloaders are used to boot other operating systems, usually, each operating system has a set of bootloaders specific for it.
Primary Bootloader
The detailed operation of the primary bootloader is device-specific. Some devices have complex capabilities such as booting from an I/O peripheral or configuring memory controller parameters.
Secondary Bootloader
The hex converter assumes the secondary bootloader is of a particular format. The hex converter’s model bootloader uses a boot table. You can use whatever format you want, but if you follow this model, the hex converter can create the boot table automatically.
Primary and Secondary boot-loader Sequence

The _c_int00 Function
The function _c_int00 is the startup routine (also called the boot routine) for C/C++ programs. It performs all the steps necessary for a C/C++ program to initialize itself.
The name _c_int00 means that it is the interrupt handler for interrupt number 0, RESET, and that it sets up the C environment. Its name need not be exactly _c_int00, but the linker sets _c_int00 as the entry point for C programs by default. The compiler’s run-time-support library provides a default implementation of _c_int00.
The startup routine is responsible for performing the following actions:
- Switch to user mode and set up the user mode stack
- Set up status and configuration registers
- Set up the stack
- Process special binit copy table, if present
- Process the run-time initialization table to autoinitialize global variables (when using the
--rom_modeloption) - Call all global constructors
- Call the function
main - Call
exitwhenmainreturns
Intel Hex File Format
- Intel-Standard Hex file format is one of the commonly used formats in the microcontroller world
- This standard is used to burn the 8051/52 program into an EPROM, PROM, etc,
- 8051 Assembler generates the Intel Standard Hex file, it can be loaded into EPROM programmer.
- Intel HEX is a file format that conveys binary information in ASCII text form.
- It is commonly used for programming microcontrollers, EPROMs, and other types of programmable logic devices.
- In a typical application, a compiler or assembler converts a program’s source code (such as in C or assembly language) to machine code and outputs it into a HEX file.
- The HEX file is then imported by a programmer to “burn” the machine code into a ROM, or is transferred to the target system for loading and execution.
Below is the format of the intel Hex file
- Position: 1 – Record Marker.
- Position: 2-3 – Record Length.
- Position: 4-7 – Address.
- Position: 8-9 – Record Type.
- Position: 10-? – Data Type.
- Last 2 Characters: Checksum.
The below table is an example of 0300300002337A1E
| Position: 1 | Record Marker | 03 (3 Byte of Data) |
| Position : 2-3 | Record Length | 0030(3 Bytes will be stored at 0030, 0031, and 0032) |
| Position: 4-7 | Address | 00 (Normal data) |
| Position : 8-9 | Record Type | 02,33, 7A. |
| Position: 10-? | Data Type | 1E |
| Last 2 Character | Checksum. |
GSM
- How do I forward all my text messages to another phone? For solution is android: Many more android apps are available to forward your SMS to some particular number. : https://play.google.com/store/apps/details?id=com.kerryn.autoforwardsms
Embedded Product Design
- Understand and analyze customer and design requirements to identify any gaps or missing information needed to perform development and testing activities
- Participate in high-level design for projects that have a high reuse factor
- Design software components based on the high-level design requirements
- Develop integration test plans and test cases to verify that the software meets the customer and the high-level requirements
- Test cases planning & Execution of test plans
- Analysis of executed test plans, and confirming that the software behavior respects the requirement documents
- Report findings (SW Bugs) on the configuration management tool
- Prepare test reports
- Perform the responsibilities of the previous technical level as per the project need
- Perform technical reviews on software component design, code, and test
- Continuously communicate work progress through attendance of daily & weekly project meetings. (Internal and external with other Value sites)
- Support his/her colleagues whenever required
in short for
- Block Diagram
- Design Circuit Diagram
- Select Correct Component
- Resistor
- Capacitor
- Diode
- Encloser Box
Embedded Real-Time Applications
Elevators (Lift)
Manufacture companies
- Kone (Fourth largest elevator manufacturer in the world. is also the pioneer of the machine room-less elevator system)
- Johns & Waygood (Acquired by Perry Engineering in the 1970s)
- Mitsubishi – Elevator
- Schindler (Second largest elevator manufacturer in the world, and the largest escalator manufacturer in the world)
Reference
Reference
Interrupt logic?
In an embedded system, interrupt logic is the mechanism that allows the processor to pause the current execution and jump to a specific Interrupt Service Routine (ISR) when a particular event occurs.
Hereโs the basic logic flow:
| Step | Description | Example |
|---|---|---|
| 1. Event Occurs | A hardware or software event triggers the interrupt request (IRQ). | Button press, timer overflow, UART receive |
| 2. CPU Detects Interrupt | The interrupt controller signals the CPU that an interrupt has occurred. | NVIC in ARM Cortex-M |
| 3. Save Context | CPU stores the current program counter (PC) and status registers. | Saves execution state |
| 4. Jump to ISR | CPU executes the ISR linked to that interrupt. | void TIM1_IRQHandler(void) |
| 5. ISR Executes | Handles the event quickly (minimal code). | Read sensor data, clear flag |
| 6. Restore Context | CPU restores saved state. | Resume main code |
| 7. Resume Main Code | CPU continues from where it left off. | Main loop resumes |
Key Points:
- Interrupt Priority: Higher-priority interrupts can interrupt lower-priority ones.
- Edge vs Level Triggered: Triggered by a change (edge) or constant state (level).
- Masking: You can enable/disable specific interrupts.
- ISR Rules:
- Keep it short and fast.
- Avoid
printfor heavy processing. - Clear interrupt flags inside ISR.
Interrupt Latency
Interrupt Latency in embedded systems means: The time delay between the occurrence of an interrupt request and the start of the interrupt service routine (ISR) execution.
Why it happens
This delay comes from:
- Current instruction execution time โ CPU finishes the instruction in progress.
- Interrupt disabling โ If interrupts are temporarily disabled in code.
- Interrupt priority checking โ CPU checks which interrupt has higher priority.
- Context saving โ Registers and program counter are saved before jumping to ISR.
Example
If a button press triggers an interrupt:
- Button press โ CPU takes a few microseconds to finish the current task โ Saves state โ Starts ISR.
That few microseconds = Interrupt Latency.
Minimizing Interrupt Latency
- Keep critical sections (where interrupts are disabled) short.
- Use faster processors or instructions.
- Prioritize interrupts properly.
- Keep ISRs short and efficient.
Flow Chart
Flowcharts will help to understand the workflow. Flow is a type of diagram to easily identify the workflow or process. In flow chart have many different symbol shapes that are used to represent different kind of process or workflow.
- Terminator
- Decision
- Process
- Circle
Code Revision Tools
- TortoiseSVN,
- GIT
- IBM Synergy.
What is Traceability Matrix Table?
- Answere will add soon



You must be logged in to post a comment.