_ _ (_) ___ | |_ ____ | |/ _ \| __|_ / | | (_) | |_ / / _/ |\___/ \__/___| |__/
This is just a rough note on setting up Visual Studio Code in Debian 12.1 (Bookworm). Apart from the first step (installing python3-venv), I expect most of this process would be the same on Windows or Mac OS.
Firstly, to get around the requirement for installing Python 3.9, install the python3-venv package:
sudo apt install python3-venv
Go to https://code.visualstudio.com/ and click the big button to download the .deb file. Install the package as follows:
sudo dpkg -i code_1.82.2-1694671812_amd64.deb
Set up a new project in VS Code as follows:
A basic example program is provided below. The following breadboard circuit was used to test it:
#include <stm32f031x6.h> // Header file for STM32F031K6
void delay(volatile int n); // Function prototype for a simple delay function
int main()
{
// Configure i/o pins
RCC->AHBENR |= 1<<17; // Enable clock for port A
RCC->AHBENR |= 1<<18; // Enable clock for port B
GPIOA->MODER |= 1; // Make pin PA0 an output (for the LED)
GPIOB->PUPDR |= 1<<8; // Enable pull-up resistor on pin B4 (button)
// This while loop repeats forever (until powered is switched off)
while(1)
{
// Turn on LED (PA0) if button (PB4) is pressed
if (GPIOB->IDR & (1<<4)) // If PB4 is set
{
GPIOA->ODR = 1; // Set PA0 (Port A, bit 0) to turn on LED
}
delay(100000); // Time delay
// Turn off LED (PA0)
GPIOA->ODR = 0; // Clear the entire output data register for Port A (bit 0 controls the LED)
delay(100000); // Time delay
}
return 0; // This point should never be reached!
}
void delay(volatile int n)
{
// Waste some time by counting down to zero
while(n--);
}