it works STM32F401 black pill - steve's libmaple core
https://youtu.be/LEJK8lathQc
and happy new year everyone
Beginning Whetstone benchmark at 84 MHz ... -Os
Loops:10000, Iterations:1, Duration:15026.61 millisec
C Converted Single Precision Whetstones:66.55 Mflops
Beginning Whetstone benchmark at 84 MHz ... -O3
Loops:10000, Iterations:1, Duration:8381.00 millisec
C Converted Single Precision Whetstones:119.32 Mflops
getting that much Mflops for only 84 mhz for $3 still feel quite worth it
Code: Select all
#include <Arduino.h>
#include <usb_serial.h>
#include "whetstone.h"
void checkcmd(void);
void printtempvbat(void);
void enablefpu(void);
void fade();
//int ledPin = 33; // LED connected to 'pin' 33 on maple mini
//int ledPin = 6; // LED connected to 'pin' PA5 olimexino
int ledPin = LED_BUILTIN; //PA6
int led1 = LED_BUILTIN; //PA7
#define PER 20
#define REP 10
int print = false;
int8_t led = 0;
bool dir = false;
int8_t n = PER;
int cnt = 0;
// the setup() method runs once when the sketch starts
void setup() {
// enablefpu();
SerialUSB.begin(0);
//initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(led1, OUTPUT);
digitalWrite(ledPin, HIGH);
// ADC_CCR_VBATE; // f401 allows only vbat or temp sensor read, setting VBATE reads vbat
ADC_COMMON->CCR |= ADC_CCR_TSVREFE; //| ADC_CCR_VBATE; // enable VREFINT, VBAT or temp sensor
//adc_calibrate(ADC1);
adc_set_sampling_time(ADC1, ADC_SMPR_480); // sample time for temp sensor
}
void blinks(int8 led_pin) {
bool led = true;
for(int i=0; i<10;i++) {
digitalWrite(led_pin, led);
led = ~led;
delay(100);
}
}
// Enable the FPU (Cortex-M4 - STM32F4xx and higher)
// http://infocenter.arm.com/help/topic/com.arm.doc.dui0553a/BEHBJHIG.html
//void enablefpu() {
// __asm volatile
// (
// " ldr.w r0, =0xE000ED88 \n" /* The FPU enable bits are in the CPACR. */
// " ldr r1, [r0] \n" /* read CAPCR */
// " orr r1, r1, #( 0xf << 20 )\n" /* Set bits 20-23 to enable CP10 and CP11 coprocessors */
// " str r1, [r0] \n" /* Write back the modified value to the CPACR */
// " dsb \n" /* wait for store to complete */
// " isb" /* reset pipeline now the FPU is enabled */
// );
//}
//the loop() method runs over and over again,
//as long as maple has power
void loop() {
checkcmd();
if (print && n == 0) printtempvbat();
fade();
}
void fade() {
digitalWrite(LED_BUILTIN,led);
led = ~led & 1;
if(led)
delay(PER-n);
else
delay(n);
if(cnt>REP) {
if(dir) {
n++;
if(n>PER) {
dir = false;
n = PER;
}
} else {
n--;
if(n<0) {
dir = true;
n = 0;
}
}
cnt = 0;
} else
cnt++;
}
void printtempvbat() {
//SerialUSB.println("Hello world F407");
//ADC1 channel 18 is vrefint 1.23v
uint16_t vrefint = adc_read(ADC1, 17);
Serial.print("Vref int (1.21v):");
Serial.print(vrefint);
Serial.println();
//ADC1 channel 16 is temperature sensor
uint16_t vtemp = adc_read(ADC1, 18);
Serial.print("temp sensor:");
Serial.print(vtemp);
Serial.println();
uint16_t mv = (1210 * vtemp) / vrefint;
Serial.print("mvolt:");
Serial.print(mv);
Serial.println();
// specs 5.3.22 temp sensor characteristics
// V 25 deg ~ 0.76v
// slope 2.5 mv/C
uint16_t v25 = 760;
float temp = (mv - v25) * 1.0 / 2.5 + 25.0;
Serial.print("temp:");
Serial.print(temp);
Serial.println();
}
void checkcmd() {
if(Serial.available()) {
char r = Serial.read();
if(r=='p') {
print = true;
} else if (r=='s') {
print = false;
} else if (r=='w') {
whetstone(84); //84 mhz
}
}
}
void blinks() {
for (int i = 0; i < 5; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
}
whetstone.h, whetstone.cpp
https://github.com/stevstrong/Arduino_S ... /whetstone
serial commands:
'p' print temperature
's' stop printing
'w' run whetstone benchmark
install:
- press reset + boot0
- release reset, hold boot0
- check for dfu device
Code: Select all
dfu-util -a 0 -s 0x8000000 -D blackpill_f401o3.bin
a recent dfu-util is needed
http://dfu-util.sourceforge.net/
or stm32cubeprogrammer
https://github.com/stm32duino/wiki/wiki ... programmer