IDE 2 rc3 Compiles with Errors and corrupts STM32F4

Hello,
Platform Win10 Pro 64, IDE 2 RC3
Not sure sure if i should be reporting this here or Arduino Forum but think it might be a STM32 variants issue.
So i am in process of building what is going to be a large multi module project on the Black Pile STM32F411CE chip
Currently the project has the .ino, two .cpp and two .h files and i have used almost every pin on the chip including RTC pins as digital out
#define MOTOR_4_CONTROLLER_AB_IN1_PIN PC15
#define MOTOR_4_CONTROLLER_AB_IN2_PIN PC14
These seem to test ok, but in the IDE .cpp file they highlighted with a "Use of Undeclared No Quick Fix" message.

Now the code compiles and build without error and is working as expected.
However sometimes after editing a file the compiler with throw an error then fail to UpLoad the code:

Error: No STM32 target found!
Upload error: Failed uploading: uploading error: exit status 1

After this error I shutdown IDE 2 rc3, restart it and the code compiles just fine.
However the STM32F411CE is damaged and the STLINK throws a cant find error.
So I have to do a Full Chip Erase with STM32CubeProgrammer, then all works just fine.

Below are the two build outputs of what is unchanged code.
This situation seems to happen almost randomly, but generally after a source code change that would compile without error.
eg passing a different integer value as a parameter to a function for testing

^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^- Below Build Normal Output But Damaged Chip ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
Sketch uses 24608 bytes (4%) of program storage space. Maximum is 524288 bytes.
Global variables use 4012 bytes (3%) of dynamic memory, leaving 127060 bytes for local variables. Maximum is 131072 bytes.


Compilation complete.

STM32CubeProgrammer v2.8.0

ST-LINK SN : 003F002B5553500720393256
ST-LINK FW : V3J8M3
Board : STLINK-V3MINI
Voltage : 3.19V
Error: No STM32 target found!
2nd connect tentative with a lower frequency (8MHz)
ST-LINK SN : 003F002B5553500720393256
ST-LINK FW : V3J8M3
Board : STLINK-V3MINI
Voltage : 3.24V
Error: No STM32 target found!
Upload error: Failed uploading: uploading error: exit status 1
^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^- Above Build Normal Output ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-

^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^- Below Erroneous Build Error Good Upload ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
C:\Users\Me\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.2.0\system/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f411xe.h:371:3: warning: type 'struct RCC_TypeDef' violates the C++ One Definition Rule [-Wodr]
371 | } RCC_TypeDef;
| ^
C:\Users\Me\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.2.0\system/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h:629:3: note: a different type is defined in another translation unit
629 | } RCC_TypeDef;
| ^
C:\Users\Me\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.2.0\system/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f411xe.h:369:17: note: the first difference of corresponding definitions is field 'RESERVED7'
369 | uint32_t RESERVED7[1]; /*!< Reserved, 0x88 */
| ^
C:\Users\Me\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.2.0\system/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h:629:3: note: a type with different number of fields is defined in another translation unit
629 | } RCC_TypeDef;
| ^
C:\Users\Me\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.2.0\cores\arduino/stm32/PinNames.h:280:3: warning: type 'PinName' violates the C++ One Definition Rule [-Wodr]
280 | } PinName;
| ^
C:\Users\Me\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.2.0\cores\arduino/stm32/PinNames.h:280:3: note: an enum with different value name is defined in another translation unit
280 | } PinName;
| ^
C:\Users\Me\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.2.0\cores\arduino/stm32/PinNames.h:164:3: note: name 'PH_0' differs from name 'PF_0' defined in another translation unit
164 | PH_0 = (PortH << 4) + 0x00,
| ^
C:\Users\Me\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.2.0\cores\arduino/stm32/PinNames.h:128:3: note: mismatching definition
128 | PF_0 = (PortF << 4) + 0x00,
| ^
Sketch uses 25212 bytes (4%) of program storage space. Maximum is 524288 bytes.
Global variables use 4012 bytes (3%) of dynamic memory, leaving 127060 bytes for local variables. Maximum is 131072 bytes.


