cancel
Showing results for 
Search instead for 
Did you mean: 

How to program STM32F4 discovery in assembly using keil uvison5

sbaadarsh
Associate II
Posted on August 14, 2016 at 15:02

Hi,

I am newbie to ARM.Recently I bought a STM32F4 discovery kit and I like to start up programming it in assembly language to get clear understanding of the processor.Can anyone please provide me a small assembly program example code.I have no idea,what are the things I have to add in the program,before I start programming in assembly.

#keil-uvision5 #stm32f4-discovery #keil-uvision #!stm32f4
8 REPLIES 8
Posted on August 14, 2016 at 18:00

Ok, but what do you actually want to achieve in assembler? Do you have any similar programming experience on any other platform? I've posted assembler examples to the forum.

Take an existing project, add the instructions you want to experiment with in startup

_stm32f4xx.s at Reset_Handler

The processor expects a vector table with initial SP and PC setting, this is how it gets to the Reset_Handler. Turn off the ''run to main'' option in the debugger settings, and you can step through all the code you have added.

Want to learn how the processor works, suggest you read the ARM TRM for the Cortex-M4, and books like those from Joseph Yiu. Several online resources dealing with ARM assembler.

Take smaller steps, look at the assembler listing or disassembly of code generated by the compiler.

http://www.keil.com/forum/61613/

You will also need to familiarize yourself with all the bus and peripheral registers of the F4 design, by reading the RM0090 Reference Manual.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
sbaadarsh
Associate II
Posted on August 15, 2016 at 08:24

Thank you Clive.I tried by adding a startup_stm32f407xx.s in the project and I run.Initially I got two errors.However I managed to get rid of one error,but still I have one error left.I attached the screenshot of the error.It shows error that undefined symbol SystemInit

I have assembly programming experience in ARM mega series microcontrollers and 8

________________

Attachments :

stmerror.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Htlm&d=%2Fa%2F0X0000000aWh%2F1zxE5L7rmEwgQB31bTLe57Rrg88PF0H5yrPIG4mfTMo&asPdf=false
Posted on August 15, 2016 at 13:32

If you have not provided source files contain those functions, then don't import and call them.

...
Reset_Handler PROC
EXPORT Reset_Handler 
LDR R0, =123456789
B . ; Infinite Loop
ENDP
...

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
sbaadarsh
Associate II
Posted on August 15, 2016 at 17:27

Thank you again Clive.I somehow figured out a way to get rid of that error message.I modified the startup_stm32f407xx.s file in the Reset_Handler part as I attached in the first picture.I found out ,where the main program start address and I directly branched to Main as I declared.Is this a right way to do so or is it cause any trouble later when flashed to the STM32f4 broad?

________________

Attachments :

found0.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtjX&d=%2Fa%2F0X0000000aWK%2Fp5Wt3BeHIsnYRE9VTWJfOfw6B2Gqf7hNZM7pISqzMqY&asPdf=false

found1.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Htlw&d=%2Fa%2F0X0000000aWj%2FJFu6nFtd0yk38VTmczK.UK.PfsMetsNpy_v.6xkAnwQ&asPdf=false
Posted on August 15, 2016 at 18:17

AVR Mega?

Looks reasonable enough, I would probably avoid letting the code plough into the literal pool by putting a loop at the end of the user code.

I tend to start with code to enable the USART and output data/diagnostics, writing small routines to output hex, decimals and strings. The STM32F4-DISCO is perhaps less than ideal in that regard.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
sbaadarsh
Associate II
Posted on August 15, 2016 at 19:01

Since I am very new to this ARM controllers and keil uvision,everythink seems too new.In AVR ,I don't use this startup to setup exception handlers and Vectors,Straight forward, open Atmel studio,selecting the microcontroller,selecting language,build and used avrdude to upload the generated .hex file.

Is there any reason,why we have to compulsory declare the Exception handlers?Why not writing the code directly?

Posted on August 15, 2016 at 21:05

You can do whatever the CPU lets you, at a minimum you need a vector table with two entries, the Initial SP and PC

If you ignore the other vectors, or having place-holder functionality for them, at some point the system is going to crash.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on August 16, 2016 at 06:21

What Clive is avoiding saying out loud, but everybody else is screaming is ''just use C!''

The ARM processors, like all RISC processors is designed to be used in conjunction with compilers. You can use assembly, but it isn't recommended, especially with a processor as complex as an ARM. Your time is better used learning the architecture from a book rather than putting together the grains of sand that is assembly code.

Other processors have been more amenable to writing assembly code, like the National Semiconductor 32000 line, but with good compilers, there just isn't much point in making processors that are programmed by hand anymore, and these processors have died out. Assembly writing is too slow and the optimizing compilers are too good.

Getting a processor started, from boot, is not where you should be learning an architecture. That is like learning building design by implementing New York's Guggenheim museum. You have far greater things to worry about, like starting the clocks, finding the device registers in the 4.2billion possible memory locations, and getting an LED blinking.

Asking if you need the vector table tells me that you haven't looked at the interrupt section of the book yet. Clive is being very generous by telling you that you don't need the vector table, but the processor is expecting it to be there, and if anything goes wrong, and it will, the processor will go to where the vector table should be, pick up your code and interpret it as an address, then generate another interrupt when that address is bogus, and repeat until you recognize that you've done something wrong. The startup files that come with your compiler take care of a zillion details that are completely arcane, easy to get wrong, and really don't need a rewrite, just use them.

What should you do? Let's see, read this: http://embedded.fm/blog/2016/2/25/do-i-need-to-know-assembly-language-to-write-c-well

Then start here: http://embedded.fm/blog/2016/2/16/embedded-software-engineering-101-introduction

I'm starting a new blog series dealing with getting started with the STM32F407 in particular, but the knowledge is very transferable to any ST ARM. Take a look at the rest of the work on embedded.fm, step away from the assembler, and grab your compiler.

A