Skip to content

Commit

Permalink
BluePill support for Roger Clarks core
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminJo committed Apr 19, 2021
1 parent 1f0b0f7 commit c9672ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ In both cases the library files itself are located in the `src` directory.<br/>
If you are using Sloeber as your IDE, you can easily define global symbols with *Properties > Arduino > CompileOptions*.<br/>
![Sloeber settings](https://github.com/ArminJo/ServoEasing/blob/master/pictures/SloeberDefineSymbols.png)

# BluePill cores
There are two cores for the PluePill.
- The original Arduino_STM32 by Roger Clark; http://dan.drown.org/stm32duino/package_STM32duino_index.json
- The CMSIS based STM32duino by ST Microsystems; https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
Generation of the high speed PWM is **complicated** for Roger Clark core and **easy** for the STM core.
Program size for _2_VoltmeterSayQ.cpp is **21 kByte** for Roger Clark core and **32 kByte** for STM core.
The 8 kHz interrupt handling requires **8 µs** for Roger Clark core and **12 µs** for STM core.

# Revision History
### Version 1.3.0
- Removed blocking wait for ATmega32U4 Serial in examples.
Expand Down
2 changes: 2 additions & 0 deletions examples/_2_VoltmeterSayQ/_2_VoltmeterSayQ.ino
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ void loop() {
int tVoltage = analogRead(A0) * tVCCVoltage / 1.023;
#elif defined(ESP32)
int tVoltage = analogRead(A0) * 3.3 / 4.096;
#elif defined(__STM32F1__) || defined(ARDUINO_ARCH_STM32F1)
int tVoltage = analogRead(0) * 3.3 / 4.096;
#elif defined(ARDUINO_ARCH_SAMD)
int tVoltage = analogRead(A1) * 3.3 / 4.096; // A0 is DAC output
#else
Expand Down
23 changes: 18 additions & 5 deletions src/Talkie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@

#include "Talkie.h"

// Enable this if you want to measure timing by toggling pin 8 on an arduino
#define MEASURE_TIMING
// Enable this if you want to measure timing by toggling pin 8 on an Arduino
//#define MEASURE_TIMING
#ifdef MEASURE_TIMING
#include "digitalWriteFast.h"
# if defined(ARDUINO_ARCH_STM32)
Expand Down Expand Up @@ -131,6 +131,7 @@ static void tcEnd();
* Timer 3 blocks PA6, PA7, PB0, PB1, so if you require one of them as tone() or Servo output, you must choose another timer.
*/
HardwareTimer sSTM32Timer(3);
HardwareTimer sSTM32PWMTimer(2);

#elif defined(STM32F1xx) || defined(ARDUINO_ARCH_STM32)
#include <HardwareTimer.h> // 4 timers and 3. timer is used for tone(), 2. for Servo
Expand Down Expand Up @@ -331,14 +332,25 @@ void Talkie::initializeHardware() {
// STM32F1 architecture for "Generic STM32F103C series" from "STM32F1 Boards (Arduino_STM32)" of Arduino Board manager
// http://dan.drown.org/stm32duino/package_STM32duino_index.json
#define DAC_PIN PA3 // T2C4
#define PWM_OUTPUT_FUNCTION(nextPwm) analogWrite(sPointerToTalkieForISR->NonInvertedOutputPin, nextPwm)
#define _10_BIT_OUTPUT
#define PWM_OUTPUT_FUNCTION(nextPwm) sSTM32PWMTimer.setCompare(TIMER_CH4, nextPwm)

/*
* Prepare 10 bit PWM @ 72 MHz
*/
pinMode(DAC_PIN, PWM); // this initializes the output pin and the timer mode
sSTM32PWMTimer.setPrescaleFactor(1);
sSTM32PWMTimer.setOverflow((1 << 10) - 1);
sSTM32PWMTimer.setCompare(TIMER_CH4, (1 << 9));
sSTM32PWMTimer.resume(); // Start timer
sSTM32PWMTimer.refresh(); // Reset to start values

/*
* Set timer for interrupts at SAMPLE_RATE
*/
sSTM32Timer.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);
sSTM32Timer.setPrescaleFactor(1);
sSTM32Timer.setOverflow(F_CPU / SAMPLE_RATE);
sSTM32Timer.setOverflow(F_CPU / SAMPLE_RATE);
sSTM32Timer.attachInterrupt(TIMER_CH1, timerInterrupt);
sSTM32Timer.resume(); // Start timer
sSTM32Timer.refresh(); // Reset to start values
Expand Down Expand Up @@ -698,7 +710,8 @@ extern "C" {
* Called every 125 microsecond / 8000 Hz
* 75 to 90 (when calling setNextSynthesizerData()) microseconds processing time @16 MHz
* 50 microseconds with 4 simple optimizations (change ">>15" to "<<1) >>16")
* 12 us for a BluePill
* 8 us for a BluePill with Roger Clarks core
* 12 us for a BluePill with official STM core
*/
#if defined(ESP32)
IRAM_ATTR
Expand Down

0 comments on commit c9672ef

Please sign in to comment.