EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: Glenn0010 on November 24, 2017, 12:15:41 pm

Title: STM32F4xx C where to find what registers/instructions to use!
Post by: Glenn0010 on November 24, 2017, 12:15:41 pm
Hi All,

I am working with the STM32F407VG discovery board. I would like to know if there is any documentation where you can find what registers/instructions you have to define to initialize a timer for example. The only documentation I have managed to find is with Assembly langue instructions but I program in C mainly.

I have been working with the LPC2119 until now (ARM7), and its datasheet is very comprehensive with regards to registers and what you have set and what the different values do.

I know that there is the CMIS library and there are files for each peripheral, however each 'instruction' of the structure in there does not really say what it does and what its different values do differently!

For example what is the difference between PWM_Mode_1 and 2 in the following?

 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

Thanks!
Title: Re: STM32F4xx C where to find what registers/instructions to use!
Post by: Monkeh on November 24, 2017, 12:26:05 pm
http://lmgtfy.com/?q=STM32F407+manual (http://lmgtfy.com/?q=STM32F407+manual)
Title: Re: STM32F4xx C where to find what registers/instructions to use!
Post by: ataradov on November 24, 2017, 07:02:41 pm
User Manual for the MCU will help with the registers, but "TIM_OCInitStructure" looks like some sort of TI library, which may be arbitrarily close or far away from the actual hardware. You would need to also find the document for that library.
Title: Re: STM32F4xx C where to find what registers/instructions to use!
Post by: newbrain on November 24, 2017, 07:49:21 pm
Yes,
Google is (sometimes) your friend, but it's not easy to ask it the right question.
It's possible that the OP has searched for STM32F407 datasheet, and could not find what they were looking for.

STM32 MCUs documentation is usually split over three manuals: reference, programmer, and datasheet.

