Bluepill F4 board, anyone still working on it?

If you made your own board, post here, unless you built a Maple or Maple mini clone etc
Post Reply
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Bluepill F4 board, anyone still working on it?

Post by ag123 »

looks interesting, for the variant
try both the PILL_401 variant
https://github.com/stm32duino/Arduino_C ... ILL_F401XX
as well as the NUCLEO F411 variant
https://github.com/stm32duino/Arduino_C ... LEO_F411RE

for the nucleo F411 variant, would need to re-do the clocks pill board is 25 Mhz while nucleo is 8 Mhz
viewtopic.php?f=41&p=398#p393
https://github.com/stm32duino/Arduino_C ... t.cpp#L150
but i'm guessing that F411 variant may get a better fit (likely has 'more' things than is available on F411CC)
but it would take to reduce the 'unnecessary things' e.g. ld script sram start and size, flash start and size
non-available pins etc

if you start with the PILL_401 variant
you could try to tune the clocks as well as the clocks i set for the 'overclocked' F401 set is literally the normal running frequency of F411 (96 Mhz)
off by 4mhz (100mhz max) as at 100mhz there are no prescalers which would keep usb running at 48mhz
viewtopic.php?f=41&p=398#p393
viewtopic.php?f=14&t=9&start=30#p392
the other things are to look in the ld script, the sram start address and size as well as flash start address and size
the other things my guess would be the pin maps to get the additional more 2 spi and sdio

my guess is to reach for the F411 reference manual and specs sheets comparing between the nucleo f411 variant and pill 401 variant to see which fits in which
Last edited by ag123 on Sun Jan 05, 2020 3:06 pm, edited 1 time in total.
Bingo600
Posts: 86
Joined: Sat Dec 21, 2019 3:56 pm

Re: Bluepill F4 board, anyone still working on it?

Post by Bingo600 »

I'll prob be using libopencm3 more than "duino" , so i'll let some one else do the porting/adaptation :oops:
I just wish i could "carve out" the USB-Serial stuff from a "Core" , and make an obj file that i could link into my opencm3 stuff.

I need interrupt based serial comms on USB , not polled ;)

I do use "duino" if i need something quick , or there is a nice lib available (ie. TCP/IP) , i even mix normal code & "duino" code if needed.
Hint ... I learned about declaring IRQ routines "extern C" in a C++ progran ... The hard way ... :(

/Bingo
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Bluepill F4 board, anyone still working on it?

Post by ag123 »

i'm wanting to try out libopencm3 as well, it seemed it tends to lead to leaner code and binaries
usb is complicated, but it seem libopencm3 has its 'own' implementation?
doing it this 'duino' way, one good thing is it is as if we are developing using ST's SDK with a 'duino' api layer on top.
so the full library of HAL is at our disposal
but i'd guess the nag would be all that additional complexity and 'fat'
the leverage with the 'official core is those complex usb core functions are available as libraries
even then it isn't easy to figure out and use, they are complicated no less
;)
Bingo600
Posts: 86
Joined: Sat Dec 21, 2019 3:56 pm

Re: Bluepill F4 board, anyone still working on it?

Post by Bingo600 »

This is actually an excellent intro to libopencm3
https://rhye.org/post/stm32-with-opencm ... uploading/

It teaches you about the environment (git submodules) , and basic makefile stuff.

The actual libopencm3 has excellent webdoc

Here's a usart irq for a stm32f030 - Just add libopencm3 in the subdir (and "make" in the libopencm3 dir) before make in the top dir

Would actually expect it works on a BP wo modification ... Well you could adapt the ld file & cortex type in the makefile , but i doubt it's needed

Ohh it's a "cludge" based on rhye & some fifo stuff i found (prefer C not C++)

/Bingo

Edit: This one looks like fun
https://github.com/satoshinm/pill_serial.git

I made a BMP out of a BP here
https://www.eevblog.com/forum/microcont ... -bluepill/

