/r/stm32f4

Photograph via snooOG

The STM32 series are great CPUs for embedded developers, hackers, musicians and the like to work with. This a place to share information, get people started with it, show off your work, answer hard questions, etc. related to the STM32 CPUs. This includes all Cortex CPUs, too, such as MSP432 and even Microchip Cortex chips.

/r/stm32f4

6,310 Subscribers

1

Trying to convert time and date from UTC to IST...In STM32

Time and date I am getting it from GPS module to my stm32 and I wanna convert it from UTC to IST. Time I have converted easily by adding time difference, depending on the time I wanna convert the date... I am struggling in date conversion can you please help me in the logic Or suggest me timezone conversion Library in C for me to use...

1 Comment
2024/10/17
11:54 UTC

3

Crazy STM32 Mystery - please HELP - pretty please with sugar on top!

4 Comments
2024/10/16
07:37 UTC

5

Do I need license to compile for USB/ Ethernet features?

I have bought the NUCLEO-F429ZI and I want to use its USB and ethernet features.

I downloaded armKEIL so I can open uVision and compile, upload code etc.

https://preview.redd.it/4jk0njmqmptd1.png?width=1768&format=png&auto=webp&s=5f6e6a72c528e9f369212bbfa5f4ff4257a3aeb6

I manage to compile code and make my own libraries for UART, I2C, SPI and now I try to use USB.
When I try to compile a already-existing USB example (HID) from uVision, I get error: "The component 'Keil::USB&MDK-Plus:Device:HID' requires a valid 'Keil MDK Professional' UBL license."

I am using the free version of license.

  1. So I can not create USB (or ethernet) projects with free version of the license?
  2. Do with other MCUs in the market need purchasing licences as well to use their Ethernet or USB features?
1 Comment
2024/10/09
10:47 UTC

6

STM32F412 Discovery kit

https://www.youtube.com/shorts/vmvPLwYT76w

https://www.youtube.com/shorts/eWtFkBsItys

https://www.youtube.com/shorts/HFJmNZtaJxQ

STM32F412 Discovery kit
"Innovation from Old Boards": Since I have old boards that have been stored away for a long time and are no longer in use, I decided to revive and repurpose them to create something useful and valuable. By transforming these old materials, I aim to develop a new and interesting project. We can apply our creativity and skills to turn the old boards into something beneficial for our daily lives or work.

https://preview.redd.it/i0jae2atkwsd1.jpg?width=1079&format=pjpg&auto=webp&s=556710f2912aa7e1cbf627114af415b97540cd11

https://preview.redd.it/tzskkqstjwsd1.jpg?width=1152&format=pjpg&auto=webp&s=8b8ffb4b30df18716d2c22d73e145329afd45ffd

0 Comments
2024/10/05
09:02 UTC

1

STM32 not working with ST-LINK V2?

Hello everyone
It's my first time messing around with STM32 microcontrollers
A few days back I got a black pill (STM32F401CCU6) and an ST-Link V2. The black pill came with 3 buttons, namely (KEY, NRST, BOOT0) and a USB-C Port. Since the ST-Link was arriving later, I connected the black pill to my PC through USB-C. The LED on the black pill turned on, I fired up the Arduino IDE, wrote a tiny blink program, and it worked.
A few days later, I got the ST-Link V2. I connected the SWCLK, SWDIO, GND and 3.3V terminals to the black pill as I found online, and connected the ST-Link to my computer. The LED inside the ST-Link turns on, but the LED on the black pill doesn't turn on. The ST-Link is detected by the STM32CubeIDE, I also did a firmware upgrade as the software suggested, but it still couldn't detect the black pill.
The black pill still works fine through USB-C.

Is this a connection issue between the ST-Link and the black pill? Or do I have to use the buttons to reconfigure/ reset the black pill to make it work with the ST-Link?

2 Comments
2024/09/29
20:57 UTC

2

Triple regular simultaneous model only stm32f4

I've trying to config Triple mode in Adc and when i use DMA mode 1 for transfer the CDR register is getting data from ADC3 only but works when DMA Mode 2

this is the code:

/*
* adc.c
*
* Created on: Sep 21, 2024
* Author: Vishnu
*/

#include <adc.h>

