YaK:: Blue Pill notes (STM32F103C8T6) | [Changes] [Calendar] [Search] [Index] [PhotoTags] |
https://github.com/stlink-org/stlink
https://www.instructables.com/STM32-Blue-Pill-Progmaming-Via-Arduino-IDE-USB/
https://www.electronicshub.org/getting-started-with-stm32f103c8t6-blue-pill/
https://dh1tw.de/2020/01/st-link-blue-pill-development-board/ Why ST-Link(v2) may not work
#undef LED_BUILTIN #define LED_BUILTIN PC13 $ st-info --probe ... Found 1 stlink programmers version: V2J29S7 serial: 51FF69064975525012352367 flash: 20971520 (pagesize: 1024) sram: 20480 chipid: 0x0410 ... find /tmp/arduino* -type f | grep bin$ st-flash --reset write /tmp/arduino_build_950069/Blink.ino.bin 0x08000000 |
Blink Pi (with no dot)
// BLINK PI #undef LED_BUILTIN #define LED_BUILTIN PC13 const char Pi[] = "31415926536"; // with no "." void send(int n) { delay(500); for (int i = 0; i < n; i++) { delay(200); digitalWrite(LED_BUILTIN, LOW); // ON delay(200); digitalWrite(LED_BUILTIN, HIGH); // OFF delay(200); } delay(500); } // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); // OFF } // the loop function runs over and over again forever void loop() { for (int p = 0; Pi[p]; p++) { send(Pi[p] - '0'); } delay(3000); } |
This does a square wave on PC13 with 1.37 microsecond period (optimized for space) or 1.47 microseconds (for speed, -O3):
// BLINK FAST, HOW FAST? //#undef LED_BUILTIN //#define LED_BUILTIN PC13 void BlinkFast(unsigned n) { for (unsigned i = 0; i < n; i++) { digitalWrite(LED_BUILTIN, LOW); // ON digitalWrite(LED_BUILTIN, HIGH); // OFF } } // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); // OFF } // the loop function runs over and over again forever void loop() { BlinkFast(0xFFFFFFFFu); } |
.arduino15/packages/stm32duino/hardware/STM32F1/2021.5.31/system/libmaple/include/libmaple/gpio.h
/** * Set or reset a GPIO pin. * * Pin must have previously been configured to output mode. * * @param dev GPIO device whose pin to set. * @param pin Pin on to set or reset * @param val If true, set the pin. If false, reset the pin. */ static inline void gpio_write_bit(gpio_dev *dev, uint8 pin, uint8 val) { val = !val; /* "set" bits are lower than "reset" bits */ dev->regs->BSRR = (1U << pin) << (16 * val); } /** * Determine whether or not a GPIO pin is set. * * Pin must have previously been configured to input mode. * * @param dev GPIO device whose pin to test. * @param pin Pin on dev to test. * @return True if the pin is set, false otherwise. */ static inline uint32 gpio_read_bit(gpio_dev *dev, uint8 pin) { return dev->regs->IDR & (1U << pin); }
.arduino15/packages/stm32duino/hardware/STM32F1/2021.5.31/cores/maple/wirish_digital.cpp
#include "wirish_time.h" #include "boards.h" uint32 digitalRead(uint8 pin) { if (pin >= BOARD_NR_GPIO_PINS) { return 0; } return gpio_read_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit) ? HIGH : LOW; } void digitalWrite(uint8 pin, uint8 val) { if (pin >= BOARD_NR_GPIO_PINS) { return; } gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, val); }
this did not blink?
// BLINK FAST, HOW FAST? #include "wirish_time.h" #include "boards.h" void BlinkFaster(unsigned n) { gpio_dev *dev = PIN_MAP[LED_BUILTIN].gpio_device; auto* regs = dev->regs; uint8 bit = PIN_MAP[LED_BUILTIN].gpio_bit; uint8 on = (1U << bit) << (16 * false); uint8 off = (1U << bit) << (16 * true); volatile uint32* pointer = ®s->BSRR; for (unsigned i = 0; i < n; i++) { // regs->BSRR = on; // regs->BSRR = off; *pointer = on; *pointer = off; } } void BlinkFast(unsigned n) { for (unsigned i = 0; i < n; i++) { digitalWrite(LED_BUILTIN, LOW); // ON digitalWrite(LED_BUILTIN, HIGH); // OFF } } // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); // OFF } // the loop function runs over and over again forever void loop() { BlinkFaster(0xFFFFFFFFu); } |
(last modified 2021-11-15) [Login] |