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
pic_micro
Associate II
Posted on December 04, 2014 at 17:45

Dear Sir,

You are saying INC files aren't available for ARM

Posted on December 04, 2014 at 18:04

Or you can use the C preprocessor before running the assembler. Your toolchain may have a straighforward support for it (gcc does).

JW

Posted on December 04, 2014 at 18:34

You are saying INC files aren't available for ARM

These would not appear to be ARM specific equates.

I'm saying that if you have your desired equates in some other file, or can generate similar equates by processing a .H file, then do that. There are not a lot of assembler resources available because that's not how the bulk of users are programming their devices. Sometimes you have to fashion your own tools, scripts, or solve problems to your own satisfaction.
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 05, 2014 at 05:41

Thanks

I can prepare a ''INC'' file inserting all registers address and name using note pad, Then can I include it to KEIL IDE ?

Please advice

pic_micro
Associate II
Posted on December 05, 2014 at 05:43

Dear Jan,

Grate thanks for the reply

I could not understand

Your feather explanation in this regard is grate

Posted on December 05, 2014 at 14:46

Sorry for the confusion - my above proposal would not work here.

Preprocessor would only help if all peripheral-related constants would be directly #defined - this is not the case with the stm32XXxxx.h headers, where addresses are defined indirectly through typedef struct.

(Explanation - I worked extensively with AVRs in the near past, using avr-gcc and avr-libc, and the peripheral-defining headers there do use direct defines also for peripheral register addresses).

Jan

Posted on December 05, 2014 at 15:17

  INCLUDE FOO.INC ; ??

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/1208.html

http://www.keil.com/support/man/docs/armasm/armasm_dom1361290015482.htm

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 07, 2014 at 03:41

Dear Sir,

I more improved my assemble program adding systic timer After configuring systic timer the LED blinking part stopped after two toggles I do not enable interrupt please advice

THUMB
RCC_AHBENR EQU 0x40021014
GPIOC_MODER EQU 0x48000800
GPIOC_ODR EQU 0x48000814
STK_CSR EQU 0xE000E010
STK_RVR EQU 0xE000E014 
STK_CVR EQU 0xE000E018
STK_CALIB EQU 0xE000E01C 
DEL1 EQU 0Xfffff
DEL2 EQU 0Xffffffff
AREA RESET,DATA,READONLY
EXPORT __Vectors
__Vectors DCD 0X20002000
DCD Reset_Handler
ALIGN
AREA MYCODE,CODE,READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler PROC
start BL Sys_init
LOOP BL blink_LED 
BNE LOOP
stop
Sys_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 R3,=STK_RVR ;Reload Value Register
LDR R4,=0Xffffff
STR R4,[R3] 
LDR R3,=STK_CVR ;Current Value Register
LDR R4,=0X0
STR R4,[R3]
LDR R3,=STK_CSR ;Control and Status Register
LDR R4,=0X7
STR R4,[R3]
BX LR
BX LR
blink_LED LDR R1, =GPIOC_ODR 
LDR R0, =0x200 
STR R0, [R1] 
BL DELAY
LDR R1, =GPIOC_ODR 
LDR R0, =0x100 
STR R0, [R1]
BL DELAY
B blink_LED
ENDP 
DELAY 
LDR R1,=DEL1
S SUBS R1,#1
CMP R1,#00
BEQ DELAY1
BNE S
DELAY1 BX LR 
ALIGN
END

Or.... I got the point I enable the ''TICKINT: SysTick exception request enable'' Thanks
pic_micro
Associate II
Posted on December 07, 2014 at 04:41

@jan

Yes, I agreed with you. When we use ''C'' the .H file has everything related to register definitions but in assembly INC files are very rear ( I think ) as explained by clive1 in his post and my previous experience with PIC 8 - 16bit also have INC files, but programmer point of view 32 bit processor working with assembly is long development cycle other than beginners who trying to understand core operations.

Posted on December 07, 2014 at 05:35

You'd want the vector table to increase in size to contain all of the system handlers, not just the initial SP/PC pair.

Look at a more complete startup_stm32f0xx.s file.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..