volatile uint32_t adc_data;
volatile uint16_t dma2_status;
uint16_t adc1_data; // Extract ADC1 data
uint16_t adc2_data;
uint16_t adc3_data;

void adc_init(void){

//Enable Clock
RCC -> AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
RCC -> AHB1ENR |= RCC_AHB1ENR_DMA2EN;
RCC -> APB1ENR |= RCC_APB1ENR_TIM2EN;
RCC -> APB2ENR |= RCC_APB2ENR_ADC1EN;
RCC -> APB2ENR |= RCC_APB2ENR_ADC2EN;
RCC -> APB2ENR |= RCC_APB2ENR_ADC3EN;

//Set PA1, PA2, PA3, as Analog port
GPIOA -> MODER |= (GPIO_MODER_MODER1_0) | (GPIO_MODER_MODER1_1);
GPIOA -> MODER |= (GPIO_MODER_MODER2_0) | (GPIO_MODER_MODER2_1);
GPIOA -> MODER |= (GPIO_MODER_MODER3_0) | (GPIO_MODER_MODER3_1);

// Configure ADC

//ADC1
ADC1 -> SQR3 |= (0X01); // Select Ch 1
ADC1 -> CR2 |= (ADC_CR2_EXTEN_0); // Enable External trigger
ADC1 -> CR2 &= ~(ADC_CR2_EXTEN_1);
ADC1 -> CR2 &= ~( (ADC_CR2_EXTSEL_0) | (ADC_CR2_EXTSEL_3)); // Select TIM2 TRGO event
ADC1 -> CR2 |= (ADC_CR2_EXTSEL_1) | (ADC_CR2_EXTSEL_2);

// ADC1 -> CR2 |= (ADC_CR2_DMA) | (ADC_CR2_DDS); //Enable DMA
ADC1 -> CR2 |= (ADC_CR2_ADON); //Enable ADC1

//ADC2
ADC2 -> SQR3 |= (0X02); // Select Ch 2
ADC2 -> CR2 |= (ADC_CR2_ADON); //Enable ADC1

//ADC3
ADC3 -> SQR3 |= (0X03); // Select Ch 3
ADC3 -> CR2 |= (ADC_CR2_ADON); //Enable ADC1

 

// Config DMA2
DMA2_Stream0 -> CR &= ~(DMA_SxCR_EN); //Disable DMA
while(( (DMA2_Stream0 -> CR) & (DMA_SxCR_EN) )){} // Wait till stream is disable
//Select Ch0
DMA2_Stream0 -> CR &= ~( (DMA_SxCR_CHSEL_0) | (DMA_SxCR_CHSEL_1) | (DMA_SxCR_CHSEL_2) );

DMA2_Stream0 -> CR |= (DMA_SxCR_PL_0) | (DMA_SxCR_PL_1); // Set very high Priority level

DMA2_Stream0 -> CR &= ~(DMA_SxCR_MSIZE_0); //Set MSize 32-bit
DMA2_Stream0 -> CR |= (DMA_SxCR_MSIZE_1);

DMA2_Stream0 -> CR &= ~(DMA_SxCR_PSIZE_0); //Set PSize 32-bit
DMA2_Stream0 -> CR |= (DMA_SxCR_PSIZE_1);

DMA2_Stream0 -> CR |= (DMA_SxCR_MINC); //Enable Mem Inc
DMA2_Stream0 -> CR |= (DMA_SxCR_PINC); //Enable Mem Inc
DMA2_Stream0 -> CR |= (DMA_SxCR_CIRC); //Enable circular mode
DMA2_Stream0 -> CR &= ~( (DMA_SxCR_DIR_0) | (DMA_SxCR_DIR_1)); //Set transfer direction

DMA2_Stream0 -> NDTR |= 1; //Set no.of data register
DMA2_Stream0 -> PAR = (uint32_t) (&(ADC -> CDR)); //Set Peri Address
DMA2_Stream0 -> M0AR = (uint32_t) (&adc_data); //Set Mem Address

// Enable DMA transfer complete interrupt
DMA2_Stream0 -> CR |= DMA_SxCR_TCIE; // Enable transfer complete interrupt

// Enable DMA interrupt in NVIC
NVIC_EnableIRQ(DMA2_Stream0_IRQn);

/* CONFIG TIMER FOR TRIGGER */
TIM2 -> PSC = (8400 - 1); // Set prescaler for 10000Hz timer frequency
TIM2 -> ARR = (10000-1); // Set auto reload value

TIM2 -> CR2 &= ~(( 1U << 4) | ( 1U << 6)); // Select update event for TRGO
TIM2 -> CR2 |= ( 1U << 5);

ADC -> CCR |= (ADC_CCR_DDS);
ADC -> CCR |= (ADC_CCR_DMA_1); //Set DMA Mode 1
ADC -> CCR |= (0x016); // Enable Dual Mode

}

