Building a Lightweight Embedded Framework with Zorb: Core Modules and Implementation Guide
This article introduces the Zorb Framework, a lightweight object‑oriented embedded framework for STM32F429, detailing its core modules, hardware setup, debugging output, assertion handling, and a basic time system with complete C code examples.
1. Introduction to Zorb Framework
Zorb Framework is a lightweight, object‑oriented embedded framework designed to accelerate application development on chips that cannot run Linux, avoiding repetitive wheel‑reinvention. Its initial feature set includes a time system (zf_time), circular buffer (zf_buffer), list (zf_list), state machine (zf_fsm), event handling (zf_event), timer (zf_timer), and task management (zf_task). The first six modules enable pure event‑driven programs suitable for small‑to‑medium embedded applications, while the task module adds support for higher‑real‑time requirements.
2. Embedded Environment Setup
The hardware platform uses an STM32F429 development board. UART1 provides debugging output, and the SysTick timer supplies system time counting. Board‑level initialization follows the vendor’s example code, configuring the UART and SysTick.
void BSP_init(void) {
/* NVIC priority group */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Initialize debug UART */
Debug_USART_init();
/* Initialize SysTick */
SystemTick_init();
}
void BSP_process(void) {
// Application‑specific processing can be placed here
}3. Debug Output
Debugging is routed through UART1 using a printf‑style mapping. Three log levels are defined: LOG_D (debug), LOG_W (warning), and LOG_E (error). The ZF_DEBUG macro prefixes messages with a rank identifier and prints them only when debugging is enabled.
#define LOG_D 0 /* normal */
#define LOG_W 1 /* warning */
#define LOG_E 2 /* error */
#ifdef _ZF_DEBUG
#if ZF_DEBUG_ON
#define ZF_DEBUG(rank, x...) do { \
char code[10] = "[rank=0]"; \
code[6] = '0' + (char)rank; \
if (code[6] != '0') printf("%s", code); \
printf(x); \
} while(0)
#else
#define ZF_DEBUG(rank, x...)
#endif
#endif4. Assertion Implementation
Assertions help locate bugs by reporting the source file and line number when a condition fails. The macro ZF_ASSERT expands to a call to ZF_assertHandle when assertions are enabled.
#define ZF_ASSERT(expression_) ((expression_) ? (void)0 : ZF_assertHandle((uint8_t *)__FILE__, (int)__LINE__))
void ZF_assertHandle(uint8_t *pFileName, int line) {
ZF_DEBUG(LOG_E, "file:%s line:%d:asserted
", pFileName, line);
while (1); // halt execution
}5. Time System
The framework defines a 1 ms tick period to keep resource consumption low. The SysTick interrupt calls ZF_timeTick(), which increments the framework’s tick counter. The provided API includes functions to get the current tick, convert ticks to milliseconds, and perform millisecond delays.
void SysTick_Handler(void) {
ZF_timeTick(); // update framework time base
}
#define ZF_TICK_PERIOD 1
#define ZF_SYSTICK() ZF_getSystemTick()
#define ZF_SYSTIME_MS() ZF_getSystemTimeMS()
#define ZF_DELAY_MS(ms_) do { \
if ((ms_) % ZF_TICK_PERIOD) ZF_delayTick((ms_) / ZF_TICK_PERIOD + 1); \
else ZF_delayTick((ms_) / ZF_TICK_PERIOD); \
} while (0)
uint32_t ZF_getSystemTick(void);
uint32_t ZF_getSystemTimeMS(void);
void ZF_delayTick(uint32_t tick);
void ZF_timeTick(void);6. Conclusion
The implemented features form the foundation of the Zorb Framework; all future extensions—such as advanced timers, task scheduling, or additional peripherals—must build upon this base. A well‑structured debugging environment and reliable time base greatly improve development efficiency and bug‑tracking in embedded projects.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