Works fine , the .scr files in rhye are for a BMP
Attachments
usart-working.zip
(8.4 KiB) Downloaded 317 times
Last edited by Bingo600 on Sun Jan 05, 2020 3:39 pm, edited 3 times in total.
Bingo600
Posts: 86
Joined: Sat Dec 21, 2019 3:56 pm

Re: Bluepill F4 board, anyone still working on it?

Post by Bingo600 »

ag123 wrote: Sun Jan 05, 2020 3:06 pm so the full library of HAL is at our disposal
I'd like to avoid HAL , as I feel the learningcurve is as tough as actually writing bare metal w. Datasheet & CMSIS.
And you'll never know when the HAL is dissapearing or totally reworked. Has happened already

I have been playing around w. CubeMX , but mostly for PLL (you just solved that)

Edit: But credit to ST , for embracing Linux too (java code for the tools) :) :)

/Bingo
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Bluepill F4 board, anyone still working on it?

Post by ag123 »

another thought though is to look at steve's libmaple core the F4 core specifically, that is nearly 'handwritten' codes with the USB Serial strapped in
https://github.com/stevstrong/Arduino_S ... er/STM32F4
my guess is it may help in your libopencm3 approach
the feeling with libmaple tend to be that it is 'so lean' it seem rather spacious even with 64k sram, but that some things are not there so 1'd need to fill it in :lol:

for usb serial, as i did a deep dive into it on stm32f103 libmaple core only
viewtopic.php?f=48&t=22#p84
https://github.com/rogerclarkmelbourne/ ... -w-signals
is that there is a 'usb core' that interacts with the hardware
i still couldn't figure out all of it but that this 'usb core' keeps state between itself and the host, i did find it extremely complex while i review codes alongside trying to understand usb.
but some of the things as i found (based on stm32f103) is that there are 16 endpoints further divided into IN (to PC) and OUT (from PC) channels.
and endpoint 0 being the control channel so it respond to SETUP requests. and stm32's hardware is so elaborate it actually handles down to each endpoint and channel.
so if for instance i want to react to the usb-cdc acm SetLineCoding (bits, parity, stops, baud) request (consider a 'command') or SetControlLineState request (i.e. setting DTR/RTS)
https://github.com/rogerclarkmelbourne/ ... ls.ino#L37
https://github.com/rogerclarkmelbourne/ ... ls.ino#L57
i can place an interface setup hook, in effect a call back function. i'd guess when the appropriate frame of data is received the usb core gets the interrupt and calls my hook. i'd guess it works similarly for the data IN and OUT channels

this is dramatically different from conventional Serial (e.g. uart), serial is pretty much emulated. so these 'hooks' would be those 'irq handlers' in which usb core literally hands us a pointer to the buffer which is the protocol pdu or data. UsbSerial abstracted all that away so that it looks like a simple serial channel.

if one bother to deal at the endpoints and in/out channels level, i'd guess it is probably possible to implement arbitrary usb protocols (e.g. HID).
but the usb protocols itself are very complex. e.g. i found that usb mass storage is literally scsi over usb, not simply a bulk transfer protocol
Last edited by ag123 on Sun Jan 05, 2020 4:23 pm, edited 4 times in total.
Bingo600
Posts: 86
Joined: Sat Dec 21, 2019 3:56 pm

Re: Bluepill F4 board, anyone still working on it?

Post by Bingo600 »

Maybe this one, for a BP
https://github.com/satoshinm/pill_serial.git

I haven't checkked, but he says it's BMP inspired , and they're heavily into libopencm3

/Bingo
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Bluepill F4 board, anyone still working on it?

Post by ag123 »

updated whetstone blinky for official core, added mcu temperature prints

Code: Select all

#include <Arduino.h>
#include <math.h>
#include "whetstone.h"

void checkcmd(void);
void printtempvbat(void);
//void enablefpu(void);
void cosfade();

int ledPin = LED_BUILTIN;
int print = false;

//used by cosfade()
#define PER 20
#define REP 10
int8_t led = 0;
int n = PER, cnt = 0;
uint8_t p = 0;

