DRV8834 with STM32

First, log in to your Simuli account and navigate to the Simuli Virtual Lab. Here we will create a new emulated instance of the STM32. Click on the Launch button under STM32 to get started.

This will open the configuration menu. First, provide a name for the project. Then, we will add the DRV8834 Stepper Motor Driver by selecting it from the list of available components. Finally, review that the name for the project and the selected sensors are correct and click on the Launch button.

Once we have clicked on the Launch button, a new instance of the STM32 will be created. It can take a few minutes, so be patient. Once the new instance is ready, an Open button will be visible. Click on this button to open and start working with our STM32.

A new tab with the built-in development environment opens up. On the left side, we have the code editor window along with the terminal at the bottom. On the right side, we have our STM32 Nucleo board with a terminal for interacting with the board and the DRV8834 connected to a stepper motor.

The STM32 already has the motor driver code loaded onto it, so the motor will start rotating when the instance is created. We will look at how we can build the code in this guide.

The STM32 instances come with support for Platform IO Core (CLI). We will be using it for working on our projects. To know more about Platform IO Core (CLI) and the different commands go to the Platform IO documentation.

First, change the working directory of the terminal to /workspace by using the cd command. type the following in the terminal.

cd /workspace

Now we need to initialise a new project with Platform IO. Type the following command in the terminal:

pio project init --board nucleo_f411re --project-option "framework=stm32cube"

The project will be initialised and some new folders will be created. Now we need to copy the motor.c file into the src folder. Type the following command:

cp motor.c ./src

After running the project init command, if you can't see the new files, you may have to reload the project files by clicking on PROJECT in the File Explorer pane.

To open the motor.c file in the IDE, just click on the name of the file in the file explorer pane. You should be aware of what is happening in the code.

Once we have copied the file to the correct location, we are ready to compile the code. Type the following command in the terminal to compile our code:

pio run

Platform IO will compile the program and create a firmware.bin file. Now we need to copy this file from .pio/build/nucleo_f411re to /workspace. Use the custom load-firmware command to do the same. Just go to the terminal and type:


Now we just need to reset the STM32. To reset the STM32, press the red button above the STM32. After the reset, the STM32 will load the new firmware, and the motor should start rotating.

Now that we are done with the basic program for the DRV8834, go ahead and modify the code to make the motor turn on via a switch. To achieve this you will have to define one of the GPIO pins as an input and then call the function to run the motor when the switch is turned on. Keep building and have fun! 🎉

Last updated