Arduino and PlatformIO compile results are different

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

So first of all, your platform version is outdated, the latest one is 12.0.0. You should update via PIO Home → Platforms → Updates or the CLI with pio platform update ststm32.

The code you’re using attempts to use the Maple core (GitHub - rogerclarkmelbourne/Arduino_STM32: Arduino STM32. Hardware files to support STM32 boards, on Arduino IDE 1.8.x including LeafLabs Maple and other generic STM32F103 boards) and not the STM32 core (GitHub - stm32duino/Arduino_Core_STM32: STM32 core support for Arduino). Ever since ST STM32 platform version 7.0.0, the default core for the generic boards was changed to the STM32 core – so you’re compiling for the wrong core.

The documentation for switching cores is available as usual. Your platformio.ini should look something like

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino
board_build.core = maple

to use the Maple core.

Note that then ofc you won’t be able to compile example code targeting the STM32 core (without changing the platformio.ini configuration).

Finally, take care to convert ino to cpp properly with your code above if you save that code in a main.cpp file – the receiver_ch1 function is not known at the time of reference in setup. Or, you can just leave it in a main.ino file.

Thank you for your answers. Unfortunately, I cannot update the Maple core due to network issues, and I only have a Nucleo F446RE board. How can I fix the code to compile successfully on the STM32 core? thanks