Hello
I am puzzled by code I wrote and I do not understand, why it does not work as expected. I have a Nucleo-L476RG and following packages installed:
contrib-piohome framework-arduino-avr-microcore framework-stm32cubef0 tool-openocd
framework-arduino-avr framework-arduino-avr-mightycore framework-stm32cubef4 tool-scons
framework-arduino-avr-attiny framework-arduino-avr-minicore tool-avrdude tool-stm32duino
framework-arduino-avr-bean framework-arduino-avr-nicai tool-avrdude@1.60300.200527 toolchain-atmelavr
framework-arduino-avr-digistump framework-arduino-avr-panstamp tool-cppcheck toolchain-gccarmnoneeabi
framework-arduino-avr-dwenguino framework-arduino-avr-prusa_rambo tool-dfuutil toolchain-gccarmnoneeabi@1.70201.0
framework-arduino-avr-majorcore framework-arduinoststm32 tool-dfuutil-arduino
framework-arduino-avr-megacore framework-cmsis tool-ldscripts-ststm32
The code I run is following:
##################################
#include <Arduino.h>
#include <wiring_digital.h>
#define button PC_13
#define led PA_5
#define rx PA_3
#define tx PA_2
HardwareSerial serial(rx, tx);
void setup() {
pinMode(button, INPUT);
pinMode(led, OUTPUT);
serial.begin(115200);
serial.println("Initalization done");
}
void loop() {
uint32_t state;
delay(200);
state = digitalRead(button);
serial.println("Loop state ");
serial.println(state);
if (state)
{
serial.println("Button pushed");
}
digitalWrite(led, !digitalRead(led));
}
#################################
I would expect, that when I push the button I see the line “Button pushed”. and the led is blinking on/off with a period of 200ms. All I see is
Independent if I push the button or not. I use a Nucleo-L476 (https://www.st.com/content/ccc/resource/technical/layouts_and_diagrams/schematic_pack/group2/74/18/73/70/3c/70/4a/52/MB1136-DEFAULT-C04_Schematic/files/MB1136-DEFAULT-C04_Schematic.pdf/jcr:content/translations/en.MB1136-DEFAULT-C04_Schematic.pdf, https://www.st.com/resource/en/user_manual/um1724-stm32-nucleo64-boards-mb1136-stmicroelectronics.pdf). platform.ini is
; PlatformIO Project Configuration File
[env:nucleo_l476rg]
platform = ststm32
board = nucleo_l476rg
framework = arduino
debug_build_flags = -Og -ggdb -g3 -fno-eliminate-unused-debug-symbols
The debug flags are introduced to keep all variables during debug, but it does not work.
If compile the same code with a nucleo64-F401RE with the same not correct behaviour.
I am clueless …
Toias