STM32F4xx C where to find what registers/instructions to use! - Page 1
Forum section: electronics / general

author: Glenn0010
author_rank: Regular Contributor
timestamp: November 24, 2017, 12:15:41 pm
content: 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!

author: Monkeh
author_rank: Super Contributor
timestamp: November 24, 2017, 12:26:05 pm
content: http://lmgtfy.com/?q=STM32F407+manual

author: ataradov
author_rank: Super Contributor
timestamp: November 24, 2017, 07:02:41 pm
content: 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.

author: newbrain
author_rank: Super Contributor
timestamp: November 24, 2017, 07:49:21 pm
content: 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 STM32F407datasheet, and could not find what they were looking for.STM32 MCUs documentation is usually split over three manuals: reference, programmer, and datasheet.Thereference manualcovers all the registers for each peripheral, with a (bare bone) explanation of how they work and how to set up and use them.Thedatasheetcontains a general family and peripherals description, differences between models in the same family, pinouts, and electrical characteristics.Theprogramming manualis 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 byCube-MX, and start from there.

author: westfw
author_rank: Super Contributor
timestamp: November 25, 2017, 12:04:03 am
content: Excellent summary!QuoteUsually "per family" - peripherals might be different between 32F4xx and 32F1xx...QuoteIncluding how many of each peripheral on that particular chip.QuoteARM 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:PORTS->ODR.reg = 0x1234; //Atmel style syntaxGPIOC->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.)

author: Glenn0010
author_rank: Regular Contributor
timestamp: November 25, 2017, 07:38:08 am
content: 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

author: hans
author_rank: Super Contributor
timestamp: November 25, 2017, 09:34:07 am
content: 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.

author: Glenn0010
author_rank: Regular Contributor
timestamp: November 25, 2017, 08:38:46 pm
content: Quote from: hans on November 25, 2017, 09:34:07 amYes 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 etcIt is amazing!

author: lgbeno
author_rank: Frequent Contributor
timestamp: November 27, 2017, 06:42:19 am
content: 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