├── README.md ├── cubemx.png ├── esp8266 ├── .cproject ├── .gitignore ├── .project ├── .settings │ ├── PlatformIO Debugger.launch │ ├── language.settings.xml │ └── org.eclipse.cdt.core.prefs ├── .travis.yml ├── README.rst ├── include │ └── README ├── lib │ └── README ├── platformio.ini ├── src │ ├── main.cpp │ └── settings.h └── test │ └── README ├── setup.jpg ├── stm32 ├── .cproject ├── .gitignore ├── .project ├── .settings │ ├── PlatformIO Debugger.launch │ ├── language.settings.xml │ └── org.eclipse.cdt.core.prefs ├── .travis.yml ├── README.rst ├── include │ ├── DHT11.h │ ├── README │ ├── delay.h │ ├── dwt_stm32_delay.h │ ├── esp8266_communication.h │ ├── main.h │ ├── stm32f1xx_hal_conf.h │ ├── stm32f1xx_it.h │ └── sys.h ├── lib │ └── README ├── platformio.ini ├── src │ ├── DHT11.c │ ├── delay.c │ ├── dwt_stm32_delay.c │ ├── esp8266_communication.c │ ├── main.c │ ├── stm32f1xx_hal_msp.c │ ├── stm32f1xx_it.c │ └── system_stm32f1xx.c └── test │ └── README ├── stm32_uart.ioc └── thingspeak_channel.png /README.md: -------------------------------------------------------------------------------- 1 | # STM32 + ESP8266 IoT demo using PlatformIO 2 | 3 | ## What is this project? 4 | 5 | - a Bluepill board (STM32F103C8) reads out a DHT11 temperature and humidity sensor. 6 | - it transmits the values via its UART2 to the RX of the ESP8266 as a simple text string, e.g. "23,40" 7 | - the ESP8266 connects to a WiFi network and pushes the data to a ThingSpeak.com channel of your choice 8 | 9 | ## Pinout 10 | 11 | - Bluepill 12 | - power (3.3V + GND) 13 | - DHT11 data pin to PA0 14 | - USART2 TX (PA2) to the RX pin (GPIO3) of the ESP8266 15 | - ESP8266 16 | - power (e.g. via USB cable for the NodeMCU) 17 | - common GND with the STM32 board 18 | - RX pin to STM32's TX pin as described above 19 | 20 | 21 | ## Settings 22 | 23 | - ESP8266 (`settings.h`) 24 | - `SECRET_SSID`, `SECRET_PASS`: place your WiFi SSID and password here 25 | - `SECRET_CH_ID`, `SECRET_WRITE_APIKEY`: place your channel ID and write API key from ThingSpeak here 26 | - STM32 27 | - no changable macros 28 | 29 | ## Setup re-creation 30 | 31 | Sign up for a thingspeak.com account, create a new channel and add two fields to it. Call them "Temperature" and "Humidity". 32 | 33 | Format the graphs in the private view as much as you like, e.g. with °C on the y axis on time on the x axis. 34 | 35 | Copy your "Channel ID: XXXXX" and "Write API Key" (in "API Keys") to the `.h` file as described above. Also put your correct WiFi credentials in there. 36 | 37 | ## IDE setup 38 | 39 | If you want to import these projects into an IDE, open your shell (`cmd.exe` or bash, ..) go into either the `esp8266` or `stm32` directory and execute the command 40 | 41 | ```sh 42 | pio init --ide=vscode 43 | ``` 44 | 45 | You can then import that folder in your IDE. For more IDEs, type `pio init --help`. 46 | 47 | ## Media 48 | 49 | ![thingspeak](thingspeak_channel.png) 50 | 51 | ![setup](setup.jpg) 52 | 53 | ![cubemx](cubemx.png) 54 | 55 | ## Credits 56 | 57 | - Maximilian Gerhardt 58 | - Delay code: https://www.controllerstech.com/create-1-microsecond-delay-stm32/ 59 | - DHT11 code: https://www.waveshare.com/wiki/DHT11_Temperature-Humidity_Sensor 60 | - STM32 base project generated with STMicroElectronics CubeMX -------------------------------------------------------------------------------- /cubemx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxgerhardt/pio-stm32-with-esp8266-dht11/05abb28a3800648c0a5425975f7e7bfa55e0d6be/cubemx.png -------------------------------------------------------------------------------- /esp8266/.cproject: -------------------------------------------------------------------------------- 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 | 62 | 76 | 77 | 78 | 79 | 116 | 130 | 131 | 132 | 133 | 170 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 250 | 264 | 265 | 266 | 267 | 304 | 318 | 319 | 320 | 321 | 358 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | platformio 401 | -f -c eclipse 402 | run -t program 403 | true 404 | true 405 | false 406 | 407 | 408 | platformio 409 | -f -c eclipse 410 | run -t uploadfs 411 | true 412 | true 413 | false 414 | 415 | 416 | platformio 417 | -f -c eclipse 418 | run 419 | true 420 | true 421 | false 422 | 423 | 424 | platformio 425 | -f -c eclipse 426 | run -t upload 427 | true 428 | true 429 | false 430 | 431 | 432 | platformio 433 | -f -c eclipse 434 | run -t clean 435 | true 436 | true 437 | false 438 | 439 | 440 | platformio 441 | -f -c eclipse 442 | test 443 | true 444 | true 445 | false 446 | 447 | 448 | platformio 449 | -f -c eclipse 450 | update 451 | true 452 | true 453 | false 454 | 455 | 456 | platformio 457 | -f -c eclipse 458 | init --ide eclipse 459 | true 460 | true 461 | false 462 | 463 | 464 | 465 | 466 | -------------------------------------------------------------------------------- /esp8266/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .pioenvs 3 | .piolibdeps 4 | -------------------------------------------------------------------------------- /esp8266/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | esp8266 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /esp8266/.settings/PlatformIO Debugger.launch: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /esp8266/.settings/language.settings.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /esp8266/.settings/org.eclipse.cdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/project/0.910961921/PATH/delimiter=; 3 | environment/project/0.910961921/PATH/operation=replace 4 | environment/project/0.910961921/PATH/value=C\:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\bin;C\:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\libnvvp;C\:\\ProgramData\\Oracle\\Java\\javapath;C\:\\WINDOWS\\system32;C\:\\WINDOWS;C\:\\WINDOWS\\System32\\Wbem;C\:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C\:\\Program Files (x86)\\GNU\\GnuPG\\pub;C\:\\Program Files (x86)\\mingw-w64\\i686-7.2.0-posix-dwarf-rt_v5-rev1\\mingw32\\bin;C\:\\Users\\Maxi\\Downloads\\GetGnuWin32\\gnuwin32\\bin;C\:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\;C\:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C\:\\Program Files (x86)\\GtkSharp\\2.12\\bin;C\:\\Users\\Maxi\\Downloads\\nano-1.0.8;C\:\\Program Files\\nodejs\\;C\:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\;C\:\\Python27\\;C\:\\Python27\\Scripts;C\:\\Program Files (x86)\\MSBuild\\14.0\\Bin;C\:\\Users\\Maxi\\nasm-2.12.02;C\:\\Windows\\twain_32\\CNQ4200;C\:\\Program Files (x86)\\Python35\\Scripts;C\:\\Users\\Maxi\\Downloads\\ffmpeg-20161230-6993bb4-win64-shared\\bin;C\:\\Program Files\\Java\\jdk1.8.0_111\\bin;C\:\\Program Files\\OpenVPN\\bin;C\:\\Users\\Maxi\\Desktop\\STM8 Dev\\sdcc\\bin;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM8;C\:\\Program Files (x86)\\Windows Live\\Shared;C\:\\Program Files\\dotnet\\;C\:\\Users\\Maxi\\Desktop\\Programming_stuff\\STM8_Dev\\sdcc\\bin;C\:\\Users\\Maxi\\Downloads\\esp32_win32_msys2_environment_and_toolchain-20170330\\msys32\\opt\\openocd-esp32\\bin;C\:\\Program Files\\Git\\cmd;C\:\\WINDOWS\\System32\\OpenSSH\\;C\:\\Windows\\twain_32\\CNQSG86;C\:\\Windows\\twain_32\\CNQ_X64;C\:\\Program Files\\TortoiseGit\\bin;C\:\\Users\\Maxi\\Downloads\\esp32ulp-elf-binutils\\bin;C\:\\Users\\Maxi\\AppData\\Local\\Microsoft\\WindowsApps;C\:\\Program Files (x86)\\Nmap;C\:\\Users\\Maxi\\AppData\\Roaming\\npm;C\:\\Users\\Maxi\\AppData\\Local\\Apps\\cURL\\bin;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM8;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM32;;C\:\\Users\\Maxi\\AppData\\Local\\Programs\\Microsoft VS Code\\bin 5 | environment/project/0.910961921/append=true 6 | environment/project/0.910961921/appendContributed=true 7 | environment/project/0.910961921.1363900502/PATH/delimiter=; 8 | environment/project/0.910961921.1363900502/PATH/operation=replace 9 | environment/project/0.910961921.1363900502/PATH/value=C\:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\bin;C\:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\libnvvp;C\:\\ProgramData\\Oracle\\Java\\javapath;C\:\\WINDOWS\\system32;C\:\\WINDOWS;C\:\\WINDOWS\\System32\\Wbem;C\:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C\:\\Program Files (x86)\\GNU\\GnuPG\\pub;C\:\\Program Files (x86)\\mingw-w64\\i686-7.2.0-posix-dwarf-rt_v5-rev1\\mingw32\\bin;C\:\\Users\\Maxi\\Downloads\\GetGnuWin32\\gnuwin32\\bin;C\:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\;C\:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C\:\\Program Files (x86)\\GtkSharp\\2.12\\bin;C\:\\Users\\Maxi\\Downloads\\nano-1.0.8;C\:\\Program Files\\nodejs\\;C\:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\;C\:\\Python27\\;C\:\\Python27\\Scripts;C\:\\Program Files (x86)\\MSBuild\\14.0\\Bin;C\:\\Users\\Maxi\\nasm-2.12.02;C\:\\Windows\\twain_32\\CNQ4200;C\:\\Program Files (x86)\\Python35\\Scripts;C\:\\Users\\Maxi\\Downloads\\ffmpeg-20161230-6993bb4-win64-shared\\bin;C\:\\Program Files\\Java\\jdk1.8.0_111\\bin;C\:\\Program Files\\OpenVPN\\bin;C\:\\Users\\Maxi\\Desktop\\STM8 Dev\\sdcc\\bin;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM8;C\:\\Program Files (x86)\\Windows Live\\Shared;C\:\\Program Files\\dotnet\\;C\:\\Users\\Maxi\\Desktop\\Programming_stuff\\STM8_Dev\\sdcc\\bin;C\:\\Users\\Maxi\\Downloads\\esp32_win32_msys2_environment_and_toolchain-20170330\\msys32\\opt\\openocd-esp32\\bin;C\:\\Program Files\\Git\\cmd;C\:\\WINDOWS\\System32\\OpenSSH\\;C\:\\Windows\\twain_32\\CNQSG86;C\:\\Windows\\twain_32\\CNQ_X64;C\:\\Program Files\\TortoiseGit\\bin;C\:\\Users\\Maxi\\Downloads\\esp32ulp-elf-binutils\\bin;C\:\\Users\\Maxi\\AppData\\Local\\Microsoft\\WindowsApps;C\:\\Program Files (x86)\\Nmap;C\:\\Users\\Maxi\\AppData\\Roaming\\npm;C\:\\Users\\Maxi\\AppData\\Local\\Apps\\cURL\\bin;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM8;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM32;;C\:\\Users\\Maxi\\AppData\\Local\\Programs\\Microsoft VS Code\\bin 10 | environment/project/0.910961921.1363900502/append=true 11 | environment/project/0.910961921.1363900502/appendContributed=true -------------------------------------------------------------------------------- /esp8266/.travis.yml: -------------------------------------------------------------------------------- 1 | # Continuous Integration (CI) is the practice, in software 2 | # engineering, of merging all developer working copies with a shared mainline 3 | # several times a day < https://docs.platformio.org/page/ci/index.html > 4 | # 5 | # Documentation: 6 | # 7 | # * Travis CI Embedded Builds with PlatformIO 8 | # < https://docs.travis-ci.com/user/integration/platformio/ > 9 | # 10 | # * PlatformIO integration with Travis CI 11 | # < https://docs.platformio.org/page/ci/travis.html > 12 | # 13 | # * User Guide for `platformio ci` command 14 | # < https://docs.platformio.org/page/userguide/cmd_ci.html > 15 | # 16 | # 17 | # Please choose one of the following templates (proposed below) and uncomment 18 | # it (remove "# " before each line) or use own configuration according to the 19 | # Travis CI documentation (see above). 20 | # 21 | 22 | 23 | # 24 | # Template #1: General project. Test it using existing `platformio.ini`. 25 | # 26 | 27 | # language: python 28 | # python: 29 | # - "2.7" 30 | # 31 | # sudo: false 32 | # cache: 33 | # directories: 34 | # - "~/.platformio" 35 | # 36 | # install: 37 | # - pip install -U platformio 38 | # - platformio update 39 | # 40 | # script: 41 | # - platformio run 42 | 43 | 44 | # 45 | # Template #2: The project is intended to be used as a library with examples. 46 | # 47 | 48 | # language: python 49 | # python: 50 | # - "2.7" 51 | # 52 | # sudo: false 53 | # cache: 54 | # directories: 55 | # - "~/.platformio" 56 | # 57 | # env: 58 | # - PLATFORMIO_CI_SRC=path/to/test/file.c 59 | # - PLATFORMIO_CI_SRC=examples/file.ino 60 | # - PLATFORMIO_CI_SRC=path/to/test/directory 61 | # 62 | # install: 63 | # - pip install -U platformio 64 | # - platformio update 65 | # 66 | # script: 67 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N 68 | -------------------------------------------------------------------------------- /esp8266/README.rst: -------------------------------------------------------------------------------- 1 | .. Copyright 2014-present PlatformIO 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | 12 | How to build PlatformIO based project 13 | ===================================== 14 | 15 | 1. `Install PlatformIO Core `_ 16 | 2. Download this repository 17 | 3. Extract ZIP archive 18 | 4. Run these commands: 19 | 20 | .. code-block:: bash 21 | 22 | # Change directory to this folder 23 | 24 | # Build project 25 | > platformio run 26 | 27 | # Upload firmware 28 | > platformio run --target upload 29 | 30 | # Build specific environment 31 | > platformio run -e nodemcuv2 32 | 33 | # Upload firmware for the specific environment 34 | > platformio run -e nodemcuv2 --target upload 35 | 36 | # Clean build files 37 | > platformio run --target clean 38 | 39 | -------------------------------------------------------------------------------- /esp8266/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /esp8266/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /esp8266/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:nodemcuv2] 12 | platform = espressif8266 13 | board = nodemcuv2 14 | framework = arduino 15 | ; uses the convenient ThingSpeak library 16 | lib_deps = ThingSpeak 17 | ; set upload port if multiple COM devices are attached to the computer 18 | ;upload_port = COM6 19 | upload_baud = 460800 -------------------------------------------------------------------------------- /esp8266/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | char ssid[] = SECRET_SSID; // your network SSID (name) 7 | char pass[] = SECRET_PASS; // your network password 8 | WiFiClient client; 9 | 10 | unsigned long myChannelNumber = SECRET_CH_ID; 11 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 12 | 13 | /* holds the current serial line */ 14 | String currentLine; 15 | 16 | int lastTemp, lastHumidity; 17 | unsigned long lastSendTime = 0; 18 | //send every 30 seconds (rate limit by ThingSpeak, 15 seconds per field) 19 | const long sendInterval = 30 * 1000; 20 | 21 | void read_serial_packet(); 22 | void send_to_thingsspeak(); 23 | void connect_to_wifi(); 24 | 25 | void setup() { 26 | //debug serial (TX) and data receive serial (RX) 27 | //when programming the ESP8266, remove the connection 28 | //from the STM32 to the ESP8266's RX pin! 29 | //can also be handled with .swap() so that RX and TX pins 30 | //get swapped to 2 different pins, but this way we can't 31 | //get the debug output from a NodeMCU 32 | Serial.begin(115200); 33 | //wait at max 1 second for a string on the serial 34 | Serial.setTimeout(1000); 35 | Serial.println("Firwmare start!"); 36 | 37 | //set WiFi mode to STATION 38 | WiFi.mode(WIFI_STA); 39 | ThingSpeak.begin(client); // Initialize ThingSpeak 40 | connect_to_wifi(); 41 | } 42 | 43 | void loop() { 44 | read_serial_packet(); 45 | 46 | //check if enough time has expired to send the data to us. 47 | if (millis() - lastSendTime >= sendInterval) { 48 | lastSendTime = millis(); 49 | send_to_thingsspeak(); 50 | } 51 | } 52 | 53 | void read_serial_packet() { 54 | if (Serial.available()) { 55 | currentLine = Serial.readStringUntil('\n'); 56 | 57 | //Serial.println("GOT LINE"); 58 | //Serial.println(currentLine); 59 | 60 | int commaSplitIndex = currentLine.indexOf(','); 61 | if (commaSplitIndex > 0) { 62 | String tempStr = currentLine.substring(0, commaSplitIndex); 63 | String humString = currentLine.substring(commaSplitIndex + 1); 64 | 65 | Serial.println("[Update] Temp: " + tempStr + " Hum: " + humString); 66 | 67 | lastTemp = tempStr.toInt(); 68 | lastHumidity = humString.toInt(); 69 | } 70 | } 71 | } 72 | 73 | void connect_to_wifi() { 74 | // Connect or reconnect to WiFi 75 | if (WiFi.status() != WL_CONNECTED) { 76 | Serial.print("Attempting to connect to SSID: "); 77 | Serial.println(SECRET_SSID); 78 | while (WiFi.status() != WL_CONNECTED) { 79 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 80 | Serial.print("."); 81 | delay(5000); 82 | } 83 | Serial.println("\nConnected."); 84 | } 85 | } 86 | 87 | void send_to_thingsspeak() { 88 | //update field 1 (temperature) and 2 (humidity) 89 | ThingSpeak.setField(1, lastTemp); 90 | ThingSpeak.setField(2, lastHumidity); 91 | //send update via HTTPS REST call 92 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 93 | if (x == 200) { 94 | Serial.println("Channel update successful."); 95 | } else { 96 | Serial.println( 97 | "Problem updating channel. HTTP error code " + String(x)); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /esp8266/src/settings.h: -------------------------------------------------------------------------------- 1 | #ifndef SRC_SETTINGS_H_ 2 | #define SRC_SETTINGS_H_ 3 | 4 | #define SECRET_SSID "ssid_here" // replace MySSID with your WiFi network name 5 | #define SECRET_PASS "password_here" // replace MyPassword with your WiFi password 6 | 7 | #define SECRET_CH_ID 000000 // replace 0000000 with your channel number 8 | #define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key 9 | 10 | #endif /* SRC_SETTINGS_H_ */ 11 | -------------------------------------------------------------------------------- /esp8266/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /setup.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxgerhardt/pio-stm32-with-esp8266-dht11/05abb28a3800648c0a5425975f7e7bfa55e0d6be/setup.jpg -------------------------------------------------------------------------------- /stm32/.cproject: -------------------------------------------------------------------------------- 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 | 44 | 50 | 51 | 52 | 53 | 72 | 78 | 79 | 80 | 81 | 100 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 154 | 160 | 161 | 162 | 163 | 182 | 188 | 189 | 190 | 191 | 210 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | platformio 245 | -f -c eclipse 246 | run -t program 247 | true 248 | true 249 | false 250 | 251 | 252 | platformio 253 | -f -c eclipse 254 | run -t uploadfs 255 | true 256 | true 257 | false 258 | 259 | 260 | platformio 261 | -f -c eclipse 262 | run 263 | true 264 | true 265 | false 266 | 267 | 268 | platformio 269 | -f -c eclipse 270 | run -t upload 271 | true 272 | true 273 | false 274 | 275 | 276 | platformio 277 | -f -c eclipse 278 | run -t clean 279 | true 280 | true 281 | false 282 | 283 | 284 | platformio 285 | -f -c eclipse 286 | test 287 | true 288 | true 289 | false 290 | 291 | 292 | platformio 293 | -f -c eclipse 294 | update 295 | true 296 | true 297 | false 298 | 299 | 300 | platformio 301 | -f -c eclipse 302 | init --ide eclipse 303 | true 304 | true 305 | false 306 | 307 | 308 | 309 | 310 | -------------------------------------------------------------------------------- /stm32/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .pioenvs 3 | .piolibdeps 4 | -------------------------------------------------------------------------------- /stm32/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | stm32 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /stm32/.settings/PlatformIO Debugger.launch: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /stm32/.settings/language.settings.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /stm32/.settings/org.eclipse.cdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/project/0.910961921/PATH/delimiter=; 3 | environment/project/0.910961921/PATH/operation=replace 4 | environment/project/0.910961921/PATH/value=C\:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\bin;C\:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\libnvvp;C\:\\ProgramData\\Oracle\\Java\\javapath;C\:\\WINDOWS\\system32;C\:\\WINDOWS;C\:\\WINDOWS\\System32\\Wbem;C\:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C\:\\Program Files (x86)\\GNU\\GnuPG\\pub;C\:\\Program Files (x86)\\mingw-w64\\i686-7.2.0-posix-dwarf-rt_v5-rev1\\mingw32\\bin;C\:\\Users\\Maxi\\Downloads\\GetGnuWin32\\gnuwin32\\bin;C\:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\;C\:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C\:\\Program Files (x86)\\GtkSharp\\2.12\\bin;C\:\\Users\\Maxi\\Downloads\\nano-1.0.8;C\:\\Program Files\\nodejs\\;C\:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\;C\:\\Python27\\;C\:\\Python27\\Scripts;C\:\\Program Files (x86)\\MSBuild\\14.0\\Bin;C\:\\Users\\Maxi\\nasm-2.12.02;C\:\\Windows\\twain_32\\CNQ4200;C\:\\Program Files (x86)\\Python35\\Scripts;C\:\\Users\\Maxi\\Downloads\\ffmpeg-20161230-6993bb4-win64-shared\\bin;C\:\\Program Files\\Java\\jdk1.8.0_111\\bin;C\:\\Program Files\\OpenVPN\\bin;C\:\\Users\\Maxi\\Desktop\\STM8 Dev\\sdcc\\bin;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM8;C\:\\Program Files (x86)\\Windows Live\\Shared;C\:\\Program Files\\dotnet\\;C\:\\Users\\Maxi\\Desktop\\Programming_stuff\\STM8_Dev\\sdcc\\bin;C\:\\Users\\Maxi\\Downloads\\esp32_win32_msys2_environment_and_toolchain-20170330\\msys32\\opt\\openocd-esp32\\bin;C\:\\Program Files\\Git\\cmd;C\:\\WINDOWS\\System32\\OpenSSH\\;C\:\\Windows\\twain_32\\CNQSG86;C\:\\Windows\\twain_32\\CNQ_X64;C\:\\Program Files\\TortoiseGit\\bin;C\:\\Users\\Maxi\\Downloads\\esp32ulp-elf-binutils\\bin;C\:\\Users\\Maxi\\AppData\\Local\\Microsoft\\WindowsApps;C\:\\Program Files (x86)\\Nmap;C\:\\Users\\Maxi\\AppData\\Roaming\\npm;C\:\\Users\\Maxi\\AppData\\Local\\Apps\\cURL\\bin;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM8;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM32;;C\:\\Users\\Maxi\\AppData\\Local\\Programs\\Microsoft VS Code\\bin 5 | environment/project/0.910961921/append=true 6 | environment/project/0.910961921/appendContributed=true 7 | environment/project/0.910961921.1363900502/PATH/delimiter=; 8 | environment/project/0.910961921.1363900502/PATH/operation=replace 9 | environment/project/0.910961921.1363900502/PATH/value=C\:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\bin;C\:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\libnvvp;C\:\\ProgramData\\Oracle\\Java\\javapath;C\:\\WINDOWS\\system32;C\:\\WINDOWS;C\:\\WINDOWS\\System32\\Wbem;C\:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C\:\\Program Files (x86)\\GNU\\GnuPG\\pub;C\:\\Program Files (x86)\\mingw-w64\\i686-7.2.0-posix-dwarf-rt_v5-rev1\\mingw32\\bin;C\:\\Users\\Maxi\\Downloads\\GetGnuWin32\\gnuwin32\\bin;C\:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\;C\:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C\:\\Program Files (x86)\\GtkSharp\\2.12\\bin;C\:\\Users\\Maxi\\Downloads\\nano-1.0.8;C\:\\Program Files\\nodejs\\;C\:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\;C\:\\Python27\\;C\:\\Python27\\Scripts;C\:\\Program Files (x86)\\MSBuild\\14.0\\Bin;C\:\\Users\\Maxi\\nasm-2.12.02;C\:\\Windows\\twain_32\\CNQ4200;C\:\\Program Files (x86)\\Python35\\Scripts;C\:\\Users\\Maxi\\Downloads\\ffmpeg-20161230-6993bb4-win64-shared\\bin;C\:\\Program Files\\Java\\jdk1.8.0_111\\bin;C\:\\Program Files\\OpenVPN\\bin;C\:\\Users\\Maxi\\Desktop\\STM8 Dev\\sdcc\\bin;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM8;C\:\\Program Files (x86)\\Windows Live\\Shared;C\:\\Program Files\\dotnet\\;C\:\\Users\\Maxi\\Desktop\\Programming_stuff\\STM8_Dev\\sdcc\\bin;C\:\\Users\\Maxi\\Downloads\\esp32_win32_msys2_environment_and_toolchain-20170330\\msys32\\opt\\openocd-esp32\\bin;C\:\\Program Files\\Git\\cmd;C\:\\WINDOWS\\System32\\OpenSSH\\;C\:\\Windows\\twain_32\\CNQSG86;C\:\\Windows\\twain_32\\CNQ_X64;C\:\\Program Files\\TortoiseGit\\bin;C\:\\Users\\Maxi\\Downloads\\esp32ulp-elf-binutils\\bin;C\:\\Users\\Maxi\\AppData\\Local\\Microsoft\\WindowsApps;C\:\\Program Files (x86)\\Nmap;C\:\\Users\\Maxi\\AppData\\Roaming\\npm;C\:\\Users\\Maxi\\AppData\\Local\\Apps\\cURL\\bin;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM8;C\:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM32;;C\:\\Users\\Maxi\\AppData\\Local\\Programs\\Microsoft VS Code\\bin 10 | environment/project/0.910961921.1363900502/append=true 11 | environment/project/0.910961921.1363900502/appendContributed=true -------------------------------------------------------------------------------- /stm32/.travis.yml: -------------------------------------------------------------------------------- 1 | # Continuous Integration (CI) is the practice, in software 2 | # engineering, of merging all developer working copies with a shared mainline 3 | # several times a day < https://docs.platformio.org/page/ci/index.html > 4 | # 5 | # Documentation: 6 | # 7 | # * Travis CI Embedded Builds with PlatformIO 8 | # < https://docs.travis-ci.com/user/integration/platformio/ > 9 | # 10 | # * PlatformIO integration with Travis CI 11 | # < https://docs.platformio.org/page/ci/travis.html > 12 | # 13 | # * User Guide for `platformio ci` command 14 | # < https://docs.platformio.org/page/userguide/cmd_ci.html > 15 | # 16 | # 17 | # Please choose one of the following templates (proposed below) and uncomment 18 | # it (remove "# " before each line) or use own configuration according to the 19 | # Travis CI documentation (see above). 20 | # 21 | 22 | 23 | # 24 | # Template #1: General project. Test it using existing `platformio.ini`. 25 | # 26 | 27 | # language: python 28 | # python: 29 | # - "2.7" 30 | # 31 | # sudo: false 32 | # cache: 33 | # directories: 34 | # - "~/.platformio" 35 | # 36 | # install: 37 | # - pip install -U platformio 38 | # - platformio update 39 | # 40 | # script: 41 | # - platformio run 42 | 43 | 44 | # 45 | # Template #2: The project is intended to be used as a library with examples. 46 | # 47 | 48 | # language: python 49 | # python: 50 | # - "2.7" 51 | # 52 | # sudo: false 53 | # cache: 54 | # directories: 55 | # - "~/.platformio" 56 | # 57 | # env: 58 | # - PLATFORMIO_CI_SRC=path/to/test/file.c 59 | # - PLATFORMIO_CI_SRC=examples/file.ino 60 | # - PLATFORMIO_CI_SRC=path/to/test/directory 61 | # 62 | # install: 63 | # - pip install -U platformio 64 | # - platformio update 65 | # 66 | # script: 67 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N 68 | -------------------------------------------------------------------------------- /stm32/README.rst: -------------------------------------------------------------------------------- 1 | .. Copyright 2014-present PlatformIO 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | 12 | How to build PlatformIO based project 13 | ===================================== 14 | 15 | 1. `Install PlatformIO Core `_ 16 | 2. Download this repository 17 | 3. Extract ZIP archive 18 | 4. Run these commands: 19 | 20 | .. code-block:: bash 21 | 22 | # Change directory to this project 23 | 24 | # Build project 25 | > platformio run 26 | 27 | # Upload firmware 28 | > platformio run --target upload 29 | 30 | # Build specific environment 31 | > platformio run -e genericSTM32F103CB 32 | 33 | # Upload firmware for the specific environment 34 | > platformio run -e genericSTM32F103CB --target upload 35 | 36 | # Clean build files 37 | > platformio run --target clean 38 | 39 | -------------------------------------------------------------------------------- /stm32/include/DHT11.h: -------------------------------------------------------------------------------- 1 | #ifndef __DHT11_H 2 | #define __DHT11_H 3 | #include "sys.h" 4 | 5 | //Set GPIO Direction 6 | #define DHT11_IO_IN() {GPIOA->CRL&=0XFFFFFFF0;GPIOA->CRL|=8<<0;} //PA0 7 | #define DHT11_IO_OUT() {GPIOA->CRL&=0XFFFFFFF0;GPIOA->CRL|=3<<0;} //PA0 8 | 9 | #define DHT11_DQ_OUT PAout(0) 10 | #define DHT11_DQ_IN PAin(0) 11 | 12 | 13 | u8 DHT11_Init(void); //Init DHT11 14 | u8 DHT11_Read_Data(u8 *temperature,u8 *humidity); //Read DHT11 Value 15 | u8 DHT11_Read_Byte(void);//Read One Byte 16 | u8 DHT11_Read_Bit(void);//Read One Bit 17 | u8 DHT11_Check(void);//Chack DHT11 18 | void DHT11_Rst(void);//Reset DHT11 19 | #endif 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /stm32/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /stm32/include/delay.h: -------------------------------------------------------------------------------- 1 | #ifndef __DELAY_H 2 | #define __DELAY_H 3 | #include "sys.h" 4 | 5 | void delay_ms(u16 nms); 6 | void delay_us(u32 nus); 7 | 8 | #endif 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 | -------------------------------------------------------------------------------- /stm32/include/dwt_stm32_delay.h: -------------------------------------------------------------------------------- 1 | #ifndef DWT_STM32_DELAY_H 2 | #define DWT_STM32_DELAY_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | 9 | #include "stm32f1xx_hal.h" 10 | 11 | /** 12 | * @brief Initializes DWT_Cycle_Count for DWT_Delay_us function 13 | * @return Error DWT counter 14 | * 1: DWT counter Error 15 | * 0: DWT counter works 16 | */ 17 | uint32_t DWT_Delay_Init(void); 18 | 19 | 20 | 21 | /** 22 | * @brief This function provides a delay (in microseconds) 23 | * @param microseconds: delay in microseconds 24 | */ 25 | __STATIC_INLINE void DWT_Delay_us(volatile uint32_t microseconds) 26 | { 27 | uint32_t clk_cycle_start = DWT->CYCCNT; 28 | 29 | /* Go to number of cycles for system */ 30 | microseconds *= (HAL_RCC_GetHCLKFreq() / 1000000); 31 | 32 | /* Delay till end */ 33 | while ((DWT->CYCCNT - clk_cycle_start) < microseconds); 34 | } 35 | 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /stm32/include/esp8266_communication.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_ESP8266_COMMUNICATION_H_ 2 | #define INCLUDE_ESP8266_COMMUNICATION_H_ 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * Uses tag-length-value format 9 | * 10 | * 1 2 Bytes 11 | * +--------------------------+ 12 | * | Tag | Length | Value | 13 | * +--------------------------+ 14 | */ 15 | 16 | /** 17 | * 18 | */ 19 | #define ESP8266_COM_TAG_TEMP_SENSOR 0x01 20 | 21 | /** 22 | * Sends a temperature and humidity value to the ESP8266 23 | */ 24 | void esp8266_send_value(uint8_t temp, uint8_t hum); 25 | 26 | #endif /* INCLUDE_ESP8266_COMMUNICATION_H_ */ 27 | -------------------------------------------------------------------------------- /stm32/include/main.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : main.hpp 4 | * Description : This file contains the common defines of the application 5 | ****************************************************************************** 6 | ** This notice applies to any and all portions of this file 7 | * that are not between comment pairs USER CODE BEGIN and 8 | * USER CODE END. Other portions of this file, whether 9 | * inserted by the user or by software development tools 10 | * are owned by their respective copyright owners. 11 | * 12 | * COPYRIGHT(c) 2019 STMicroelectronics 13 | * 14 | * Redistribution and use in source and binary forms, with or without modification, 15 | * are permitted provided that the following conditions are met: 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | ****************************************************************************** 37 | */ 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __MAIN_H 40 | #define __MAIN_H 41 | /* Includes ------------------------------------------------------------------*/ 42 | 43 | /* Includes ------------------------------------------------------------------*/ 44 | /* USER CODE BEGIN Includes */ 45 | 46 | /* USER CODE END Includes */ 47 | 48 | /* Private define ------------------------------------------------------------*/ 49 | 50 | /* ########################## Assert Selection ############################## */ 51 | /** 52 | * @brief Uncomment the line below to expanse the "assert_param" macro in the 53 | * HAL drivers code 54 | */ 55 | /* #define USE_FULL_ASSERT 1U */ 56 | 57 | /* USER CODE BEGIN Private defines */ 58 | 59 | /* USER CODE END Private defines */ 60 | 61 | #ifdef __cplusplus 62 | extern "C" { 63 | #endif 64 | void _Error_Handler(char *, int); 65 | 66 | #define Error_Handler() _Error_Handler(__FILE__, __LINE__) 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | #endif /* __MAIN_H */ 80 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 81 | -------------------------------------------------------------------------------- /stm32/include/stm32f1xx_hal_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_conf.h 4 | * @brief HAL configuration file. 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | *

