Ask questions and find answers on STM32Cube packages, including HAL, LL and middleware, and expansion software.
Most recent activity
hello.I am using STM32F407VGT6 chip and trying to send data to PC with USB CDC function.But in the below function, the TrySendUsbPacket() function is not executing due to queue full phenomenon.void EnqueueUsbPacket(const uint8_t* data) { uint16_t next_tail = (usb_queue_tail + 1) % USB_QUEUE_SIZE; if (next_tail == usb_queue_head) { // Queue full: handle accordingly (error, framedrop, etc.) return; } memcpy((void*)usb_queue[usb_queue_tail].data, data, USB_FRAME_SIZE); usb_queue_tail = next_tail; TrySendUsbPacket(); // Add to queue and try to send immediately }I've put my full function as an attachment, can anyone tell me why the USB transfer doesn't happen until the queue is full?
Hi there,I would like to control WS2812B LEDs with a PWM timer and DMA.There are various tutorials on this, but they have not helped me and I am now asking you. Because it requires slightly different configurations depending on the model (F3, F4, G4, G0), I'm a bit overwhelmed.I start a DMA transfer, wait for the last pulse with an interrupt and stop the DMA transfer. So far so good in theory. I still have problems with the implementation.Even the simplest DMA example without WS2812B protocol does not work for me.Clock SYSCLK/HCLK: 170 MHzTIM1 CH4 configuredPrescaler: 170-1 => 1 MHZCounter Preiod: 100-1 => 10 kHzDMAMemory -> PeripheralData Width: Word (32 bit)6 PWM pulses (= 600 us) should be sent outTIM1 Mode + ConfigurationDMA SettingsSource:TIM_HandleTypeDef htim1; DMA_HandleTypeDef hdma_tim1_ch4; /* never used?! */ uint32_t data[] = { 30, 80, 20, 60, 10, 50 }; void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) { HAL_TIM_PWM_Stop_DMA(&htim1,
I was trying to build a flight controller with this board. I was using rizacelik's repo for this project. At first, i was using the 3.0.1 firmware .hex file but then later wanted to switch to the newer 8.0.0 firmware so i flashed the newer .hex file (e.g , inav_8.0.0_STM32F411CE.hex) because the MPU6050 module wired correctly would hang my board for some odd reason. after the flash it didn't necessarily hang the board, but didn't get proper reads yet. the gyro was detected, but not the accelerometer. I was tweaking all in the configuration tab and maybe the uart1 and usb in ports tab (i don't remember clearly what was my last action in the Inav program), then suddenly the board stopped working. i disconnected everything and came to see that the USB Type-C direct connection with my pc was not working anymore. i tried multiple other working cables, no clue. Then I used my ST-Link V2 programmer, and it connected the board. I used the Cube programmer to erase the chip memory and refla
I used Cude IDE version 1.18.1. successfully then upgraded and wrote the second project (timer). I'm using Nucelo-64 STM32 F411RE with clock rate 84Mhz. My new project is to use the TIM4 with the settings: PSC: 8399, CP: 10000 to toggle the LED per second. The LED doesn't turn on/off whatsoever. (My prior project - to use the user button - doesn't work either!)My files: lib.hpp: #ifndef INC_LIB_HPP_ #define INC_LIB_HPP #if __cplusplus extern "C" { #endif void run(); void HAL_GPIO_EXTI_Callback(uint16_t); void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *); #if __cplusplus } #endif #endiflib.cpp:#include "main.h" #include "lib.hpp" #include <stdio.h> auto pressed = 0u; auto flag = false; void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == B1_Pin) flag = true; else flag = false; } void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin); } void run() { while (1) { if(flag){ pres
I've been previously programming the STM32F103C6T6 blue pill with an FTDI via UART and am now trying to flash a USB bootloader binary to program it directly via USB.I've closely followed the guide on https://www.electrosoftcloud.com/en/stm32f103-bootloader-and-programming/ - I've successfully flashed the generic_bootloader_pc_13.bin file via UART, installed the required drivers, and followed the BOOT0 pattern correctly. On connecting via USB, the board is detected as "Maple DFU" in the Device Manager.But STM32CubeProgrammer keeps showing "No DFU detected" when I try connecting via USB and pressing the refresh button.However, when I enter the PID and VID specified in the Maple DFU driver properties shown below in STM32CubeProgrammer: On refreshing and trying to connect, the error "unknown or unsupported device" is displayed:I've followed several online resources, and nobody seems to encounter this issue.Can anyone provide any insights into why this might occur?
I’m using NUCLEO STM32H753ZI.I use ST ID: STM32cudeIDEI have HardFault_Handler when call vTaskStart_Scheduler() using FreeRTOS Could you please let me know how to resolve this issue? Below is the sample code int main(void) { (void) HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Enable the CPU Cache */ CPU_CACHE_Enable(); BaseType_t xReturned; TaskHandle_t xHandle = NULL; /* Create tasks / xReturned = xTaskCreate( Task_Code, “SB”, configMINIMAL_STACK_SIZE, (void) NULL, tskIDLE_PRIORITY+2U, &xHandle ); if( xReturned == pdPASS ) { vTaskStartScheduler(); } else { } while(1);
For a project i want to save log files in the external SPI of the Stm32n6 for this is already tried to configure xspi2 and the external memory, but i am not sure if i have done it right. I also have found no source on how to continue with the Code after this maybe someone can help with this.
I successfully configured the I2S2 interface to a sample rate of 48KHz. The attached WCMCU-5102 is connected to these three wires. I2S2_WS = PA3I2S2_CK = PA5I2S2_SDO = PB1 FLT = GNDDMP = GNDSCL = GNDFMT = GND XMT = Vdd (3.3V) static void MX_I2S2_Init(void) { /* USER CODE BEGIN I2S2_Init 0 */ /* USER CODE END I2S2_Init 0 */ /* USER CODE BEGIN I2S2_Init 1 */ /* USER CODE END I2S2_Init 1 */ hi2s2.Instance = SPI2; hi2s2.Init.Mode = I2S_MODE_MASTER_TX; hi2s2.Init.Standard = I2S_STANDARD_PHILIPS; hi2s2.Init.DataFormat = I2S_DATAFORMAT_16B; hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE; hi2s2.Init.AudioFreq = I2S_AUDIOFREQ_48K; hi2s2.Init.CPOL = I2S_CPOL_LOW; hi2s2.Init.FirstBit = I2S_FIRSTBIT_MSB; hi2s2.Init.WSInversion = I2S_WS_INVERSION_DISABLE; hi2s2.Init.Data24BitAlignment = I2S_DATA_24BIT_ALIGNMENT_RIGHT; hi2s2.Init.MasterKeepIOState = I2S_MASTER_KEEP_IO_STATE_DISABLE; if (HAL_I2S_Init(&hi2s2) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN I2
Hi all!On an STM32 project I'm working on, I want my USB port (USB C in that case) to work either in Host Mode or in Device Mode, depending on a menu change from the user. For added context, this is for a MIDI project in which the MC will either use USB Host or USB Device as a means of communication.It appears the mode is determined by the state of Pin PA13 (SYS_JTMS_SWDIO), but I would rather do everything in software, as the USB connection will be the same (the implementation will differ between the two).Also, when I set the USB mode to OTH/Dual_Role_Device, all of the USB files are being deleted. Should I just save the files used in Host_Only and in Device_Only in another folder, or is there a cleaner way to have both implementations at the same time? If I need to code everything from scratch, I would love to have some pointers on where to begin.Thanks in advance!
Dear ST's experts,I want to send/receive data through UART between STM32 and PC. The data must be sent to PC every 500ms and then STM32 receive data from PC. I have configured UART2 with DMA in circular mode. I am using the function HAL_UART_TxCpltCallback to pause the UART (HAL_UART_DMAPause(&huart2);) to send data every 500ms. My problem is that when I use the above function, receiving data does not work properly.How I can solve the problem?Should I use DMA in normal mode for TX?
Hello,I am working with the STM32U5G9ZJT6Q MCU to implement a USB UVC application. Here are the key details of my setup:MCU: STM32U5G9ZJT6QSystem Clock: 160 MHzUSB PHY External Clock: 32 MHzData Source: DCMI captures data at 640x480 resolution in 8-bit format.USB Configuration: Isochronous transfers for UVC video streaming.The issue I am facing is that for each isochronous packet, only 30 micro packets contain valid data, while the remaining 98 micro packets (out of 128 total) are empty. This limits the overall data throughput.I would like to understand how I can increase the number of micro packets with valid data in each isochronous packet to optimize data transfer performance.Steps I have tried:Verified DCMI and DMA data reception – data appears to be received correctly.Adjusted isochronous max packet size (HS_MPS) but did not see a significant improvement.Could this be related to:USB descriptor configuration?DMA/USB buffer handling?Timing or bandwidth issues with the USB PHY or DCM
I'm looking for some guidance on using DMA with SPI. I have the M4 core on an STM32H755 set up as a master in full duplex mode, and as long as I invoke the SPI transfer using interrupts, the program runs fine. When I try to migrate to DMA, however, I note that the program is successful on the first pass only, triggering the callback, etc., but on the second time through, I always get an error, apparently because the transmit is still busy (?) I have used SPI and DMA often before without incident, but I don't know what else to check in this case. Any insights are appreciated. See the screen shots of where the code is finally failing. Line 2508 is in the HAL SPI driver C file, the point at which the driver attempts to start the DMA with IT, and the second shot shows the result of this call in the HAL DMA file, line 695. Thanks
Hi, I'm working on a STM32h747 dual core and I'm trying to put the CM4 to sleep so that it wakes up only on a CM7 event. I used _WFE on CM4 and _SEV on CM7 but the CM4 is never wake up. I release a HSEM directly after WFE in CM4 to notify the CM7 that the CM4 is awake and I never receive it. I tested the HSEM mechanism without putting the CM4 to sleep and it works well. Here the sleep procedure for the CM4 : // Disable SEVONPEND => this bit define all pending interrupt (even disabled) as event CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk)); // Disable all interrups __disable_irq(); // Enter in stop mode /* Select the regulator state in STOP mode */ MODIFY_REG (PWR->CR1, PWR_CR1_LPDS, PWR_MAINREGULATOR_ON); /* Set SLEEPDEEP bit of Cortex System Control Register */ SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk); /* Ensure that all instructions are done before entering STOP mode */ __DSB (); __ISB (); //Generate an event to clean pending events __SEV(); __WF
Hii Team, I'm using STM32G070RBT6 MCU to communicate with ADS124S06. I've configured the SPI on the MCU for Mode1 and GPIOs CS, RST, START pins as output (NO pull up/ pull down) and DRDY as input (NO pull up/ pull down). GPIO Configuration:SPI Configuartion:Clock Configuration: Code : the ADS124S06_Init function: bool ADS124S06_Init(ADS124S06_Handle *dev) { DEBUG_PRINT("Entered init Function"); // RESET pin sequence HAL_GPIO_WritePin(dev->reset_port, dev->reset_pin, GPIO_PIN_RESET); HAL_Delay(1); HAL_GPIO_WritePin(dev->reset_port, dev->reset_pin, GPIO_PIN_SET); HAL_Delay(5); ADS124S06_WriteRegister(dev, 0x02, 0x54); // I/p MUX: AIN5-AIN4 0x54 HAL_Delay(1); ADS124S06_WriteRegister(dev, 0x03, 0x00); // GAIN: PGA=1, 20SPS ADS124S06_WriteRegister(dev, 0x04, 0x14); // DataRAte : 20SPS, osc-4.096MHz HAL_Delay(1); ADS124S06_WriteRegister(dev, 0x05, 0x0A); // REF : internal 2.5V On always. ADS124S06_WriteRegister(dev, 0x06, 0x0
Hello everyone,I'm using AZURERTOS on my STM32F407 microcontroller. My goal is to use the FPU to perform some mathematical operations (FFT, etc.). Could you help me figure out how to activate the FPU and how to tell when it's active, taking into account the RTOS I'm using?- I am using STM32CUBEIDE Thank You!
STM32H523HEYX Flash Write Issue1.I’m currently working on a project using the STM32H523HEYX.I'm using STM32CubeIDE, and the firmware libraries are up to date.I’m also using STM32 X-CUBE-FREERTOS.I’m trying to write data to Flash memory using the following functions:2. HAL_FLASHEx_Erase(...);HAL_FLASH_Program(FLASH_TYPEPROGRAM_QUADWORD, ASDF, (uint32_t)&quadData[0]);However, the code triggers a HardFault when executed.3. When I run the same code on a STM32H533 Nucleo board, it works without any fault and writes to Flash successfully.4. I'm not sure why this Flash issue only occurs on the STM32H523HEYX.If anyone has experienced a similar issue or knows of any related problems, I’d appreciate your advice.Thank you, fellow developers!
Hello.I've been struggling for several weeks to fix an issue when sending data over MQTT using LwIP on an STM32F407 microcontroller.For periodic message publishing, I'm using the following code:void MqttPublishTask(void const * argument) { err_t err; while(1) { xEventGroupWaitBits(mqttSendEventGroup, pdFALSE, pdTRUE, portMAX_DELAY); if(mqtt_client_is_connected(&client)) { cJSON *root = cJSON_CreateObject(); for(uint8_t i = 0; i < (nodeID - 64); i++) { cJSON *tap_metrics = cJSON_CreateObject(); cJSON_AddNumberToObject(tap_metrics, "ER", taps[i].alarmCode); cJSON_AddNumberToObject(tap_metrics, "C", taps[i].coldWater); cJSON_AddNumberToObject(tap_metrics, "H", taps[i].hotWater); cJSON_AddNumberToObject(tap_metrics, "E", taps[i].totalEnergy); cJSON_AddNumberToObject(tap_metrics, "T", taps[i].waterFlowTime); cJSON_AddNumberToObject(tap_metrics, "N", taps[i].numberOfUses); snprintf(serialString, sizeof(serialString), "%lu", taps[i
Hello everyone,I ran into a problem. First of all, I have two tablets: one with a bootloader and another without it. Tablet without bootloader works fine so its something bad in bootloader. I’m trying to plug in and unplug the power supply, and sometimes this happens:What can cause it? I'm adding my bootloader code/* 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 -----------------------------
Hi,I'm using an STM32H7 board with a LAN8742 PHY, configured via STM32CubeMX.LwIP is initialized without RTOS, and Ethernet is in RMII mode. The main goal of this project is to receive data over UART and forward it via Ethernet.I want the STM32 board to connect to a standard router using a physical Ethernet cable, obtain a dynamic IP address via DHCP, and then transmit the received UART data over the network.Currently, the board does not seem to request or receive any IP address — while the PC connected to the same router receives an IP successfully, the STM32 does not. So far I've verified: MX_LWIP_Init() is called from main.c MX_LWIP_Process() is called inside the main while (1) loop MAC address is manually set in ethernetif.c: MACAddr[0] = 0x02; MACAddr[1] = 0x12; MACAddr[2] = 0x34; MACAddr[3] = 0x56; MACAddr[4] = 0x78; MACAddr[5] = 0x9A; DHCP is enabled in .ioc under LwIP configuration netif_add(), netif_set_default(), netif_set_up() and dhcp_start() are called ETH is
Hello,I am trying to fill a buffer from the on-board MEMS microphone using the BSP_AUDIO_IN_RecordPDM() function. However, execution pauses around HAL_SAI_Receive_DMA() and the BSP_AUDIO_IN_IRQHandler() is called. The stack trace is as follows:Checking the hdma variable on the debugger, I can see the error code is 1, corresponding (I believe) to a transfer error. I tried looking at the relevant registers with breakpoints, but they were at 0x0 at every point:I've tried almost everything under the sun. I disabled the D-Cache and allocated all the memory to RAM_D1, I tried allocating my buffer (copied below) to each of RAM_D1, D2, and D3ALIGN_32BYTES (uint16_t recordPDMBuf[AUDIO_IN_PDM_BUFFER_SIZE]) __attribute__((section(".RAM_D1")));My linker script looks like this:/* Highest address of the user mode stack */ _estack = ORIGIN(RAM_D1) + LENGTH(RAM_D1); /* end of "RAM_D1" Ram type memory */ _Min_Heap_Size = 0x800 ; /* required amount of heap */ _Min_Stack_Size = 0x800 ; /* requ
I've been working on a project on STM32F746-Discovery with only CMSIS (no other libraries written by not me) on a Windows machine in STM32CubeIDE. I used the default STM startup file (.s with a vector table and a memory initialization), the startup_stm32f746nghx.s. This file, among other things, defines a list of weak IRQ handler hooks with interrupt handler names. So naturally I took the name HASH_RNG_IRQHandler straight from the file. I declared the function extern "C" to prevent name mangling in C++, besides, it's far from the first interrupt handler in the project. All of them work without an issue. When I compiled and ran the project, I found myself hardfaulting. I debugged my way through everything, but everything looked solid. It just suddenly crashed after I enabled the RNG peripheral. I verified everything there was to verify, but found nothing odd, right before RNGEN, the RNG showed no error flags, no seed error, no clock error. My gut feel told me to look at t
Hello,I am trying to use the PKA module on a STM32U5 controller. I have configured the clock at 160Mhz and also initialized the Ring. However, when I try to initialize the PKA, it runs into ADDRERRF = 1, I was expecting ofcourse INITOK to be 1. Does anyone have Idea what am I missing here or what might be causing the ADDRERRF? Thanks,Abhi
Title: UART Loopback with Interrupts Halts After Second Transmission on STM32H747I-DISCO Hello everyone, I'm working on a simple UART loopback test on an STM32H747I-DISCO board using the HAL libraries, and I've run into an issue where my interrupt-driven communication halts unexpectedly. The goal is to have USART2 continuously transmit a byte, receive it back via a physical loopback (TX and RX pins are connected), increment the value, and repeat the process. I'm using an LED to visually confirm when a byte is successfully received. The process starts correctly but stops after the first full cycle. Here is the exact sequence of events I'm observing with the debugger: main() calls HAL_UART_Transmit_IT() to send the first byte. The HAL_UART_TxCpltCallback() is successfully triggered. Inside the TxCpltCallback, I call HAL_UART_Receive_IT() to arm the receiver. The byte is received, and HAL_UART_RxCpltCallback() is successfully triggered. The LED toggles as expected. Inside t
Hello,I have a STM32H747I-DISCO I want to use to record audio. In my test code I tried to record 3 seconds of audio after pressing the JOY_SEL button. I tried to setup the configuration of peripheral SAI4 for PDM and to use DMA and PDM2PCM using the CubeMX tool. I also tried to just use the BSP provided by ST for the discovery board. I was not able to get either the manual configuration or the BSP configuration to work. I have already looked at AN5027 and the examples provided by ST in the STM32Cube_FW_H7_V1.12.1 repository. The examples provide audio recording but for different boards. The DFSDM example for this board is not that useful when using SAI for communication. Any guidance or detailed procedure on how to setup the on-board digital microphone using SAI for the STM32H747I-DISCO is much appreciated!Manual/BSP Setup:CPU ICache enabledCPU DCache enabledFreeRTOS enabledGPIOs for joy stick button configuredTIM6 and TIM3 used for sysclks for Core M7 and Core M4 respectively. (b
Hi,I try to use 6 external interrupts but only EXT4_15 is functionning. All is functionning correctly when i use HAL_GPIO_ReadPin() function without interrupts. Thank you for your HELP void EXTI0_1_IRQHandler(void) { /* USER CODE BEGIN EXTI0_1_IRQn 0 */ /* USER CODE END EXTI0_1_IRQn 0 */ HAL_GPIO_EXTI_IRQHandler(EV5_Pin); HAL_GPIO_EXTI_IRQHandler(EV6_Pin); /* USER CODE BEGIN EXTI0_1_IRQn 1 */ /* USER CODE END EXTI0_1_IRQn 1 */ } /** * @brief This function handles EXTI line 2 and 3 interrupts. */ void EXTI2_3_IRQHandler(void) { /* USER CODE BEGIN EXTI2_3_IRQn 0 */ /* USER CODE END EXTI2_3_IRQn 0 */ HAL_GPIO_EXTI_IRQHandler(EV89_Pin); /* USER CODE BEGIN EXTI2_3_IRQn 1 */ /* USER CODE END EXTI2_3_IRQn 1 */ } /** * @brief This function handles EXTI line 4 to 15 interrupts. */ void EXTI4_15_IRQHandler(void) { /* USER CODE BEGIN EXTI4_15_IRQn 0 */ /* USER CODE END EXTI4_15_IRQn 0 */ HAL_GPIO_EXTI_IRQHandler(EV2_Pin); HAL_GPIO_EXTI_IRQHandler(EV14_Pin)
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.