The reference manual (http://www.st.com/resource/en/reference_manual/dm00031020.pdf) covers all the registers for each peripheral, with a (bare bone) explanation of how they work and how to set up and use them.

The datasheet (http://www.st.com/resource/en/datasheet/stm32f405rg.pdf) contains a general family and peripherals description, differences between models in the same family, pinouts, and electrical characteristics.

The programming manual (http://www.st.com/resource/en/programming_manual/dm00046982.pdf) is for core specific information, almost a 1 to 1 rewrite of ARM documentation. It includes also description of ARM core peripherals, e.g. NVIC and SYSCTL.

It's quite a lot, more than 1k pages for for an F4...

To program, in the OP example a timer, include the stmf4xx.h file from the CMSIS, no need for the HAL or LL (the two ST provided abstraction libraries, and where the TIM_OCInitStructure came from), and work your way using the reference manual.

For a beginner with STM32s, it might be easier to have initialization code generated by Cube-MX (http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html), and start from there.
Title: Re: STM32F4xx C where to find what registers/instructions to use!
Post by: westfw on November 25, 2017, 12:04:03 am
Excellent summary!

Quote
The reference manual (http://www.st.com/resource/en/reference_manual/dm00031020.pdf) covers all the registers for each peripheral
Usually "per family" - peripherals might be different between 32F4xx and 32F1xx...

Quote
The datasheet (http://www.st.com/resource/en/datasheet/stm32f405rg.pdf) contains a general family and peripherals description, differences between models in the same family
Including how many of each peripheral on that particular chip.

Quote
The programming manual (http://www.st.com/resource/en/programming_manual/dm00046982.pdf) is for core specific information, almost a 1 to 1 rewrite of ARM documentation. It includes also description of ARM core peripherals, e.g. NVIC and SYSCTL.
ARM also has separate "programing reference manual" and "architecture reference manual"; you may need both.

It's probably also useful/necessary to drill down through the CMSIS directory structure until you find the .h file for the particular chip, so you can see exactly how the register/field/bit/value names from the "reference manual" translate into the symbols you need for your actual code.  Some of this is supposed to be standardized (by CMSIS), but conformance is ... sporadic, and subject to some interpretation.  For example:
Code: [Select]
   PORTS[2]->ODR.reg = 0x1234;   //Atmel style syntax
   GPIOC->ODR = 0x1234; // ST style syntax.
(also, Atmel defines bitfields like "USART1.STATUS.bit.RXRDY", while it looks like ST only defines bitmasks.  Stuff like that.)

My particular STMCube install (v1.4) has this file at ...STM32Cube_FW_F4_V1.4.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f405xx.h, and it's a single file.  Other vendors or chips may use different include file structures as well (Atmel has separate "component/periph.h" files that describe each peripheral independently of where it lives in any particular chip.)
Title: Re: STM32F4xx C where to find what registers/instructions to use!
Post by: Glenn0010 on November 25, 2017, 07:38:08 am
Thanks to All that replied. I just got confused by all the documentation available and could not find the one for the registers, as I was searching for the "datasheet" not the manual. Now with the manual and the cmsis library I can make some more sense of how it actually works and what the different parameters mean.

Its incredible what a huge leap there is in technology between the LPC119 and the STM32F4!!. I will be able to include more features in my BLDC motor Controller ;)
Title: Re: STM32F4xx C where to find what registers/instructions to use!
Post by: hans on November 25, 2017, 09:34:07 am
As far as I know, NXP also have "User manuals" for their parts, even the older ARM7TDMI ones.

For larger complex digital chips/MCU's, you'll find that the datasheet is more useful for designing the board and the user manual is useful for firmware development. However checking the user manual during PCB development could be useful.

For example if you're planning peripherals. STM32CubeMX can help with that on the pin assignment level, but there may be other constraints, like APB bus traffic/clocks but above all DMA.
I got burned once by that a timer generated a DMA request event for a SPI peripheral that was on the other APB bus, introducing large latencies. This was caused because I could not use a timer available on the same APB bus of SPI, because it's DMA channel was conflicting with another serial peripheral I was using DMA. It's unfortunate the programmability of the DMA channels is not as 'infinite' as it could be, so double check the planning. :)
Title: Re: STM32F4xx C where to find what registers/instructions to use!
Post by: Glenn0010 on November 25, 2017, 08:38:46 pm
As far as I know, NXP also have "User manuals" for their parts, even the older ARM7TDMI ones.

For larger complex digital chips/MCU's, you'll find that the datasheet is more useful for designing the board and the user manual is useful for firmware development. However checking the user manual during PCB development could be useful.

For example if you're planning peripherals. STM32CubeMX can help with that on the pin assignment level, but there may be other constraints, like APB bus traffic/clocks but above all DMA.
I got burned once by that a timer generated a DMA request event for a SPI peripheral that was on the other APB bus, introducing large latencies. This was caused because I could not use a timer available on the same APB bus of SPI, because it's DMA channel was conflicting with another serial peripheral I was using DMA. It's unfortunate the programmability of the DMA channels is not as 'infinite' as it could be, so double check the planning. :)

Yes you're right. I hues when I typed in LPC2119 datasheet, the user manual came up and didnt notice it was actually called the user manual.

Yes I have actually used the STMCube just to make assigning the pins easier etc, however I still program using the CMSIS library rather than the HAL library.. Its a shame that the cube doesn't really explain what each 'command' in the configuration actually does, especially for beginners with the architecture. Seem like if it is developed more it could have a lot of potential.

Yeah I totally get where you are coming from, I guess the higher the complexity of the micro the more likely it is that you run into issues like the one you pointed out. But I am really amazed at how much more powerful it is than the LPC2119. I am drooling at the dead time generator and XOR gate for the hall sensors. Like I am really geeking out at it. As with the 2119 I had to solve the deadtime isuess with a gate driver, but then your dead time is kind of lock, more components etc

It is amazing!
Title: Re: STM32F4xx C where to find what registers/instructions to use!
Post by: lgbeno on November 27, 2017, 06:42:19 am
You may also want to check out libopencm3.  I've been using this for a STM32F415 project and it is pretty nice.


Sent from my iPhone using Tapatalk Pro