Some Information on the BluePill (STM32F103C)

Below are some observations one might encounter when working with the STM32F103C as a micronctoller in conjunction with the Arduino STM32 library. A good secondary source for documentation s Leaflabs Maple.

Some of these details here are specific to a certain STM32F103C model, such as the LED pin. The following information should be used to guide, rather than to follow directly.

Electrical

  • The onboard LED is on pin PC13. Lights up when the output for this pin is LOW.
  • Has an onboard 3.3V voltage regulator. This drops input power from the 5V pin and from USB to 3.3V
  • Operates on 3.3V, rather than 5V on an Arduino.
  • The Blue Pill's 5V regulator is not the best in the world, especially when sourced from cheap Chinese sites, so don't expect the Blue Pill to be able to run a lot of LEDs or Servos. The stock 3.3V regulator can handle up to 300mA.

Pinout

More Pin Info

  • Non-5V tolerant pins will be damanged when receiving a voltage near 5V.
  • Pins PA9 and PA10 are used to interface with the USB to TTL adapter. However, you should not need to do this. (e=read the seciton on Uploading)
  • Pins PC13, PC14, PC15 are to be used if crucially needed. These pins cannot sink or source a lot of current. Damage to these pins could result in damage to the internal oscillators and the real time clock.
  • Pin PB2 is useable, but placed in an awkward position.
  • Pins marked ADC support analogRead() and pinMode(PIN, INPUT_ANALOG). These pins are 12-bit, so the range is 0 to 4096.
  • Pins can be 'softly' pulled up to 3.3V or down to ground with the pin modes INPUT_PULLUP or INPUT_PULLDOWN with the use of internal 22k resistors. Example: If INPUT_PULLUP is used, the state will be high unless an external device is specifically pulling the pin down to ground. The “gentle” pull up will not affect the state of the input.
    • This is best used for digital inputs.
    • INPUT is the same as INPUT_FLOATING
  • To enable PWM output on PA11, we must give up serial over USB, since one of the USB data signals is mapped to this pin. To do this, comment out all the contents in void USBSerial::begin(void) in usb_serial.cpp located in .platformio\packages\framework-arduinoststm32\STM32F1\cores\maple
  • PA12 is HIGH when the Blue Pill is turned on (before any code execution).

Software

  • With PlatformIO and the Arduino STM32 library, the Blue Pill can be used very similary to an Arduino. Follow these instructions to get up and running.
  • One can use the traditional pinModes by using itegers such as pinMode(13, OUTPUT), but it is recommended to use enums pinMode(PA3, OUTPUT).
  • It is possible to iterate over a set of pins by iterating through the enums:
enum {
    PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11, PA12, PA13,PA14,PA15,
    PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PB8, PB9, PB10, PB11, PB12, PB13,PB14,PB15,
    PC13, PC14,PC15
};

Uploading

  • To have the system be able to detect the serial device over USB, download the Arduino STM32 repo, navigate to \drivers\win and execute the install_drivers.bat script.
  • Once done, the Blue Pill should show up in Device Manager as a Maple Serial device.
  • Ensure that platformio.ini has the appropriate settings (Load with your COM port):
