2019-05-22 07:30 PM
Hi,
I would like to convert Arduino code to STM32 IDE code.
Could you please suggest for me ?
Thank you
2019-05-22 10:01 PM
If it's just a test code, have you considered STM32Duino?
The conversion is not that simple. I think you need to recode the program manually.
2019-05-22 10:21 PM
Hi
Thank you very much for your suggestion.
I tried to learn many IDEs and compare its function such as Arduino, CooCox, IAR, Keil, Mikroelektronika, System Workbench for STM32, TrueSTUDIO and etc.
But I would like to use STM32 IDE. Because it is free and great IDE for me.
2019-05-22 10:38 PM
>I tried to learn many IDEs ...
An IDE is just the human interface (HMI) to the toolchain, i.e. compiler/linker (or interpreter).
Most of the named IDEs are based on a C/C++ toolchain, so the best option is to come to grips with that language.
AFAIK there exists no "translator" between Arduino and C/C++. I think you would need to rewrite your code.
2019-06-01 07:14 PM - last edited on 2024-11-21 03:09 AM by Andrew Neil
Hi @Community member,
Are you create your project with STM32CubeMX? I highly recommend, it's a piece of cake to configure and generate all peripherals code!
You can use advanced macros to swap arduino standard routines with STM32CubeMX, like this:
// Define the GPIO pin and port, that was originally connected arduino Digital 10 and 11, in the STM32.
#define D10_Pin GPIO_PIN_4
#define D10_GPIO_Port GPIOC
#define D11_Pin GPIO_PIN_5
#define D11_GPIO_Port GPIOC
// Advanced macro to swap routine names and parameters.
#define digitalWrite(PIN_NAME,PIN_STATE) HAL_GPIO_WritePin(D##PIN_NAME##_GPIO_Port,D##PIN_NAME##_Pin,GPIO_PIN_##PIN_STATE)
#define digitalRead(PIN_NAME) HAL_GPIO_ReadPin(D##PIN_NAME##_GPIO_Port,D##PIN_NAME##_Pin)
// Simple test of this implementation. Should work like a champ!
void test (){
if( digitalRead(11) ) digitalWrite( 10,SET );
else digitalWrite( 10,RESET );
}
You can put this code in another C file, I recommend create it in the Middlewares folder, like this: "Middlewares/MyCode/source".
In the main.c file, add the prototypes:
void setup ();
void loop ();
Between USER_CODE labels.
And in the main routine, add setup and loop calls:
int main () {
[...] // STM32CumeMX code Generated.
/* Infinite loop */
/* USER CODE BEGIN WHILE */
setup();
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
loop();
}
/* USER CODE END 3 */
}
Be aware of the USER CODE labels, as the STM32CubeMX will only leave user code between this labels! Otherwise It will be deleted every time you generate code!!
More about macros here:
https://www.cprogramming.com/tutorial/cpreprocessor.html
Or you can simply refactor code using "Refactor->Rename... Alt+Shift+R" tool in every routine and pin names.
Best regards.
2020-03-25 03:40 AM
I just wanna say that thank you !!
your explanation is great and clearly
2020-03-25 11:34 PM
Thank you very much for your help.
2024-04-28 09:16 AM
S'il vous plaît.. j'ai un code Arduino pour un projet sur esp32 .. (le code représente un bluetooth car controller)
Je veux le convertir en un langage c pour un STM32F407.
S'il vous plaît, est ce que vous pouvez m'aider.. c'était urgent .
Et merci d'avance.
2024-04-28 02:18 PM
"Please.. I have an Arduino code for a project on esp32.. (the code represents a bluetooth car controller)
I want to convert it to a c language for a STM32F407.
Please, can you help me... it was urgent. And thank you in advance."
For do-your-job type "Urgent" perhaps see https://www.fiverr.com/ http://www.catb.org/~esr/faqs/smart-questions.html#urgent
Hard to know how portable your current code is. The Arduino drivers hide a lot of the detail/complexity and are in C++. You should review the code for the project in it's totality, all the source is within the Arduino environment.
Generally what's in the INO is relatively top-level and superficial, the real complexity will be within the drivers and how it interacts with the hardware. Functionality of the ESP32 may simply not exist in the STM32 library code.
Look at what stm32duino currently offers as platforms.
2024-11-21 02:52 AM - edited 2024-11-21 04:50 AM
Appreciate your reply as I have some arduino code to port to stm32 and your solution seems very straightforward and logical. I should also mention, for others, I believe it is now possible to put the arduino core on to an STM32 board (nucleo-64 and so on) and use the Arduino IDE 2 directly to write a sketch. See, for example: https://github.com/stm32duino/Arduino_Core_STM32/wiki/Getting-Started