设置 GPIOC->ODR[13] = 1 不会调亮用户 LED,而是通过将其保留为默认值(即 0)来调亮它。 【STM32F103C8T6(蓝色药丸)】

Setting GPIOC->ODR[13] = 1 is not tuning up the user LED, rather it is turned up by leaving it to default (i.e. 0). [STM32F103C8T6 (blue pill)]

我最近开始使用 CMSIS Core 框架学习裸机嵌入式开发。我不明白为什么用户 LED 没有通过将 ODR[13] 设置为 1 打开,而是通过将其保留为默认值即 0.

打开

这是我写的代码。

 #include "stm32f103xb.h"


int main(void){
    /** 
    * Enable clock for APB2 bus
    * RCC_AP2ENR --> BIT 4 --> 1
    **/
    RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;

    /**
     * Set GPIOC PIN 13 OUTPUT
     * GPIOC_CRH --> BIT(23,22,21,20) = (0,0,0,1)
     * MODE13[1:0] = 0 1
     * CNF13[1:0] = 0 0
     */
    GPIOC->CRH = GPIO_CRH_MODE13_0 | (GPIOC->CRH & ~ GPIO_CRH_CNF13);
    
    while(1){
        GPIOC->ODR |= GPIO_ODR_ODR13; // commenting this line turns on the LED
    }
}

免责声明:我有软件背景,我作为爱好者使用STM32F103C8T6 blue pill。

话虽如此,据stm32-base.org, it seems that the user LED on PC13 is wired in sink mode。这可以解释为什么将 ODR[13] 设置为 0 为 LED 供电:这确实允许电流流过负载 - 请参阅 stm32-base.org 页面上的原理图: