Skip to main content
11 votes

I want to learn a real microcontroller with STM32F4. Which library should I use (HAL, SPL, or CMSIS)?

If you really want to learn a specific microcontroller, ditch the vendor provided libraries (which are often bug ridden anyway), and work from the datasheet to set registers up yourself. You're best ...
Colin's user avatar
  • 4,577
9 votes
Accepted

STM32 HAL_DELAY hangs with HAL_GetTick=0

As an advanced STM32 user I can say that you did not handle the SysTick interrupt. The HAL library enables the SysTick timer and interrupts for it. In stm32f4xx_it.c file add this function call: <...
unalignedmemoryaccess's user avatar
9 votes

I want to learn a real microcontroller with STM32F4. Which library should I use (HAL, SPL, or CMSIS)?

If your goal is to understand in detail how the microcontroller works, then just use the register declaration file (stm32fxxx.h) and work directly with the hardware. It is not that difficult, and for ...
Jon's user avatar
  • 5,117
9 votes
Accepted

Difference between I2C STM32 HAL functions

The MEM functios can directly read and write devices that have register address based access. They write the register addresss before reading or writing the register data. Most chips are like this. ...
Justme's user avatar
  • 172k
8 votes

How to use libraries with delays inside within a time critical STM32 HAL application?

You can implement an RTOS and replace the HAL_Delay for the equivalent Thread_Sleep function available. But the library doesn't look very complicated, you can probably pick any of the options and do ...
Jeroen3's user avatar
  • 24k
7 votes

I2C busy flag strange behaviour

ST has released an errata sheet called: STM32F100xC, STM32F10 0xD and STM32F100xE high-density value line device limitations. The interesting point here is: 2.9.7 I2C analog filter may provide ...
AxelBe's user avatar
  • 71
7 votes
Accepted

STM32F072 - Working with HAL and FatFS

I've finally manage to implement low-level drivers and they seem to work nicely. I'm sharing source code of my implementation in case somebody else gets stuck at the same part that I was.
Calculon's user avatar
  • 152
7 votes

Getting PWM to work on STM32F4 using ST's HAL libraries

I'm using STCubeMX and the generated HAL initialization files. Process verified on my F302 Nucleo Board. I set up advanced Timer 1 (TIM1) with a normal and complementary output, no dead time. Here's ...
Shreeyak Sajjan's user avatar
7 votes

Multiple(five) alarm time setting in stm32f0 mcu

Check AN3371 at the official website of ST. However, according to paragraph 2 there are only 2 alarms (A and B). Alternatives: Keep 5 alarms in your own code, set the first alarm (A) as alarm 1. ...
Michel Keijzers's user avatar
7 votes
Accepted

STM32 RTC with HAL libraries

The solution is to call both GetTime and GetDate at the same time, If you call only GetTime it does not update correctly: ...
Robert's user avatar
  • 101
6 votes
Accepted

STM32 HAL drivers

If you do not want to use the STM32CubeMX code generator tool but still need simple example projects then you should use the STM32Cubexx firmware examples that are available for all STM32 series. ...
Bence Kaulics's user avatar
6 votes

I2C busy flag strange behaviour