// the setup() method runs once when the sketch starts
void setup() {

// not needed fpu is enabled in the core
//	enablefpu();

	//initialize the digital pin as an output:
	pinMode(ledPin, OUTPUT);
	digitalWrite(ledPin, LOW);

	//these are codes for steve's libmaple core, left here as a ref
	// 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

	pinMode(ATEMP, INPUT_ANALOG);
	pinMode(AVREF, INPUT_ANALOG);

}


// 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 && cnt == 0) printtempvbat();
	cosfade();
}


void cosfade() {
  digitalWrite(LED_BUILTIN,led);
  led = ~led & 1;
  if(led)
    delay(PER-p);
  else
    delay(p);
  if(cnt>REP) {
	  float nf, perf;
	  n = n>PER?0:n+1;
	  nf = n * 1.0;
	  perf = PER * 1.0;
	  p = perf * ( cos(2 * PI * nf/perf) / 2.0 + 0.5 );
	  cnt=0;
  } else
	  cnt++;

}


void printtempvbat() {
	//ADC1 channel 18 is vrefint 1.23v
	//uint16_t vrefint = adc_read(ADC1, 17);
	uint16_t vrefint = analogRead(AVREF);
	Serial.print("Vref int (1.21v):");
	Serial.print(vrefint);
	Serial.println();

	//ADC1 channel 16 is temperature sensor
	//uint16_t vtemp = adc_read(ADC1, 18);
	uint16_t vtemp = analogRead(ATEMP);
	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();

	/* for stm32f401 it is either temp or vbat
	//ADC1 channel 17 is VBAT / 2
	uint16_t vbatsens = adc_read(ADC1, 18);
	Serial.print("VBAT/2 sensor:");
	Serial.print(vbatsens);
	Serial.println();

	uint16_t vbat = vbatsens * 2.0 * 1230 / vrefint;
	Serial.print("VBAT (mv):");
	Serial.print(vbat);
	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(F_CPU/1000000);
		}
	}
}

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 from
https://github.com/stevstrong/Arduino_S ... /whetstone

serial terminal commands
p - print temperature
s - stop printing
w - run whetstone benchmark
Attachments
PILL_F401XX.zip
(26.67 KiB) Downloaded 345 times
Bingo600
Posts: 86
Joined: Sat Dec 21, 2019 3:56 pm

Re: Bluepill F4 board, anyone still working on it?

Post by Bingo600 »

Just installed Stevies core , and built for a F401
viewtopic.php?p=350#p350

This one fails - ATEMP unknown
viewtopic.php?p=509#p509


I'm getting poor results on wheatstone , like .... really poor

Could that be the GCC vers ??
.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++

I can't see any float (abi messages) in the build output ... Geez i no NOT miss the Arduino IDE ...


Well here's output

Beginning Whetstone benchmark at 84 MHz ...

Loops:10000, Iterations:1, Duration:71458.00 millisec
C Converted Single Precision Whetstones:13.99 Mflops
Beginning Whetstone benchmark at 84 MHz ...

Loops:10000, Iterations:1, Duration:71450.09 millisec
C Converted Single Precision Whetstones:14.00 Mflops

/Bingo
Bingo600
Posts: 86
Joined: Sat Dec 21, 2019 3:56 pm

Re: Bluepill F4 board, anyone still working on it?

Post by Bingo600 »

I got HW float enabled (i think) -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant

Beginning Whetstone benchmark at 84 MHz ...

Loops:10000, Iterations:1, Duration:29795.44 millisec
C Converted Single Precision Whetstones:33.56 Mflops

Wonder what FCPU i'm running
Can't be all wrong , as USB is workingBeginning Whetstone benchmark at 84 MHz ...

Previous was -oS now with -o3
Loops:10000, Iterations:1, Duration:22780.49 millisec
C Converted Single Precision Whetstones:43.90 Mflops


/Bingo
Post Reply

Return to “Custom design boards”