Ask questions and find answers on STM32Cube packages, including HAL, LL and middleware, and expansion software.
Most recent activity
In a project using the STM32L451RET6, SPI3 is configured as follows* Full Duplex Slave* Hardware NSS Disable* Frame Format Motoroloa* Data Size 8* CPOL High* CPHA 2 Edge* DMA: * SPI3_TX Ch2 Mem to Per, Priority Low * SPI3_RX Ch1 Per to Mem, Priority HighThis works fine for a fixed packet length. Sometimes, however, the master may send a shorter packet (i.e. less than BUFFERLEN). In this case, it is necessary to end the slave SPI receive session and process the master's command. Consider the following code snippet:#define NSS (HAL_GPIO_ReadPin( NSS_GPIO_Port, NSS_Pin )) #define BUFFERSIZE 16 uint8_t SpiTxBuffer[BUFFERSIZE], SpiRxBuffer[BUFFERSIZE]; typedef enum { Idle, Wait, Done, WaitForNSS, Error } State_t; State_t State = Idle; int main(void) { /** Usual MX boilerplate here. STM32L451REx SPI Slave on SPI3 with DMA, 8 bit data, soft NSS */ while(1) { switch (State) { case Idle: if(!NSS) { State = Wait; if( HAL_SPI_TransmitReceive_DMA( &hspi3, Spi
I noticed that the ROM constants for ADC calibration values in the LL headers (*_ll_adc.h) are not defined as addresses of const data.e.g. #define VREFINT_CAL_ADDR ((uint16_t*) (0x1FF07A2A)) #define TEMPSENSOR_CAL1_ADDR ((uint16_t*) (0x1FF07A2C)) #define TEMPSENSOR_CAL2_ADDR ((uint16_t*) (0x1FF07A2E)) And it should be: #define VREFINT_CAL_ADDR ((const uint16_t*) (0x1FF07A2A)) #define TEMPSENSOR_CAL1_ADDR ((const uint16_t*) (0x1FF07A2C)) #define TEMPSENSOR_CAL2_ADDR ((const uint16_t*) (0x1FF07A2E)) Trying to write to it probably results in hardfault errors, but it should raise compile errors too in my opinion.
I believe I discovered a bug in the SPI driver in relation to using HAL_SPI_TransmitReceive_IT() that causes buffer overflows, which also made it tricky to discover.In our project, I had switched our SPI handlers to from blocking to non-blocking using the interrupt APIs.The bug happens when calling HAL_SPI_TransmitReceive_IT() which hits:HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, const uint8_t *pTxData, uint8_t *pRxData, uint16_t Size) { ... /* Fill in the TxFIFO */ while ((__HAL_SPI_GET_FLAG(hspi, SPI_FLAG_TXP)) && (tmp_TxXferCount != 0UL)) { ... hspi->pTxBuffPtr += sizeof(~); hspi->TxXferCount--; // <--- This decrements until 0 ... Then when an interrupt hits for SPI_TxISR_32BIT, SPI_TxISR_16BIT, or SPI_TxISR_8BIT it hits:static void SPI_TxISR_8BIT(SPI_HandleTypeDef *hspi) { /* Transmit data in 8 Bit mode */ *(__IO uint8_t *)&hspi->Instance->TXDR = *((const uint8_t *)hspi->pTxBuffPtr); hspi-&
Hi,I discovered today with some of my students this potential bug in the stm32g431xx.h file: #define RNG_CR_CED_Pos (5U)#define RNG_CR_CED_Msk (0x1UL << RNG_CR_IE_Pos) /*!< 0x00000020 */#define RNG_CR_CED RNG_CR_IE_MskAs RNG_CR_IE_Pos is equal to 3... This mask is not correct.It is quite strange: the comment is true... according to the Reference manuel 0440.I suggest this correction: #define RNG_CR_CED_Pos (5U)#define RNG_CR_CED_Msk (0x1UL << RNG_CR_CED_Pos) /*!< 0x00000020 */#define RNG_CR_CED RNG_CR_CED_Msk (I checked the last version of this file using this official github : https://github.com/STMicroelectronics/cmsis-device-g4/blob/7c39c32593b03764aaa57531588b8bf7cdd443a5/Include/stm32g431xx.h ) In the HAL, the assert can't detect the fail... "checking itself" : assert_param(IS_RNG_CED(hrng->Init.ClockErrorDetection));And this line used this CED... faking:MODIFY_REG(hrng->Instance->CR, RNG_CR_CED, hrng->Ini
Split from this thread. I did and it is all the same. Here is an example when I measure on port PB1 the voltage from VREF divided by 3 (2.5V/3 = 0,833..V). Voltage checked with multimeter. /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Private includes ------------------------------------------------
Hi all,I'm looking for an example (STM32CubeIDE) allowing to call a function located in RAM in order to copy flash bank2 to flash bank1 and then restart the CPU.Regards,
Hello everyone, I'm developing a secondary bootloader (sboot) based on the STM32F429 chip, aiming to achieve "program updates without a programmer" — simply placing the compiled application file on an SD card allows the microcontroller to automatically load and run it upon power-up, greatly simplifying debugging and update processes. Currently, I'm using Cube IDE for development, with the following hardware configuration: Main controller: STM32F429 (internal Flash stores sboot; internal SRAM starts at 0x20000000 with a capacity of 256KB)External storage: Kioxia 64GB SD card (connected via the SDIO bus, used to store the application program boot.bin)External memory: 32MB SDRAM (starts at address 0xC0000000, driven by the FSMC controller, used to load and run boot.bin)Functional Process DescriptionThe sboot is 固化 (burned) in the STM32's internal Flash. Upon power-up, it executes the following steps: Initialize the minimal system (such as basic configurations for clocks, GPIOs,
Hi,I tried to bring up the USB host on the USB-A connector, but without success.As a starting point, I took the example project:STM32CubeN6\Projects\STM32N6570-DK\Applications\USBX\Ux_Host_DualClass (for the USB Type-C connector), replaced USB1 with USB2 throughout the code, and enabled the USB power switch via GPIO.The device receives 5V, but no USB2 interrupt is triggered.Below is my USB2 initialization. In line 18, I triedRCC_USBPHY2REFCLKSOURCE_HSE_DIRECT, and RCC_USBOTGHS2CLKSOURCE_HSE_DIRECT,but neither case works.It seems I’m missing something else. What could be wrong on my side?void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd) { if (hhcd->Instance == USB2_OTG_HS) { /* USER CODE BEGIN USB_OTG_HS_MspInit 0 */ /* USER CODE END USB_OTG_HS_MspInit 0 */ /* Enable VDDUSB */ __HAL_RCC_PWR_CLK_ENABLE(); HAL_PWREx_EnableVddUSBVMEN(); while(__HAL_PWR_GET_FLAG(PWR_FLAG_USB33RDY)); HAL_PWREx_EnableVddUSB(); /** Initializes the peripherals clock */ RCC_PeriphCLKInitTypeDef
Hello, I am working on an STM32F446RE with a custom bootloader and FreeRTOS application. Bootloader address: 0x08000000 Application address: 0x0800C000 The bootloader successfully jumps to the application by setting MSP, PC, and SCB->VTOR. In my application, I configured FreeRTOS to use a hardware timer (TIM14) instead of SysTick as the OS tick source. Problem:When I flash the application directly, it runs fine.But when I run through the bootloader, the application stops working as soon as it calls HAL_Delay(). If I comment out HAL_Delay(), the app continues normally. After the RTOS kernel starts, I get a HardFault on the first interrupt. I suspect this is related to SysTick still being dirty from the bootloader, while my application is configured to use TIMx as the tick source. My questions: What is the recommended way to cleanly reinitialize the HAL tick and interrupt system after jumping from a bootloader to an application that uses TIMx instead of SysTick? Should I
I'm already achieved a USBX-MSC class, and also a FileX in MCU local.I know that using two file systems at the same time is not recommended, but still have some questions. 1. I implement the ux_deveice_msc.c as followed. Use PC-Windows to create a file such as my_test.txt to U-DISK, successfully and the local FileX will see the new file immediately. UINT USBD_STORAGE_Read(VOID *storage_instance, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status) { UINT status = UX_SUCCESS; /* USER CODE BEGIN USBD_STORAGE_Read */ UINT fxStatus = FX_SUCCESS; while (number_blocks--) { fxStatus = fx_media_read(sdioDisk, lba, data_pointer); if (fxStatus != FX_SUCCESS) { status = UX_ERROR; break; } data_pointer += sdioDisk->fx_media_bytes_per_sector; lba++; } /* USER CODE END USBD_STORAGE_Read */ return status; } UINT USBD_STORAGE_Write(VOID *storage_instance, ULONG lun, UCHAR *data_pointer, ULONG number_blocks
ST moderator: Thread moved from "STM32CubeIDE" forum to "STM32 MCUs Embedded software" forum. Hello, I am currently working on STM32H755 (dual-core M7/M4) and trying to use the FMC interface to connect to an external SRAM. I have checked the STM32CubeH7 firmware package, but I could not find any ready-made FMC SRAM example for STM32H755 (most examples for STM32H745). I have checked the STM32CubeH7 firmware package,and it seems that for STM32H745 (and STM32H755) there is only an FMC SDRAM example available,located under: STM32CubeH7\Projects\STM32H745I-DISCO\Examples\FMC\FMC_SDRAM_DataMemory Could you please provide: An official or working example project for STM32H755 FMC SRAM Clarification about which core (M7 or M4) should configure the FMC? Best regards,Allen
void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef* SMBUSHandle) { /** Error_Handler() function is called when error occurs. * 1- When Slave doesn't acknowledge its address, Master restarts * communication. 2- When Master doesn't acknowledge the last data * transferred, Slave doesn't care in this example. */ if (HAL_SMBUS_GetError(SMBUSHandle) != HAL_SMBUS_ERROR_ACKF) { printf("failed\r\n"); /* Turn Off LED2 */ } } /** * @brief Slave Address Match callbacks. * hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None */ void HAL_SMBUS_AddrCallback(SMBUS_HandleTypeDef* hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode) { SlaveAddrMatchCode = (AddrMatchCode << 1); HAL_SMBUS_EnableListen_IT(&hsmbus1); uint8_t tx_buff = 0x00; HAL_SMBUS_Slave_Transmit_IT(&hsmbus1, &tx_buff, 1, SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC); // HAL_SMBUS_Slave_Transmit_IT(&hsmbus1, &am
I was looking for a way to create a high level abstracted layer that can be agnostic to the lower layer TCP/IP stack, like NetxDuo or LWIP, running under the higher abstracted layer.I have came across suggestion to implement a `plug-in` based implementation of the higher level abstracted layer. Kindly suggest me your opinions, what could be the best way to implement such high level abstracted layer that can be agnostic to the lower level TCP/IP stack running ? Also if there is an example of someone doing something similar? Thanks a lot.
Hi I am evaluating STM32F303RE for a product and will be using https://www.st.com/en/evaluation-tools/nucleo-f303re.html for evaluation My technical requirements are FreeRTOS support is mandatory, as our applications use a communication stack supported on FreeRTOS only. MCUboot as the bootloader Secure boot support on MCUboot I have successfully enabled FreeRTOS support. Do you have any reference with MCUboot + FreeRTOS support? PS: MCUboot + zephyr works on the board, but not FreeRTOS. Thanks
Dear forum,I have a simple application using an STM32L4 and the analog COMP2 interrupt to blink a PWM LED. The device also uses USB virtual COM port capabilities for a simple terminal with a few commands. Everything works as expected.Now, I want the device to enter a low power consumption state after some idle time. The device must wake up through the same COMP2 interrupt I'm using to blink the LED. A full system reset is acceptable too.I'm successfully putting the device into stop mode, and it seems the wake-up interrupt is working as well. However, the problem is that after waking up, the device encounters a hard fault. I've tried everything, but the stack appears to be corrupted. Even NVIC_SystemReset() is not working.I'm pasting the important parts of my code here. Any help or ideas would be welcome. /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body *****************
Hello,I am trying to implement a USB HID keyboard on an STM32F042 without HAL or LL, just simple register defs. I took an example code generated in CubeIDE with HAL and a few other examples. I extended the example with HAL to also implement the LEDs which all works fine. I understand how it basically works. I define the descriptors and configure the Endpoints etc. Then I need to transfer the descriptors when the host requires them. But what I can not figure out is how exactly the descriptors are actually transferred. The HAL is so overloaded that it seems impossible to find the exact lines of code where the descriptors are transferred to the host and how that is done exactly. Also where do I put the report descriptor to send some key presses? Can anyone give me some info on how that is done?
I'm using the nucleo-H753ZI board to test mcuboot.The setup works and I can successfully run the bootloader and the application in slot0_partition using zephyr sysbuild.However when trying to upload an image I get the following flash write error:[00:00:29.758,000] <inf> mcuboot_util: Image index: 0, Swap type: none[00:00:29.758,000] <inf> mcuboot_util: Image index: 0, Swap type: none[00:00:29.922,000] <err> flash_stm32h7: Status Bank2: 0x00040000[00:00:29.922,000] <err> STREAM_FLASH: flash_write error -5 offset=0x00100000[00:00:29.922,000] <err> mcumgr_img_grp: Irrecoverable error: flash write failed: 12Here is my flash0 dts: &flash0 { partitions { compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; boot_partition: partition@0 { label = "mcuboot"; reg = <0x00000000 DT_SIZE_K(128)>; }; slot0_partition: partition@20000 { label = "image-0"; reg = <0x00020000 DT_SIZE_K(896)>; }; slot1_partition: partition@100
Hi,where do I find the full HAL API documentation? Is there a wiki? And also is there a way to pull it up in CubeIDE (I'm not referring to the autocomplete)? Also is there a repository with all examples organised by topic, for example PWM, I2C etc.? Thank you
Hi,I'm using a SMT32H562ZGT6 uC with RTC pheripheral enabled and clock source from LSE. But HAL_RTC_Init() function returns HAL_TIMEOUT. Investigating I found the method RTC_EnterInitMode returns HAL_TIMEOUT.Clock configuration is performed before calling the RTC initiazlization using The SystemClock_Config generated by cubeMX:void BSP::SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0); while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) { } /** Configure LSE Drive Capability * Warning : Only applied when the LSE is disabled. */ HAL_PWR_EnableBkUpAccess(); __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCI
This is to document various uses of delays like HAL_Delay() in STM32 code. I have found 2 decent uses 1. Put at the start of /* USER CODE BEGIN 2 */ to stop the code from executing when we are reprogramming the board. 2. Put at the start of /* USER CODE BEGIN 2 */ to give time to properly initialize DMA related functionality. /* USER CODE BEGIN 2 */ HAL_Delay(2000); HAL_UARTEx_ReceiveToIdle_DMA( &huart7, gsm_response_buffer, GSM_RESPONSE_BUFFER_SIZE); __HAL_DMA_DISABLE_IT(&hdma_uart7_rx, DMA_IT_HT); /* USER CODE END 2 */ without the delay the DMA reception was not working. Please put any other / any modification anyone find / know here to make it as a central repository. Edited by ST moderator to be inline with the community rules especially with the code sharing. In next time please use </> button to paste your code. Please read this post: How to insert source code
Hello Saket_Om, Now is better :). Next challenge is how to convert it for my target. I am using STM32u585Qii3. It seems there is no straight way in STM32Cube to migrate between controllers with different packages. Split from the thread below. (new question) Re: STM32u5 ADC not reading properly - STMicroelectronics Community
I have an SPI slave running on STM32L4 in DMA mode. Here is the basic structure (simplified for this posting): #define NSS (HAL_GPIO_ReadPin( SPI3_NSS_GPIO_Port, SPI3_NSS_Pin )) #define BUFFERSIZE 32 uint8_t SpiTxBuffer[BUFFERSIZE], SpiRxBuffer[BUFFERSIZE]; typedef enum { Idle, Wait, Abort, Done } State_t; State_t State = Idle; int main(void) { /* Usual MX boilerplate here. */ while(1) { switch (State) { case Idle: if(!NSS) { if( HAL_SPI_TransmitReceive_DMA( &hspi, SpiTxBuffer, SpiRxBuffer, BUFFERSIZE ) != HAL_OK ) { Error_Handler(); } State = Wait; } break; case Wait: if(NSS) { if( HAL_SPI_Abort_IT(&hspi) == HAL_OK) { State = Abort; } else { Error_Handler(); } } break; case Abort: break; case Done: DoSomethingWithTheData(); State = Idle; } DoSomethingElse(); /*Do some task while waiting for SPI to arrive*/ } } void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) { State = Done; } void HAL_SPI_AbortCpltCall
I'm relatively new to STM32 and it's my first time working with DMA so this will probably be a very basic question.I'm using STM32G474 and I want to have 3 channels of advanced timer TIM8 working in "PWM generation CHx CHxN" mode. At a later stage I'm looking to run FOC on them, but for now I just want to change the duty cycle of each channel period by period, by reading the duty cycle for the next period from a predefined table and transferring the duty cycle value using circular burst DMA to update all 3 channels at the same time without software overhead.These are my DMA settings for TIM8 in the ioc fileI can't find the settings for which register i want to write to using DMA. I have ChatGPT telling me that DMA can only write to CCR register and Gemini telling me I can set which register to write to in the ioc. Both are pointing me to reference manual RM0440 (https://www.st.com/resource/en/reference_manual/dm00355726.pdf), but I'm getting overwhelmed there and can't find anything re
I want to use the standalone CRC module to offload calculations AND transfers from CPU - using purely DMA memory transfers - is this possible on the STM32G474RE?
Hello @Community, I am working on the STM32F746NG board. In my application, I want to communicate with a PLC using the EtherNet/IP communication protocol to exchange real-time data. The problem I am facing is that my board does not respond to ping when FreeRTOS is enabled. Without FreeRTOS, the board is pinging correctly. Has anyone faced this issue before? If yes, please guide me on how to resolve it. Any suggestions or solutions will be greatly appreciated. Thank you!
ST Community highlights – April to June 2026
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.