PlatformIO and Arduino IDE compilation results are different

Post here first, or if you can't find a relevant section!
leonardo
Posts: 18
Joined: Sat Mar 06, 2021 2:37 pm

PlatformIO and Arduino IDE compilation results are different

Post by leonardo »

Hello everyone, when I compile this code under arduino IDE, it can compile successfully.

Code: Select all

#include "Arduino.h"
uint32_t now, receiver_input1, receiver_input1_previous;

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() {
  now = micros();                                                    //Store the current micros() value
  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
}
but when I compile under PlatformIO, the following error appears.

Code: Select all

Processing genericSTM32F103ZE (platform: ststm32; board: genericSTM32F103ZE; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F103ZE.html
PLATFORM: ST STM32 (8.0.0) > STM32F103ZE (64k RAM. 512k Flash)
HARDWARE: STM32F103ZET6 72MHz, 64KB RAM, 512KB 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/genericSTM32F103ZE/src/main.cpp.o
src/main.cpp: In function 'void setup()':
src/main.cpp:6:25: error: 'receiver_ch1' was not declared in this scope; did you mean 'receiver_input1'?
    6 |   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:16:23: error: base operand of '->' is not a pointer
   16 |   if (0B1 & GPIOB_BASE->IDR >> 10 )receiver_input1_previous = now;   //If input PB10 is high start measuring the time
      |                       ^~
*** [.pio/build/genericSTM32F103ZE/src/main.cpp.o] Error 1
=============================================================== [FAILED] Took 3.95 seconds ===============================================================
The terminal process "platformio 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.
Looking forward to your reply :-)
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: PlatformIO and Arduino IDE compilation results are different

Post by ag123 »

try adding that

Code: Select all

#include <Arduino.h>
? Note just wild guesses, i'm not using platformIO
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: PlatformIO and Arduino IDE compilation results are different

Post by GonzoG »

Put declaration of receiver_ch1 before setup().
leonardo
Posts: 18
Joined: Sat Mar 06, 2021 2:37 pm

Re: PlatformIO and Arduino IDE compilation results are different

Post by leonardo »

GonzoG wrote: Sat Mar 06, 2021 9:41 pm Put declaration of receiver_ch1 before setup().
Yeah,you are right! Now there is only one error left.

Code: Select all

Processing genericSTM32F103ZE (platform: ststm32; board: genericSTM32F103ZE; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F103ZE.html
PLATFORM: ST STM32 (8.0.0) > STM32F103ZE (64k RAM. 512k Flash)
HARDWARE: STM32F103ZET6 72MHz, 64KB RAM, 512KB 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/genericSTM32F103ZE/src/main.cpp.o
src/main.cpp: In function 'void receiver_ch1()':
src/main.cpp:6:23: error: base operand of '->' is not a pointer
    6 |   if (0B1 & GPIOB_BASE->IDR >> 10 )receiver_input1_previous = now;   //If input PB10 is high start measuring the time
      |                       ^~
*** [.pio/build/genericSTM32F103ZE/src/main.cpp.o] Error 1
=============================================================== [FAILED] Took 3.47 seconds ===============================================================
The terminal process "platformio 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: PlatformIO and Arduino IDE compilation results are different

Post by GonzoG »

Don't know which core you use (Roger Clark's or STM) but GIOx_BASE is not a pointer in any.
In Roger's core you need to use GPIOx->regs->IDR
in STM core: GPIOx->IDR
leonardo
Posts: 18
Joined: Sat Mar 06, 2021 2:37 pm

Re: PlatformIO and Arduino IDE compilation results are different

Post by leonardo »

GonzoG wrote: Sun Mar 07, 2021 10:13 am Don't know which core you use (Roger Clark's or STM) but GIOx_BASE is not a pointer in any.
In Roger's core you need to use GPIOx->regs->IDR
in STM core: GPIOx->IDR
OK,Thank you very much!
leonardo
Posts: 18
Joined: Sat Mar 06, 2021 2:37 pm