This is less an answer and more a warning... I got stuck with the same problem and the code above helped (along with stretching the I2C reset and initialising the clock before the GPIO - see linked ...
Happy Heyoka's user avatar
6 votes
Accepted

STM32 HAL UART Transmit DMA problem

First of all I can't get the stm to transmit at baud rates higher then the standard 115200, according to the datasheets both the FT2232H and the STM32F7 should be capable of at least 12M baud. The ...
followed Monica to Codidact's user avatar
6 votes
Accepted

Coding style in STM32 HAL code

A do { something; } while (0) is a typical pattern in macros, where you want to make sure that all instructions get executed. Example why this is important: ...
filo's user avatar
  • 9,096
5 votes

How to read from multiple channels of the ADC on an STM32F407?

hadc1.Init.ScanConvMode = DISABLE; the sequencer is disabled so you cant read or even convert data coming from the other channel. Also you have to define the rank ...
Aymen Lachkhem's user avatar
5 votes

STM32 ADC conversion using HAL

I would like to add that for my setup (nucleo-h743) it was not enough to set: hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV; I also had to enable the overrun ...
biglotusturtle's user avatar
5 votes
Accepted

LTC4015 variable I2C speed operation

Your snip of the datasheet is missing a very important part - the heading. If you look up from the 400kHz you can see it's in the MAX column. So the speed specified is simply the maximum clock rate. ...
mike65535's user avatar
  • 1,505
5 votes

STM32: Difference between HAL_xxx_Init() and HAL_xxx_MspInit()

The ST User Manual UM1725 - Description of STM32F4 HAL and LL drivers, see pages 61 - 63, gives an explanation: The peripheral initialization is done through HAL_PPP_Init() while the hardware ...
m00wn's user avatar
  • 342
5 votes

Large delay between I2C messages on STM32F303 - trying to read as fast as possible

These Callback functions are called from the I2C interrupt handler. You shouldn't make other API calls from them. HAL_I2C_Master_Transmit_IT() check timeouts etc which might not work from an interrupt ...
Anders Petersson's user avatar
4 votes
Accepted

How to know UART DMA TX is finished for RS485 enable process in STM32F4 CubeMX

You should use the following function: HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) and make sure that the ...
Bence Kaulics's user avatar
4 votes

Misunderstanding of hal_spi Communication Functions

SPI is a very simple interface, which essentially amounts to connecting shift registers between two chips. There is no handshaking of any sort that occurs. If nothing is connected to the SPI of the ...
David Moore's user avatar
4 votes

Use STM32 interrupt with FreeRTOS

I am aware this is an old question, but I had issues with that as well. The new FreeRTOS for STM32 recommend to use signals as faster and simpler alternative to Semaphores, especially for the ...
EmbeddedGuy's user avatar
4 votes

STM32 PWM output frequency is off

You cannot produce 12.288 MHz by integer division of a 180 MHz source. The closest you would come would be dividing by 14, which would yield the 12.857 and some following decimals, which is likely ...
Chris Stratton's user avatar
4 votes
Accepted

How to use timers in STM32 board and HAL library in order to measure speed of motor?

Best way is to set up a timer in encoder mode to count the pulses of your sensor. If you have both A and B pulses then choose encoder mode TIM_ENCODERMODE_TI12 if ...
Bence Kaulics's user avatar
4 votes

STM32 SPI SCLK stops ticking

I think you misunderstood the functionality of HAL_SPI_TransmitReceive function. It doesn't first transmit tx buffer then receive to rx buffer. It does both at the ...
HeyYO's user avatar
  • 744
4 votes

CAN communication not working

CANH (Channel 2) and CANL (Channel 0) receive info If channel 2 is truly CANH, with the same time base as CANL on channel 0, then that's obviously your problem. It doesn't look healthy at all, it ...
Lundin's user avatar
  • 22.2k
4 votes

Timer1 on stm32f4

I don't really like the HAL, so here is how to do what you want by just accessing the timer peripheral directly: ...
Jon's user avatar
  • 5,117
4 votes

Timer1 on stm32f4

My solution would be almost identical to @Jon's, but I'd start the timer in one-shot mode, to avoid getting a second interrupt when processing the first takes too long. This way, no timer stop ...
followed Monica to Codidact's user avatar
4 votes
Accepted

STM32F4 struct unnamed has no field brr

BRR Register isn't defined for the GPIOs in the STM32F4 MCUs .You can use BSRR regster instead. for more information see the STM32F4-Reference manual page 286 and also STM32f4xx.h file for the ...
Amin Rostami's user avatar
4 votes

STM32 HAL driver for register value update

While it would be tempting to think that if you are going to use the HAL libraries, you should maintain that abstraction and not pierce it, in fact it is often necessary to bypass them. If you look ...
Chris Stratton's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible