[LIBMAPLE] Support for blackpill F401 board

Post Reply
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

[LIBMAPLE] Support for blackpill F401 board

Post by stevestrong »

I just committed some changes to support Blackpill F401 in my repo.
Blinky works, and anything else should also work, as I tried a lot of interfaces of F411 which was used as base for F401.

Should anyone give it a try and find some problems, please open an issue in my repo.

Remarks:
- PB11 is missing from the LQFP48 package so I2C2 is not supported.

PS: Admin: feel free to move this post to any other better suited place if needed.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: [LIBMAPLE] Support for blackpill F401 board

Post by ag123 »

hi steve,

i think we need to rework the clock setting f4 code.
blackpill f411 runs on a 25mhz crystal
while
disco f411 runs on a 8mhz crystal
https://github.com/stevstrong/Arduino_S ... f411.h#L41
https://github.com/stevstrong/Arduino_S ... cF4.c#L277

my thoughts are either to do like the official core
the system clock config is defined in the variant itself
https://github.com/stm32duino/Arduino_C ... t.cpp#L106

or we can do something similar to libopencm3
we can have the variant maintain a structure containing some clock setups
https://github.com/libopencm3/libopencm ... /rcc.c#L52

Code: Select all

	{ /* 84MHz */
		.pllm = 16,
		.plln = 336,
		.pllp = 4,
		.pllq = 7,
	...
and a call back function needs to be defined in the variant to return the structure, it can even be a static structure or class that needs to be defined in the variant, initialized at reset so that the rcc_init_clocks() would look for those values in that structure.
but i just thought that this approach may lead to ifdefs, while the variant call back can be a fixed function to return a fixed structure
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: [LIBMAPLE] Support for blackpill F401 board

Post by ag123 »

HardwareTimer.setperiod(uint32_t usecs) is making it running 2 times too fast.

test sketch

Code: Select all

#include <Arduino.h>

uint32_t start = 0;

void timerhandler() {
	toggleLED();

	int secs = (millis()-start)/1000;
	Serial.println(secs);
}

void setup() {
	pinMode(LED_BUILTIN, OUTPUT);
	digitalWrite(LED_BUILTIN, 0);

	SerialUSB.begin();

	start = millis();

	Timer1.init();
	Timer1.setPeriod(1000000);
	Timer1.attachInterrupt(0, timerhandler);
	Timer1.refresh();
	Timer1.resume();
}

void loop() {
	asm("wfi");
}
this code use the timer to blink the led and print the seconds elapsed. the number of seconds is measured using millis() whcih is based on systick_uptime. systick is running at the correct 1ms intervals.

results

Code: Select all

7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
hence the timer is running at 2 Hz, when a 1 s period is specified

the fix is change
https://github.com/stevstrong/Arduino_S ... er.cpp#L57

Code: Select all

uint16 HardwareTimer::setPeriod(uint32 microseconds)
...
  uint32 period_cyc = microseconds * (CYCLES_PER_MICROSECOND / 2);
...
to

Code: Select all

uint16 HardwareTimer::setPeriod(uint32 microseconds)
...
  uint32 period_cyc = microseconds * (CYCLES_PER_MICROSECOND );
...
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: [LIBMAPLE] Support for blackpill F401 board

Post by stevestrong »

stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: [LIBMAPLE] Support for blackpill F401 board

Post by stevestrong »

Regarding the RCC, I also had thoughts on it, I may use something similar to libopencm3.
Thanks for opening an issue, I will work on it.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: [LIBMAPLE] Support for blackpill F401 board

Post by ag123 »

thanks !
Bingo600
Posts: 86
Joined: Sat Dec 21, 2019 3:56 pm

Re: [LIBMAPLE] Support for blackpill F401 board

Post by Bingo600 »

Damm ... So my enhancement has been a waste of time ;) ;)

viewtopic.php?p=747#p747


Well Steve .. You could apply the patch , while you're "thinking" about the "golden solution"

I did use libopencm3 for my F411 board , but as ie. 96MHz wasn't in i had to do a "local" struct , and use that.
What i mean is there's prob. no "One fits all"

/Bingo
Post Reply

Return to “STM32F4 based boards”