cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 WITH Assembly

pic_micro
Associate II
Posted on November 30, 2014 at 13:00

Dear All ,

I written a program in assembly to tern on bit 8 on GPOIC It is compiled well but LED does not on processor STM32F051R8T6 IDE KEIL

PRESERVE8
THUMB
RCC_APB2ENR EQU 0X40021018
GPIOC_CRH EQU 0x40011004
GPIOC_ODR EQU 0x4001100C
DEL1 EQU 0X10
DEL2 EQU 0X10
AREA RESET,DATA,READONLY
EXPORT __Vectors
__Vectors DCD 0X20002000
DCD Reset_Handler
ALIGN
AREA MYCODE,CODE,READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler PROC
clock_init
ldr R6, =RCC_APB2ENR 
movs R0, #0x1C
str R0, [R6]
ldr R6, =GPIOC_CRH
ldr R0, =0x3333333 
str R0, [R6]
LDR r1, =GPIOC_ODR
LDR r0, =0x0A00 
STR r0, [r1] 
ENDP 
B DELAY
DELAY 
SUBS R2,#1
BNE DELAY
DEL SUBS R3,#1
BNE DEL
B Reset_Handler
ALIGN
END

39 REPLIES 39
Posted on November 30, 2014 at 14:56

The MODER register for pins 0..7 is at +0x00 not +0x04

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pic_micro
Associate II
Posted on November 30, 2014 at 15:38

 I think 

Port configuration register high (GPIOx_CRH) (x=A..G)

Address offset: 0x04

I need to set  pin 8 and 9 of GPIOC as an output

Posted on November 30, 2014 at 16:01

Sorry read PC0

You'll still need to enable the GPIOC clock on the AHB. Bit 19 of RCC_AHBENR (not APB)

You might also want to get into the habit of masking/oring on to the registers so as not to disturb existing clocks/settings.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pic_micro
Associate II
Posted on December 01, 2014 at 17:36 Dear Sir, Please check that this code have some errors

;PRESERVE8
THUMB
RCC_AHBENR EQU 0x40021014
GPIOC_MODER EQU 0x40020800
GPIOC_CRH EQU 0x40011004
GPIOC_ODR EQU 0x40020814
DEL1 EQU 0X10
DEL2 EQU 0X10
AREA RESET,DATA,READONLY
EXPORT __Vectors
__Vectors DCD 0X20002000
DCD Reset_Handler
ALIGN
AREA MYCODE,CODE,READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler PROC
clock_init
LDR R6, =RCC_AHBENR 
LDR R0, =0x8000 ; Bit 19 of RCC_AHBENR 
STR R0, [R6]
LDR R6, = GPIOC_MODER
LDR R0, = 0x100
STR R0, [R6]
LDR R1, =GPIOC_ODR 
LDR R0, =0x300 
STR R0, [R1] 
ENDP 
B DELAY
DELAY 
SUBS R2,#1
BNE DELAY
DEL SUBS R3,#1
BNE DEL
B Reset_Handler
ALIGN
END

Posted on December 01, 2014 at 18:35

0x8000 would be bit 15, 0x80000 would be bit 19

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pic_micro
Associate II
Posted on December 01, 2014 at 18:48

Yes, Grate thanks now it is working

I will come on next steps

;PRESERVE8
THUMB
RCC_AHBENR EQU 0x40021014
GPIOC_MODER EQU 0x48000800
GPIOC_ODR EQU 0x48000814
DEL1 EQU 0X10
DEL2 EQU 0X10
AREA RESET,DATA,READONLY
EXPORT __Vectors
__Vectors DCD 0X20002000
DCD Reset_Handler
ALIGN
AREA MYCODE,CODE,READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler PROC
clock_init
LDR R6, =RCC_AHBENR 
LDR R0, =0x80000 ; Bit 19 of RCC_AHBENR 
STR R0, [R6]
LDR R6, = GPIOC_MODER
LDR R0, = 0x55555555
STR R0, [R6]
LDR R1, =GPIOC_ODR 
LDR R0, =0x200 
STR R0, [R1] 
LDR R1, =GPIOC_ODR 
LDR R0, =0x100 
STR R0, [R1]
ENDP 
B DELAY
DELAY 
SUBS R2,#1
BNE DELAY
DEL SUBS R3,#1
BNE DEL
B Reset_Handler
ALIGN
END

pic_micro
Associate II
Posted on December 01, 2014 at 19:03

Dear clive1

Can we ignore the following definitions, inserting header file of the target MCU, top of the code?

RCC_AHBENR EQU 0x40021014
GPIOC_MODER EQU 0x48000800
GPIOC_ODR EQU 0x48000814

Please advice
pic_micro
Associate II
Posted on December 02, 2014 at 17:33

Dear All

Can we use the header file instead of following definitions

RCC_AHBENR EQU 0x40021014
GPIOC_MODER EQU 0x48000800
GPIOC_ODR EQU 0x48000814

Posted on December 02, 2014 at 18:34

I guess if you have one with equivalent equates in it...

There's probably a tool to convert .H to .INC formats, I've used one in the past.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..