[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_port = COM8
upload_protocol = dfu
  • Upload the sketch from PlatformIO. The IDE will attempt to set the Blue Pill into DFU mode to upload the sketch. If this fails, or it is stuck, simply hit the RESET button on the Blue Pill when PlatformIO is searching for DFU devices.
    • Becuase USB uploading does not require moving BOOT0 to 1, resetting the Blue Pill will only provide a short window to allow the IDE to upload the sketch.

Using Motors and Servos Simultaneously

This information is applicable for when the microcontroller is used to switch motors and to control servos using the default libraries.

When servo.attach() is called on a certain pin, the hardware timer responsible for creating the PWM signal is set to a certain period/frequency. On the Blue Pill, this period/frequency is synchronized across all pins that the timer is responsible for. So if you have a motor running on the same timer as a servo but another motor running on a different motor, the motor speeds will differ because their PWM frequencies will differ.

One fix is to coordinate pinouts such that all motors run on their own timer, but usually we can't afford this luxury so we turn towards a different solution, by synchronizing all of the timers to be the same.

void timerSetup() {
    for (int i = 1; i <= 4; i++) {
        HardwareTimer timer(i);
        timer.pause();
        timer.setPeriod(20000);
        timer.refresh();
        timer.resume();
    }
}

A period of 20 milliseconds is chosen because this is the period that servo.attach() sets the pins to.

Motors and Sensing

Motors add noise to the system, and this brings about bad news if the pins are floating.

When using limit switches, since the states can be interpreted digitally, the appropriate pinmode should be INPUT_PULLDOWN.

When using analog inputs, it is desirable to be stopped when reading to minimize noise. Other electrical and mechanical considerations can also reduce noise.

Fourier Transform of a Generic Gaussian A Hackintosh Experience as a Long Time Windows User
 

Add a comment

Comments

Finally, an easy way to offer affordable payments to ALL customers and credit grades Don't leave money on the table, now you'll be able to turn people with low credit scores into paying customers! == Must Be A US Based Business To Qualify == Send me a message at my contact info below for info Jessica Snyder jessica.snyder@helloratespros.com https://helloratespros.com/5-6/
Written on Sun, 21 Apr 2024 05:12:08 by Tanesha Lonergan
Hello there! I hope this email finds you well! I couldn't help but notice that your website could be getting more traffic. Don't worry; I've got just the solution to skyrocket your online presence! I recently stumbled upon an incredible opportunity tailored specifically for small businesses like yours: https://tinyurl.com/bigmoney10off And here's the best part - I've secured an exclusive 10% discount just for you! Simply use the code "BigMoney" at checkout to claim your savings. This offer is too good to pass up. Imagine the possibilities for your business once you implement the strategies outlined in this ebook! Don't miss out on this opportunity to take your business to new heights. Grab your copy today and watch your website soar! Warm regards! PS: Remember, this exclusive discount won't last forever. Act now to secure your savings and unlock the full potential of your website! Check it now: https://tinyurl.com/bigmoney10off
Written on Fri, 19 Apr 2024 14:21:45 by Garry Kuster
Boost Your Videos with Submagic - The Best AI Tool for Short-Form Content Hey there, Are you tired of spending hours creating captions, searching for the perfect transitions, and adding sound effects to your videos? Submagic is here to save the day! Elevate your content creation game with Submagic, the ultimate AI tool for short-form content. Take your videos to the next level with our easy-to-use features that will save you time and money. Don't waste any more time on manual video editing tasks when Submagic can do it all for you in seconds. Trusted by over 500k creators and businesses, including big names like Grant Cardone and David Goggins. Whether you're a content creator, video editor, or business owner, Submagic has everything you need to create engaging videos that stand out. Try Submagic now and see the difference it can make in your content creation process. click here: https://stopify.co/I00GIF Generate captions, add B-rolls, create dynamic transitions, highlight key moments with Auto-Zoom, include sound effects, and generate video descriptions all with the power of AI. Testimonial: "Submagic has revolutionized my video editing process. It's a game-changer!" - Jason, Happy Submagic User Sign up for Submagic today and discover why it's the go-to tool for creators worldwide. https://stopify.co/I00GIF Don't miss out on the opportunity to streamline your video editing process with Submagic. Join the thousands of creators already using Submagic and transform your videos today. https://stopify.co/I00GIF Humorous P.S.: Who needs a magic wand when you have Submagic? Try it out and see the magic happen! Let Submagic take your videos from ordinary to extraordinary. Sign up now and unleash your creativity! Best regards, Mark, Submagic Team
Written on Fri, 19 Apr 2024 13:18:08 by Houston Frith
Finally, an easy way to offer affordable payments to ALL customers and credit grades More approvals = More Profits == Must Be A US Based Business To Qualify == visit: https://helloratespros.com/5-6/ OR email me here: jessica.snyder@helloratespros.com
Written on Thu, 18 Apr 2024 22:21:04 by Alica Perivolaris
Have a business you want to get off the ground but lack the funding? I can invest, email me here: info@financeworldwidehk.com
Written on Thu, 18 Apr 2024 19:08:03 by Ahmad Mayers
Are rising business expenses and the cash flow roller coaster causing you stress? Who said running a business was easy? Especially when the cost of nearly everything continues to skyrocket. Cut yourself a break from the stress of rising expenses with a working capital solution that will provide you the relief needed to get through these challenging times. Get a no obligation working capital quote in less than 2 minutes. *I can only help US businesses* Send me an email here to find out more: elizabeth.miller@helloratesfastfunding.com Elizabeth Miller Working Capital Loan Specialist 295 Seven Farms Drive Suite C- 201 Charleston, SC 29492 www.HelloRatesFastFunding.com elizabeth.miller@helloratesfastfunding.com
Written on Mon, 15 Apr 2024 17:57:32 by Julieta Bradberry