cancel
Showing results for 
Search instead for 
Did you mean: 

How should I start programming stm32f4-discovery using register level programming( NO CMSIS,HAL or SPL)?

Nimesh Khopade
Associate II

Posted on February 19, 2017 at 20:31

7 REPLIES 7
Posted on February 20, 2017 at 02:08

Read the RM0090 Reference Manual and understand the bit level functionality of the peripheral registers.

For the Cortex-M4 ARM has a TRM, and Joseph Yiu has a series of books that provide alternate perspective.

Have you any other experience programming micro-controllers at this level? Can you leverage that knowledge?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 20, 2017 at 17:37

I have programmed 8051 series, pic16f series using registers, I have also used Tiva c(Tm4c123 & Tm4c1294 Launchpads) but for that I used spl in code composer studio so I have no basic Idea of programming ARM using registers.

Also,How to set Keil run time environment for register level programming?

Thank You.

Posted on February 20, 2017 at 18:14

Can you pull in the stm32f4xx.h, or equivalent, file and use peripheral register structures?

ie

VTOR->SCB = 0x08000000;

or

if (USART1->SR & 0x80) // TXE

  USART1->DR = 0x55;

You could create pointers at specific addresses if that is the way you want to do it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 20, 2017 at 19:33

Yes sort of!!!!

Thanks for the Help.

Posted on February 21, 2017 at 00:56

+1 to all Clive said above, except the example

SCB->VTOR = 0x08000000;

or

if (USART1->SR & USART_SR_TXE) // TXE

  USART1->DR = 0x55;

;)

I recommend to avoid the 'magic numbers'. IMO it's better to use the symbols defined in the headers. Unfortunately, ST doesn't properly define values for non-single-bit fields int he registers (I try to pester them for this at all possible occasions :) ) so I augment my headers.

If you have an STM32F4 DISCO or the related EVAL, this snippet - www.efton.sk/STM32/b.c  demonstrates blinking LEDS using timer. (Augmented header www.efton.sk/STM32/stm32f4xx.zip - it's an older version of the header so don't use it for your work, I just give it here as the example of the augmentations). I threw clock or any other than the default C memory clear/init  out of my startup code; I know it's there on ARMs insistence but IMO it does not belong there, I do all clocks etc. inits wherever I find it appropriate, usually at the beginning of main().

I don't use Keil (I use CodeBlocks with EPSDebugger, or just plain gcc at times with a simplistic programmers' editor I prefer), so can't speak for that, sorry.

My 2eurocents.

JW

Posted on February 21, 2017 at 01:04

Trying to gauge the level of no library I'm playing to.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Max
ST Employee
Posted on February 21, 2017 at 04:19

I also recommend treating the libraries provided by ST (SPL or HAL) as coding examples. 

This may save you some debugging time when accessing the hardware when a specific register access mode is required ( like for example 16-bit access or when read-modify-write operation should be avoided )

Max