void adc_start(void){

DMA2_Stream0 -> CR |= (DMA_SxCR_EN); // Enable DMA
TIM2 -> CR1 |= ( TIM_CR1_CEN); // Enable TIM2

}

// Interrupt Service Routine for DMA2 Stream 0
void DMA2_Stream0_IRQHandler(void) {
// Check for DMA transfer complete interrupt flag
if(DMA2->LISR & DMA_LISR_TCIF0) {
// Clear the interrupt flag
DMA2->LIFCR |= DMA_LIFCR_CTCIF0;
// Set flag to indicate that the transfer is complete
dma2_status = 1;

}
}

0 Comments
2024/09/23
15:45 UTC

1

Thonny won't run Micropython on NUCLEO-F401RE (Mac)

I am trying to use a NUCLEO-F401RE with Thonny and micropython in mac (Sonoma 14.6.1). However, Thonny cannot connect to the NUCLEO-F401RE, and it throws the following error:

Device is busy or does not respond. Your options:

  - wait until it completes current work;
  - use Ctrl+C to interrupt current work;
  - reset the device and try again;
  - check connection properties;
  - make sure the device has suitable MicroPython / CircuitPython / firmware;
  - make sure the device is not in bootloader mode.

Also, it won't appear in the files window.

However, I checked the port configuration in Thoony and the device file appears as an option. Also, the NUCLEO-F401RE appears in the Mac system report under the USB Device tree.

The firmware I installed in the NUCLEO-F401RE is called NUCLEO_F401RE.bin and downloaded it from this GitHub repository:https://github.com/curtywang/stm32_micropython_mbed_bins/releases/tag/v1.19

Since my mac only has USB-C, I've tried using different USB adaptors (both original and third party ones) but non of them work.

PD: I need to do this for a class, and a classmate (who also has a Mac) has the same problem.

I am trying to use a NUCLEO-F401RE with Thonny and micropython in mac (Sonoma 14.6.1). However, Thonny cannot connect to the NUCLEO-F401RE, and it throws the following error:

Device is busy or does not respond. Your options:

  - wait until it completes current work;
  - use Ctrl+C to interrupt current work;
  - reset the device and try again;
  - check connection properties;
  - make sure the device has suitable MicroPython / CircuitPython / firmware;
  - make sure the device is not in bootloader mode.

Also, it won't appear in the files window.

However, I checked the port configuration in Thoony and the device file appears as an option. Also, the NUCLEO-F401RE appears in the Mac system report under the USB Device tree.

The firmware I installed in the NUCLEO-F401RE is called NUCLEO_F401RE.bin and downloaded it from this GitHub repository:https://github.com/curtywang/stm32_micropython_mbed_bins/releases/tag/v1.19

Since my mac only has USB-C, I've tried using different USB adaptors (both original and third party ones) but non of them work.

PD: I need to do this for a class, and a classmate (who also has a Mac) has the same problem.

1 Comment
2024/09/23
01:12 UTC

1

Undefined Reference to _estack and _sdata When Building STM32 Project with Simulink and CubeMX

I'm trying to build a project using Simulink to generate code for my STM32F411RE board. I'm using STM32CubeMX to configure the peripherals and importing the generated .ioc file into Simulink. Everything seems to be set up correctly, but when I try to build the model, I encounter the following errors during the linking phase:

undefined reference to `_estack`
undefined reference to `_sdata`
undefined reference to `_sidata`
undefined reference to `_sbss`
undefined reference to `_ebss`

These errors seem related to the startup file or memory sections, and I'm not sure whether the issue is with CubeMX's generated configuration or something in the Simulink setup.

