In order to test the PWM multi-channel capture, I downloaded this code from elsewhere,
I can successfully compile successfully on the Arduino IDE,
But there will be many errors in PlatformIO compilation
Is this because of my kernel selection error?
#include <Arduino.h>
#include <libmaple/scb.h>
uint32_t now, systick_counter, receiver_input1, receiver_input1_previous;
uint8_t int_flag;
void setup() {
Serial.begin(57600); //Start serial port at 57600bps
attachInterrupt(PB10, receiver_ch1, CHANGE); //Connect changing PB10 to routine receiver_ch1
}
void loop() {
delayMicroseconds(3500); //Wait 3500us to simulate a 250Hz refresh rate
Serial.println(receiver_input1); //Print the receiver input to the serial monitor
}
void receiver_ch1() {
systick_counter = SYSTICK_BASE->CNT; //Read SysTick counter
if (0b1 & SCB_BASE->ICSR >> 26) { //If SysTick interrupt flag is set
int_flag = 1; //Set interrupt flag
systick_counter = SYSTICK_BASE->CNT; //Re-read the SysTick counter
}
else int_flag = 0; //SysTick interrupt flag is not set during reading
now = (systick_uptime_millis * 1000) +
(SYSTICK_RELOAD_VAL + 1 - systick_counter) / CYCLES_PER_MICROSECOND; //Calculate the total microseconds
if (int_flag)now += 1000; //If the SysTick interrupt is set 1000us have to added to get the correct microseconds result
if (0B1 & GPIOB_BASE->IDR >> 10 )receiver_input1_previous = now; //If input PB10 is high start measuring the time
else receiver_input1 = now - receiver_input1_previous; //If input PB10 is low calculate the total pulse time
}
Compilation result:
Processing genericSTM32F103C8 (platform: ststm32; board: genericSTM32F103C8; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F103C8.html
PLATFORM: ST STM32 (8.0.0) > STM32F103C8 (20k RAM. 64k Flash)
HARDWARE: STM32F103C8T6 72MHz, 20KB RAM, 64KB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
PACKAGES:
- framework-arduinoststm32 4.10900.200819 (1.9.0)
- framework-cmsis 2.50501.200527 (5.5.1)
- toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 18 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/genericSTM32F103C8/src/main.cpp.o
src/main.cpp:2:10: fatal error: libmaple/scb.h: No such file or directory
2 | #include <libmaple/scb.h>
| ^~~~~~~~~~~~~~~~
compilation terminated.
src/main.cpp:9:33: error: 'receiver_ch1' was not declared in this scope; did you mean 'receiver_input1'?
9 | attachInterrupt(PB10, receiver_ch1, CHANGE); //Connect changing PB10 to routine receiver_ch1
| ^~~~~~~~~~~~
| receiver_input1
src/main.cpp: In function 'void receiver_ch1()':
src/main.cpp:18:29: error: 'SYSTICK_BASE' was not declared in this scope
18 | systick_counter = SYSTICK_BASE->CNT; //Read SysTick counter
| ^~~~~~~~~~~~
src/main.cpp:19:29: error: base operand of '->' is not a pointer
19 | if (0b1 & SCB_BASE->ICSR >> 26) { //If SysTick interrupt flag is set
| ^~
src/main.cpp:25:18: error: 'systick_uptime_millis' was not declared in this scope
25 | now = (systick_uptime_millis * 1000) +
| ^~~~~~~~~~~~~~~~~~~~~
src/main.cpp:26:14: error: 'SYSTICK_RELOAD_VAL' was not declared in this scope
26 | (SYSTICK_RELOAD_VAL + 1 - systick_counter) / CYCLES_PER_MICROSECOND; //Calculate the total microseconds
| ^~~~~~~~~~~~~~~~~~
src/main.cpp:26:58: error: 'CYCLES_PER_MICROSECOND' was not declared in this scope
26 | (SYSTICK_RELOAD_VAL + 1 - systick_counter) / CYCLES_PER_MICROSECOND; //Calculate the total microseconds
| ^~~~~~~~~~~~~~~~~~~~~~
src/main.cpp:29:31: error: base operand of '->' is not a pointer
29 | if (0B1 & GPIOB_BASE->IDR >> 10 )receiver_input1_previous = now; //If input PB10 is high start measuring the time
*** [.pio/build/genericSTM32F103C8/src/main.cpp.o] Error 1