STM32duino Blue Pill Stuck While Runing

Hi,

I am using STM32F103 Blue Pill Board connected a AS5600 magnetic encoder over PB11 SDA and PB10 SCL I2C lines.
The code upload to the STM32 Blue Pill over ST-LINK V2:

#include "Arduino.h"
#include <SoftwareSerial.h>

#include "AS5600.h"
#include "Wire.h"

TwoWire Wire2(PB11, PB10);
AS5600 as5600(&Wire2);   //  use default Wire

SoftwareSerial ser(PA3, PA2);
#define Serial ser

void setup()  
{
  Serial.begin(57600);
  Serial.println(__FILE__);
  Serial.print("AS5600_LIB_VERSION: ");
  Serial.println(AS5600_LIB_VERSION);
  as5600.begin(PB12);  //  set direction pin.
  as5600.setDirection(AS5600_CLOCK_WISE);  // default, just be explicit.
  int b = as5600.isConnected();
  Serial.print("Connect: ");
  Serial.println(b);
  //pinMode(PC13, OUTPUT);
} 
void loop()  
{ 
  //  Serial.print(millis());
  //  Serial.print("\t");
  Serial.println(as5600.readAngle());
  digitalWrite(LED_BUILTIN, LOW);

  //Serial.print("\t");
  //Serial.println(as5600.rawAngle());
  //  Serial.println(as5600.rawAngle() * AS5600_RAW_TO_DEGREES);
 delay(2000);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);
}

ESP32 to read the encoder data over serial:

#include "Arduino.h"

void setup() {
       
  // put your setup code here, to run once:
Serial.begin(9600);
Serial2.begin(57600);

}

void loop() {

//-------------------------------Check Serial Port---------------------------------------
 
 while (Serial2.available()){
  delay(1);
  if(Serial2.available()>0){
  char c = Serial2.read();
    Serial.print(c);   
  }
 }
}

When the reset button on STM32 Blue Pill is pressed:

␀␀␀␀␀␀���;␀␀␀␀␀␀␂␀␀␀␀␀␀␀␀␀␀␀␀src\main.cpp
AS5600_LIB_VERSION: 0.4.0
Connect: 1
0

and it stucks.

STM32 Blue Pill .ini file:
(I have used upload_flags = -c set CPUTAPID 0x2ba01477
due to the fake chip id)

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:blackpill_f103c8]
platform = ststm32
board = blackpill_f103c8
framework = arduino
upload_flags = -c set CPUTAPID 0x2ba01477
lib_deps = 
	robtillaart/AS5600@^0.4.0
	Wire
	khoih-prog/STM32_PWM@^1.0.1
monitor_speed = 9600

I want code to loop. What can be the problem?

…but… LED_BUILTIN is also PB12. So your pins are conficting.

Hi maxgerhardt,

Thanks for your attention. Actually, in my Blue Pill board the builtin led is connected to the PC13. However as you mentioned it is defined as PB12. Also I forgot to define pin type! I revised the code, but the problem is the same.

#include "Arduino.h"
#include <SoftwareSerial.h>

#include "AS5600.h"
#include "Wire.h"

TwoWire Wire2(PB11, PB10);
AS5600 as5600(&Wire2);  

SoftwareSerial ser(PA3, PA2);
#define Serial ser

#define LED_BUILTIN PC13

void setup()  
{
  Serial.begin(57600);
  Serial.println(__FILE__);
  Serial.print("AS5600_LIB_VERSION: ");
  Serial.println(AS5600_LIB_VERSION);

  as5600.begin(PB12);  //  set direction pin.
  as5600.setDirection(AS5600_CLOCK_WISE);  // default, just be explicit.
  int b = as5600.isConnected();
  Serial.print("Connect: ");
  Serial.println(b);

  pinMode(LED_BUILTIN, OUTPUT);
} 
void loop()  
{ 

  Serial.println(as5600.readAngle());
  digitalWrite(LED_BUILTIN, LOW);
 delay(2000);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);
}

You revised which code? The code below is the same, still using PB12. If anyhting, if you have a blue pull, you should be changing

to bluepill_f103c8, to fix the LED definition. Or better yet, just leave the LED blinking code out for now. In any case, you should not be modifying framework files to fix this (C:\Users\<user>\.platformio\packages\framework-arduinoststm32), as any changes would be destroyed on packet updates and is unreproducible for other computers.

PB12 for LED? This sounds wrong:
https://i.stack.imgur.com/lIPdd.png
LED_BUILTIN is at pin PC13.