Here’s what I’ve done so far:

  • I created the project in STM32CubeMX for my board and configured peripherals like timers.
  • Imported the .ioc file into Simulink to generate code.
  • Tried building the code, which results in the linker error related to undefined memory references.

Has anyone encountered this issue before? Any suggestions on how to fix this?

Thanks for any help!

3 Comments
2024/09/22
21:50 UTC

1

TRIPLE MODE ADC IN STM32F407. Need help

0 Comments
2024/09/22
20:54 UTC

1

No Response from PZEM-004T Module using USART Communication

I'm currently facing an issue with my custom USART driver for communicating with the PZEM-004T module. I've successfully developed and tested this driver, and it works perfectly with other devices like the ESP32, where I receive responses without any problems. However, when I attempt to communicate with the PZEM-004T, the data sent appears correctly on the logic analyzer, but I receive no response from the slave, i also tried sending the command from pc using Tera Term 5 but same. I've verified that I’m using the correct settings: a baud rate of 9600, 8 data bits, 1 stop bit, and no parity. Additionally, I've checked the Special Function Registers (SFRs) to ensure everything is set up correctly. I've also tried changing the slave address and modifying the Modbus command, but none of these adjustments have yielded any results. Any guidance or suggestions on how to troubleshoot this issue would be greatly appreciated.

I don’t believe the problem from my code as i said i already tested it with other SLAVES. I think the sensor isn’t receiving the right command or something, but I've checked with others who used the same command and received a reply.

I’m really struggling with this problem, and I would greatly appreciate any help anyone can offer.

https://preview.redd.it/z4dfy47s97qd1.png?width=1918&format=png&auto=webp&s=4eb6ba75f70d79932da5b2b80f032870e6f1bb88

https://reddit.com/link/1fm8sen/video/1vgldtrra7qd1/player

0 Comments
2024/09/21
17:54 UTC

1

ST32F44 and ADS1299 no data on MISO

Hi so this is the setup: PC6=ADC_CLKSEL; PD11=ADC_PDWN; PD13=ADC_DRDY; PD15=ADC_CS; PB13=SPI_SCK;PB14=SPI_MISO; PB15=SPI_MOSI and PC7 =ADS_RESET.

Initialization

Initialization

when I hit the while loop I'm doing the request for the device ID

https://preview.redd.it/5jtrr7pqsnpd1.png?width=566&format=png&auto=webp&s=56ed81ac8570b55029c1c57e019149d5ae6d4cb8

result on the logical analyzer

https://preview.redd.it/o8o0zetfunpd1.jpg?width=897&format=pjpg&auto=webp&s=d9791cad57655a3f2d66f9b592b9c41f9d16ed9d

I see the request goin but nothing comes back on the MISO.

For CUBE MX

https://preview.redd.it/5ljx96citnpd1.jpg?width=1119&format=pjpg&auto=webp&s=9b4e5ee407532fc29078fefc524919705447b82e

Question , what I'm doing wrong ? Only thing that comes in my mind is I'm doing something wrong during the Initialization steps ?

3 Comments
2024/09/19
00:23 UTC

1

Absolutely Baffling STM32 Mystery - please help!

0 Comments
2024/09/16
03:12 UTC

1

I need help with interfacing my barcode scanner as a device with the stm32f401 as a USB host

I had a ton of experiments trying to get it working but nothing happened and no progress at all. Even YouTube tutorials that work with them like rockets don't even say blah with me.

Currently,

  • I have stm32f401 (blackpill) powered by the st-link USB from the laptop.
  • A power supply with 5V output is needed to supply the scanner with the 5V / 85mA it needs.
  • I have the scanner's male USB plugged into a female USB with a 4-wire extension for each pin.

the 4-wires are connected like this:
GND wire: power supply GND
VCC wire: power supply VCC
D+ : to stm32 D+
D- : to stm32 D-

stm32, the scanner's USB and the power supply have common ground.

Are there any further considerations HW or SW that I need to consider?

0 Comments
2024/09/14
16:00 UTC

0

Tìm cảm biến độ ẩm đất

Mọi người cho em hỏi có cảm biến độ ẩm đất nào phù hợp để đo độ ẩm đất cho vườn cây sầu riêng, trả tính hiệu về vi đều khiển không ạ