© COPYRIGHT(c) 2019 STMicroelectronics

9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Define to prevent recursive inclusion -------------------------------------*/ 36 | #ifndef __STM32F1xx_HAL_CONF_H 37 | #define __STM32F1xx_HAL_CONF_H 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #include "main.h" 44 | /* Exported types ------------------------------------------------------------*/ 45 | /* Exported constants --------------------------------------------------------*/ 46 | 47 | /* ########################## Module Selection ############################## */ 48 | /** 49 | * @brief This is the list of modules to be used in the HAL driver 50 | */ 51 | 52 | #define HAL_MODULE_ENABLED 53 | /*#define HAL_ADC_MODULE_ENABLED */ 54 | /*#define HAL_CRYP_MODULE_ENABLED */ 55 | /*#define HAL_CAN_MODULE_ENABLED */ 56 | /*#define HAL_CEC_MODULE_ENABLED */ 57 | /*#define HAL_CORTEX_MODULE_ENABLED */ 58 | /*#define HAL_CRC_MODULE_ENABLED */ 59 | /*#define HAL_DAC_MODULE_ENABLED */ 60 | /*#define HAL_DMA_MODULE_ENABLED */ 61 | /*#define HAL_ETH_MODULE_ENABLED */ 62 | /*#define HAL_FLASH_MODULE_ENABLED */ 63 | #define HAL_GPIO_MODULE_ENABLED 64 | /*#define HAL_I2C_MODULE_ENABLED */ 65 | /*#define HAL_I2S_MODULE_ENABLED */ 66 | /*#define HAL_IRDA_MODULE_ENABLED */ 67 | /*#define HAL_IWDG_MODULE_ENABLED */ 68 | /*#define HAL_NOR_MODULE_ENABLED */ 69 | /*#define HAL_NAND_MODULE_ENABLED */ 70 | /*#define HAL_PCCARD_MODULE_ENABLED */ 71 | /*#define HAL_PCD_MODULE_ENABLED */ 72 | /*#define HAL_HCD_MODULE_ENABLED */ 73 | /*#define HAL_PWR_MODULE_ENABLED */ 74 | /*#define HAL_RCC_MODULE_ENABLED */ 75 | /*#define HAL_RTC_MODULE_ENABLED */ 76 | /*#define HAL_SD_MODULE_ENABLED */ 77 | /*#define HAL_MMC_MODULE_ENABLED */ 78 | /*#define HAL_SDRAM_MODULE_ENABLED */ 79 | /*#define HAL_SMARTCARD_MODULE_ENABLED */ 80 | /*#define HAL_SPI_MODULE_ENABLED */ 81 | /*#define HAL_SRAM_MODULE_ENABLED */ 82 | /*#define HAL_TIM_MODULE_ENABLED */ 83 | #define HAL_UART_MODULE_ENABLED 84 | /*#define HAL_USART_MODULE_ENABLED */ 85 | /*#define HAL_WWDG_MODULE_ENABLED */ 86 | 87 | #define HAL_CORTEX_MODULE_ENABLED 88 | #define HAL_DMA_MODULE_ENABLED 89 | #define HAL_FLASH_MODULE_ENABLED 90 | #define HAL_GPIO_MODULE_ENABLED 91 | #define HAL_PWR_MODULE_ENABLED 92 | #define HAL_RCC_MODULE_ENABLED 93 | 94 | /* ########################## Oscillator Values adaptation ####################*/ 95 | /** 96 | * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. 97 | * This value is used by the RCC HAL module to compute the system frequency 98 | * (when HSE is used as system clock source, directly or through the PLL). 99 | */ 100 | #if !defined (HSE_VALUE) 101 | #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ 102 | #endif /* HSE_VALUE */ 103 | 104 | #if !defined (HSE_STARTUP_TIMEOUT) 105 | #define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */ 106 | #endif /* HSE_STARTUP_TIMEOUT */ 107 | 108 | /** 109 | * @brief Internal High Speed oscillator (HSI) value. 110 | * This value is used by the RCC HAL module to compute the system frequency 111 | * (when HSI is used as system clock source, directly or through the PLL). 112 | */ 113 | #if !defined (HSI_VALUE) 114 | #define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/ 115 | #endif /* HSI_VALUE */ 116 | 117 | /** 118 | * @brief Internal Low Speed oscillator (LSI) value. 119 | */ 120 | #if !defined (LSI_VALUE) 121 | #define LSI_VALUE 40000U /*!< LSI Typical Value in Hz */ 122 | #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz 123 | The real value may vary depending on the variations 124 | in voltage and temperature. */ 125 | 126 | /** 127 | * @brief External Low Speed oscillator (LSE) value. 128 | * This value is used by the UART, RTC HAL module to compute the system frequency 129 | */ 130 | #if !defined (LSE_VALUE) 131 | #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/ 132 | #endif /* LSE_VALUE */ 133 | 134 | #if !defined (LSE_STARTUP_TIMEOUT) 135 | #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */ 136 | #endif /* LSE_STARTUP_TIMEOUT */ 137 | 138 | /* Tip: To avoid modifying this file each time you need to use different HSE, 139 | === you can define the HSE value in your toolchain compiler preprocessor. */ 140 | 141 | /* ########################### System Configuration ######################### */ 142 | /** 143 | * @brief This is the HAL system configuration section 144 | */ 145 | #define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ 146 | #define TICK_INT_PRIORITY ((uint32_t)0) /*!< tick interrupt priority (lowest by default) */ 147 | #define USE_RTOS 0 148 | #define PREFETCH_ENABLE 1 149 | 150 | /* ########################## Assert Selection ############################## */ 151 | /** 152 | * @brief Uncomment the line below to expanse the "assert_param" macro in the 153 | * HAL drivers code 154 | */ 155 | /* #define USE_FULL_ASSERT 1U */ 156 | 157 | /* ################## Ethernet peripheral configuration ##################### */ 158 | 159 | /* Section 1 : Ethernet peripheral configuration */ 160 | 161 | /* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ 162 | #define MAC_ADDR0 2 163 | #define MAC_ADDR1 0 164 | #define MAC_ADDR2 0 165 | #define MAC_ADDR3 0 166 | #define MAC_ADDR4 0 167 | #define MAC_ADDR5 0 168 | 169 | /* Definition of the Ethernet driver buffers size and count */ 170 | #define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ 171 | #define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ 172 | #define ETH_RXBUFNB ((uint32_t)8) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ 173 | #define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ 174 | 175 | /* Section 2: PHY configuration section */ 176 | 177 | /* DP83848_PHY_ADDRESS Address*/ 178 | #define DP83848_PHY_ADDRESS 0x01U 179 | /* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ 180 | #define PHY_RESET_DELAY ((uint32_t)0x000000FF) 181 | /* PHY Configuration delay */ 182 | #define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF) 183 | 184 | #define PHY_READ_TO ((uint32_t)0x0000FFFF) 185 | #define PHY_WRITE_TO ((uint32_t)0x0000FFFF) 186 | 187 | /* Section 3: Common PHY Registers */ 188 | 189 | #define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */ 190 | #define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */ 191 | 192 | #define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */ 193 | #define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */ 194 | #define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */ 195 | #define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */ 196 | #define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */ 197 | #define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */ 198 | #define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */ 199 | #define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */ 200 | #define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */ 201 | #define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */ 202 | 203 | #define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */ 204 | #define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */ 205 | #define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */ 206 | 207 | /* Section 4: Extended PHY Registers */ 208 | #define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */ 209 | 210 | #define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */ 211 | #define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */ 212 | 213 | /* Includes ------------------------------------------------------------------*/ 214 | /** 215 | * @brief Include module's header file 216 | */ 217 | 218 | #ifdef HAL_RCC_MODULE_ENABLED 219 | #include "stm32f1xx_hal_rcc.h" 220 | #endif /* HAL_RCC_MODULE_ENABLED */ 221 | 222 | #ifdef HAL_GPIO_MODULE_ENABLED 223 | #include "stm32f1xx_hal_gpio.h" 224 | #endif /* HAL_GPIO_MODULE_ENABLED */ 225 | 226 | #ifdef HAL_DMA_MODULE_ENABLED 227 | #include "stm32f1xx_hal_dma.h" 228 | #endif /* HAL_DMA_MODULE_ENABLED */ 229 | 230 | #ifdef HAL_ETH_MODULE_ENABLED 231 | #include "stm32f1xx_hal_eth.h" 232 | #endif /* HAL_ETH_MODULE_ENABLED */ 233 | 234 | #ifdef HAL_CAN_MODULE_ENABLED 235 | #include "stm32f1xx_hal_can.h" 236 | #endif /* HAL_CAN_MODULE_ENABLED */ 237 | 238 | #ifdef HAL_CEC_MODULE_ENABLED 239 | #include "stm32f1xx_hal_cec.h" 240 | #endif /* HAL_CEC_MODULE_ENABLED */ 241 | 242 | #ifdef HAL_CORTEX_MODULE_ENABLED 243 | #include "stm32f1xx_hal_cortex.h" 244 | #endif /* HAL_CORTEX_MODULE_ENABLED */ 245 | 246 | #ifdef HAL_ADC_MODULE_ENABLED 247 | #include "stm32f1xx_hal_adc.h" 248 | #endif /* HAL_ADC_MODULE_ENABLED */ 249 | 250 | #ifdef HAL_CRC_MODULE_ENABLED 251 | #include "stm32f1xx_hal_crc.h" 252 | #endif /* HAL_CRC_MODULE_ENABLED */ 253 | 254 | #ifdef HAL_DAC_MODULE_ENABLED 255 | #include "stm32f1xx_hal_dac.h" 256 | #endif /* HAL_DAC_MODULE_ENABLED */ 257 | 258 | #ifdef HAL_FLASH_MODULE_ENABLED 259 | #include "stm32f1xx_hal_flash.h" 260 | #endif /* HAL_FLASH_MODULE_ENABLED */ 261 | 262 | #ifdef HAL_SRAM_MODULE_ENABLED 263 | #include "stm32f1xx_hal_sram.h" 264 | #endif /* HAL_SRAM_MODULE_ENABLED */ 265 | 266 | #ifdef HAL_NOR_MODULE_ENABLED 267 | #include "stm32f1xx_hal_nor.h" 268 | #endif /* HAL_NOR_MODULE_ENABLED */ 269 | 270 | #ifdef HAL_I2C_MODULE_ENABLED 271 | #include "stm32f1xx_hal_i2c.h" 272 | #endif /* HAL_I2C_MODULE_ENABLED */ 273 | 274 | #ifdef HAL_I2S_MODULE_ENABLED 275 | #include "stm32f1xx_hal_i2s.h" 276 | #endif /* HAL_I2S_MODULE_ENABLED */ 277 | 278 | #ifdef HAL_IWDG_MODULE_ENABLED 279 | #include "stm32f1xx_hal_iwdg.h" 280 | #endif /* HAL_IWDG_MODULE_ENABLED */ 281 | 282 | #ifdef HAL_PWR_MODULE_ENABLED 283 | #include "stm32f1xx_hal_pwr.h" 284 | #endif /* HAL_PWR_MODULE_ENABLED */ 285 | 286 | #ifdef HAL_RTC_MODULE_ENABLED 287 | #include "stm32f1xx_hal_rtc.h" 288 | #endif /* HAL_RTC_MODULE_ENABLED */ 289 | 290 | #ifdef HAL_PCCARD_MODULE_ENABLED 291 | #include "stm32f1xx_hal_pccard.h" 292 | #endif /* HAL_PCCARD_MODULE_ENABLED */ 293 | 294 | #ifdef HAL_SD_MODULE_ENABLED 295 | #include "stm32f1xx_hal_sd.h" 296 | #endif /* HAL_SD_MODULE_ENABLED */ 297 | 298 | #ifdef HAL_MMC_MODULE_ENABLED 299 | #include "stm32f1xx_hal_mmc.h" 300 | #endif /* HAL_MMC_MODULE_ENABLED */ 301 | 302 | #ifdef HAL_NAND_MODULE_ENABLED 303 | #include "stm32f1xx_hal_nand.h" 304 | #endif /* HAL_NAND_MODULE_ENABLED */ 305 | 306 | #ifdef HAL_SPI_MODULE_ENABLED 307 | #include "stm32f1xx_hal_spi.h" 308 | #endif /* HAL_SPI_MODULE_ENABLED */ 309 | 310 | #ifdef HAL_TIM_MODULE_ENABLED 311 | #include "stm32f1xx_hal_tim.h" 312 | #endif /* HAL_TIM_MODULE_ENABLED */ 313 | 314 | #ifdef HAL_UART_MODULE_ENABLED 315 | #include "stm32f1xx_hal_uart.h" 316 | #endif /* HAL_UART_MODULE_ENABLED */ 317 | 318 | #ifdef HAL_USART_MODULE_ENABLED 319 | #include "stm32f1xx_hal_usart.h" 320 | #endif /* HAL_USART_MODULE_ENABLED */ 321 | 322 | #ifdef HAL_IRDA_MODULE_ENABLED 323 | #include "stm32f1xx_hal_irda.h" 324 | #endif /* HAL_IRDA_MODULE_ENABLED */ 325 | 326 | #ifdef HAL_SMARTCARD_MODULE_ENABLED 327 | #include "stm32f1xx_hal_smartcard.h" 328 | #endif /* HAL_SMARTCARD_MODULE_ENABLED */ 329 | 330 | #ifdef HAL_WWDG_MODULE_ENABLED 331 | #include "stm32f1xx_hal_wwdg.h" 332 | #endif /* HAL_WWDG_MODULE_ENABLED */ 333 | 334 | #ifdef HAL_PCD_MODULE_ENABLED 335 | #include "stm32f1xx_hal_pcd.h" 336 | #endif /* HAL_PCD_MODULE_ENABLED */ 337 | 338 | #ifdef HAL_HCD_MODULE_ENABLED 339 | #include "stm32f1xx_hal_hcd.h" 340 | #endif /* HAL_HCD_MODULE_ENABLED */ 341 | 342 | 343 | /* Exported macro ------------------------------------------------------------*/ 344 | #ifdef USE_FULL_ASSERT 345 | /** 346 | * @brief The assert_param macro is used for function's parameters check. 347 | * @param expr: If expr is false, it calls assert_failed function 348 | * which reports the name of the source file and the source 349 | * line number of the call that failed. 350 | * If expr is true, it returns no value. 351 | * @retval None 352 | */ 353 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 354 | /* Exported functions ------------------------------------------------------- */ 355 | void assert_failed(uint8_t* file, uint32_t line); 356 | #else 357 | #define assert_param(expr) ((void)0U) 358 | #endif /* USE_FULL_ASSERT */ 359 | 360 | #ifdef __cplusplus 361 | } 362 | #endif 363 | 364 | #endif /* __STM32F1xx_HAL_CONF_H */ 365 | 366 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 367 | -------------------------------------------------------------------------------- /stm32/include/stm32f1xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_it.h 4 | * @brief This file contains the headers of the interrupt handlers. 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2019 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __STM32F1xx_IT_H 36 | #define __STM32F1xx_IT_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "stm32f1xx_hal.h" 44 | #include "main.h" 45 | /* Exported types ------------------------------------------------------------*/ 46 | /* Exported constants --------------------------------------------------------*/ 47 | /* Exported macro ------------------------------------------------------------*/ 48 | /* Exported functions ------------------------------------------------------- */ 49 | 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void MemManage_Handler(void); 53 | void BusFault_Handler(void); 54 | void UsageFault_Handler(void); 55 | void SVC_Handler(void); 56 | void DebugMon_Handler(void); 57 | void PendSV_Handler(void); 58 | void SysTick_Handler(void); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* __STM32F1xx_IT_H */ 65 | 66 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 67 | -------------------------------------------------------------------------------- /stm32/include/sys.h: -------------------------------------------------------------------------------- 1 | #include "stm32f1xx.h" 2 | #include "stm32f1xx_hal.h" 3 | #include 4 | 5 | typedef uint8_t u8; 6 | typedef uint16_t u16; 7 | typedef uint32_t u32; 8 | 9 | //GPIO Macro Definition 10 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 11 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 12 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 13 | 14 | //GPIO Adress Map 15 | #define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C 16 | #define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C 17 | #define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C 18 | #define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C 19 | #define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C 20 | #define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C 21 | #define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C 22 | 23 | #define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808 24 | #define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08 25 | #define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008 26 | #define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408 27 | #define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808 28 | #define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08 29 | #define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08 30 | 31 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) 32 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) 33 | 34 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) 35 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) 36 | 37 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) 38 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) 39 | 40 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) 41 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) 42 | 43 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) 44 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) 45 | 46 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) 47 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) 48 | 49 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) 50 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /stm32/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /stm32/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:genericSTM32F103CB] 12 | platform = ststm32 13 | board = genericSTM32F103CB 14 | framework = stm32cube 15 | ; uplaod via serial bootloader 16 | ; means: BOOT1 to 0, BOOT0 to 1, then RESET board 17 | ; you can also set upload_protocol = stlink and remove the upload port. 18 | ;upload_protocol = serial 19 | ;upload_port = COM3 -------------------------------------------------------------------------------- /stm32/src/DHT11.c: -------------------------------------------------------------------------------- 1 | #include "DHT11.h" 2 | #include "delay.h" 3 | 4 | //Reset DHT11 5 | void DHT11_Rst(void) 6 | { 7 | DHT11_IO_OUT(); //SET OUTPUT 8 | DHT11_DQ_OUT=0; //GPIOA.0=0 9 | delay_ms(20); //Pull down Least 18ms 10 | DHT11_DQ_OUT=1; //GPIOA.0=1 11 | delay_us(30); //Pull up 20~40us 12 | } 13 | 14 | u8 DHT11_Check(void) 15 | { 16 | u8 retry=0; 17 | DHT11_IO_IN();//SET INPUT 18 | while (DHT11_DQ_IN&&retry<100)//DHT11 Pull down 40~80us 19 | { 20 | retry++; 21 | delay_us(1); 22 | }; 23 | if(retry>=100) 24 | return 1; 25 | else 26 | retry=0; 27 | while (!DHT11_DQ_IN&&retry<100)//DHT11 Pull up 40~80us 28 | { 29 | retry++; 30 | delay_us(1); 31 | }; 32 | if(retry>=100) 33 | return 1;//chack error 34 | return 0; 35 | } 36 | 37 | u8 DHT11_Read_Bit(void) 38 | { 39 | u8 retry=0; 40 | while(DHT11_DQ_IN&&retry<100)//wait become Low level 41 | { 42 | retry++; 43 | delay_us(1); 44 | } 45 | retry=0; 46 | while(!DHT11_DQ_IN&&retry<100)//wait become High level 47 | { 48 | retry++; 49 | delay_us(1); 50 | } 51 | delay_us(40);//wait 40us 52 | if(DHT11_DQ_IN) 53 | return 1; 54 | else 55 | return 0; 56 | } 57 | 58 | u8 DHT11_Read_Byte(void) 59 | { 60 | u8 i,dat; 61 | dat=0; 62 | for (i=0;i<8;i++) 63 | { 64 | dat<<=1; 65 | dat|=DHT11_Read_Bit(); 66 | } 67 | return dat; 68 | } 69 | 70 | u8 DHT11_Read_Data(u8 *temperature,u8 *humidity) 71 | { 72 | u8 buf[5]; 73 | u8 i; 74 | DHT11_Rst(); 75 | if(DHT11_Check()==0) 76 | { 77 | for(i=0;i<5;i++) 78 | { 79 | buf[i]=DHT11_Read_Byte(); 80 | } 81 | if((buf[0]+buf[1]+buf[2]+buf[3])==buf[4]) 82 | { 83 | *humidity=buf[0]; 84 | *temperature=buf[2]; 85 | } 86 | } 87 | else 88 | return 1; 89 | return 0; 90 | } 91 | 92 | u8 DHT11_Init(void) 93 | { 94 | GPIO_InitTypeDef GPIO_InitStructure; 95 | 96 | GPIO_InitStructure.Pin= GPIO_PIN_0; 97 | GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 98 | GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH; 99 | HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); 100 | HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0, GPIO_PIN_RESET); 101 | 102 | DHT11_Rst(); 103 | return DHT11_Check(); 104 | } 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /stm32/src/delay.c: -------------------------------------------------------------------------------- 1 | #include "delay.h" 2 | #include "sys.h" 3 | #include 4 | 5 | 6 | void delay_us(u32 nus) 7 | { 8 | DWT_Delay_us(nus); 9 | } 10 | 11 | 12 | void delay_ms(u16 nms) 13 | { 14 | HAL_Delay(nms); 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 | -------------------------------------------------------------------------------- /stm32/src/dwt_stm32_delay.c: -------------------------------------------------------------------------------- 1 | #include "dwt_stm32_delay.h" 2 | 3 | 4 | /** 5 | * @brief Initializes DWT_Clock_Cycle_Count for DWT_Delay_us function 6 | * @return Error DWT counter 7 | * 1: clock cycle counter not started 8 | * 0: clock cycle counter works 9 | */ 10 | uint32_t DWT_Delay_Init(void) { 11 | /* Disable TRC */ 12 | CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk; // ~0x01000000; 13 | /* Enable TRC */ 14 | CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // 0x01000000; 15 | 16 | /* Disable clock cycle counter */ 17 | DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk; //~0x00000001; 18 | /* Enable clock cycle counter */ 19 | DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; //0x00000001; 20 | 21 | /* Reset the clock cycle counter value */ 22 | DWT->CYCCNT = 0; 23 | 24 | /* 3 NO OPERATION instructions */ 25 | __ASM volatile ("NOP"); 26 | __ASM volatile ("NOP"); 27 | __ASM volatile ("NOP"); 28 | 29 | /* Check if clock cycle counter has started */ 30 | if(DWT->CYCCNT) 31 | { 32 | return 0; /*clock cycle counter started*/ 33 | } 34 | else 35 | { 36 | return 1; /*clock cycle counter not started*/ 37 | } 38 | } 39 | 40 | /* Use DWT_Delay_Init (); and DWT_Delay_us (microseconds) in the main */ 41 | -------------------------------------------------------------------------------- /stm32/src/esp8266_communication.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "stm32f1xx_hal.h" 4 | 5 | /* UART2 object from main.c */ 6 | extern UART_HandleTypeDef huart2; 7 | 8 | static void esp8266_write_bytes(void* data, size_t len) { 9 | HAL_UART_Transmit(&huart2, (uint8_t*) data, (uint16_t) len, 1000); 10 | } 11 | 12 | static void esp8266_send_packet(uint8_t tag, uint8_t* data, size_t len) { 13 | esp8266_write_bytes(&tag, 1); 14 | uint16_t packetLen = (uint16_t) len; 15 | esp8266_write_bytes(&packetLen, 2); 16 | esp8266_write_bytes(data, len); 17 | } 18 | 19 | void esp8266_send_value(uint8_t temp, uint8_t hum) { 20 | char line[10]; 21 | snprintf(line, sizeof(line), "%d,%d\n", temp, hum); 22 | esp8266_write_bytes(line, strlen(line)); 23 | //uint8_t data[2] = { temp, hum }; 24 | //esp8266_send_packet(ESP8266_COM_TAG_TEMP_SENSOR, data, sizeof(data)); 25 | } 26 | -------------------------------------------------------------------------------- /stm32/src/main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "stm32f1xx_hal.h" 3 | #include 4 | #include // STDOUT_FILENO, STDERR_FILENO 5 | #include 6 | #include 7 | #include 8 | 9 | UART_HandleTypeDef huart1; 10 | UART_HandleTypeDef huart2; 11 | 12 | void SystemClock_Config(void); 13 | static void MX_GPIO_Init(void); 14 | static void MX_USART2_UART_Init(void); 15 | static void MX_USART1_UART_Init(void); 16 | 17 | /* will make printf() work by writing data to UART1 */ 18 | int _write(int file, char *data, int len) 19 | { 20 | if ((file != STDOUT_FILENO) && (file != STDERR_FILENO)) 21 | { 22 | errno = EBADF; 23 | return -1; 24 | } 25 | 26 | // arbitrary timeout 1000 27 | HAL_StatusTypeDef status = 28 | HAL_UART_Transmit(&huart1, (uint8_t*)data, len, 1000); 29 | 30 | // return # of bytes written - as best we can tell 31 | return (status == HAL_OK ? len : 0); 32 | } 33 | 34 | int main(void) { 35 | HAL_Init(); 36 | SystemClock_Config(); 37 | MX_GPIO_Init(); 38 | MX_USART2_UART_Init(); 39 | MX_USART1_UART_Init(); 40 | 41 | //blinky test 42 | for(int i=0; i < 6; i++ ){ 43 | printf("BLINKY\n"); 44 | HAL_Delay(1000); 45 | HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); 46 | } 47 | //initialize delay 48 | DWT_Delay_Init(); 49 | 50 | //intialize sensor 51 | DHT11_Init(); 52 | while(1) { 53 | //take a reading 54 | u8 temp = 0, hum = 0; 55 | DHT11_Read_Data(&temp, &hum); 56 | 57 | printf("TEMP %d HUM %d\n", temp, hum); 58 | 59 | //transfer it to the esp8266 via USART2 60 | esp8266_send_value(temp, hum); 61 | 62 | HAL_Delay(1000); 63 | } 64 | } 65 | void SystemClock_Config(void) { 66 | 67 | RCC_OscInitTypeDef RCC_OscInitStruct; 68 | RCC_ClkInitTypeDef RCC_ClkInitStruct; 69 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 70 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 71 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; 72 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 73 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 74 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 75 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; 76 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { 77 | _Error_Handler(__FILE__, __LINE__); 78 | } 79 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK 80 | | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; 81 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 82 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 83 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 84 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 85 | 86 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { 87 | _Error_Handler(__FILE__, __LINE__); 88 | } 89 | 90 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); 91 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 92 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 93 | } 94 | 95 | /* USART1 init function */ 96 | static void MX_USART1_UART_Init(void) { 97 | 98 | huart1.Instance = USART1; 99 | huart1.Init.BaudRate = 115200; 100 | huart1.Init.WordLength = UART_WORDLENGTH_8B; 101 | huart1.Init.StopBits = UART_STOPBITS_1; 102 | huart1.Init.Parity = UART_PARITY_NONE; 103 | huart1.Init.Mode = UART_MODE_TX_RX; 104 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 105 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; 106 | if (HAL_UART_Init(&huart1) != HAL_OK) { 107 | _Error_Handler(__FILE__, __LINE__); 108 | } 109 | 110 | } 111 | 112 | /* USART2 init function */ 113 | static void MX_USART2_UART_Init(void) { 114 | 115 | huart2.Instance = USART2; 116 | huart2.Init.BaudRate = 115200; 117 | huart2.Init.WordLength = UART_WORDLENGTH_8B; 118 | huart2.Init.StopBits = UART_STOPBITS_1; 119 | huart2.Init.Parity = UART_PARITY_NONE; 120 | huart2.Init.Mode = UART_MODE_TX_RX; 121 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 122 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 123 | if (HAL_UART_Init(&huart2) != HAL_OK) { 124 | _Error_Handler(__FILE__, __LINE__); 125 | } 126 | 127 | } 128 | 129 | static void MX_GPIO_Init(void) { 130 | 131 | GPIO_InitTypeDef GPIO_InitStruct; 132 | 133 | /* GPIO Ports Clock Enable */ 134 | __HAL_RCC_GPIOC_CLK_ENABLE(); 135 | __HAL_RCC_GPIOD_CLK_ENABLE(); 136 | __HAL_RCC_GPIOA_CLK_ENABLE(); 137 | __HAL_RCC_GPIOB_CLK_ENABLE(); 138 | 139 | /*Configure GPIO pin Output Level */ 140 | HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); 141 | 142 | /*Configure GPIO pin : PC13 */ 143 | GPIO_InitStruct.Pin = GPIO_PIN_13; 144 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 145 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 146 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 147 | 148 | } 149 | 150 | 151 | void _Error_Handler(char * file, int line) { 152 | while (1) { 153 | } 154 | } 155 | 156 | #ifdef USE_FULL_ASSERT 157 | 158 | /** 159 | * @brief Reports the name of the source file and the source line number 160 | * where the assert_param error has occurred. 161 | * @param file: pointer to the source file name 162 | * @param line: assert_param error line source number 163 | * @retval None 164 | */ 165 | void assert_failed(uint8_t* file, uint32_t line) 166 | { 167 | /* USER CODE BEGIN 6 */ 168 | /* User can add his own implementation to report the file name and line number, 169 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 170 | /* USER CODE END 6 */ 171 | 172 | } 173 | 174 | #endif 175 | -------------------------------------------------------------------------------- /stm32/src/stm32f1xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : stm32f1xx_hal_msp.c 4 | * Description : This file provides code for the MSP Initialization 5 | * and de-Initialization codes. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* Includes ------------------------------------------------------------------*/ 40 | #include "stm32f1xx_hal.h" 41 | 42 | extern void _Error_Handler(char *, int); 43 | /* USER CODE BEGIN 0 */ 44 | 45 | /* USER CODE END 0 */ 46 | /** 47 | * Initializes the Global MSP. 48 | */ 49 | void HAL_MspInit(void) 50 | { 51 | /* USER CODE BEGIN MspInit 0 */ 52 | 53 | /* USER CODE END MspInit 0 */ 54 | 55 | __HAL_RCC_AFIO_CLK_ENABLE(); 56 | 57 | HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); 58 | 59 | /* System interrupt init*/ 60 | /* MemoryManagement_IRQn interrupt configuration */ 61 | HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0); 62 | /* BusFault_IRQn interrupt configuration */ 63 | HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0); 64 | /* UsageFault_IRQn interrupt configuration */ 65 | HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0); 66 | /* SVCall_IRQn interrupt configuration */ 67 | HAL_NVIC_SetPriority(SVCall_IRQn, 0, 0); 68 | /* DebugMonitor_IRQn interrupt configuration */ 69 | HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0); 70 | /* PendSV_IRQn interrupt configuration */ 71 | HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0); 72 | /* SysTick_IRQn interrupt configuration */ 73 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 74 | 75 | /**NONJTRST: Full SWJ (JTAG-DP + SW-DP) but without NJTRST 76 | */ 77 | __HAL_AFIO_REMAP_SWJ_NONJTRST(); 78 | 79 | /* USER CODE BEGIN MspInit 1 */ 80 | 81 | /* USER CODE END MspInit 1 */ 82 | } 83 | 84 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) 85 | { 86 | 87 | GPIO_InitTypeDef GPIO_InitStruct; 88 | if(huart->Instance==USART1) 89 | { 90 | /* USER CODE BEGIN USART1_MspInit 0 */ 91 | 92 | /* USER CODE END USART1_MspInit 0 */ 93 | /* Peripheral clock enable */ 94 | __HAL_RCC_USART1_CLK_ENABLE(); 95 | 96 | /**USART1 GPIO Configuration 97 | PA9 ------> USART1_TX 98 | PA10 ------> USART1_RX 99 | */ 100 | GPIO_InitStruct.Pin = GPIO_PIN_9; 101 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 102 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 103 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 104 | 105 | GPIO_InitStruct.Pin = GPIO_PIN_10; 106 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 107 | GPIO_InitStruct.Pull = GPIO_NOPULL; 108 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 109 | 110 | /* USER CODE BEGIN USART1_MspInit 1 */ 111 | 112 | /* USER CODE END USART1_MspInit 1 */ 113 | } 114 | else if(huart->Instance==USART2) 115 | { 116 | /* USER CODE BEGIN USART2_MspInit 0 */ 117 | 118 | /* USER CODE END USART2_MspInit 0 */ 119 | /* Peripheral clock enable */ 120 | __HAL_RCC_USART2_CLK_ENABLE(); 121 | 122 | /**USART2 GPIO Configuration 123 | PA2 ------> USART2_TX 124 | PA3 ------> USART2_RX 125 | */ 126 | GPIO_InitStruct.Pin = GPIO_PIN_2; 127 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 128 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 129 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 130 | 131 | GPIO_InitStruct.Pin = GPIO_PIN_3; 132 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 133 | GPIO_InitStruct.Pull = GPIO_NOPULL; 134 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 135 | 136 | /* USER CODE BEGIN USART2_MspInit 1 */ 137 | 138 | /* USER CODE END USART2_MspInit 1 */ 139 | } 140 | 141 | } 142 | 143 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) 144 | { 145 | 146 | if(huart->Instance==USART1) 147 | { 148 | /* USER CODE BEGIN USART1_MspDeInit 0 */ 149 | 150 | /* USER CODE END USART1_MspDeInit 0 */ 151 | /* Peripheral clock disable */ 152 | __HAL_RCC_USART1_CLK_DISABLE(); 153 | 154 | /**USART1 GPIO Configuration 155 | PA9 ------> USART1_TX 156 | PA10 ------> USART1_RX 157 | */ 158 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); 159 | 160 | /* USER CODE BEGIN USART1_MspDeInit 1 */ 161 | 162 | /* USER CODE END USART1_MspDeInit 1 */ 163 | } 164 | else if(huart->Instance==USART2) 165 | { 166 | /* USER CODE BEGIN USART2_MspDeInit 0 */ 167 | 168 | /* USER CODE END USART2_MspDeInit 0 */ 169 | /* Peripheral clock disable */ 170 | __HAL_RCC_USART2_CLK_DISABLE(); 171 | 172 | /**USART2 GPIO Configuration 173 | PA2 ------> USART2_TX 174 | PA3 ------> USART2_RX 175 | */ 176 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); 177 | 178 | /* USER CODE BEGIN USART2_MspDeInit 1 */ 179 | 180 | /* USER CODE END USART2_MspDeInit 1 */ 181 | } 182 | 183 | } 184 | 185 | /* USER CODE BEGIN 1 */ 186 | 187 | /* USER CODE END 1 */ 188 | 189 | /** 190 | * @} 191 | */ 192 | 193 | /** 194 | * @} 195 | */ 196 | 197 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 198 | -------------------------------------------------------------------------------- /stm32/src/stm32f1xx_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_it.c 4 | * @brief Interrupt Service Routines. 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2019 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm32f1xx_hal.h" 35 | #include "stm32f1xx.h" 36 | #include "stm32f1xx_it.h" 37 | 38 | /* USER CODE BEGIN 0 */ 39 | 40 | /* USER CODE END 0 */ 41 | 42 | /* External variables --------------------------------------------------------*/ 43 | 44 | /******************************************************************************/ 45 | /* Cortex-M3 Processor Interruption and Exception Handlers */ 46 | /******************************************************************************/ 47 | 48 | /** 49 | * @brief This function handles Non maskable interrupt. 50 | */ 51 | void NMI_Handler(void) 52 | { 53 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 54 | 55 | /* USER CODE END NonMaskableInt_IRQn 0 */ 56 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 57 | 58 | /* USER CODE END NonMaskableInt_IRQn 1 */ 59 | } 60 | 61 | /** 62 | * @brief This function handles Hard fault interrupt. 63 | */ 64 | void HardFault_Handler(void) 65 | { 66 | /* USER CODE BEGIN HardFault_IRQn 0 */ 67 | 68 | /* USER CODE END HardFault_IRQn 0 */ 69 | while (1) 70 | { 71 | } 72 | /* USER CODE BEGIN HardFault_IRQn 1 */ 73 | 74 | /* USER CODE END HardFault_IRQn 1 */ 75 | } 76 | 77 | /** 78 | * @brief This function handles Memory management fault. 79 | */ 80 | void MemManage_Handler(void) 81 | { 82 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 83 | 84 | /* USER CODE END MemoryManagement_IRQn 0 */ 85 | while (1) 86 | { 87 | } 88 | /* USER CODE BEGIN MemoryManagement_IRQn 1 */ 89 | 90 | /* USER CODE END MemoryManagement_IRQn 1 */ 91 | } 92 | 93 | /** 94 | * @brief This function handles Prefetch fault, memory access fault. 95 | */ 96 | void BusFault_Handler(void) 97 | { 98 | /* USER CODE BEGIN BusFault_IRQn 0 */ 99 | 100 | /* USER CODE END BusFault_IRQn 0 */ 101 | while (1) 102 | { 103 | } 104 | /* USER CODE BEGIN BusFault_IRQn 1 */ 105 | 106 | /* USER CODE END BusFault_IRQn 1 */ 107 | } 108 | 109 | /** 110 | * @brief This function handles Undefined instruction or illegal state. 111 | */ 112 | void UsageFault_Handler(void) 113 | { 114 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 115 | 116 | /* USER CODE END UsageFault_IRQn 0 */ 117 | while (1) 118 | { 119 | } 120 | /* USER CODE BEGIN UsageFault_IRQn 1 */ 121 | 122 | /* USER CODE END UsageFault_IRQn 1 */ 123 | } 124 | 125 | /** 126 | * @brief This function handles System service call via SWI instruction. 127 | */ 128 | void SVC_Handler(void) 129 | { 130 | /* USER CODE BEGIN SVCall_IRQn 0 */ 131 | 132 | /* USER CODE END SVCall_IRQn 0 */ 133 | /* USER CODE BEGIN SVCall_IRQn 1 */ 134 | 135 | /* USER CODE END SVCall_IRQn 1 */ 136 | } 137 | 138 | /** 139 | * @brief This function handles Debug monitor. 140 | */ 141 | void DebugMon_Handler(void) 142 | { 143 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 144 | 145 | /* USER CODE END DebugMonitor_IRQn 0 */ 146 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 147 | 148 | /* USER CODE END DebugMonitor_IRQn 1 */ 149 | } 150 | 151 | /** 152 | * @brief This function handles Pendable request for system service. 153 | */ 154 | void PendSV_Handler(void) 155 | { 156 | /* USER CODE BEGIN PendSV_IRQn 0 */ 157 | 158 | /* USER CODE END PendSV_IRQn 0 */ 159 | /* USER CODE BEGIN PendSV_IRQn 1 */ 160 | 161 | /* USER CODE END PendSV_IRQn 1 */ 162 | } 163 | 164 | /** 165 | * @brief This function handles System tick timer. 166 | */ 167 | void SysTick_Handler(void) 168 | { 169 | /* USER CODE BEGIN SysTick_IRQn 0 */ 170 | 171 | /* USER CODE END SysTick_IRQn 0 */ 172 | HAL_IncTick(); 173 | HAL_SYSTICK_IRQHandler(); 174 | /* USER CODE BEGIN SysTick_IRQn 1 */ 175 | 176 | /* USER CODE END SysTick_IRQn 1 */ 177 | } 178 | 179 | /******************************************************************************/ 180 | /* STM32F1xx Peripheral Interrupt Handlers */ 181 | /* Add here the Interrupt Handlers for the used peripherals. */ 182 | /* For the available peripheral interrupt handler names, */ 183 | /* please refer to the startup file (startup_stm32f1xx.s). */ 184 | /******************************************************************************/ 185 | 186 | /* USER CODE BEGIN 1 */ 187 | 188 | /* USER CODE END 1 */ 189 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 190 | -------------------------------------------------------------------------------- /stm32/src/system_stm32f1xx.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f1xx.c 4 | * @author MCD Application Team 5 | * @version V4.2.0 6 | * @date 31-March-2017 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. 8 | * 9 | * 1. This file provides two functions and one global variable to be called from 10 | * user application: 11 | * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier 12 | * factors, AHB/APBx prescalers and Flash settings). 13 | * This function is called at startup just after reset and 14 | * before branch to main program. This call is made inside 15 | * the "startup_stm32f1xx_xx.s" file. 16 | * 17 | * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used 18 | * by the user application to setup the SysTick 19 | * timer or configure other parameters. 20 | * 21 | * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must 22 | * be called whenever the core clock is changed 23 | * during program execution. 24 | * 25 | * 2. After each device reset the HSI (8 MHz) is used as system clock source. 26 | * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to 27 | * configure the system clock before to branch to main program. 28 | * 29 | * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on 30 | * the product used), refer to "HSE_VALUE". 31 | * When HSE is used as system clock source, directly or through PLL, and you 32 | * are using different crystal you have to adapt the HSE value to your own 33 | * configuration. 34 | * 35 | ****************************************************************************** 36 | * @attention 37 | * 38 | *