Re: PlatformIO and Arduino IDE compilation results are different

Post by leonardo »

hey guys,For further verification, I purchased a Generic STM32F103C series and ST Nucleo F446RE respectively.

Yes, the compilation and upload are successful, and the print data is also normal.
But I found that the time taken by the interrupt in the two cases is not the same

Why is the execution time of this interrupt on Nucleo F446RE slower than the general STM32F103C series :(

IDE:Arduino IDE
board:Generic STM32F103C series (20k ram 64k flash)
Cycle Time:timecnt=36 μs

Code: Select all

uint32_t now, receiver_input1, receiver_input1_previous;

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
  
  unsigned int timecnt;
  timecnt = micros()-timecnt;
  
  Serial.println(receiver_input1);                                   //Print the receiver input to the serial monitor
  
  timecnt = micros()-timecnt;				
  Serial.print("\t");
  Serial.print("micros=");//print the "timecnt"
  Serial.println(timecnt);
}

void receiver_ch1() {
  now = micros();                                                    //Store the current micros() value
  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
}


IDE:Arduino IDE
board:ST Nucleo F446RE (180MHz, 128KB RAM, 512KB Flash)
Cycle Time:timecnt=4670 μs

Code: Select all

#include "Arduino.h"

uint32_t now, receiver_input1, receiver_input1_previous;

void receiver_ch1() {
  now = micros();                                                    
  if (0B1 & GPIOB->IDR >>10)receiver_input1_previous = now;   
  else receiver_input1 = now - receiver_input1_previous;             
}

void setup() {
  Serial.begin(9600); 
  attachInterrupt(PB10, receiver_ch1, CHANGE);                       
}

void loop() {
  delayMicroseconds(3500);  
   
  unsigned int timecnt;
  timecnt = micros()-timecnt;                                        
  
  Serial.print(receiver_input1);                                   //Print the receiver input to the serial monitor

  timecnt = micros()-timecnt;//Subtract the last result after the function test is completed
  Serial.print("\t");
  Serial.print("micros=");//print the "timecnt"
  Serial.println(timecnt);

}
Last edited by leonardo on Thu Mar 11, 2021 12:47 am, edited 1 time in total.
ozcar
Posts: 143
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: PlatformIO and Arduino IDE compilation results are different

Post by ozcar »

I don't know what you expect timecnt to be. If you are trying to determine how long the Serial.println(receiver_input1) takes, then you should have just set timecnt = micros(), not timecnt = micros()-timecnt initially.

You probably should have declared receiver_input1 as volatile too, but that should not make any difference to what you see for timecnt.
leonardo
Posts: 18
Joined: Sat Mar 06, 2021 2:37 pm

Re: PlatformIO and Arduino IDE compilation results are different

Post by leonardo »

Hi ozcar.
I use "timecnt" to calculate the execution time of the interrupt. Because I found that the execution time of this interrupt on Nucleo F446RE is slower than the general STM32F103C series. I want to know why this happens
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: PlatformIO and Arduino IDE compilation results are different

Post by GonzoG »

But your code is totally wrong.
timecnt measures time of Serial.print(), but it's wrong:

Code: Select all

 unsigned int timecnt;
  timecnt = micros()-timecnt;
  
this part gives you undetermined result as timecnt is just declared but there's no value assigned to it. If you just declare a variable it doesn't meant it will be set to zero.
It should should be:

Code: Select all

timecnt = micros();
And in you're ISR you measure button state change time.

You cannot measure interrupt reaction time with code. You'll need 2ch oscilloscope or 2ch logic analyzer so you can compare signal from button with signal from MCU pin triggered by interrupt.

Also you're ISR isn't as fast as it can be. This 10 bit shift needs time.
You can use

Code: Select all

digitalReadFast(digitalPinToPinName(pin));
and set optimization to fastest (-O3)
Post Reply

Return to “General discussion”