0 Comments
2024/09/13
02:36 UTC

1

I need help in integrating the functions from shared .c files to my main.c file. I want to implement PID controller in c language using STM32 MCU.

Hello and Thanks for coming to read my question.

I am very beginer to the c coding, i didn't have any coding experience so i am facing a lot of difficulties in generating the code for PID controller.

I found pid_controller.c and pid_controller.h libaries for online for PID controller which can be used with microcontroller.

I have STM32F407, and with the help of cube IDE software I have created the template main.c file

based on pid_contro.c and h files I am wiriting the code but unable to write correct code and everytime getting error, actually I don't know which functions and variables I could include from pid_controller.c and pid_controller.h files into my main.c file so that the code should run in sequence and correctly.

I also don't know which function should be written inside the int main(void) and inside the while () and outside the main(void).

If someone is willing to help me I will appreciate and happy to offer him/her a coffee.

My code can be found via following link PID Controller

0 Comments
2024/09/09
14:06 UTC

1

Unable to Clear UIF Bit in TIM2 Interrupt Handler During Debugging

I wrote firmware for an STM32 where I enabled interrupts using TIM2. However, when I set a breakpoint in the interrupt handler during debugging, I am unable to clear the UIF bit in the SR register. What could be causing this issue?

1 Comment
2024/09/08
17:45 UTC

3

PWM and DMA

Hello to everyone, I'm looking here for someone that could explain in simple words how to manipulate the PWM mode of the Timers using the DMA.

Purpose : I want to understand exactly step by step how to use PWM so I could use it for a Programmable LED. Yes I know I can find already written code for LED but usually everyone does it a little different.

What I know/understand so far :

So far I know how to enable the TIM in PWM mode and how to set up the frequency and all that stuff. Example for a frequency of 72Mz using the Prescaler=0 and Counter Perion( ARR)=900-1 or ( Prescaler 90-1 and ARR=100-1) im getting a frequency of 80Kz for the PWM.

In the STM Documentation UM1725 they have 2 methods to use the DMA: HAL_DMA_Start() and for the PWM HAL_TIM_PWM_Start_DMA.

What I'm more interested in the second one .

HAL_TIM_PWM_Start_DMA (TIM_HandleTypeDef * htim, uint32_t Channel, const uint32_t * pData, uint16_t Length) from docs I understand that

htim=the timer that we are using

Channel =channell that we are using from the Timer

pData=is the data that we want to transmit

Lenght=lenght of the data.

So logically pData should contain the data that needs to be transmitted to the LED, now how to manipulate the data or better how to put the data in.

So data that we transmit for one LED should look like this [111111111111111111111111] (24 bits) + reset bit.

Now the first question do I have to transmit the number 16777215 +reset ( or other number not bigger than that )or I have to transmit an array of 0 and 1 or just direct 111111111101011111111111?

Now the second question . According to LED documentation to get 0 or 1 you have to have the PWM high or low for a specific period of time. As i know i can control that using the CCR ((CCR/ARR)*100%) and we get for how long we want to pulse stay high. So if I want to create 0 or 1 i have to create 2 Methods (M0 and M1) that change the CCR then when I writhe the pData , if I need an array of 0 and 1's, for each position in array I could invoke the Method that is necessary in a "for loop" till I fill the array and then place that array in the HAL_TIM_PWM_Start_DMA. method and wait till the data is transmitted , any recommendation of the method to call for the DMA transmission status are welcome,.

So how much off I'm from understanding the process of transmitting data to LED ? what recommendations would you give? and is is even possible do add 0 and 1's to an array just modifying the CCR value?

0 Comments
2024/09/04
17:45 UTC

3

im not able to set SWSTART bit to 1 to begin the conversion on ADC, but why?

#define RCC_AHB1ENR (*(volatile unsigned long *)0x40023830)

#define RCC_APB2ENR (*(volatile unsigned long *)0x40023844)

#define GPIOA_MODER (*(volatile unsigned long *)0x40020000)

#define ADC1_SR (*(volatile unsigned long *)0x40012000)

#define ADC1_CR1 (*(volatile unsigned long *)0x40012004)

#define ADC1_CR2 (*(volatile unsigned long *)0x40012008)

