Uploading your Arduino program to STM32

Now that we have set up Arduino IDE to work with the STM32 Nucleo boards, paste the given code in Arduino IDE.

#include <Arduino.h>

// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200

// Microstepping mode. If you hardwired it to save pins, set to the same value here.
#define MICROSTEPS 1

#define DIR 10
#define STEP 9
#define M0 11
#define M1 12

#include "DRV8834.h"

DRV8834 stepper(MOTOR_STEPS, DIR, STEP, M0, M1);

void setup() {
    /*
     * Set target motor RPM=1
     */
     pinMode(9, OUTPUT);
     pinMode(10, OUTPUT);
     pinMode(11, OUTPUT);
     pinMode(12, OUTPUT);
     
     Serial.begin(9600);
     Serial.println("DRV8834");
    stepper.begin(1, MICROSTEPS);

    // if using enable/disable on ENABLE pin (active LOW) instead of SLEEP uncomment next line
    // stepper.setEnableActiveState(LOW);
    stepper.enable();
}

void loop() {
    stepper.rotate(360);
}

Now we need to export the compiled binaries. Go to Sketch and select the Export Compiled binaries option. Once this is done, navigate to the folder where we saved the sketch and a .bin file should be available. We need to upload this to the built-in IDE on Simuli Virtual Lab. Go to your STM32 instance in Simuli Virtual Lab and open the file viewer sidebar. Right-click anywhere in this sidebar and select Upload Files.... A new window pops up: here we select the .bin file that we got after exporting the compiled binaries and click open.

Now we need to rename the bin file from yourfile.bin to firmware.bin. We will use the terminal to achieve the same. Go to the terminal, first, let's change our directory to /workspace using cd, and then we will rename the files using mv.

cd /workspace
mv yourfile.bin firmware.bin

Write these commands in the terminal and execute them.

Make sure you change yourfile.bin in the command to the actual name of the bin file.

Finally, we just need to reset the STM32, i.e. click on the red power button above the top left corner of the STM32. When the STM32 restarts, it will use our new firmware.bin file.

Last updated