© COPYRIGHT(c) 2017 STMicroelectronics

39 | * 40 | * Redistribution and use in source and binary forms, with or without modification, 41 | * are permitted provided that the following conditions are met: 42 | * 1. Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * 2. Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 48 | * may be used to endorse or promote products derived from this software 49 | * without specific prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 52 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 54 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 57 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 58 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 59 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 61 | * 62 | ****************************************************************************** 63 | */ 64 | 65 | /** @addtogroup CMSIS 66 | * @{ 67 | */ 68 | 69 | /** @addtogroup stm32f1xx_system 70 | * @{ 71 | */ 72 | 73 | /** @addtogroup STM32F1xx_System_Private_Includes 74 | * @{ 75 | */ 76 | 77 | #include "stm32f1xx.h" 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup STM32F1xx_System_Private_TypesDefinitions 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F1xx_System_Private_Defines 92 | * @{ 93 | */ 94 | 95 | #if !defined (HSE_VALUE) 96 | #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. 97 | This value can be provided and adapted by the user application. */ 98 | #endif /* HSE_VALUE */ 99 | 100 | #if !defined (HSI_VALUE) 101 | #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. 102 | This value can be provided and adapted by the user application. */ 103 | #endif /* HSI_VALUE */ 104 | 105 | /*!< Uncomment the following line if you need to use external SRAM */ 106 | #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) 107 | /* #define DATA_IN_ExtSRAM */ 108 | #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ 109 | 110 | /*!< Uncomment the following line if you need to relocate your vector Table in 111 | Internal SRAM. */ 112 | /* #define VECT_TAB_SRAM */ 113 | #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. 114 | This value must be a multiple of 0x200. */ 115 | 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /** @addtogroup STM32F1xx_System_Private_Macros 122 | * @{ 123 | */ 124 | 125 | /** 126 | * @} 127 | */ 128 | 129 | /** @addtogroup STM32F1xx_System_Private_Variables 130 | * @{ 131 | */ 132 | 133 | /******************************************************************************* 134 | * Clock Definitions 135 | *******************************************************************************/ 136 | #if defined(STM32F100xB) ||defined(STM32F100xE) 137 | uint32_t SystemCoreClock = 24000000U; /*!< System Clock Frequency (Core Clock) */ 138 | #else /*!< HSI Selected as System Clock source */ 139 | uint32_t SystemCoreClock = 72000000U; /*!< System Clock Frequency (Core Clock) */ 140 | #endif 141 | 142 | const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; 143 | const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; 144 | 145 | /** 146 | * @} 147 | */ 148 | 149 | /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes 150 | * @{ 151 | */ 152 | 153 | #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) 154 | #ifdef DATA_IN_ExtSRAM 155 | static void SystemInit_ExtMemCtl(void); 156 | #endif /* DATA_IN_ExtSRAM */ 157 | #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ 158 | 159 | /** 160 | * @} 161 | */ 162 | 163 | /** @addtogroup STM32F1xx_System_Private_Functions 164 | * @{ 165 | */ 166 | 167 | /** 168 | * @brief Setup the microcontroller system 169 | * Initialize the Embedded Flash Interface, the PLL and update the 170 | * SystemCoreClock variable. 171 | * @note This function should be used only after reset. 172 | * @param None 173 | * @retval None 174 | */ 175 | void SystemInit (void) 176 | { 177 | /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ 178 | /* Set HSION bit */ 179 | RCC->CR |= 0x00000001U; 180 | 181 | /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ 182 | #if !defined(STM32F105xC) && !defined(STM32F107xC) 183 | RCC->CFGR &= 0xF8FF0000U; 184 | #else 185 | RCC->CFGR &= 0xF0FF0000U; 186 | #endif /* STM32F105xC */ 187 | 188 | /* Reset HSEON, CSSON and PLLON bits */ 189 | RCC->CR &= 0xFEF6FFFFU; 190 | 191 | /* Reset HSEBYP bit */ 192 | RCC->CR &= 0xFFFBFFFFU; 193 | 194 | /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ 195 | RCC->CFGR &= 0xFF80FFFFU; 196 | 197 | #if defined(STM32F105xC) || defined(STM32F107xC) 198 | /* Reset PLL2ON and PLL3ON bits */ 199 | RCC->CR &= 0xEBFFFFFFU; 200 | 201 | /* Disable all interrupts and clear pending bits */ 202 | RCC->CIR = 0x00FF0000U; 203 | 204 | /* Reset CFGR2 register */ 205 | RCC->CFGR2 = 0x00000000U; 206 | #elif defined(STM32F100xB) || defined(STM32F100xE) 207 | /* Disable all interrupts and clear pending bits */ 208 | RCC->CIR = 0x009F0000U; 209 | 210 | /* Reset CFGR2 register */ 211 | RCC->CFGR2 = 0x00000000U; 212 | #else 213 | /* Disable all interrupts and clear pending bits */ 214 | RCC->CIR = 0x009F0000U; 215 | #endif /* STM32F105xC */ 216 | 217 | #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) 218 | #ifdef DATA_IN_ExtSRAM 219 | SystemInit_ExtMemCtl(); 220 | #endif /* DATA_IN_ExtSRAM */ 221 | #endif 222 | 223 | #ifdef VECT_TAB_SRAM 224 | SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ 225 | #else 226 | SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ 227 | #endif 228 | } 229 | 230 | /** 231 | * @brief Update SystemCoreClock variable according to Clock Register Values. 232 | * The SystemCoreClock variable contains the core clock (HCLK), it can 233 | * be used by the user application to setup the SysTick timer or configure 234 | * other parameters. 235 | * 236 | * @note Each time the core clock (HCLK) changes, this function must be called 237 | * to update SystemCoreClock variable value. Otherwise, any configuration 238 | * based on this variable will be incorrect. 239 | * 240 | * @note - The system frequency computed by this function is not the real 241 | * frequency in the chip. It is calculated based on the predefined 242 | * constant and the selected clock source: 243 | * 244 | * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) 245 | * 246 | * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) 247 | * 248 | * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) 249 | * or HSI_VALUE(*) multiplied by the PLL factors. 250 | * 251 | * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value 252 | * 8 MHz) but the real value may vary depending on the variations 253 | * in voltage and temperature. 254 | * 255 | * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value 256 | * 8 MHz or 25 MHz, depending on the product used), user has to ensure 257 | * that HSE_VALUE is same as the real frequency of the crystal used. 258 | * Otherwise, this function may have wrong result. 259 | * 260 | * - The result of this function could be not correct when using fractional 261 | * value for HSE crystal. 262 | * @param None 263 | * @retval None 264 | */ 265 | void SystemCoreClockUpdate (void) 266 | { 267 | uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; 268 | 269 | #if defined(STM32F105xC) || defined(STM32F107xC) 270 | uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; 271 | #endif /* STM32F105xC */ 272 | 273 | #if defined(STM32F100xB) || defined(STM32F100xE) 274 | uint32_t prediv1factor = 0U; 275 | #endif /* STM32F100xB or STM32F100xE */ 276 | 277 | /* Get SYSCLK source -------------------------------------------------------*/ 278 | tmp = RCC->CFGR & RCC_CFGR_SWS; 279 | 280 | switch (tmp) 281 | { 282 | case 0x00U: /* HSI used as system clock */ 283 | SystemCoreClock = HSI_VALUE; 284 | break; 285 | case 0x04U: /* HSE used as system clock */ 286 | SystemCoreClock = HSE_VALUE; 287 | break; 288 | case 0x08U: /* PLL used as system clock */ 289 | 290 | /* Get PLL clock source and multiplication factor ----------------------*/ 291 | pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; 292 | pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; 293 | 294 | #if !defined(STM32F105xC) && !defined(STM32F107xC) 295 | pllmull = ( pllmull >> 18U) + 2U; 296 | 297 | if (pllsource == 0x00U) 298 | { 299 | /* HSI oscillator clock divided by 2 selected as PLL clock entry */ 300 | SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; 301 | } 302 | else 303 | { 304 | #if defined(STM32F100xB) || defined(STM32F100xE) 305 | prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; 306 | /* HSE oscillator clock selected as PREDIV1 clock entry */ 307 | SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; 308 | #else 309 | /* HSE selected as PLL clock entry */ 310 | if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) 311 | {/* HSE oscillator clock divided by 2 */ 312 | SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; 313 | } 314 | else 315 | { 316 | SystemCoreClock = HSE_VALUE * pllmull; 317 | } 318 | #endif 319 | } 320 | #else 321 | pllmull = pllmull >> 18U; 322 | 323 | if (pllmull != 0x0DU) 324 | { 325 | pllmull += 2U; 326 | } 327 | else 328 | { /* PLL multiplication factor = PLL input clock * 6.5 */ 329 | pllmull = 13U / 2U; 330 | } 331 | 332 | if (pllsource == 0x00U) 333 | { 334 | /* HSI oscillator clock divided by 2 selected as PLL clock entry */ 335 | SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; 336 | } 337 | else 338 | {/* PREDIV1 selected as PLL clock entry */ 339 | 340 | /* Get PREDIV1 clock source and division factor */ 341 | prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; 342 | prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; 343 | 344 | if (prediv1source == 0U) 345 | { 346 | /* HSE oscillator clock selected as PREDIV1 clock entry */ 347 | SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; 348 | } 349 | else 350 | {/* PLL2 clock selected as PREDIV1 clock entry */ 351 | 352 | /* Get PREDIV2 division factor and PLL2 multiplication factor */ 353 | prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; 354 | pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; 355 | SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; 356 | } 357 | } 358 | #endif /* STM32F105xC */ 359 | break; 360 | 361 | default: 362 | SystemCoreClock = HSI_VALUE; 363 | break; 364 | } 365 | 366 | /* Compute HCLK clock frequency ----------------*/ 367 | /* Get HCLK prescaler */ 368 | tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; 369 | /* HCLK clock frequency */ 370 | SystemCoreClock >>= tmp; 371 | } 372 | 373 | #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) 374 | /** 375 | * @brief Setup the external memory controller. Called in startup_stm32f1xx.s 376 | * before jump to __main 377 | * @param None 378 | * @retval None 379 | */ 380 | #ifdef DATA_IN_ExtSRAM 381 | /** 382 | * @brief Setup the external memory controller. 383 | * Called in startup_stm32f1xx_xx.s/.c before jump to main. 384 | * This function configures the external SRAM mounted on STM3210E-EVAL 385 | * board (STM32 High density devices). This SRAM will be used as program 386 | * data memory (including heap and stack). 387 | * @param None 388 | * @retval None 389 | */ 390 | void SystemInit_ExtMemCtl(void) 391 | { 392 | __IO uint32_t tmpreg; 393 | /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is 394 | required, then adjust the Register Addresses */ 395 | 396 | /* Enable FSMC clock */ 397 | RCC->AHBENR = 0x00000114U; 398 | 399 | /* Delay after an RCC peripheral clock enabling */ 400 | tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); 401 | 402 | /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ 403 | RCC->APB2ENR = 0x000001E0U; 404 | 405 | /* Delay after an RCC peripheral clock enabling */ 406 | tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); 407 | 408 | (void)(tmpreg); 409 | 410 | /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ 411 | /*---------------- SRAM Address lines configuration -------------------------*/ 412 | /*---------------- NOE and NWE configuration --------------------------------*/ 413 | /*---------------- NE3 configuration ----------------------------------------*/ 414 | /*---------------- NBL0, NBL1 configuration ---------------------------------*/ 415 | 416 | GPIOD->CRL = 0x44BB44BBU; 417 | GPIOD->CRH = 0xBBBBBBBBU; 418 | 419 | GPIOE->CRL = 0xB44444BBU; 420 | GPIOE->CRH = 0xBBBBBBBBU; 421 | 422 | GPIOF->CRL = 0x44BBBBBBU; 423 | GPIOF->CRH = 0xBBBB4444U; 424 | 425 | GPIOG->CRL = 0x44BBBBBBU; 426 | GPIOG->CRH = 0x444B4B44U; 427 | 428 | /*---------------- FSMC Configuration ---------------------------------------*/ 429 | /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ 430 | 431 | FSMC_Bank1->BTCR[4U] = 0x00001091U; 432 | FSMC_Bank1->BTCR[5U] = 0x00110212U; 433 | } 434 | #endif /* DATA_IN_ExtSRAM */ 435 | #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ 436 | 437 | /** 438 | * @} 439 | */ 440 | 441 | /** 442 | * @} 443 | */ 444 | 445 | /** 446 | * @} 447 | */ 448 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 449 | -------------------------------------------------------------------------------- /stm32/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /stm32_uart.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | FREERTOS.IPParameters=Tasks01 3 | FREERTOS.Tasks01=defaultTask,0,128,StartDefaultTask,Default,NULL 4 | File.Version=6 5 | KeepUserPlacement=false 6 | Mcu.Family=STM32F1 7 | Mcu.IP0=FREERTOS 8 | Mcu.IP1=NVIC 9 | Mcu.IP2=RCC 10 | Mcu.IP3=SYS 11 | Mcu.IP4=USART1 12 | Mcu.IP5=USART2 13 | Mcu.IPNb=6 14 | Mcu.Name=STM32F103C(8-B)Tx 15 | Mcu.Package=LQFP48 16 | Mcu.Pin0=PC13-TAMPER-RTC 17 | Mcu.Pin1=PD0-OSC_IN 18 | Mcu.Pin10=PB3 19 | Mcu.Pin11=VP_FREERTOS_VS_ENABLE 20 | Mcu.Pin12=VP_SYS_VS_Systick 21 | Mcu.Pin2=PD1-OSC_OUT 22 | Mcu.Pin3=PA2 23 | Mcu.Pin4=PA3 24 | Mcu.Pin5=PA9 25 | Mcu.Pin6=PA10 26 | Mcu.Pin7=PA13 27 | Mcu.Pin8=PA14 28 | Mcu.Pin9=PA15 29 | Mcu.PinsNb=13 30 | Mcu.UserConstants= 31 | Mcu.UserName=STM32F103C8Tx 32 | MxCube.Version=4.23.0 33 | MxDb.Version=DB.4.0.230 34 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 35 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false 36 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 37 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false 38 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 39 | NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false 40 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 41 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false 42 | NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:true\:false 43 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 44 | PA10.Mode=Asynchronous 45 | PA10.Signal=USART1_RX 46 | PA13.Mode=JTAG_4_pins 47 | PA13.Signal=SYS_JTMS-SWDIO 48 | PA14.Mode=JTAG_4_pins 49 | PA14.Signal=SYS_JTCK-SWCLK 50 | PA15.Mode=JTAG_4_pins 51 | PA15.Signal=SYS_JTDI 52 | PA2.Mode=Asynchronous 53 | PA2.Signal=USART2_TX 54 | PA3.Mode=Asynchronous 55 | PA3.Signal=USART2_RX 56 | PA9.Mode=Asynchronous 57 | PA9.Signal=USART1_TX 58 | PB3.Mode=JTAG_4_pins 59 | PB3.Signal=SYS_JTDO-TRACESWO 60 | PC13-TAMPER-RTC.Locked=true 61 | PC13-TAMPER-RTC.Signal=GPIO_Output 62 | PCC.Checker=false 63 | PCC.Line=STM32F103 64 | PCC.MCU=STM32F103C(8-B)Tx 65 | PCC.PartNumber=STM32F103C8Tx 66 | PCC.Seq0=0 67 | PCC.Series=STM32F1 68 | PCC.Temperature=25 69 | PCC.Vdd=3.3 70 | PD0-OSC_IN.Mode=HSE-External-Oscillator 71 | PD0-OSC_IN.Signal=RCC_OSC_IN 72 | PD1-OSC_OUT.Mode=HSE-External-Oscillator 73 | PD1-OSC_OUT.Signal=RCC_OSC_OUT 74 | PinOutPanel.RotationAngle=0 75 | RCC.ADCFreqValue=36000000 76 | RCC.AHBFreq_Value=72000000 77 | RCC.APB1CLKDivider=RCC_HCLK_DIV2 78 | RCC.APB1Freq_Value=36000000 79 | RCC.APB1TimFreq_Value=72000000 80 | RCC.APB2Freq_Value=72000000 81 | RCC.APB2TimFreq_Value=72000000 82 | RCC.FCLKCortexFreq_Value=72000000 83 | RCC.FamilyName=M 84 | RCC.HCLKFreq_Value=72000000 85 | RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value 86 | RCC.MCOFreq_Value=72000000 87 | RCC.PLLCLKFreq_Value=72000000 88 | RCC.PLLMCOFreq_Value=36000000 89 | RCC.PLLMUL=RCC_PLL_MUL9 90 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 91 | RCC.SYSCLKFreq_VALUE=72000000 92 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 93 | RCC.TimSysFreq_Value=72000000 94 | RCC.USBFreq_Value=72000000 95 | RCC.VCOOutput2Freq_Value=8000000 96 | USART1.IPParameters=VirtualMode 97 | USART1.VirtualMode=VM_ASYNC 98 | USART2.IPParameters=VirtualMode 99 | USART2.VirtualMode=VM_ASYNC 100 | VP_FREERTOS_VS_ENABLE.Mode=Enabled 101 | VP_FREERTOS_VS_ENABLE.Signal=FREERTOS_VS_ENABLE 102 | VP_SYS_VS_Systick.Mode=SysTick 103 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 104 | -------------------------------------------------------------------------------- /thingspeak_channel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxgerhardt/pio-stm32-with-esp8266-dht11/05abb28a3800648c0a5425975f7e7bfa55e0d6be/thingspeak_channel.png --------------------------------------------------------------------------------