Skip to main content
Associate
September 16, 2024
Question

How to covert the code according to STM32CUBEIDE

  • September 16, 2024
  • 2 replies
  • 1657 views

I have Arduino program how covert it to STM32CUBEIDE suggest me any websites or channel for applying logics and change the program to it tell me any forum where i could learn the logic and apply it to real world applications

Here i have given the code below

#define HIGH_SIDE_A 9 // High-side MOSFET on side A
#define HIGH_SIDE_B 11 // High-side MOSFET on side B


#define FREQUENCY 60// 60 Hz
#define DUTY_CYCLE 100 // 100% duty cycle


int dt=8333.33; //dead-time
unsigned long period;
unsigned long highStateDuration;
unsigned long lowStateDuration;
unsigned long lastChangeTime;
bool isHighState = true;


void setup() {
 pinMode(HIGH_SIDE_A, OUTPUT);
 pinMode(HIGH_SIDE_B, OUTPUT);
 
 
 period = 1000000 / FREQUENCY; // Period in microseconds
 highStateDuration = (period * DUTY_CYCLE) / 100; // High state duration
 lowStateDuration = highStateDuration; // Low state duration is equal to high state duration
}


void loop() {
 unsigned long currentTime = micros();
 
 if (isHighState && currentTime - lastChangeTime >= highStateDuration) {
 // Switch to Low State
 digitalWrite(HIGH_SIDE_A, LOW);
 delayMicroseconds((period * dt) / 100); // 10% of period as dead time
 digitalWrite(HIGH_SIDE_B, HIGH);
 lastChangeTime = currentTime;
 isHighState = false;
 } else if (!isHighState && currentTime - lastChangeTime >= lowStateDuration) {
 // Switch to High State
 digitalWrite(HIGH_SIDE_B, LOW);
 delayMicroseconds((period * dt) / 100); // 10% of period as dead time
 digitalWrite(HIGH_SIDE_A, HIGH);
 lastChangeTime = currentTime;
 isHighState=true;
}
}

2 replies

STTwo-32
Technical Moderator
September 16, 2024

Hello @i_am_sandy and welcome to the ST Community.

In fact, there is not any app that can do this. You have to do it manually if you are familiar with the Cube. We have a lot of tutorials that can help you to learn programming throw Cube (on YouTube, Wiki, ...). Also, you can keep using CubeIDE with the extension STM32DUINO that will help you programming STM32 MCUs throw Arduino.

Best Regards.

STTwo-32 

Associate
September 16, 2024

It's fine but I want to work in STM32CUBEIDE

 

STTwo-32
Technical Moderator
September 16, 2024

So, the only way is to do that manually, for that you need to a be able to use the CubeIDE for programming. The YouTube Tutorials may be a good Start.  Also, Wikis can do the job.

Best Regards.

STTwo-32

mƎALLEm
Technical Moderator
September 16, 2024

Hello @i_am_sandy  and welcome to the community,

Not sure if there is a simple solution for that. I think you need to understand what the code is doing and port it yourself.

In any case, see these threads: 

https://community.st.com/t5/stm32cubeide-mcus/convert-arduino-code-to-stm32-ide-code/td-p/382900

https://community.st.com/t5/stm32-mcus-motor-control/hi-i-would-like-to-convert-arduino-code-to-stm32-cube-ide-code/td-p/176585

https://forum.arduino.cc/t/how-to-convert-arduino-code-into-stm32-code/1238178/6

 

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."