STM32F103C8 Arduino ST-link

From media_wiki
Jump to: navigation, search

Arduino using ST-Link V2

References:
Blue Pill STM32duino Wiki https://wiki.stm32duino.com/index.php?title=Blue_Pill
ST-LINK/V2 USB driver Windows https://www.st.com/en/development-tools/stsw-link009.html
Setting up the Blue Pill in Arduino Environment 
Step 1. From the Arduino IDE Tools Tab: Board Manager 
        a. Download Arduino SAM Boards. Now the basic arm drivers are installed.
Step 2. Download and Setup STM32 Blue Pill board package : https://github.com/rogerclarkmelbourne/Arduino_STM32
        a. UnZip and place in Arduino Hardware Folder C:\Program Files\Arduino\hardware
Step 3. Install Windows drivers from C:\Program Files\Arduino\hardware\Arduino_STM32-master\drivers\win
        a. Right Click on file install_drivers.bat and Run as Administrator.
Step 5. Ensure correct setting: 
               Board STM Nucleo F103RB (ST-LINK)
               Optimize Smallest(Default)
               Variant Nucleo @ 72MHz w/crystal
Step 6. Open blink program.
        a. Add to Blink Program #define LED_BUILTIN PC13.
        b. Connect St-Link to Blue Pill. Plug in ST-Link to USB port.
        b. Compile and download.
#define LED_BUILTIN PC13 // Use pin PC13 on Blue Pill void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }


Now lets Fade an LED
Connect an Led on your bread board to Pin PA9 on the Blue Pill.
Load the following program in your Arduino IDE. 
int led = PA9; // the PWM pin the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by void setup() { // declare pin PA9 to be an output: pinMode(led, OUTPUT); } // the loop routine runs over and over again forever: void loop() { // set the brightness of pin 9: analogWrite(led, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } // wait for 30 milliseconds to see the dimming effect delay(30); }

STM32F103C8 Class

Main Page