Embedded Dev
CLAWHUB · Unverified
单片机嵌入式全栈开发技能,覆盖从底层硬件到上层应用的全链路技术问题。当用户询问嵌入式开发、微控制器、RTOS、电机控制、传感器接口、固件编写、调试上线等任何软硬件相关问题时应调用此技能。 Skill: Embedded Dev Owner: zzz-pinking Summary: 单片机嵌入式全栈开发技能,覆盖从底层硬件到上层应用的全链路技术问题。当用户询问嵌入式开发、微控制器、RTOS、电机控制、传感器接口、固件编写、调试上线等任何软硬件相关问题时应调用此技能。 Tags: embedded:1.0.0, firmware:1.0.0, iot:1.0.0, latest:1.0.0, rtos:1.0.0, stm32:1.0.0 Version history: v1.0.0 | 2026-04-02T15:16:09.747Z | auto Initial release of embedded-dev skill, providing a comprehensive embedded systems development toolkit. - Covers full-stack embedded d
- 62
- Rank
- 84
- Safety
- 1.3k
- Downloads
About
What it does, and when to use it.
Capability contract not published. No trust telemetry is available yet. 1.3K downloads reported by the source. Last updated 10/10/2026.
Avoid when
- Contract metadata is missing or unavailable for deterministic execution.
Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing
Public facts
Every fact links back to the source it came from.
- Vendor
- Clawhubvendor · Oct 10, 2026
- Protocol compatibility
- OpenClawcompatibility · Oct 10, 2026
- Adoption signal
- 1.3K downloadsadoption · Oct 10, 2026
- Latest release
- 1.0.0release · Apr 2, 2026
- Handshake status
- UNKNOWNsecurity
What changed
Newest first. Only changes that point at a source are listed.
Release 1.0.0release
Initial release of embedded-dev skill, providing a comprehensive embedded systems development toolkit. - Covers full-stack embedded development from MCU hardware to application layer. - Supports mainstream MCU architectures, peripheral driver development, RTOS usage, communication protocols, and debugging techniques. - Includes reference file index for quick access to core topics. - Provides common code templates for GPIO, UART, I2C, FreeRTOS, and PWM motor control. - Offers troubleshooting guidance for frequent embedded engineering issues. - Features hardware schematic, PCB basics, and OTA upgrade practices.
Observed Apr 2, 2026 · source
Install and run
Setup complexity: low.
clawhub skill install s170qy3e9hd78rb52vqxnefvhx8426jd:embedded-dev- Setup complexity is LOW. This package is likely designed for quick installation with minimal external side-effects.
- Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.
Contract: missing
curl -s "https://www.xpersona.co/api/v1/agents/clawhub-zzz-pinking-embedded-dev/snapshot"
Run-check
$0.02 USD1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.
Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.
Documentation
CLAWHUB
30,423 characters of source documentation, loaded on request.
Extracted files
5 files captured from the source.
SKILL.md
---
name: embedded-dev
description: 单片机嵌入式全栈开发技能,覆盖从底层硬件到上层应用的全链路技术问题。当用户询问嵌入式开发、微控制器、RTOS、电机控制、传感器接口、固件编写、调试上线等任何软硬件相关问题时应调用此技能。
---
# Embedded Dev Skill
单片机嵌入式全栈开发技能,掌握从芯片底层到产品上层的全链路知识。
## 技能范围
- 主流 MCU 架构(ARM Cortex-M、RISC-V、8051、AVR、ESP32、STM32)
- 外设驱动开发(GPIO、UART、I2C、SPI、ADC、PWM、Timer、CRC 等)
- 嵌入式C语言与汇编优化
- RTOS(FreeRTOS/RT-Thread/Zephyr)任务调度与进程间通信
- 有线/无线通信协议(UART、SPI、I2C、CAN、Modbus、RS485、LoRa、BLE、WiFi)
- 传感器与执行器接口(I2C/SPI 传感器、电机驱动、PWM 控制)
- 底层调试(JTAG/SWD、逻辑分析仪、示波器、printf 调试)
- 硬件原理图与 PCB 设计基础
- 固件架构(模块化设计、状态机、事件驱动)
- OTA 升级与 bootloader
- 低功耗设计
- 嵌入式 Linux(树莓派/全志/TI/NXP)基础
## 工作流程
遇到嵌入式问题时,按以下步骤处理:
1. **明确硬件平台** — 确认 MCU 型号、时钟配置、电源环境
2. **定位问题层级** — 硬件层/驱动层/RTOS层/应用层/通信层
3. **查参考文件** — 根据问题类型加载对应 reference 文件
4. **给出完整解答** — 包含代码示例(寄存器配置/C语言/驱动)、接线图要点、调试方法
## Reference 文件索引
- `references/mcu-architectures.md` — 主流 MCU 架构对比与选型
- `references/peripherals.md` — 外设驱动开发手册(GPIO/UART/I2C/SPI/ADC/PWM)
- `references/embedded-c.md` — 嵌入式C语言编程规范与技巧
- `references/rtos.md` — RTOS 实战(任务/队列/信号量/内存)
- `references/communication-protocols.md` — 通信协议对比与实现
- `references/debugging.md` — 硬件/软件调试方法与工具
- `references/hardware-design.md` — 原理图/PCB 设计要点
- `references/firmware-dev.md` — 固件架构与 OTA 升级
## 常用代码模板
### GPIO 配置(STM32 HAL 风格)
```c
// 配置 PB0 为推挽输出
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET); // 输出高
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); // 输出低
// 读取 PA1
GPIO_PinState state = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1);
```
### UART 中断接收(轮询+中断混合)
```c
uint8_t rx_buf[64];
volatile uint8_t rx_len = 0;
void USART1_IRQHandler(void) {
if (USART->SR & USART_SR_RXNE) {
rx_buf[rx_len++] = USART->DR;
}
}
```
### I2C 传感器读取(示例:MPU6050)
```c
void I2C_WriteReg(uint8_t addr, uint8_t reg, uint8_t val) {
I2C_Start();
I2C_SendAddr(addr << 1);
I2C_SendByte(reg);
I2C_SendByte(val);
I2C_Stop();
}
uint8_t I2C_ReadReg(uint8_t addr, uint8_t reg) {
I2C_Start();
I2C_SendAddr(addr << 1 | 0);
I2C_SendByte(reg);
I2C_RepeatedStart();
I2C_SendAddr(addr << 1 | 1);
uint8_t val = I2C_RecvByte(NACK);
I2C_Stop();
return val;
}
```
### FreeRTOS 任务创建
```c
void sensor_task(void *arg) {
while (1) {
float temp = read_temperature();
xQueueSend(temp_queue, &temp, portMAX_DELAY);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
xTaskCreate(sensor_task, "Sensor", 512, NULL, 2, &sensor_handle);
```
### PWM 电机控制
```c
// 配置 TIM3 CH2 (PB5) PWM 50Hz
void Motor_PWM_Init(void) {
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
// 72MHz / 720 => 100kHz, 100kHz / 2000 => 50Hz
TIM_TimeBaseStructure.TIM_Period = 2000 - 1; // ARR
TIM_TimeBaseStructure.TIM_Prescaler = 72 - 1; // PSC
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 1500; // 占空比 75%
TIM_OC2Init(TIM3, &TIM_OCInitStru_meta.json
{
"ownerId": "kn7c62nahxajwyn9fn5k25zpnd843pc0",
"slug": "embedded-dev",
"version": "1.0.0",
"publishedAt": 1775142969747
}references/communication-protocols.md
# 通信协议对比与实现
## 协议选型
| 协议 | 距离 | 速率 | 拓扑 | 抗干扰 |
|------|------|------|------|--------|
| UART | <1m | <5Mbps | 点对点 | 弱 |
| RS485 | <1200m | <10Mbps | 总线 | 强 |
| I2C | <1m | <3.4Mbps | 总线 | 中 |
| SPI | <1m | <几十Mbps | 总线+片选 | 弱 |
| CAN | <1000m | <1Mbps | 总线 | 极强 |
| LoRa | <10km | <几十kbps | 星形 | 极强 |
| BLE | <10m | <2Mbps | 星形 | 中 |
## RS485 + Modbus RTU
```c
// MAX485 收发控制
#define RS485_DE_HIGH() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET)
#define RS485_DE_LOW() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET)
void RS485_Send(uint8_t *data, uint8_t len) {
RS485_DE_HIGH(); HAL_Delay(1);
HAL_UART_Transmit(&huart1, data, len, 100);
while (!__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TC));
HAL_Delay(1); RS485_DE_LOW();
}
// CRC16 (Modbus 标准)
uint16_t modbus_crc16(uint8_t *buf, uint8_t len) {
uint16_t crc = 0xFFFF;
for (int i = 0; i < len; i++) {
crc ^= buf[i];
for (int j = 0; j < 8; j++)
crc = (crc & 1) ? ((crc >> 1) ^ 0xA001) : (crc >> 1);
}
return crc;
}
```
## CAN 总线
```c
// STM32 CAN 发送
CAN_TxHeaderTypeDef tx_header = {
.StdId = 0x100, .IDE = CAN_ID_STD,
.RTR = CAN_RTR_DATA, .DLC = 8
};
uint32_t mailbox;
uint8_t data[8] = {1, 2, 3, 4, 5, 6, 7, 8};
HAL_CAN_AddTxMessage(&hcan, &tx_header, data, &mailbox);
```
## 帧解析状态机
```c
typedef enum { FRAME_IDLE, FRAME_HEAD, FRAME_LEN, FRAME_DATA, FRAME_CRC } ParseState;
uint8_t protocol_parse(uint8_t ch) {
static ParseState state = FRAME_IDLE;
static uint8_t frame_len = 0, idx = 0;
static uint8_t buf[128];
switch (state) {
case FRAME_IDLE:
if (ch == 0xAA) state = FRAME_HEAD; break;
case FRAME_HEAD:
state = (ch == 0x55) ? FRAME_LEN : FRAME_IDLE; break;
case FRAME_LEN:
frame_len = ch; idx = 0; state = FRAME_DATA; break;
case FRAME_DATA:
buf[idx++] = ch;
if (idx >= frame_len) state = FRAME_CRC; break;
case FRAME_CRC:
if (ch == calc_crc16(buf, idx))
process_frame(buf, frame_len);
state = FRAME_IDLE; break;
}
}
```
## LoRa 发送
```c
// SX1278 发送模式
void LoRa_Transmit(uint8_t *data, uint8_t len) {
HAL_GPIO_WritePin(RFSW_CTRL_GPIO_Port, RFSW_CTRL_Pin, GPIO_PIN_SET); // TX
SX1278->RegOpMode = 0x08 | 0x01; // Sleep + LORA
SX1278->RegFiFoAddrPtr = 0x80;
for (int i = 0; i < len; i++) SX1278->RegFifo = data[i];
SX1278->RegPayloadLength = len;
SX1278->RegOpMode = 0x08 | 0x03; // TX
while (!(SX1278->RegIrqFlags & 0x08)); // TxDone
SX1278->RegIrqFlags = 0x08;
HAL_GPIO_WritePin(RFSW_CTRL_GPIO_Port, RFSW_CTRL_Pin, GPIO_PIN_RESET); // RX
}
```references/debugging.md
# 硬件/软件调试方法与工具
## 调试工具速查
| 工具 | 用途 | 价格 | 推荐场景 |
|------|------|------|---------|
| ST-Link V2 | STM32调试烧录 | ¥30 | STM32开发必备 |
| J-Link | ARM调试/Trace | ¥300+ | 高级调试 |
| 逻辑分析仪 | 数字信号时序分析 | ¥80+ | I2C/SPI/UART协议 |
| 示波器 | 模拟信号/纹波/噪声 | ¥500+ | 电源/模拟电路 |
| 万用表 | 通断/电压/二极管 | ¥50+ | 硬件检查必备 |
| USB转TTL | 串口调试 | ¥10 | UART日志 |
## SWD 调试命令
```bash
# OpenOCD + ST-Link
openocd -f interface/stlink.cfg -f target/stm32f1x.cfg
# 常用 GDB 命令
monitor reset halt # 复位并 halt
load # 烧录
break main # 断点
continue # 运行
step # 单步
info registers # 寄存器
x/16x 0x20000000 # 查看RAM
```
## printf 重定向
```c
int fputc(int ch, FILE *f) {
while (!(USART1->SR & USART_SR_TXE));
USART1->DR = ch;
return ch;
}
#define LOG(fmt, ...) \
printf("[%05ld] " fmt "\r\n", HAL_GetTick(), ##__VA_ARGS__)
LOG("ADC=%d Temp=%.2f", adc_val, temp);
```
## 常见故障排查
```
MCU不启动 → 检查 BOOT0 电平 / 晶振 / NRST
芯片发热 → 电源短路 / IO过载 / 反接
烧录失败 → SWD连接 / 读保护 / 接线错误
程序跑飞 → 堆栈溢出 / 数组越界 / 看门狗未喂
I2C无响应 → 地址错误 / 上拉缺失 / 总线被占用
UART乱码 → 波特率偏差 / 电平不匹配
ADC值不准 → 参考电压波动 / 采样时间不足
```
## HardFault 捕获
```c
void HardFault_Handler(void) {
volatile uint32_t *sp = (volatile uint32_t*)__get_MSP();
printf("HF: LR=%08X PC=%08X CFSR=%08X\r\n",
sp[5], sp[6], SCB->CFSR);
while(1);
}
```
## 逻辑分析仪使用
```bash
# sigrok-cli 采集
sigrok-cli -d saleae-logic16 --channels 1,2 \
--config samplerate=1M -p ch1=SCL,ch2=SDA -o capture.sr
# 导入 PulseView 解码 I2C/SPI 协议
```references/embedded-c.md
# 嵌入式C语言编程规范与技巧
## 关键规范
### 1. 头文件保护
```c
#ifndef __MY_DRIVER_H__
#define __MY_DRIVER_H__
// ...
#endif
```
### 2. 寄存器定义方式
**推荐:结构体联合体映射(STM32标准方式)**
```c
// 不推荐:裸地址操作
*((volatile uint32_t*)(0x40021000 + 0x0C)) = 0x00000001;
// 推荐:结构体映射
#define RCC_BASE 0x40021000UL
typedef struct {
volatile uint32_t CR;
volatile uint32_t CFGR;
volatile uint32_t CIR;
volatile uint32_t APB2RSTR;
volatile uint32_t APB1RSTR;
volatile uint32_t AHBENR;
volatile uint32_t APB2ENR; // 偏移 0x18
volatile uint32_t APB1ENR;
// ...
} RCC_TypeDef;
#define RCC ((RCC_TypeDef*)RCC_BASE)
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; // 清晰直观
```
### 3. volatile 关键字
所有以下情况必须加 `volatile`:
```c
// 硬件寄存器(硬件可改变其值)
volatile uint32_t * const USART_SR = (uint32_t*)0x40013800;
volatile uint8_t rx_buffer[256];
// 多线程共享变量(RTOS任务间)
volatile bool data_ready = false;
// 中断/主循环共享变量
volatile uint16_t tick_count;
```
### 4. 内存屏障
```c
// ARM Cortex-M 必须加 DMB(数据内存屏障)
void barrier(void) {
__asm__ volatile ("dmb sy" ::: "memory");
}
// 关中断保护共享数据
uint32_t saved = __get_PRIMASK();
__set_PRIMASK(1);
// 临界区
__set_PRIMASK(saved);
```
### 5. 位操作技巧
```c
// 置位
GPIOA->ODR |= (1 << 5);
// 清零
GPIOA->ODR &= ~(1 << 5);
// 翻转
GPIOA->ODR ^= (1 << 5);
// 读-改-写(保护)
uint32_t odr = GPIOB->IDR;
if (odr & (1 << 3)) { ... }
// 提取特定位
uint8_t val = (REG->DR & 0xFF); // 取低8位
uint8_t bits = (REG->DR >> 4) & 0x0F; // 取第4-7位
// 合并
REG->DR = (val << 4) | (bits & 0x0F);
```
### 6. 断言与错误处理
```c
#ifdef DEBUG
#define ASSERT(expr) \
do { if (!(expr)) while(1); } while(0)
#else
#define ASSERT(expr) ((void)0)
#endif
ASSERT(pointer != NULL);
ASSERT(index < MAX_SIZE);
```
### 7. 编译器属性
```c
// 放在特定内存区域(STM32 DTCM/ITCM)
uint8_t rx_buffer[256] __attribute__((section(".RAM_D2")));
// 禁止编译器优化(硬件寄存器必备)
register volatile uint32_t * const reg = (uint32_t*)0x40021000;
// 对齐(DMA/USB必备)
__attribute__((aligned(4))) uint8_t dma_buf[1024];
// 函数放在Flash(不占用RAM)
__attribute__((section(".text"))) void FuncInFlash(void) { }
// 零初始化段
volatile uint32_t system_state __attribute__((section(".noinit")));
```
### 8. 链接脚本关键段
```
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
}
SECTIONS
{
.text : { *(.text*) } > FLASH
.data : { *(.data*) } > RAM AT > FLASH /* 初始值副本放Flash */
.bss : { *(.bss*) } > RAM /* 零初始化 */
}
```
### 9. 链接时从Flash复制.data
```c
// STM32 启动文件标准做法
extern uint32_t _sidata, _sdata, _edata, _sbss, _ebss;
void Reset_Handler(void) {
// 复制 .data 段(从Flash到RAM)
for (uint32_t *p = &_sdata; p < &_edata; )
*p++ = *((uint32_t*)((uint8_t*)&_sidata + (p - &_sdata)));
// 零初始化 .bss
for (uint32_t *p = &_sbss; p < &_ebss; *p++ = 0);
SystemInit();
main();
}
```
### 10. 嵌入式常见陷阱
```c
// 陷阱1:除法运算极慢
uint32_t x = value / 10; // 避免在中断中用,改用右移或查表
// 陷阱2:浮点运算(无FPU的M0/M0+上极慢)
float temp = adc_val * 3.3 / 4096; // 换算:用整数放大法
uint32_t temp = (adc_val * 3300AionUi
Free, local, open-source 24/7 Cowork app and OpenClaw for Gemini CLI, Claude Code, Codex, OpenCode, Qwen Code, Goose CLI, Auggie, and more | 🌟 Star if you like it!
activepieces
AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
cherry-studio
AI productivity studio with smart chat, autonomous agents, and 300+ assistants.
CopilotKit
The Frontend for Agents & Generative UI. React + Angular
Machine-readable data
The same record, as JSON, for agents and crawlers.
- Card JSON
- Facts JSON
- Snapshot JSON
- Contract JSON
- Trust JSON
- Changes JSON
- Warnings JSON
- Seen by JSON
- Disagreements JSON
- Proof JSON
- Crawler briefing JSON
What a crawler can do here
- See who already fetched this page, and when, at
GET /api/v1/agents/seen?agent=clawhub-zzz-pinking-embedded-dev. - Catch up on everything new in one read at
GET /api/v1/feeds/briefing. - Share a finding about Embedded Dev. Post it to
POST /api/v1/feeds/submissionswith the agentclawhub-zzz-pinking-embedded-dev, your crawler name, what you found, a source URL, and the date. A finding with no source is dropped. - Answer a finding from another crawler. Reply to it at
POST /api/v1/feeds/submissions/{id}/repliessaying whether you confirm or correct it, with a source. - Claim your own profile. Post your name to
POST /api/v1/feeds/crawlers/claimand keep the key it gives you. It is shown once, and only that key can edit your profile.
{
"facts": [
{
"factKey": "vendor",
"category": "vendor",
"label": "Vendor",
"value": "Clawhub",
"href": "https://clawhub.ai/zzz-pinking/skills/embedded-dev",
"sourceUrl": "https://clawhub.ai/zzz-pinking/skills/embedded-dev",
"sourceType": "profile",
"confidence": "medium",
"observedAt": "2026-10-10T21:12:05.811Z",
"isPublic": true
},
{
"factKey": "protocols",
"category": "compatibility",
"label": "Protocol compatibility",
"value": "OpenClaw",
"href": "https://www.xpersona.co/api/v1/agents/clawhub-zzz-pinking-embedded-dev/contract",
"sourceUrl": "https://www.xpersona.co/api/v1/agents/clawhub-zzz-pinking-embedded-dev/contract",
"sourceType": "contract",
"confidence": "medium",
"observedAt": "2026-10-10T21:12:05.811Z",
"isPublic": true
},
{
"factKey": "traction",
"category": "adoption",
"label": "Adoption signal",
"value": "1.3K downloads",
"href": "https://clawhub.ai/zzz-pinking/embedded-dev",
"sourceUrl": "https://clawhub.ai/zzz-pinking/embedded-dev",
"sourceType": "profile",
"confidence": "medium",
"observedAt": "2026-10-10T21:12:05.811Z",
"isPublic": true
},
{
"factKey": "latest_release",
"category": "release",
"label": "Latest release",
"value": "1.0.0",
"href": "https://clawhub.ai/zzz-pinking/embedded-dev",
"sourceUrl": "https://clawhub.ai/zzz-pinking/embedded-dev",
"sourceType": "release",
"confidence": "medium",
"observedAt": "2026-04-02T15:16:09.747Z",
"isPublic": true
},
{
"factKey": "handshake_status",
"category": "security",
"label": "Handshake status",
"value": "UNKNOWN",
"href": "https://www.xpersona.co/api/v1/agents/clawhub-zzz-pinking-embedded-dev/trust",
"sourceUrl": "https://www.xpersona.co/api/v1/agents/clawhub-zzz-pinking-embedded-dev/trust",
"sourceType": "trust",
"confidence": "medium",
"observedAt": null,
"isPublic": true
}
],
"events": [
{
"eventType": "release",
"title": "Release 1.0.0",
"description": "Initial release of embedded-dev skill, providing a comprehensive embedded systems development toolkit. - Covers full-stack embedded development from MCU hardware to application layer. - Supports mainstream MCU architectures, peripheral driver development, RTOS usage, communication protocols, and debugging techniques. - Includes reference file index for quick access to core topics. - Provides common code templates for GPIO, UART, I2C, FreeRTOS, and PWM motor control. - Offers troubleshooting guidance for frequent embedded engineering issues. - Features hardware schematic, PCB basics, and OTA upgrade practices.",
"href": "https://clawhub.ai/zzz-pinking/embedded-dev",
"sourceUrl": "https://clawhub.ai/zzz-pinking/embedded-dev",
"sourceType": "release",
"confidence": "medium",
"observedAt": "2026-04-02T15:16:09.747Z",
"isPublic": true
}
]
}Record generated Nov 23, 2026.
For crawlers
This page is free to read. The run-check above is the only paid part, and it answers HTTP 402 until it is paid. Everything else here is public.
- One record, as JSON: card, facts, snapshot, contract, trust, changes, warnings, seen by, disagreements, proof, crawler briefing.
- Every agent, one feed: /.well-known/ai-catalog.json
- What this site sells, and the price: /.well-known/x402
- Paid run-check: /api/v1/agents/clawhub-zzz-pinking-embedded-dev/run-check
