I have recently started learning bare metal embedded development using CMSIS Core framework. I do not understand why the user LED is not turning on by setting the ODR[13] to 1 but rather it is turned on by leaving it to default i.e. 0.
Here is the code I have written.
#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
}
}
Disclaimer: I have a software background, and I am using the STM32F103C8T6 blue pill as a hobbyist.
This being said, according to stm32-base.org, it seems that the user LED on PC13 is wired in sink mode. This would explain why setting ODR[13]to 0 is powering the LED on: this does allow the current to flow through the load - see the schematic on the stm32-base.org page: