cancel
Showing results for 
Search instead for 
Did you mean: 

Assembly Code Example

drobison
Associate II
Posted on May 01, 2013 at 00:02

I've made up a board and embedded a STM32F4 on it.  I want example assembly code to compile and upload to the chip.  I can't find any on the entire internet for a Cortex-M4.  Does anyone have a link to a generic GPIO blinking program I can run to get myself started, like a hello world in assembly for the STM32?

#assembly-gpio-code-example-corte #mixing-assm-code-with-c
25 REPLIES 25
drobison
Associate II
Posted on May 01, 2013 at 00:52

http://pygmy.utoh.org/riscy/cortex/led-stm32.html

John F.
Senior
Posted on May 01, 2013 at 10:11

While I appreciate you want something simple to begin with, you really ought to consider the CMSIS and ST Peripheral Library. Apart from anything else, use of the library will greatly increase your chances of getting useful support here. Using the peripheral library does not prevent you from writing efficient code.

Posted on May 01, 2013 at 15:11

I wouldn't discourage anyone from trying to use assembly, the Cortex-M3 is designed for easy C usage, but being able to read/write assembler is very useful, and a skill many do not possess. I'll post some example if it helps, and take questions.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
emalund
Associate III
Posted on May 01, 2013 at 17:03

I wouldn't discourage anyone from trying to use assembly, the Cortex-M3 is designed for easy C usage, but being able to read/write assembler is very useful, and a skill many do not possess. I'll post some example if it helps, and take questions.

I do partially agree.  I do know, and agree it is essential, enough M3 assembly to read the disassembly, but would never attempt to get fluent enough to write it beyond possibly a very small routine.

if the OP is, in effect, saying ''I do not know C'' my absolute recommendation is, forget about the M3 till you have learned C.

Erik
John F.
Senior
Posted on May 01, 2013 at 17:05

''Examples'' ... Yes please. ''Discourage'' not intended ... but I stand by my comments.

dthedens23
Associate II
Posted on May 01, 2013 at 17:10

I look at C vs ASM as a ''time to market'' thing.

With C, I can get to the minimum viable product in much less time than using ASM with less defects and better readability.

the microcontrollers offered these days have large code and data space so there is less need of hand tuned firmware.

ASM is used only when there is a need to optimize some portion of code.

Agile Development suggests that optimization should not be done until one measures and determines that there is a need.

So, last time I used ASM was two years ago!  The C/C++ compilers are good.

drobison
Associate II
Posted on May 01, 2013 at 17:18

I know C++, FORTRAN, JAVA, HTML, BASIC ...  I even taught a class on C at ITT Tech.  My situation is the STM32 will be used to input Analog signals and output PWMs.  So the STM32 is like a closed loop feedback path.  The code will primarily be interrupt service routines, that take digitally processed signals in real time and use that info to modulate digital PWMs for output.  Timing need to be under 50us for everything.  Is there a library for high power applications?

I have another question though.  I see my sample code will starts at 0x00000000, while my flash memory starts at 0x08000000.  The Cortex-M? literature says my vector table should start at 0x00000000, but I read that for STM32 the vector table starts at 0x08000000. The flash starts at 0x08000000.  How is this?  Is it shadowed at 0x00000000?  Is this part of the flash ART?  Its a huge idioscncracy I have yet found an explanation for.

Posted on May 01, 2013 at 18:52

The zero mapping/shadowing is defined by the BOOTx pins, a behaviour outside the core defined by the implementer, in this case ST.

After boot you can reprogram SCB->VTOR to change the vector table address, based on the vector usage by ST, this needs to fall on a 512 byte boundary.

For the F4 see RM0090 Rev 4 see ''2.4 Boot Configuration'', and ''8.2.1 SYSCFG memory remap register (SYSCFG_MEMRMP)''

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

OK, that sheds a better light.

I would still start up everything in C using CMSIS which will do all the setup; the stuff that is not your core competence.

Then, after all is setup and good to go,  your main loop can venture off into ASM land.

easier to understand C->ASM calling convention than do all the startup stuff.