Why declaring a global variable causes the interrupt to be disabed?

/**
 * Compile options:
 * Board : Generic STM32F1 -> BluePill F103C8 OR BlackPill F103C8
 * USART-> Enabled
 * USBCDC -> Enabled
 * Optimized : Anything without LTO
 * C runtime: Newlib nano
 * Bootloader : HID 2.2
 */

/* Includes */
#include <STM32FreeRTOS.h>
#include <RCSwitch.h>

#define RX433PIN PB6

//String someName = "Ok";

/* Remote transceiver */
RCSwitch remote433 = RCSwitch();

void setup()
{
  //Debug console
  Serial.begin(9600);
  // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
  while (!Serial);

  //config BUILTIN lED for output
  pinMode(LED_BUILTIN , OUTPUT);
  //turns it off
  digitalWrite(LED_BUILTIN, HIGH);

  remote433.enableReceive(RX433PIN);
  Serial.print("Starting...");
}

int i =0;
void loop()
{
  if(millis() - i>1000)
  {
    i = millis();
    digitalToggle(LED_BUILTIN);
  }
  if(remote433.available())
  {
    digitalToggle(LED_BUILTIN);
    Serial.print("Received ");
    Serial.print( remote433.getReceivedValue() );
    Serial.print(" / ");
    Serial.print( remote433.getReceivedBitlength() );
    Serial.print("bit ");
    Serial.print("Protocol: ");
    Serial.println( remote433.getReceivedProtocol() );

    remote433.resetAvailable();
  }
}

I'm using a bluepill STM32 and IDE 2.2.1. in the above code once i uncomment someName the interrupt for the 433 RF won't work anymore. this only happens in STM32. any ideas? (STM32FreeRTOS.h must be included for this to happen)

so if you don't include STM32FreeRTOS.h everything works fine?

if you allocate memory differently like

char someName[20] = "Ok";

do you have an issue?

Yes if i remove STM32FreeRTOS.h or use std::string the problem is solved.
I've been struggling to find out the problem for days. somehow , something causes the interrupt to not be activated. but how that's related to declaring a variable , i have no Idea!

Seems to point at an incompatibility between String and std:string in the context of STM32FreeRTOS.h...
that's weird... Not sure how to debug that... (besides not using the String class)

I had a lot of trouble debugging this. but it turns out others are also experiencing the same problem in similar cases.
It seems declaring a Class global Variable sets the basepri register to non-zero value which should normally not happen.

so for now I have to manually set it back to zero

1 Like

good fact findings...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.