#define ADC1_SMPR2 (*(volatile unsigned long *)0x40012010)

#define ADC1_SQR3 (*(volatile unsigned long *)0x40012034)

#define ADC1_DR (*(volatile unsigned long *)0x4001204C)

void adc_init(void) {

// 1. Enable the clock for GPIOA and ADC1

RCC_AHB1ENR |= (1 << 0); // Enable GPIOA clock

RCC_APB2ENR |= (1 << 8); // Enable ADC1 clock

// 2. Configure PA0 as analog mode

GPIOA_MODER |= (3 << 0); // Set PA0 to analog mode (MODER0[1:0] = 11)

// 3. Configure ADC1

ADC1_CR2 = 0; // Reset CR2

ADC1_CR1 = 0; // Reset CR1

ADC1_SMPR2 |= (7 << 0); // Set sampling time for channel 0 (480 cycles)

// 4. Select the channel (assuming channel 0, PA0)

ADC1_SQR3 |= (0 << 0); // Channel 0 is selected as the 1st conversion in regular sequence

// 5. Enable ADC

ADC1_CR2 |= (1 << 0); // ADON: Enable ADC

}

unsigned int adc_read(void) {

// 1. Start conversion

ADC1_CR2 |= (1 << 30); // SWSTART: Start conversion of regular channels

// 2. Wait for conversion to complete

while (!(ADC1_SR & (1 << 1))); // Wait for EOC (End Of Conversion)

// 3. Read and return the ADC value

return ADC1_DR; // Read the ADC converted value

}

int main(void) {

adc_init();

unsigned int adc_value;

while (1) {

adc_value = adc_read();

// Use adc_value as needed

}

}

0 Comments
2024/09/02
17:30 UTC

0

Clones only working while hot?

0 Comments
2024/08/31
09:47 UTC

0

Generating code in STM32Cube IDE

I am experiencing some difficulty in code generation .I have tried using the device configuration tool code generaton but it wont generate code.

1 Comment
2024/08/29
16:00 UTC

1

Newbie here

I uses to program in arduino . I made few automation projects with ir sensor, dc motors, servos, lcd display, oled display. I learnt c and c++ during my college days. Now I'm learning to do programming on stm32f401cdu6 (blackpill) and done my first blinking program . But I'm still confused about data types, why they are declared different here. How to read a sensor value and display in console. How to display in lcd 2×16 or in a small oled display . All i want to do is read sensor value and set a digital pin on or off. Pls suggest me any books or any forums to get details. Thank-you in advance

3 Comments
2024/08/26
17:29 UTC

1

Stm32f401CB proteus simulation

I am trying to write my own drivers for this board using keil 5 IDE, but trying to blink a led using the drivers I 've written didn't work. Although, writing the same idea but using HAL libraries on stm32 cube IdE worked just fine, I can't figure what's wrong. Any tips?

0 Comments
2024/08/24
12:59 UTC

1

Beer night yall

I'm live on Twitch, come hang out! https://www.twitch.tv/cimaron123?sr=a

0 Comments
2024/08/23
21:41 UTC

2

How can I change the Kp, Ki Values in real time while code is running on STM32CubeIDE?

"I'm trying to tune a PI controller for my STM32 microcontroller. After writing the code and setting the parameters, I've been uploading it to the device. However, it's a lengthy process to stop the code, change values, rebuild, and debug each time.

Is there a faster way to modify the Kp and Ki gains without constantly stopping and restarting the code? I've tried using Live Expressions, but it doesn't seem to work in STM32CubeIDE

9 Comments
2024/08/23
02:12 UTC

2

What have I go to do to get the STM32 board to show up in Available DFU devices in DfuSe?

8 Comments
2024/08/21
12:23 UTC

3

how to write some data to external SRAM and MRAM, STM32F4

Hi, I have 2 external SRAM(1 bank) and MRAM(4 bank) memory chips connected to the stm32f4 via FMC. The STM32F4 datasheet indicates that the memory addresses for bank 1 are 0x60000000, and for bank 4 are 0x90000000, while I can write and read data to SRAM at the initial address, and when trying to write or read, it gives the error cannot access memory. How can this be fixed?

0 Comments
2024/08/20
11:22 UTC

2 Comments
2024/08/15
06:38 UTC

Back To Top