In ECE362, students will learn fundamentals of microcontrollers, including their operation, and usage. In addition to the lecture portion of the course, students are expected to complete a series of lab experiments using a microcontroller platform and IDE. Computers and measurement equipment are provided in the course laboratory facilities to assist students in completing labs, however, the course has also been designed to allow students to perform experiment exercises on their own computers at home or elsewhere. Instructions provided in this lab document serves as a guide to setting up the microcontroller development environment used in ECE362 to provide a consistent user experience between home and the laboratory.
Make sure that you read this document in full. There are two ways in here to destroy your development board.
Open your ECE 362 lab kit and find the STM32F091RCT microcontroller development board. It should look like the one in the image below.
Your ECE Master/Mini kit has a large, four-panel breadboard similar to the one pictured below. Place the devboard so that it is on the bottom of the second panel, shown below:
Typically, these will be a little hard to get in there, but you should not have to remove it once itâs in there. To prevent damage to the board, press down on the buttons. Do not apply force to anything else, as parts of the board are delicate and may become damaged. When inserting, make sure there are two holes on either side of the development board to leave room to plug in peripherals. Next, connect the USB programmer (shiny colored device with a light on it, pictured below) to the devboard.
It is important that this programmer only ever gets connected to the black header on the side of the devboard. If you manage to place it on the exposed pins on the long sides of the devboard, you will irreversably damage the development board. After plugging in the programming side to the devboard , you should see a red and a green LED light up. If it does not light up, unplug the programmer and call over a TA so they can take a look at it.
For our course, the Eclipse IDE will be used, alongside of the SystemWorkbench for STM32 plugin. Eclipse is open source, so it may not seem like the most user-friendly when you are first using it. After extended use, you should be able to navigate it pretty well. Here are instructions on how to set it up on your machine, as well as on the lab computers.
Fortunately for you, one of the past instructors created a setup package that you can invoke to (mostly) take care of this for you. Open a terminal window, and invoke this line of code:
~ece362/bin/setup
After running this, you should see new icons appear on your desktop. One of them reruns the setup program, which you can use to update your configuration if any new applications are needed. Another icon is created for System Workbench, which is the main application that you will use.
Warning
Skip this step if you are on the lab machines. You already set up SystemWorkbench via the setup command above.
NOTE: I have cached the most recent installers into the Brightspace, so you can download them without going through the OpenSTM registration process now. There are Ubuntu and Windows installers. These are located in their own tab on the bottom of the tab list on Brightspace.
The version of Linux that this application is supported on is Ubuntu LTS. It might work on other distributions, or it might not. You can get the installation package here. A couple of different ways to install it are located below:
bash install_sw4stm32_linux_64bits-latest.run
or
sudo apt install lib32ncurses5 make
or
sudo apt install libpython2.7:i386 libncurses5:i386 make
Pick the one that works best for your distribution, and keep track of where the installer puts the required folders. These will be important later. The installation script should set up a link on your desktop by which you can invoke System Workbench. If not, invoke it with
[the path to the installation directory]/eclipse
NOTE: I have cached the most recent installers into the Brightspace, so you can download them without going through the OpenSTM registration process now. There are Ubuntu and Windows installers. These are located in their own tab on the bottom of the tab list on Brightspace.
Eclipse works on Windows 10 and 11. You can find the installation package here. Once downloaded, run the installer. Keep track of where the installer puts the required folders. These will be important later. Sometimes Windows may require a driver for the STLink programming device. Download and install the driver, located here.
For this class, we will use the OpenSTM32 Standard Peripheral Library as the core of our work. In a sum, itâs a script that starts the chip up, as well as a couple of other scripts that provide memory address acronyms. This is nice because you will not have to constantly look up the memory addresses for each part of the chip, which is a huge pain. You can find it here, or cached on the Brightspace.
NOTE: I cached a renamed version on the Brightspace now, so you no longer have to mess with the version or rename it. Simply drop the zip file into the Firmwares folder, and extract it into the same folder. You should have two copies: one zipped, and one unzipped.
Once downloaded, moved the zip file into the their repective directory. If you chose the default locations, typically theyâre located in:
~/.ac6/SW4STM32/firmwares
for Linux, or
C:\Users\<username>\AppData\Roaming\Ac6\SW4STM32\firmwares
for Windows.
For the lab machines, you need to enable the ability to view hidden files, as having the dot in front of ac6 makes it a hidden file. You can do this by selecting the view tab on the file explorer, and checking the box that says âshow hidden files.â
Move the zip file into the firmwares directory, and unzip it inside of that location. None of use are really sure why, but Eclipse looks for both the zipped and unzipped version. They must have the same name, otherwise Eclipse will pretend like itâs not there. If you download an earlier or later version than V1.5, you may have to rename it to V1.5, as shown in section 5.4 of this document. None of us really know why, but Eclipse sometimes only likes V1.5. It might also only look for one specific naming covention, like the one shown below. If all else fails, try naming both of your files like this:
stm32f0_stdperiph_lib_v150
stm32f0_stdperiph_lib_v150.zip
This is what your Firmwares folder should look like after:
Now that the software is installed, we can begin configuration. Start this by selecting the âWindowâ dropdown at the top of the screen, and selecting the âSettingsâ option. As youâre doing this, make sure that youâre changing the settings highlighted with the red Xs.
Here, we configure the general workspace preferences. Open the âGeneralâ dropdown, and select âWorkspace.â Here, unselect âbuild automaticallyâ and select âSave automatically before build.â After, change your text file encoding to UTF-8, and new text file line delimiters to Unix. This helps standardize what you and the TAs look at, and enables a setting to build the correct version of your project, as Eclipse only builds the last-saved version. An example setting is shown below:
Next, drop down the âEditorsâ tab, and select âText Editors.â Check the âShow print marginâ tab so you can see where the printer would stop in case your code ever needs to be printed out. An example setting is shown below:
Open the âC/C++â dropdown, and then select âIndexer.â Make sure âUse active build configurationâ is checked. An example setting is shown below:
Eclipse, like other IDEs, automatically formats code for you. However, it needs to be told to not use tabs. Open the âC/C++â dropdown, open the âCode Styleâ dropdown within it, and then select âFormatter.â Select âNewâ to open a new template, and select âK&R Câ as your base. Make sure to select âSpaces onlyâ for your tab policy. Past that, youâre free to format your code however you want. Make sure you save and apply after. An example setting is shown below:
Open the âC/C++â dropdown, then the âBuildâ dropdown within it. Then select the âConsoleâ tab. In there, check âBring console to top when building (if present) and âWrap lines on the console.â These make sure that the build console is present, as well as ensuring that the console is visible if you have it open. After, increase the number of lines to something larger. I typically use 5,000, as itâs atypical for a program of our nature to print anything larger than that. An example setting is shown below:
Time to test out our configuration! Ensure that your Devboard is plugged into the computer, and restart SystemWorkbench, then follow these instructions.
At the top of the screen, open the âFileâ dropdown. Select the âNewâ option, and then select the âProjectâ button. In the opened âSelect a Wizardâ dialog box, select âC projectâ and then hit âNextâ
Select the âAc6 STM32 MCU Projectâ button, and enter a project name as âTest,â as this will be your test project to make sure the chip works as intended. Hit âNext.â On the next âSelect Configurationâ dialog, just press âNext.â
Select the âMCUâ tab at the top of the window. After, ensure that the âSeries:â dropdown contains the STM32F0. After, youâll need to select the specific model of microcontroller, so that it knows which peripherals to load in. Ours is the STM32F091RCTx, which is located near the bottom of the dropdown menu. After, donât hit âFinish,â hit âNext.â
Select âStandard Peripheral Library (StdPeriph).â It will look for the standard peripheral library that you had installed earlier. This may take a few moments, as these files are quite large and it likes to verify them each time they get opened. Do not use the âCube HALâ option, or the âNo firmwareâ option. Cube HAL is still a work in progress from STM, and no firmware means that youâll need to manually program in a startup sequence and memory locations (which, for our purposes, you really donât want to do. For those of you that asked, the no firmware setting is bare-metal programming).
After this, it should find your SPL. If it doesnât, refer to section 3 of this manual to make sure that you did it correctly. If itâs still not working, call a TA over. Click âFinish,â and the wizard will go about automatically creating your project.
Note
If pre-caching the library doesnât work, donât panic. Try the download button again, ensure that thereâs no change in the filenames for the ZIP file or the extracted folder, and that you made sure to place them in the right folder.
Inside of your project, there will be a few top level directories. Hereâs what they contain:
Double-click on the src folder to open it, and then double click on main.c to edit it. Itâll open the editor window, which will take up the majority of your screen. This is where you can write and edit code. When creating this new project, it shouldâve filled in an infinite for loop in the main file, as well as a commented header.
There is a very similar build/save/run interface at the top of the window that you might recognize from the ARM IDE used earlier in the class. Go ahead and click the hammer icon in the top left to build the project. Thereâs not much to build, so this should go by pretty quickly and without any hangups.
To get the debugger running correctly, click the âRunâ dropdown at the top of the screen, and then the âDebug Configurationsâ button just below the middle of the dropdown. In the âCreate, manage, and run configurationsâ dialog that appears, double click the âAc6 STM32 Debuggingâ option that appears on the left sidebar. This opens a new debug configuration. After, rename this configuration to the projectâs name, and then use the âsearch projectâ button to find your .elf file that was generated by the build. Make sure you click âApplyâ to save your changes.
Next, which is probably the most important part, is to select the âDebuggerâ tab. This brings you to debugger-specific settings. One of these settings is generated incorrectly for our application, and must be changed each time. You can get to this setting by selecting âShow Generator Optionsâ and then changing the Reset Mode from âConnect under resetâ to âSoftware System Reset,â like shown below:
This will reset each time you make a new debug configuration, which will happen each week. If you do not change this, you will get a message saying that the microcontroller will not connect. This is typically why. If youâre curious, your debugger is not a real STLink. Itâs a cheap knockoff that our supplier makes, but they work well enough, and they reduce the kit costs by around $30.
Lets try debugging a program! First, clear out your main file, and enter this instead:
#include "stm32f0xx.h"
int main(void)
{
int x = 0;
int y = 0;
for(;;)
{
x += 1;
y -= 1;
}
}
After, click the blue bug at the top of the screen. This will rebuild your project and prompt you to switch into Debug Mode. Click yes, and itâll change your screen in a few different ways, like shown below:
The console is now the bottom of the screen, the editor is the bottom-left pane, and there are multiple useful memory/register tools located in the top-right pane.
Here is a breakdown of the debug tools located at the top of the window:
Youâll also note that the light on the debugger will start blinking. This is normal, and shows that itâs in normal operation. At this point, you can explore what each button does. Specifically, the different step over/into buttons. You will have a prelab later to explore these functions in more depth.
Call over a TA, and demonstrate that your debugger is working, and show them what each button does. They will check you off for this step if you can.
Begin with terminating the debugger. Switch bag into âeditorâ view by clicking the button to the left of the bug on the top right corner of the debug window. Copy and paste this code into your main.c file:
void setup_serial(void)
{
RCC->AHBENR |= 0x00180000;
GPIOC->MODER |= 0x02000000;
GPIOC->AFR[1] |= 0x00020000;
GPIOD->MODER |= 0x00000020;
GPIOD->AFR[0] |= 0x00000200;
RCC->APB1ENR |= 0x00100000;
USART5->CR1 &= ~0x00000001;
USART5->CR1 |= 0x00008000;
USART5->BRR = 0x340;
USART5->CR1 |= 0x0000000c;
USART5->CR1 |= 0x00000001;
}
int main(void)
{
setup_serial();
while(1)
{
if((USART5->ISR & USART_ISR_RXNE))
{
USART5->TDR = USART5->RDR;
}
}
}
This code segment has the STM32 âlistenâ for inputs on the serial terminal, and echo them back. Essentially, if you use the terminal, itâll replicate characters that you press on the terminal so you can see them. If you run a blank piece of code and try to type on the terminal, itâll stay blank.
Do these things:
Some example pictures:
After this is wired properly, check one last time to make sure the adapter is in 3V mode. Then, connect the adapeter to your computer with the USB cable in your lab kit.
Open your terminal, and enter in this command:
screen /dev/ttyUSB0 115200
Your terminal should go blank. After, instead of the debug button, click the green âRunâ symbol to the right of the bug symbol. This programs your microcontroller and runs your code. Then, click back to your terminal and try typing some things. You should see the terminal show whatever characters you have typed.
On your personal computer, download and install a program called TeraTerm. Itâs an open-source serial terminal. After installation, open it. You should see a dialog like the one shown below. Select âSerial Port,â and then find the âUSB Serial Portâ option. It does not have to be COM5, so long as it knows as itâs a USB serial port.
After, click the âSetupâ dropdown, and click the âSerial Portâ option. Ensure that the port thatâs selected is the COM port that the serial port defaults to. Then, change âSpeedâ to 115200. Click âOK.â
After, instead of the debug button, click the green âRunâ symbol to the right of the bug symbol. This programs your microcontroller and runs your code. Then, click back to your terminal and try typing some things. You should see the terminal show whatever characters you have typed.
Call over a TA and show them that your serial port is working. This constitutes the last checkoff.