Compilation complete.

STM32CubeProgrammer v2.8.0

ST-LINK SN : 003F002B5553500720393256
ST-LINK FW : V3J8M3
Board : STLINK-V3MINI
Voltage : 3.20V
SWD freq : 24000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x431
Revision ID : Rev A
Device name : STM32F411xC/E
Flash size : 512 KBytes
Device type : MCU
Device CPU : Cortex-M4
BL Version : 0x__

Memory Programming ...
Opening and parsing file: ERIN_MOTOR_TEST_1.ino.bin
File : ERIN_MOTOR_TEST_1.ino.bin
Size : 25648 Bytes
Address : 0x08000000

Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 1]
Download in Progress:

File download complete
Time elapsed during download operation: 00:00:00.903

RUNNING Program ...
Address: : 0x8000000
Application is running, Please Hold on...
Start operation achieved successfully


upload complete.

^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^- Above Erroneous Build Error Good Upload ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-

Hi @imk123. Thanks for your report.

Does the issue also occur if you upload the minimal File > New sketch?

Please tell me the exact selections you have in the Arduino IDE's Tools menu. For example:

  • Tools > Board > STM32 MCU based boards > Generic STM32F4 series
  • Tools > Debug symbols > None
  • Tools > Optimize > Smallest (-Os default)
  • Tools > Board Part Number > BlackPill F411CE
  • Tools > C Runtime Library > Newlib Nano (default)
  • Tools > Upload method > STM32CubeProgrammer (SWD)
  • Tools > USB Support (if available) > None
  • Tools > U(S)ART support > Enabled (generic 'Serial')
  • Tools > USB Speed (if available) > Low/Full Speed

Hello ptillisch and sorry for late reply.
I have not been able to make it happen with basic sketch.
Current setup is

  • Tools > Board > STM32 MCU based boards > Generic STM32F4 series
  • Tools > Debug symbols > None
  • Tools > Optimize > Smallest (-Os default) With LTO
  • Tools > Board Part Number > BlackPill F411CE
  • Tools > C Runtime Library > Newlib Nano (default)
  • Tools > Upload method > STM32CubeProgrammer (SWD)
  • **Tools > USB Support (if available) > CDC generics serial supersede U(S)ART
  • Tools > U(S)ART support > Enabled (generic 'Serial')
  • Tools > USB Speed (if available) > Low/Full Speed

So only change is Optimize > Smallest (-Os default)** With LTO

Hope that help.. BTW I must have re compile yesterday ten times and it didn't happen, however couple of days ago it was happening all the time.
Although I have had the random compiler errors and when i compiled again it compiled perfectly. It seems to be related to changes to the .H files eg change #defines to other values but no hard proof.

is this a clue
in a .h file I have
#define MOTOR_4_CONTROLLER_AB_IN1_PIN PC15
#define MOTOR_4_CONTROLLER_AB_IN2_PIN PC14

in cpp file i have
pinMode( MOTOR_4_CONTROLLER_AB_IN1_PIN , OUTPUT );
pinMode( MOTOR_4_CONTROLLER_AB_IN2_PIN , OUTPUT );

when i float cursor over MOTOR_4_CONTROLLER_AB_IN2_PIN in .cpp it shows an error
Undeclared identifier No Quick Fix

Although the code compile and seems to work fine.

PS Think IDE 2 rc3 is really looking VERY good and am really happy with it.

IMK

Unfortunately, I am a bit stumped by this complex issue. I did recently run into another issue while using the stm32duino boards platform with Arduino IDE 2.x, which I reported here:

(I simplified it down by using the Uno for the demonstration in the bug report)

But I don't have any reason to believe that bug is the cause of the problem you experienced other than the fact that you are using the same platform I was, which is really no reason at all.