在mbed站点上随便浏览,看到一篇文章
https://developer.mbed.org/handbook/mbed-library-internals
(叫啥好,mbed 库技术内幕?mbed库深入揭秘?
那些做翻译的真不容易啊)
NND的,写了一堆内容发现自己看着都别扭,统统删掉
还是想哪写哪方便,白话文。
mbed的文章中是以LPC17xx的blink为例进行的说明
从LPC17xx datasheet中查询到对应的GPIO的寄存器地址
然后对对应寄存器进行set或者clear操作,从而实现点灯灭灯
#include "mbed.h"
// Reuse initialization code from the mbed library
DigitalOut led1(LED1); // P1_18
int main() {
unsigned int mask_pin18 = 1 << 18;
volatile unsigned int *port1_set = (unsigned int *)0x2009C038;
volatile unsigned int *port1_clr = (unsigned int *)0x2009C03C;
while (true) {
*port1_set |= mask_pin18;
wait(0.5);
*port1_clr |= mask_pin18;
wait(0.5);
}
}
那么对Nucleo L053R8而言
我们首先需要知道的是板载LED连接到哪个GPIO
在ST的文档中我们找到这样一段话:
LEDs
The tricolor LED (green, orange, red) LD1 (COM) provides information about ST-LINK communication status. LD1 default color is red. LD1 turns to green to indicate that communication is in progress between the PC and the ST-LINK/V2-1, with the following setup:
?Slow blinking Red/Off: at power-on before USB initialization
?Fast blinking Red/Off: after the first correct communication between the PC and STLINK/
V2-1 (enumeration)
?Red LED On: when the initialization between the PC and ST-LINK/V2-1 is complete
?Green LED On: after a successful target communication initialization
?Blinking Red/Green: during communication with target
?Green On: communication finished and successful.
?Orange On: Communication failure
User LD2: the green LED is a user LED connected to Arduino signal D13 corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on the STM32 target. Please refer to Table 10 to Table 21.
?When the I/O is HIGH value, the LED is on.
?When the I/O is LOW, the LED is off.
LD3 PWR: the red LED indicates that the MCU part is powered and +5V power is available.
有这个图可以看出,这个LED连接至D13, PA5
| 有奖活动 | |
|---|---|
| 2026年“我要开发板活动”第三季,开始了! | |
| 硬核工程师专属补给计划——填盲盒 | |
| “我踩过的那些坑”主题活动——第002期 | |
| 【EEPW电子工程师创研计划】技术变现通道已开启~ | |
| 发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
| 【EEPW在线】E起听工程师的声音! | |
| 高校联络员开始招募啦!有惊喜!! | |
| 【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
我要赚赏金打赏帖 |
|
|---|---|
| 以启明云端ESP32P4开发板实现TF卡读写功能被打赏¥28元 | |
| 【分享开发笔记,赚取电动螺丝刀】树莓派5串口UART0配置被打赏¥25元 | |
| 【STM32F103ZET6】17:分享在Rtos项目中断管理的使用经验被打赏¥23元 | |
| 【STM32F103ZET6】16:分享在中断中恢复串口任务,遇到的问题被打赏¥31元 | |
| 在FireBeetle2ESP32-C5上实现温度大气压检测及显示被打赏¥21元 | |
| 【分享开发笔记,赚取电动螺丝刀】SAME51双串口收发配置被打赏¥27元 | |
| Chaos-nano操作系统在手持式VOC检测设备上的应用被打赏¥37元 | |
| 【分享开发笔记,赚取电动螺丝刀】关于在导入第三方库lib时,wchart类型冲突的原因及解决方案被打赏¥30元 | |
| 在FireBeetle2ESP32-C5上实现温湿度检测和显示被打赏¥20元 | |
| 在FireBeetle2ESP32-C5上实现光照强度检测及显示被打赏¥21元 | |