Инструкция может кому пригодиться.
Если в CH32F103С8
delayMicroseconds() Считает е в 2 раза быстре
hardware\Arduino_STM32\STM32F1\system\libmaple\stm32f1\include\series\stm32.h
стр245 define STM32_DELAY_US_MULT (F_CPU / 6000000L)
Заменить на define STM32_DELAY_US_MULT (F_CPU / 3000000L)
hardware\Arduino_STM32\STM32F1\cores\maple\wirish_time.cpp
void delayMicroseconds(uint32 us) {
delay_us(us);
}
hardware\Arduino_STM32\STM32F1\system\libmaple\include\libmaple\Delay.h
static inline void delay_us(uint32 us) {
if (us==0)
{
return;
}
us *= STM32_DELAY_US_MULT;
/* fudge for function call overhead */
us--;
asm volatile(" mov r0, %[us] \n\t"
"1: subs r0, #1 \n\t"
" bhi 1b \n\t"
:
: [us] "r" (us)
: "r0");
}
Скейтч для проверки.
Правильный результат должен быть около 10000
void setup() {
Serial.begin(9600);
// Wait for serial to be ready.
while (!Serial);
Serial.print(F_CPU/1000000);
Serial.println(F(" MHz"));
}
void loop() {
uint32 t0 = millis();
for(int j=0;j<1000;j++) {
delayMicroseconds(10000);
}
uint32 t = millis() - t0;
Serial.println(t);
delay(2000);
}
PS
Если кто сможет добавить отдельную плату с такими настройками, будет здорово.
Но пока ручками править под конкретную плату.