forked from stm32duino/Arduino_Core_STM32
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBareMinimum.ino
122 lines (106 loc) · 2.42 KB
/
BareMinimum.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* This sketch is for CI build purpose.
* It allows to test build of built-in libraries
* and can not be executed.
*/
#include <EEPROM.h>
#ifndef STM32MP1xx
#include <IWatchdog.h>
#endif
#ifdef TIMER_SERVO
#include <Servo.h>
#endif
#include <SPI.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#ifndef USER_BTN
#define USER_BTN 2
#endif
#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif
#ifndef PIN_SERIAL_RX
#define PIN_SERIAL_RX 0
#endif
#ifndef PIN_SERIAL_TX
#define PIN_SERIAL_TX 1
#endif
#ifndef Serial
HardwareSerial Serial(PIN_SERIAL_RX, PIN_SERIAL_TX);
#endif
#ifdef TIMER_SERVO
Servo servo;
#endif
SoftwareSerial swSerial(10, 11);
void setup() {
// Serial HW & SW
#if !defined(USBD_USE_CDC) && !defined(DISABLE_GENERIC_SERIALUSB)
Serial.setRx(PIN_SERIAL_RX);
Serial.setTx(digitalPinToPinName(PIN_SERIAL_TX));
#endif
Serial.begin(9600); // start serial for output
while (!Serial) {};
swSerial.begin(4800);
swSerial.write("x");
if (!swSerial.isListening()) {
swSerial.listen();
if (swSerial.available()) {
swSerial.read();
}
}
swSerial.end();
// EEPROM
byte value = EEPROM.read(0x01);
EEPROM.write(EEPROM.length()-1, value);
#ifndef STM32MP1xx
// IWDG
if (!IWatchdog.isReset(true)) {
IWatchdog.begin(10000000);
IWatchdog.isEnabled();
}
IWatchdog.reload();
#endif
#ifdef TIMER_SERVO
// Servo
servo.attach(3, 900, 2100);
servo.write(1500);
servo.detach();
#endif
// SPI
SPISettings settings(SPI_SPEED_CLOCK_DEFAULT, MSBFIRST, SPI_MODE_0);
SPI.setMISO(PIN_SPI_MISO);
SPI.setMOSI(PIN_SPI_MOSI);
SPI.setSCLK(PIN_SPI_SCK);
SPI.setSSEL(digitalPinToPinName(PIN_SPI_SS));
SPI.begin(PIN_SPI_SS);
SPI.beginTransaction(1, settings);
SPI.endTransaction();
SPI.transfer(1);
SPI.end();
// Wire
Wire.setSCL(PIN_WIRE_SCL);
Wire.setSDA(digitalPinToPinName(PIN_WIRE_SDA));
Wire.setClock(400000);
Wire.begin(4);
Wire.onRequest(requestEvent);
Wire.onReceive(receiveEvent);
Wire.beginTransmission(4);
Wire.endTransmission();
Wire.requestFrom(2, 1);
Wire.end();
}
void loop() {
}
// Wire
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int) {
while (1 < Wire.available()) {
Wire.read();
}
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Wire.write("x");
}