1

My objective is to write bare metal assembly code for STM32F103 that turns PB1 LED on.

ussrback
  • 491
  • 2
  • 8
  • 22

1 Answers1

0

Update: Reset value of every register is mentioned on top of the register in Reference Manual (Attached is snap below). enter image description here

===============================================

Wherever there are multi-bit parameters in registers, I am making a habbit of clearing them first and then applying a desired NON Zero value.

In case of setting Zero values, there is no need for clearing them. You are already clearing it.

here is a sample code i use.

////Clearing the bit masks. Need to keep it a practice at all multibit parameters
GPIOA->CRL=(GPIOA->CRL & ~((3U<<GPIO_CRL_CNF7_Pos) | (3U<<GPIO_CRL_CNF5_Pos)))
        | (2U<<GPIO_CRL_CNF7_Pos) | (2U<<GPIO_CRL_CNF5_Pos);//setting desired values

Here in above code, I want to set Configuration of PA7 & PA5 to Alternate Port function (Push-Pull).

So I cleared those bits and then set the desired value.

If i wanted to set a Zero in these bits, then I can simply write as below (Written for PC13)

GPIOC->CRH |= (GPIOC->CRH & ~(1U<<GPIO_CRH_CNF13_Pos)) | (2U<<GPIO_CRH_MODE13_Pos);     //LED PIN