STM32 NUCLEO F411RE - Arduino IDE

Greetings, I have a question about programming the NUCLEO - F411RE board with the arduino ide, I want to get the full potential of the board and I don't know if programming it in the arduino ide limits it instead of programming it with CUBEide.

I have used both - CUBEide probably gives more low level control but Arduino IDE works OK, e.g. three phase square wave

// STM32 Nucleo board three phase square wave

// https://github.com/khoih-prog/STM32_TimerInterrupt

#define phase1 PB5  // signal output pins
#define phase2 PB6
#define phase3 PB7

#include "STM32TimerInterrupt.h"

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "STM32_ISR_Timer.h"

#define HW_TIMER_INTERVAL_US 10L

// Init STM32 timer TIM1
STM32Timer ITimer(TIM2);

// Init STM32_ISR_Timer
STM32_ISR_Timer ISR_Timer;

volatile int counter = 0;  // interrupt counter
void TimerHandler() {
  static byte state = 0;  // determines which phase to invert
  switch (state) {
    case 0: digitalWrite(phase1, !digitalRead(phase1)); break;  // invert phase 1
    case 1: digitalWrite(phase3, !digitalRead(phase3)); break;  // invert phase 3
    case 2: digitalWrite(phase2, !digitalRead(phase2)); break;  // invert phase 2
    case 3: digitalWrite(phase1, !digitalRead(phase1)); break;  // invert phase 1
    case 4: digitalWrite(phase3, !digitalRead(phase3)); break;  // invert phase 3
    case 5: digitalWrite(phase2, !digitalRead(phase2)); break;  // invert phase 2
  }
  if (++state >= 6) state = 0;  // reset state ?
  counter++;
}

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;
  delay(2000);
  Serial.println("STM32 Nucleo board three phase square wave");
  pinMode(phase1, OUTPUT);
  pinMode(phase2, OUTPUT);
  pinMode(phase3, OUTPUT);
  digitalWrite(phase3, 1);
  // Interval in microsecs
  if (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_US * 10, TimerHandler)) {
    Serial.print(F("Starting ITimer OK"));
  } else
    Serial.println(F("Can't set ITimer. Select another freq. or interval"));
}

// display interrupt counter every seconds
void loop() {
  static unsigned long timert = millis();
  if (millis() - timert >= 1000) {
    Serial.println(counter);
    counter = 0;
    timert = millis();
  }
}

photo

what do you want to do?

1 Like

If You want to use Arduino then use the Arduino environment.
If You want to use an STM32 You need to use and learn the ST environment.

This is what browser shows when you type:
"disadvantages of using Arduino IDE for STM32 Boards".

Using Arduino IDE for STM32 boards has several drawbacks, primarily related to its limited features and the STM32's advanced capabilities. The Arduino IDE's simplicity, while beneficial for beginners, can hinder advanced development and doesn't fully leverage the STM32's power. It lacks features like code refactoring, debugging tools, and version control, and the limited library management can cause compatibility issues. Additionally, Arduino's programming language and framework, while familiar, don't expose the full potential of the STM32's peripherals and features.

Here's a more detailed breakdown:

  1. Limited Features and Development Tools:
  • Lack of Advanced Debugging:

The Arduino IDE's debugging capabilities are limited, making it harder to pinpoint issues in complex projects.

  • No Code Refactoring:

Refactoring code for clarity and maintainability is difficult or impossible within the Arduino IDE.

  • Limited Version Control:

Integrating version control tools is not natively supported, making it harder to manage and track code changes.

  • Basic Library Management:

The Arduino IDE's library system can be problematic, leading to potential compatibility issues and conflicts.

  1. STM32's Advanced Features are Not Fully Accessible:
  • Hides Low-Level Control:

The Arduino framework abstract away many low-level details, which can hinder learning and understanding the STM32's capabilities.

  • Limited Access to Peripherals:

The Arduino IDE may not provide full access to all of the STM32's peripherals and their configurations.

  • No Real-Time Operating System (RTOS) Support:

The Arduino framework doesn't readily support RTOS, which is crucial for real-time applications.

  • Limited Performance Optimization:

The Arduino IDE offers limited options for optimizing code and performance for STM32's high processing power.

  1. Compatibility and Specificity:
  • STM32DUINO Core:

While the Arduino IDE can be used with STM32, the "STM32duino" core might not be the most up-to-date or comprehensive solution.

  • Limited Support for ST's Ecosystem:

The Arduino IDE doesn't fully integrate with STMicroelectronics' own tools and libraries (STM32CubeIDE), which are designed to optimize the STM32.

  1. Alternative Solutions:
  • STM32CubeIDE:

STMicroelectronics provides its own IDE (STM32CubeIDE) which is more powerful and offers better integration with their ecosystem.

  • PlatformIO:

PlatformIO is a popular alternative IDE that supports multiple microcontroller families, including STM32, and offers a more comprehensive development environment.

  • Keil MDK and IAR EWARM:

These are also well-regarded IDEs for STM32 development, known for their advanced features and debugging tools.

2 Likes

Hi thanks for your answer, right now I'm going to use it for normal purposes as an arduino but I expect to have a higher performance, readings sensors signal, transmiting those signals, do you think that stm32 can use all its capability with Arduini ide?
PD: I'm reading a square signal with stm, with cube ide is so necesary too use the timers but I receive it with a tipical arduino code, so it call my attention the libraries you are using where do I get them? is there material to study and use with stm32 and arduino ide?

Yeah, cubeide gives more access to all stm32 functions but I want to know if programming stm32 with arduino ide makes it slower or does not let to give all its potential for the taks that I'm going to program in it

There is a common saying among software developers:

Premature optimization is the root of all evil.

It is very likely that you will be able to accomplish your projects using the Arduino framework via the "STM32 MCU based boards" platform (AKA "STM32duino").

STMicroelectronics provides resources for the development and maintenance of this platform, so although it is a project of the Arduino community, it is far beyond a simple hobby project.

This platform is very popular and used by many members of the Arduino community. It has been used to make incredibly advanced projects.

So if you want to use the Arduino framework with your board, then just go for it.

Conversely, if you prefer to focus on learning how to use the closed source STM32CubeIDE, or PlatformIO then I'm sure you will be happy with those too.

depends on your project requirements, e.g.
what sensors? what data acquisition rates? etc
you mention transmitting signals - how? WiFi, LoRa, NRF24L10, etc?

install the Arduino core support for STM32 based boards as referenced by @ptillisch and experiment with your STM32 Nucleo dev board, e.g. run some of the example code

give us the requirements specification for your project?

using the Arduino framework can make it simpler to port code to other microcontrollers, e.g. recently ported a project from a STM32 to ESP32 which is also supported by the Arduino IDE