Author Topic: STM32F4xx C where to find what registers/instructions to use!  (Read 619 times)

0 Members and 1 Guest are viewing this topic.

Offline Glenn0010

  • Contributor
  • Posts: 26
  • Country: mt
STM32F4xx C where to find what registers/instructions to use!
« on: November 24, 2017, 11: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!
 

Offline Monkeh

  • Super Contributor
  • ***
  • Posts: 5108
  • Country: gb
 
The following users thanked this post: Glenn0010

Online ataradov

  • Super Contributor
  • ***
  • Posts: 3699
  • Country: us
  • I informed you thusly
    • Personal site
Re: STM32F4xx C where to find what registers/instructions to use!
« Reply #2 on: November 25, 2017, 06:02:41 AM »
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.
Alex
 

Online newbrain

  • Frequent Contributor
  • **
  • Posts: 385
  • Country: se
Re: STM32F4xx C where to find what registers/instructions to use!
« Reply #3 on: November 25, 2017, 06:49:21 AM »
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 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 contains a general family and peripherals description, differences between models in the same family, pinouts, and electrical characteristics.

The programming manual 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, and start from there.
 
The following users thanked this post: Glenn0010

Offline westfw

  • Super Contributor
  • ***
  • Posts: 2352
  • Country: us
Re: STM32F4xx C where to find what registers/instructions to use!
« Reply #4 on: November 25, 2017, 11:04:03 AM »
Excellent summary!

Quote
The reference manual covers all the registers for each peripheral
Usually "per family" - peripherals might be different between 32F4xx and 32F1xx...

Quote
The datasheet 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 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.)
 
The following users thanked this post: Glenn0010

Offline Glenn0010

  • Contributor
  • Posts: 26
  • Country: mt
Re: STM32F4xx C where to find what registers/instructions to use!
« Reply #5 on: November 25, 2017, 06:38:08 PM »
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 ;)
 

Offline hans

  • Frequent Contributor
  • **
  • Posts: 824
  • Country: nl
Re: STM32F4xx C where to find what registers/instructions to use!
« Reply #6 on: November 25, 2017, 08:34:07 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. :)
 
The following users thanked this post: newbrain

Offline Glenn0010

  • Contributor
  • Posts: 26
  • Country: mt
Re: STM32F4xx C where to find what registers/instructions to use!
« Reply #7 on: November 26, 2017, 07:38:46 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. :)

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!
 

Offline lgbeno

  • Frequent Contributor
  • **
  • Posts: 337
  • Country: 00
Re: STM32F4xx C where to find what registers/instructions to use!
« Reply #8 on: November 27, 2017, 05:42:19 PM »
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
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf