Browse Source

Add code and schematics

master
Lukas 3 years ago
parent
commit
6383680532
30 changed files with 8720 additions and 0 deletions
  1. +1
    -0
      Arduino
  2. +1
    -0
      ESP32
  3. +2864
    -0
      KiCad/noise_sensor.kicad_pcb
  4. +248
    -0
      KiCad/noise_sensor.pro
  5. +870
    -0
      KiCad/noise_sensor.sch
  6. BIN
      KiCad/pcb_3d.png
  7. BIN
      STL/master_bottom.stl
  8. BIN
      STL/master_complete.png
  9. BIN
      STL/master_top.stl
  10. BIN
      STL/slave_bottom_v2.stl
  11. BIN
      STL/slave_top_v2.stl
  12. +490
    -0
      STM32/Core/Inc/SX1278.h
  13. +95
    -0
      STM32/Core/Inc/SX1278_hw.h
  14. +102
    -0
      STM32/Core/Inc/arduinoFFT.h
  15. +70
    -0
      STM32/Core/Inc/correction_values.h
  16. +79
    -0
      STM32/Core/Inc/defs.h
  17. +84
    -0
      STM32/Core/Inc/main.h
  18. +352
    -0
      STM32/Core/Inc/stm32g0xx_hal_conf.h
  19. +69
    -0
      STM32/Core/Inc/stm32g0xx_it.h
  20. +69
    -0
      STM32/Core/Inc/types.h
  21. +293
    -0
      STM32/Core/Src/SX1278.c
  22. +60
    -0
      STM32/Core/Src/SX1278_hw.c
  23. +280
    -0
      STM32/Core/Src/arduinoFFT.cpp
  24. +1135
    -0
      STM32/Core/Src/main.cpp
  25. +550
    -0
      STM32/Core/Src/stm32g0xx_hal_msp.c
  26. +208
    -0
      STM32/Core/Src/stm32g0xx_it.c
  27. +159
    -0
      STM32/Core/Src/syscalls.c
  28. +80
    -0
      STM32/Core/Src/sysmem.c
  29. +290
    -0
      STM32/Core/Src/system_stm32g0xx.c
  30. +271
    -0
      STM32/noise_sensor.ioc

+ 1
- 0
Arduino

@@ -0,0 +1 @@
Subproject commit c12eaf2651eb6cc169811b1f17a2870c3a3076f2

+ 1
- 0
ESP32

@@ -0,0 +1 @@
Subproject commit 1966efbfbdb31c02db904cc2ced81cf7de6e8958

+ 2864
- 0
KiCad/noise_sensor.kicad_pcb
File diff suppressed because it is too large
View File


+ 248
- 0
KiCad/noise_sensor.pro View File

@@ -0,0 +1,248 @@
update=Wed 24 Feb 2021 09:56:57 PM CET
version=1
last_client=kicad
[general]
version=1
RootSch=
BoardNm=
[cvpcb]
version=1
NetIExt=net
[eeschema]
version=1
LibDir=
[eeschema/libraries]
[pcbnew]
version=1
PageLayoutDescrFile=
LastNetListRead=masterarbeit.net
CopperLayerCount=2
BoardThickness=1.6
AllowMicroVias=0
AllowBlindVias=0
RequireCourtyardDefinitions=0
ProhibitOverlappingCourtyards=1
MinTrackWidth=0.2
MinViaDiameter=0.4
MinViaDrill=0.3
MinMicroViaDiameter=0.2
MinMicroViaDrill=0.09999999999999999
MinHoleToHole=0.25
TrackWidth1=0.25
ViaDiameter1=0.8
ViaDrill1=0.4
dPairWidth1=0.2
dPairGap1=0.25
dPairViaGap1=0.25
SilkLineWidth=0.12
SilkTextSizeV=1
SilkTextSizeH=1
SilkTextSizeThickness=0.15
SilkTextItalic=0
SilkTextUpright=1
CopperLineWidth=0.2
CopperTextSizeV=1.5
CopperTextSizeH=1.5
CopperTextThickness=0.3
CopperTextItalic=0
CopperTextUpright=1
EdgeCutLineWidth=0.05
CourtyardLineWidth=0.05
OthersLineWidth=0.15
OthersTextSizeV=1
OthersTextSizeH=1
OthersTextSizeThickness=0.15
OthersTextItalic=0
OthersTextUpright=1
SolderMaskClearance=0
SolderMaskMinWidth=0
SolderPasteClearance=0
SolderPasteRatio=0
[pcbnew/Layer.F.Cu]
Name=F.Cu
Type=0
Enabled=1
[pcbnew/Layer.In1.Cu]
Name=In1.Cu
Type=0
Enabled=0
[pcbnew/Layer.In2.Cu]
Name=In2.Cu
Type=0
Enabled=0
[pcbnew/Layer.In3.Cu]
Name=In3.Cu
Type=0
Enabled=0
[pcbnew/Layer.In4.Cu]
Name=In4.Cu
Type=0
Enabled=0
[pcbnew/Layer.In5.Cu]
Name=In5.Cu
Type=0
Enabled=0
[pcbnew/Layer.In6.Cu]
Name=In6.Cu
Type=0
Enabled=0
[pcbnew/Layer.In7.Cu]
Name=In7.Cu
Type=0
Enabled=0
[pcbnew/Layer.In8.Cu]
Name=In8.Cu
Type=0
Enabled=0
[pcbnew/Layer.In9.Cu]
Name=In9.Cu
Type=0
Enabled=0
[pcbnew/Layer.In10.Cu]
Name=In10.Cu
Type=0
Enabled=0
[pcbnew/Layer.In11.Cu]
Name=In11.Cu
Type=0
Enabled=0
[pcbnew/Layer.In12.Cu]
Name=In12.Cu
Type=0
Enabled=0
[pcbnew/Layer.In13.Cu]
Name=In13.Cu
Type=0
Enabled=0
[pcbnew/Layer.In14.Cu]
Name=In14.Cu
Type=0
Enabled=0
[pcbnew/Layer.In15.Cu]
Name=In15.Cu
Type=0
Enabled=0
[pcbnew/Layer.In16.Cu]
Name=In16.Cu
Type=0
Enabled=0
[pcbnew/Layer.In17.Cu]
Name=In17.Cu
Type=0
Enabled=0
[pcbnew/Layer.In18.Cu]
Name=In18.Cu
Type=0
Enabled=0
[pcbnew/Layer.In19.Cu]
Name=In19.Cu
Type=0
Enabled=0
[pcbnew/Layer.In20.Cu]
Name=In20.Cu
Type=0
Enabled=0
[pcbnew/Layer.In21.Cu]
Name=In21.Cu
Type=0
Enabled=0
[pcbnew/Layer.In22.Cu]
Name=In22.Cu
Type=0
Enabled=0
[pcbnew/Layer.In23.Cu]
Name=In23.Cu
Type=0
Enabled=0
[pcbnew/Layer.In24.Cu]
Name=In24.Cu
Type=0
Enabled=0
[pcbnew/Layer.In25.Cu]
Name=In25.Cu
Type=0
Enabled=0
[pcbnew/Layer.In26.Cu]
Name=In26.Cu
Type=0
Enabled=0
[pcbnew/Layer.In27.Cu]
Name=In27.Cu
Type=0
Enabled=0
[pcbnew/Layer.In28.Cu]
Name=In28.Cu
Type=0
Enabled=0
[pcbnew/Layer.In29.Cu]
Name=In29.Cu
Type=0
Enabled=0
[pcbnew/Layer.In30.Cu]
Name=In30.Cu
Type=0
Enabled=0
[pcbnew/Layer.B.Cu]
Name=B.Cu
Type=0
Enabled=1
[pcbnew/Layer.B.Adhes]
Enabled=1
[pcbnew/Layer.F.Adhes]
Enabled=1
[pcbnew/Layer.B.Paste]
Enabled=1
[pcbnew/Layer.F.Paste]
Enabled=1
[pcbnew/Layer.B.SilkS]
Enabled=1
[pcbnew/Layer.F.SilkS]
Enabled=1
[pcbnew/Layer.B.Mask]
Enabled=1
[pcbnew/Layer.F.Mask]
Enabled=1
[pcbnew/Layer.Dwgs.User]
Enabled=1
[pcbnew/Layer.Cmts.User]
Enabled=1
[pcbnew/Layer.Eco1.User]
Enabled=1
[pcbnew/Layer.Eco2.User]
Enabled=1
[pcbnew/Layer.Edge.Cuts]
Enabled=1
[pcbnew/Layer.Margin]
Enabled=1
[pcbnew/Layer.B.CrtYd]
Enabled=1
[pcbnew/Layer.F.CrtYd]
Enabled=1
[pcbnew/Layer.B.Fab]
Enabled=1
[pcbnew/Layer.F.Fab]
Enabled=1
[pcbnew/Layer.Rescue]
Enabled=1
[pcbnew/Netclasses]
[pcbnew/Netclasses/Default]
Name=Default
Clearance=0.2
TrackWidth=0.25
ViaDiameter=0.8
ViaDrill=0.4
uViaDiameter=0.3
uViaDrill=0.1
dPairWidth=0.2
dPairGap=0.25
dPairViaGap=0.25
[schematic_editor]
version=1
PageLayoutDescrFile=
PlotDirectoryName=
SubpartIdSeparator=0
SubpartFirstId=65
NetFmtName=Pcbnew
SpiceAjustPassiveValues=0
LabSize=50
ERC_TestSimilarLabels=1

+ 870
- 0
KiCad/noise_sensor.sch View File

@@ -0,0 +1,870 @@
EESchema Schematic File Version 4
EELAYER 30 0
EELAYER END
$Descr A4 11693 8268
encoding utf-8
Sheet 1 1
Title ""
Date ""
Rev ""
Comp ""
Comment1 ""
Comment2 ""
Comment3 ""
Comment4 ""
$EndDescr
$Comp
L RF_Module:RFM95W-868S2 U2
U 1 1 5FF4BB32
P 9850 2050
F 0 "U2" H 10250 2650 50 0000 C CNN
F 1 "RFM95W-868S2" H 10250 2550 50 0000 C CNN
F 2 "masterarbeit:HOPERF_RFM9XW_SMD_Castellated" H 6550 3700 50 0001 C CNN
F 3 "https://www.hoperf.com/data/upload/portal/20181127/5bfcbea20e9ef.pdf" H 6550 3700 50 0001 C CNN
1 9850 2050
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR0102
U 1 1 5FF4FCA4
P 5700 4550
F 0 "#PWR0102" H 5700 4300 50 0001 C CNN
F 1 "GND" H 5705 4377 50 0000 C CNN
F 2 "" H 5700 4550 50 0001 C CNN
F 3 "" H 5700 4550 50 0001 C CNN
1 5700 4550
1 0 0 -1
$EndComp
Text GLabel 5000 2750 0 50 Input ~ 0
RX
Text GLabel 5000 2650 0 50 Input ~ 0
TX
Text GLabel 5000 4050 0 50 Input ~ 0
SWCLK
Text GLabel 5000 3950 0 50 Input ~ 0
SWDIO
Text GLabel 5000 3850 0 50 Input ~ 0
SDA
Text GLabel 5000 3750 0 50 Input ~ 0
SCL
Text GLabel 5000 4150 0 50 Input ~ 0
LRCL_WS
Text GLabel 6400 3150 2 50 Input ~ 0
DOUT
Text GLabel 6400 2950 2 50 Input ~ 0
BCLK
Text GLabel 5000 3050 0 50 Input ~ 0
MOSI
Text GLabel 5000 3150 0 50 Input ~ 0
SPI_NSS
Text GLabel 5000 2950 0 50 Input ~ 0
MISO
Text GLabel 6400 2650 2 50 Input ~ 0
DIO0
Text GLabel 5000 3250 0 50 Input ~ 0
LED1
Text GLabel 6400 3450 2 50 Input ~ 0
SCK
Text GLabel 5000 3350 0 50 Input ~ 0
SPI_RESET
Text GLabel 9350 2250 0 50 Input ~ 0
SPI_RESET
Text GLabel 9350 2050 0 50 Input ~ 0
SPI_NSS
Text GLabel 9350 1950 0 50 Input ~ 0
MISO
Text GLabel 9350 1850 0 50 Input ~ 0
MOSI
Text GLabel 9350 1750 0 50 Input ~ 0
SCK
Text GLabel 10350 2450 2 50 Input ~ 0
DIO0
$Comp
L power:+3V3 #PWR0103
U 1 1 5FF567B1
P 9850 800
F 0 "#PWR0103" H 9850 650 50 0001 C CNN
F 1 "+3V3" H 9865 973 50 0000 C CNN
F 2 "" H 9850 800 50 0001 C CNN
F 3 "" H 9850 800 50 0001 C CNN
1 9850 800
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR0104
U 1 1 5FF56D78
P 9850 2800
F 0 "#PWR0104" H 9850 2550 50 0001 C CNN
F 1 "GND" H 9855 2627 50 0000 C CNN
F 2 "" H 9850 2800 50 0001 C CNN
F 3 "" H 9850 2800 50 0001 C CNN
1 9850 2800
1 0 0 -1
$EndComp
Wire Wire Line
9750 2650 9750 2800
Wire Wire Line
9750 2800 9850 2800
Wire Wire Line
9950 2650 9950 2800
Wire Wire Line
9950 2800 9850 2800
Connection ~ 9850 2800
Wire Wire Line
9850 2650 9850 2800
$Comp
L Device:LED D1
U 1 1 5FF59892
P 2850 3700
F 0 "D1" H 2843 3917 50 0000 C CNN
F 1 "LED" H 2843 3826 50 0000 C CNN
F 2 "LED_THT:LED_D3.0mm" H 2850 3700 50 0001 C CNN
F 3 "~" H 2850 3700 50 0001 C CNN
1 2850 3700
1 0 0 -1
$EndComp
$Comp
L Device:R R3
U 1 1 5FF5B2E5
P 3150 3700
F 0 "R3" V 2943 3700 50 0000 C CNN
F 1 "480R" V 3034 3700 50 0000 C CNN
F 2 "Resistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolder" V 3080 3700 50 0001 C CNN
F 3 "~" H 3150 3700 50 0001 C CNN
1 3150 3700
0 1 1 0
$EndComp
$Comp
L power:GND #PWR0107
U 1 1 5FF5DFEA
P 2400 3700
F 0 "#PWR0107" H 2400 3450 50 0001 C CNN
F 1 "GND" H 2405 3527 50 0000 C CNN
F 2 "" H 2400 3700 50 0001 C CNN
F 3 "" H 2400 3700 50 0001 C CNN
1 2400 3700
1 0 0 -1
$EndComp
Wire Wire Line
2700 3700 2400 3700
Text GLabel 3300 3700 2 50 Input ~ 0
LED1
$Comp
L Connector_Generic:Conn_02x03_Odd_Even J1
U 1 1 5FF594B6
P 10000 5350
F 0 "J1" H 10050 5667 50 0000 C CNN
F 1 "Debug/USART" H 10050 5576 50 0000 C CNN
F 2 "Connector_PinHeader_2.54mm:PinHeader_2x03_P2.54mm_Vertical" H 10000 5350 50 0001 C CNN
F 3 "~" H 10000 5350 50 0001 C CNN
1 10000 5350
1 0 0 -1
$EndComp
$Comp
L Jumper:Jumper_2_Open JP1
U 1 1 5FF5D896
P 2950 3250
F 0 "JP1" H 2950 3485 50 0000 C CNN
F 1 "Jumper_2_Open" H 2950 3394 50 0000 C CNN
F 2 "Jumper:SolderJumper-2_P1.3mm_Open_RoundedPad1.0x1.5mm" H 2950 3250 50 0001 C CNN
F 3 "~" H 2950 3250 50 0001 C CNN
1 2950 3250
1 0 0 -1
$EndComp
$Comp
L power:+3V3 #PWR04
U 1 1 5FF6967E
P 9350 5250
F 0 "#PWR04" H 9350 5100 50 0001 C CNN
F 1 "+3V3" H 9365 5423 50 0000 C CNN
F 2 "" H 9350 5250 50 0001 C CNN
F 3 "" H 9350 5250 50 0001 C CNN
1 9350 5250
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR05
U 1 1 5FF6AAAA
P 9350 5350
F 0 "#PWR05" H 9350 5100 50 0001 C CNN
F 1 "GND" H 9355 5177 50 0000 C CNN
F 2 "" H 9350 5350 50 0001 C CNN
F 3 "" H 9350 5350 50 0001 C CNN
1 9350 5350
1 0 0 -1
$EndComp
Wire Wire Line
9350 5250 9800 5250
Wire Wire Line
9350 5350 9800 5350
Text GLabel 10300 5450 2 50 Input ~ 0
SWCLK
Text GLabel 9800 5450 0 50 Input ~ 0
SWDIO
Text GLabel 10300 5350 2 50 Input ~ 0
TX
Text GLabel 10300 5250 2 50 Input ~ 0
RX
Text GLabel 6400 3750 2 50 Input ~ 0
I²C-ADDRESS
Text GLabel 3150 3250 2 50 Input ~ 0
I²C-ADDRESS
Wire Wire Line
2750 3250 2500 3250
Wire Wire Line
7000 5400 6750 5400
Wire Wire Line
7000 5250 6750 5250
$Comp
L power:GND #PWR06
U 1 1 5FFA14A5
P 9050 4450
F 0 "#PWR06" H 9050 4200 50 0001 C CNN
F 1 "GND" H 9055 4277 50 0000 C CNN
F 2 "" H 9050 4450 50 0001 C CNN
F 3 "" H 9050 4450 50 0001 C CNN
1 9050 4450
1 0 0 -1
$EndComp
$Comp
L power:+3V3 #PWR07
U 1 1 5FFA26C5
P 10550 4150
F 0 "#PWR07" H 10550 4000 50 0001 C CNN
F 1 "+3V3" H 10565 4323 50 0000 C CNN
F 2 "" H 10550 4150 50 0001 C CNN
F 3 "" H 10550 4150 50 0001 C CNN
1 10550 4150
1 0 0 -1
$EndComp
$Comp
L Connector_Generic:Conn_01x04 J3
U 1 1 5FFACF3F
P 7800 3150
F 0 "J3" H 7718 2725 50 0000 C CNN
F 1 "I²C IN" H 7718 2816 50 0000 C CNN
F 2 "Connector_JST:JST_PH_B4B-PH-SM4-TB_1x04-1MP_P2.00mm_Vertical" H 7800 3150 50 0001 C CNN
F 3 "~" H 7800 3150 50 0001 C CNN
1 7800 3150
-1 0 0 1
$EndComp
$Comp
L power:GND #PWR012
U 1 1 5FFBDD82
P 8300 3250
F 0 "#PWR012" H 8300 3000 50 0001 C CNN
F 1 "GND" H 8305 3077 50 0000 C CNN
F 2 "" H 8300 3250 50 0001 C CNN
F 3 "" H 8300 3250 50 0001 C CNN
1 8300 3250
1 0 0 -1
$EndComp
Wire Wire Line
8000 3250 8300 3250
$Comp
L Device:R R1
U 1 1 5FFC59E5
P 8200 2750
F 0 "R1" H 8270 2796 50 0000 L CNN
F 1 "4k7" H 8270 2705 50 0000 L CNN
F 2 "Resistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolder" V 8130 2750 50 0001 C CNN
F 3 "~" H 8200 2750 50 0001 C CNN
1 8200 2750
1 0 0 -1
$EndComp
$Comp
L power:+3V3 #PWR011
U 1 1 5FFC76F6
P 8200 2600
F 0 "#PWR011" H 8200 2450 50 0001 C CNN
F 1 "+3V3" H 8215 2773 50 0000 C CNN
F 2 "" H 8200 2600 50 0001 C CNN
F 3 "" H 8200 2600 50 0001 C CNN
1 8200 2600
1 0 0 -1
$EndComp
$Comp
L power:+3V3 #PWR013
U 1 1 5FFC7E83
P 8600 2750
F 0 "#PWR013" H 8600 2600 50 0001 C CNN
F 1 "+3V3" H 8615 2923 50 0000 C CNN
F 2 "" H 8600 2750 50 0001 C CNN
F 3 "" H 8600 2750 50 0001 C CNN
1 8600 2750
1 0 0 -1
$EndComp
Text GLabel 8300 2950 2 50 Input ~ 0
SCL
Wire Wire Line
8000 2950 8200 2950
Wire Wire Line
8200 2950 8200 2900
Wire Wire Line
8000 3050 8600 3050
Wire Wire Line
8200 2950 8300 2950
Connection ~ 8200 2950
$Comp
L Device:R R2
U 1 1 5FFDE894
P 8600 2900
F 0 "R2" H 8670 2946 50 0000 L CNN
F 1 "4k7" H 8670 2855 50 0000 L CNN
F 2 "Resistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolder" V 8530 2900 50 0001 C CNN
F 3 "~" H 8600 2900 50 0001 C CNN
1 8600 2900
1 0 0 -1
$EndComp
Text GLabel 8750 3050 2 50 Input ~ 0
SDA
Wire Wire Line
8600 3050 8750 3050
Connection ~ 8600 3050
Wire Wire Line
8000 3150 9050 3150
$Comp
L power:+5V #PWR014
U 1 1 5FFE92DB
P 9050 3150
F 0 "#PWR014" H 9050 3000 50 0001 C CNN
F 1 "+5V" H 9065 3323 50 0000 C CNN
F 2 "" H 9050 3150 50 0001 C CNN
F 3 "" H 9050 3150 50 0001 C CNN
1 9050 3150
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR017
U 1 1 600498C3
P 7000 5400
F 0 "#PWR017" H 7000 5150 50 0001 C CNN
F 1 "GND" H 7005 5227 50 0000 C CNN
F 2 "" H 7000 5400 50 0001 C CNN
F 3 "" H 7000 5400 50 0001 C CNN
1 7000 5400
1 0 0 -1
$EndComp
$Comp
L power:+BATT #PWR016
U 1 1 6004B1B0
P 7000 5250
F 0 "#PWR016" H 7000 5100 50 0001 C CNN
F 1 "+BATT" H 7015 5423 50 0000 C CNN
F 2 "" H 7000 5250 50 0001 C CNN
F 3 "" H 7000 5250 50 0001 C CNN
1 7000 5250
1 0 0 -1
$EndComp
$Comp
L masterarbeit-rescue:STM32G071KxT-STM32G0 U4
U 1 1 6007BB38
P 5700 3450
F 0 "U4" H 6250 4650 50 0000 C CNN
F 1 "STM32G071KxT" H 6050 4550 50 0000 C CNN
F 2 "Package_QFP:LQFP-32_7x7mm_P0.8mm" H 5600 2400 50 0001 R CNN
F 3 "https://www.st.com/resource/en/datasheet/stm32g071kb.pdf" H 5700 3450 50 0001 C CNN
1 5700 3450
1 0 0 -1
$EndComp
$Comp
L power:+3V3 #PWR02
U 1 1 600941E8
P 2050 1700
F 0 "#PWR02" H 2050 1550 50 0001 C CNN
F 1 "+3V3" H 2065 1873 50 0000 C CNN
F 2 "" H 2050 1700 50 0001 C CNN
F 3 "" H 2050 1700 50 0001 C CNN
1 2050 1700
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR08
U 1 1 60094D04
P 2050 2600
F 0 "#PWR08" H 2050 2350 50 0001 C CNN
F 1 "GND" H 2055 2427 50 0000 C CNN
F 2 "" H 2050 2600 50 0001 C CNN
F 3 "" H 2050 2600 50 0001 C CNN
1 2050 2600
1 0 0 -1
$EndComp
$Comp
L Device:R R4
U 1 1 6009A5CC
P 2050 2000
F 0 "R4" V 1843 2000 50 0000 C CNN
F 1 "?R" V 1934 2000 50 0000 C CNN
F 2 "Resistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolder" V 1980 2000 50 0001 C CNN
F 3 "~" H 2050 2000 50 0001 C CNN
1 2050 2000
-1 0 0 1
$EndComp
$Comp
L Device:R R5
U 1 1 600A5EBF
P 2050 2300
F 0 "R5" V 1843 2300 50 0000 C CNN
F 1 "?R" V 1934 2300 50 0000 C CNN
F 2 "Resistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolder" V 1980 2300 50 0001 C CNN
F 3 "~" H 2050 2300 50 0001 C CNN
1 2050 2300
-1 0 0 1
$EndComp
Wire Wire Line
2050 1700 2050 1850
Wire Wire Line
2050 2450 2050 2600
Text GLabel 2350 2150 2 50 Input ~ 0
DEVICE_ID
Wire Wire Line
2350 2150 2050 2150
Connection ~ 2050 2150
$Comp
L Connector_Generic:Conn_01x05 J4
U 1 1 600AF8B5
P 7000 1450
F 0 "J4" H 7080 1492 50 0000 L CNN
F 1 "Microphone Connector" H 7080 1401 50 0000 L CNN
F 2 "Connector_PinSocket_2.54mm:PinSocket_1x05_P2.54mm_Vertical" H 7000 1450 50 0001 C CNN
F 3 "~" H 7000 1450 50 0001 C CNN
1 7000 1450
1 0 0 -1
$EndComp
Text GLabel 6800 1550 0 50 Input ~ 0
DOUT
$Comp
L power:+3V3 #PWR09
U 1 1 600B8034
P 6250 1250
F 0 "#PWR09" H 6250 1100 50 0001 C CNN
F 1 "+3V3" H 6265 1423 50 0000 C CNN
F 2 "" H 6250 1250 50 0001 C CNN
F 3 "" H 6250 1250 50 0001 C CNN
1 6250 1250
1 0 0 -1
$EndComp
Text GLabel 6800 1650 0 50 Input ~ 0
LRCL_WS
Text GLabel 6800 1450 0 50 Input ~ 0
BCLK
$Comp
L power:GND #PWR015
U 1 1 600BB656
P 6250 1350
F 0 "#PWR015" H 6250 1100 50 0001 C CNN
F 1 "GND" H 6255 1177 50 0000 C CNN
F 2 "" H 6250 1350 50 0001 C CNN
F 3 "" H 6250 1350 50 0001 C CNN
1 6250 1350
1 0 0 -1
$EndComp
Wire Wire Line
6250 1250 6800 1250
Wire Wire Line
6250 1350 6800 1350
$Comp
L power:GND #PWR01
U 1 1 600F4120
P 2500 3250
F 0 "#PWR01" H 2500 3000 50 0001 C CNN
F 1 "GND" H 2505 3077 50 0000 C CNN
F 2 "" H 2500 3250 50 0001 C CNN
F 3 "" H 2500 3250 50 0001 C CNN
1 2500 3250
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR019
U 1 1 601233C9
P 3350 2600
F 0 "#PWR019" H 3350 2350 50 0001 C CNN
F 1 "GND" H 3355 2427 50 0000 C CNN
F 2 "" H 3350 2600 50 0001 C CNN
F 3 "" H 3350 2600 50 0001 C CNN
1 3350 2600
1 0 0 -1
$EndComp
$Comp
L Device:R R6
U 1 1 601233D3
P 3350 2000
F 0 "R6" V 3143 2000 50 0000 C CNN
F 1 "?R" V 3234 2000 50 0000 C CNN
F 2 "Resistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolder" V 3280 2000 50 0001 C CNN
F 3 "~" H 3350 2000 50 0001 C CNN
1 3350 2000
-1 0 0 1
$EndComp
$Comp
L Device:R R7
U 1 1 601233DD
P 3350 2300
F 0 "R7" V 3143 2300 50 0000 C CNN
F 1 "?R" V 3234 2300 50 0000 C CNN
F 2 "Resistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolder" V 3280 2300 50 0001 C CNN
F 3 "~" H 3350 2300 50 0001 C CNN
1 3350 2300
-1 0 0 1
$EndComp
Wire Wire Line
3350 1700 3350 1850
Wire Wire Line
3350 2450 3350 2600
Wire Wire Line
3650 2150 3350 2150
Connection ~ 3350 2150
Text GLabel 3650 2150 2 50 Input ~ 0
BATT_SENSE
$Comp
L power:+BATT #PWR018
U 1 1 6012E3E3
P 3350 1700
F 0 "#PWR018" H 3350 1550 50 0001 C CNN
F 1 "+BATT" H 3365 1873 50 0000 C CNN
F 2 "" H 3350 1700 50 0001 C CNN
F 3 "" H 3350 1700 50 0001 C CNN
1 3350 1700
1 0 0 -1
$EndComp
Text GLabel 5000 2850 0 50 Input ~ 0
DEVICE_ID
Text GLabel 6400 2750 2 50 Input ~ 0
BATT_SENSE
$Comp
L Connector_Generic:Conn_01x01 J2
U 1 1 601E388E
P 6550 5250
F 0 "J2" H 6468 5025 50 0000 C CNN
F 1 "Conn_01x01" H 6468 5116 50 0000 C CNN
F 2 "Connector_Wire:SolderWirePad_1x01_SMD_1x2mm" H 6550 5250 50 0001 C CNN
F 3 "~" H 6550 5250 50 0001 C CNN
1 6550 5250
-1 0 0 1
$EndComp
$Comp
L Connector_Generic:Conn_01x01 J5
U 1 1 601E3EB3
P 6550 5400
F 0 "J5" H 6550 5600 50 0000 C CNN
F 1 "Conn_01x01" H 6550 5500 50 0000 C CNN
F 2 "Connector_Wire:SolderWirePad_1x01_SMD_1x2mm" H 6550 5400 50 0001 C CNN
F 3 "~" H 6550 5400 50 0001 C CNN
1 6550 5400
-1 0 0 1
$EndComp
$Comp
L Regulator_Linear:L78L33_TO92 U1
U 1 1 600FF264
P 9050 4150
F 0 "U1" H 9050 4392 50 0000 C CNN
F 1 "L78L33_TO92" H 9050 4301 50 0000 C CNN
F 2 "Package_TO_SOT_THT:TO-92_Inline" H 9050 4375 50 0001 C CIN
F 3 "http://www.st.com/content/ccc/resource/technical/document/datasheet/15/55/e5/aa/23/5b/43/fd/CD00000446.pdf/files/CD00000446.pdf/jcr:content/translations/en.CD00000446.pdf" H 9050 4100 50 0001 C CNN
1 9050 4150
1 0 0 -1
$EndComp
$Comp
L Connector_Generic:Conn_01x01 J6
U 1 1 60111880
P 10550 1750
F 0 "J6" H 10630 1792 50 0000 L CNN
F 1 "Conn_01x01" H 10630 1701 50 0000 L CNN
F 2 "Connector_PinSocket_2.54mm:PinSocket_1x01_P2.54mm_Vertical" H 10550 1750 50 0001 C CNN
F 3 "~" H 10550 1750 50 0001 C CNN
1 10550 1750
1 0 0 -1
$EndComp
$Comp
L power:+3V3 #PWR010
U 1 1 60190E33
P 5700 1300
F 0 "#PWR010" H 5700 1150 50 0001 C CNN
F 1 "+3V3" H 5715 1473 50 0000 C CNN
F 2 "" H 5700 1300 50 0001 C CNN
F 3 "" H 5700 1300 50 0001 C CNN
1 5700 1300
1 0 0 -1
$EndComp
$Comp
L Device:C_Small C4
U 1 1 601CF5F2
P 8450 4250
F 0 "C4" H 8542 4296 50 0000 L CNN
F 1 "100nF" H 8542 4205 50 0000 L CNN
F 2 "Capacitor_SMD:C_1206_3216Metric_Pad1.33x1.80mm_HandSolder" H 8450 4250 50 0001 C CNN
F 3 "~" H 8450 4250 50 0001 C CNN
1 8450 4250
1 0 0 -1
$EndComp
$Comp
L Device:C_Small C3
U 1 1 601CF5F8
P 8050 4250
F 0 "C3" H 8142 4296 50 0000 L CNN
F 1 "4.7µF" H 8142 4205 50 0000 L CNN
F 2 "Capacitor_SMD:C_1206_3216Metric_Pad1.33x1.80mm_HandSolder" H 8050 4250 50 0001 C CNN
F 3 "~" H 8050 4250 50 0001 C CNN
1 8050 4250
1 0 0 -1
$EndComp
$Comp
L Device:C_Small C6
U 1 1 601E7ABB
P 9600 950
F 0 "C6" V 9371 950 50 0000 C CNN
F 1 "4.7µF" V 9462 950 50 0000 C CNN
F 2 "Capacitor_SMD:C_1206_3216Metric_Pad1.33x1.80mm_HandSolder" H 9600 950 50 0001 C CNN
F 3 "~" H 9600 950 50 0001 C CNN
1 9600 950
0 1 1 0
$EndComp
$Comp
L Device:C_Small C7
U 1 1 601EC4C2
P 9600 1350
F 0 "C7" V 9371 1350 50 0000 C CNN
F 1 "100nF" V 9462 1350 50 0000 C CNN
F 2 "Capacitor_SMD:C_1206_3216Metric_Pad1.33x1.80mm_HandSolder" H 9600 1350 50 0001 C CNN
F 3 "~" H 9600 1350 50 0001 C CNN
1 9600 1350
0 1 1 0
$EndComp
Wire Wire Line
9350 1350 9500 1350
Wire Wire Line
9850 1350 9850 1550
$Comp
L power:GND #PWR024
U 1 1 601EF438
P 9350 1450
F 0 "#PWR024" H 9350 1200 50 0001 C CNN
F 1 "GND" H 9355 1277 50 0000 C CNN
F 2 "" H 9350 1450 50 0001 C CNN
F 3 "" H 9350 1450 50 0001 C CNN
1 9350 1450
1 0 0 -1
$EndComp
Wire Wire Line
9350 1350 9350 1450
Connection ~ 9350 1350
Wire Wire Line
9500 950 9350 950
Wire Wire Line
9350 950 9350 1350
Wire Wire Line
9700 950 9850 950
Wire Wire Line
9850 950 9850 800
Wire Wire Line
9850 1350 9700 1350
Wire Wire Line
9850 1350 9850 950
Connection ~ 9850 1350
Connection ~ 9850 950
$Comp
L Device:C_Small C8
U 1 1 601D17B5
P 10000 4250
F 0 "C8" H 10092 4296 50 0000 L CNN
F 1 "4.7µF" H 10092 4205 50 0000 L CNN
F 2 "Capacitor_SMD:C_1206_3216Metric_Pad1.33x1.80mm_HandSolder" H 10000 4250 50 0001 C CNN
F 3 "~" H 10000 4250 50 0001 C CNN
1 10000 4250
1 0 0 -1
$EndComp
$Comp
L Device:C_Small C5
U 1 1 601D17AF
P 9550 4250
F 0 "C5" H 9642 4296 50 0000 L CNN
F 1 "100nF" H 9642 4205 50 0000 L CNN
F 2 "Capacitor_SMD:C_1206_3216Metric_Pad1.33x1.80mm_HandSolder" H 9550 4250 50 0001 C CNN
F 3 "~" H 9550 4250 50 0001 C CNN
1 9550 4250
1 0 0 -1
$EndComp
Wire Wire Line
9350 4150 9550 4150
Connection ~ 9550 4150
Wire Wire Line
9550 4150 10000 4150
Connection ~ 10000 4150
Wire Wire Line
10000 4150 10550 4150
$Comp
L power:GND #PWR025
U 1 1 602799D7
P 9550 4350
F 0 "#PWR025" H 9550 4100 50 0001 C CNN
F 1 "GND" H 9555 4177 50 0000 C CNN
F 2 "" H 9550 4350 50 0001 C CNN
F 3 "" H 9550 4350 50 0001 C CNN
1 9550 4350
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR026
U 1 1 60279F5C
P 10000 4350
F 0 "#PWR026" H 10000 4100 50 0001 C CNN
F 1 "GND" H 10005 4177 50 0000 C CNN
F 2 "" H 10000 4350 50 0001 C CNN
F 3 "" H 10000 4350 50 0001 C CNN
1 10000 4350
1 0 0 -1
$EndComp
Wire Wire Line
8750 4150 8450 4150
Connection ~ 8450 4150
$Comp
L power:+BATT #PWR020
U 1 1 60296798
P 7650 4150
F 0 "#PWR020" H 7650 4000 50 0001 C CNN
F 1 "+BATT" H 7665 4323 50 0000 C CNN
F 2 "" H 7650 4150 50 0001 C CNN
F 3 "" H 7650 4150 50 0001 C CNN
1 7650 4150
1 0 0 -1
$EndComp
$Comp
L power:+5V #PWR021
U 1 1 60297059
P 7900 4150
F 0 "#PWR021" H 7900 4000 50 0001 C CNN
F 1 "+5V" H 7915 4323 50 0000 C CNN
F 2 "" H 7900 4150 50 0001 C CNN
F 3 "" H 7900 4150 50 0001 C CNN
1 7900 4150
1 0 0 -1
$EndComp
Wire Wire Line
8050 4150 8450 4150
Wire Wire Line
8050 4150 7900 4150
Connection ~ 8050 4150
Connection ~ 7900 4150
Wire Wire Line
7900 4150 7650 4150
$Comp
L power:GND #PWR022
U 1 1 6029A386
P 8050 4350
F 0 "#PWR022" H 8050 4100 50 0001 C CNN
F 1 "GND" H 8055 4177 50 0000 C CNN
F 2 "" H 8050 4350 50 0001 C CNN
F 3 "" H 8050 4350 50 0001 C CNN
1 8050 4350
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR023
U 1 1 6029A978
P 8450 4350
F 0 "#PWR023" H 8450 4100 50 0001 C CNN
F 1 "GND" H 8455 4177 50 0000 C CNN
F 2 "" H 8450 4350 50 0001 C CNN
F 3 "" H 8450 4350 50 0001 C CNN
1 8450 4350
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR03
U 1 1 602CBD63
P 5150 2000
F 0 "#PWR03" H 5150 1750 50 0001 C CNN
F 1 "GND" H 5155 1827 50 0000 C CNN
F 2 "" H 5150 2000 50 0001 C CNN
F 3 "" H 5150 2000 50 0001 C CNN
1 5150 2000
1 0 0 -1
$EndComp
Wire Wire Line
5150 1550 5150 1900
Wire Wire Line
5700 1300 5700 1550
$Comp
L Device:C_Small C1
U 1 1 602D3A6D
P 5450 1550
F 0 "C1" V 5221 1550 50 0000 C CNN
F 1 "4.7µF" V 5312 1550 50 0000 C CNN
F 2 "Capacitor_SMD:C_1206_3216Metric_Pad1.33x1.80mm_HandSolder" H 5450 1550 50 0001 C CNN
F 3 "~" H 5450 1550 50 0001 C CNN
1 5450 1550
0 1 1 0
$EndComp
$Comp
L Device:C_Small C2
U 1 1 602D6D94
P 5450 1900
F 0 "C2" V 5221 1900 50 0000 C CNN
F 1 "100nF" V 5312 1900 50 0000 C CNN
F 2 "Capacitor_SMD:C_1206_3216Metric_Pad1.33x1.80mm_HandSolder" H 5450 1900 50 0001 C CNN
F 3 "~" H 5450 1900 50 0001 C CNN
1 5450 1900
0 1 1 0
$EndComp
Wire Wire Line
5550 1550 5700 1550
Connection ~ 5700 1550
Wire Wire Line
5700 1550 5700 1900
Wire Wire Line
5550 1900 5700 1900
Connection ~ 5700 1900
Wire Wire Line
5700 1900 5700 2350
Wire Wire Line
5350 1550 5150 1550
Wire Wire Line
5350 1900 5150 1900
Connection ~ 5150 1900
Wire Wire Line
5150 1900 5150 2000
$Comp
L masterarbeit-rescue:B3U-1000P-dk_Tactile-Switches S1
U 1 1 60128DFA
P 6600 4150
F 0 "S1" H 6600 4447 60 0000 C CNN
F 1 "B3U-1000P" H 6600 4341 60 0000 C CNN
F 2 "digikey-footprints:Switch_Tactile_SMD_B3U-1000P" H 6800 4350 60 0001 L CNN
F 3 "https://omronfs.omron.com/en_US/ecb/products/pdf/en-b3u.pdf" H 6800 4450 60 0001 L CNN
F 4 "SW1020CT-ND" H 6800 4550 60 0001 L CNN "Digi-Key_PN"
F 5 "B3U-1000P" H 6800 4650 60 0001 L CNN "MPN"
F 6 "Switches" H 6800 4750 60 0001 L CNN "Category"
F 7 "Tactile Switches" H 6800 4850 60 0001 L CNN "Family"
F 8 "https://omronfs.omron.com/en_US/ecb/products/pdf/en-b3u.pdf" H 6800 4950 60 0001 L CNN "DK_Datasheet_Link"
F 9 "/product-detail/en/omron-electronics-inc-emc-div/B3U-1000P/SW1020CT-ND/1534357" H 6800 5050 60 0001 L CNN "DK_Detail_Page"
F 10 "SWITCH TACTILE SPST-NO 0.05A 12V" H 6800 5150 60 0001 L CNN "Description"
F 11 "Omron Electronics Inc-EMC Div" H 6800 5250 60 0001 L CNN "Manufacturer"
F 12 "Active" H 6800 5350 60 0001 L CNN "Status"
1 6600 4150
1 0 0 -1
$EndComp
Wire Wire Line
6800 4150 7200 4150
$Comp
L Device:R R8
U 1 1 6012EEB6
P 7200 4300
F 0 "R8" V 6993 4300 50 0000 C CNN
F 1 "1k" V 7084 4300 50 0000 C CNN
F 2 "Resistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolder" V 7130 4300 50 0001 C CNN
F 3 "~" H 7200 4300 50 0001 C CNN
1 7200 4300
-1 0 0 1
$EndComp
$Comp
L power:GND #PWR027
U 1 1 6012F7EF
P 7200 4450
F 0 "#PWR027" H 7200 4200 50 0001 C CNN
F 1 "GND" H 7205 4277 50 0000 C CNN
F 2 "" H 7200 4450 50 0001 C CNN
F 3 "" H 7200 4450 50 0001 C CNN
1 7200 4450
1 0 0 -1
$EndComp
$EndSCHEMATC

BIN
KiCad/pcb_3d.png View File

Before After
Width: 972  |  Height: 569  |  Size: 194 KiB

BIN
STL/master_bottom.stl View File


BIN
STL/master_complete.png View File

Before After
Width: 1573  |  Height: 883  |  Size: 77 KiB

BIN
STL/master_top.stl View File


BIN
STL/slave_bottom_v2.stl View File


BIN
STL/slave_top_v2.stl View File


+ 490
- 0
STM32/Core/Inc/SX1278.h View File

@@ -0,0 +1,490 @@
/**
* Author Wojciech Domski <Wojciech.Domski@gmail.com>
* www: www.Domski.pl
*
* work based on DORJI.COM sample code and
* https://github.com/realspinner/SX1278_LoRa
*/

#ifndef __SX1278_H__
#define __SX1278_H__

#include <stdint.h>
#include <stdbool.h>

#include <SX1278_hw.h>
#ifdef __cplusplus
extern "C" {
#endif

#define SX1278_MAX_PACKET 256
#define SX1278_DEFAULT_TIMEOUT 3000

/* RFM98 Internal registers Address */
/********************LoRa mode***************************/
#define LR_RegFifo 0x00
/* Common settings */
#define LR_RegOpMode 0x01
#define LR_RegFrMsb 0x06
#define LR_RegFrMid 0x07
#define LR_RegFrLsb 0x08
/* Tx settings */
#define LR_RegPaConfig 0x09
#define LR_RegPaRamp 0x0A
#define LR_RegOcp 0x0B
/* Rx settings */
#define LR_RegLna 0x0C
/* LoRa registers */
#define LR_RegFifoAddrPtr 0x0D
#define LR_RegFifoTxBaseAddr 0x0E
#define LR_RegFifoRxBaseAddr 0x0F
#define LR_RegFifoRxCurrentaddr 0x10
#define LR_RegIrqFlagsMask 0x11
#define LR_RegIrqFlags 0x12
#define LR_RegRxNbBytes 0x13
#define LR_RegRxHeaderCntValueMsb 0x14
#define LR_RegRxHeaderCntValueLsb 0x15
#define LR_RegRxPacketCntValueMsb 0x16
#define LR_RegRxPacketCntValueLsb 0x17
#define LR_RegModemStat 0x18
#define LR_RegPktSnrValue 0x19
#define LR_RegPktRssiValue 0x1A
#define LR_RegRssiValue 0x1B
#define LR_RegHopChannel 0x1C
#define LR_RegModemConfig1 0x1D
#define LR_RegModemConfig2 0x1E
#define LR_RegSymbTimeoutLsb 0x1F
#define LR_RegPreambleMsb 0x20
#define LR_RegPreambleLsb 0x21
#define LR_RegPayloadLength 0x22
#define LR_RegMaxPayloadLength 0x23
#define LR_RegHopPeriod 0x24
#define LR_RegFifoRxByteAddr 0x25
#define LR_RegModemConfig3 0x26
/* I/O settings */
#define REG_LR_DIOMAPPING1 0x40
#define REG_LR_DIOMAPPING2 0x41
/* Version */
#define REG_LR_VERSION 0x42
/* Additional settings */
#define REG_LR_PLLHOP 0x44
#define REG_LR_TCXO 0x4B
#define REG_LR_PADAC 0x4D
#define REG_LR_FORMERTEMP 0x5B
#define REG_LR_AGCREF 0x61
#define REG_LR_AGCTHRESH1 0x62
#define REG_LR_AGCTHRESH2 0x63
#define REG_LR_AGCTHRESH3 0x64

/********************FSK/ook mode***************************/
#define RegFIFO 0x00
#define RegOpMode 0x01
#define RegBitRateMsb 0x02
#define RegBitRateLsb 0x03
#define RegFdevMsb 0x04
#define RegFdevLsb 0x05
#define RegFreqMsb 0x06
#define RegFreqMid 0x07
#define RegFreqLsb 0x08
#define RegPaConfig 0x09
#define RegPaRamp 0x0a
#define RegOcp 0x0b
#define RegLna 0x0c
#define RegRxConfig 0x0d
#define RegRssiConfig 0x0e
#define RegRssiCollision 0x0f
#define RegRssiThresh 0x10
#define RegRssiValue 0x11
#define RegRxBw 0x12
#define RegAfcBw 0x13
#define RegOokPeak 0x14
#define RegOokFix 0x15
#define RegOokAvg 0x16
#define RegAfcFei 0x1a
#define RegAfcMsb 0x1b
#define RegAfcLsb 0x1c
#define RegFeiMsb 0x1d
#define RegFeiLsb 0x1e
#define RegPreambleDetect 0x1f
#define RegRxTimeout1 0x20
#define RegRxTimeout2 0x21
#define RegRxTimeout3 0x22
#define RegRxDelay 0x23
#define RegOsc 0x24
#define RegPreambleMsb 0x25
#define RegPreambleLsb 0x26
#define RegSyncConfig 0x27
#define RegSyncValue1 0x28
#define RegSyncValue2 0x29
#define RegSyncValue3 0x2a
#define RegSyncValue4 0x2b
#define RegSyncValue5 0x2c
#define RegSyncValue6 0x2d
#define RegSyncValue7 0x2e
#define RegSyncValue8 0x2f
#define RegPacketConfig1 0x30
#define RegPacketConfig2 0x31
#define RegPayloadLength 0x32
#define RegNodeAdrs 0x33
#define RegBroadcastAdrs 0x34
#define RegFifoThresh 0x35
#define RegSeqConfig1 0x36
#define RegSeqConfig2 0x37
#define RegTimerResol 0x38
#define RegTimer1Coef 0x39
#define RegSyncWord 0x39
#define RegTimer2Coef 0x3a
#define RegImageCal 0x3b
#define RegTemp 0x3c
#define RegLowBat 0x3d
#define RegIrqFlags1 0x3e
#define RegIrqFlags2 0x3f
#define RegDioMapping1 0x40
#define RegDioMapping2 0x41
#define RegVersion 0x42
#define RegPllHop 0x44
#define RegPaDac 0x4d
#define RegBitRateFrac 0x5d

/**********************************************************
**Parameter table define
**********************************************************/

#define SX1278_POWER_20DBM 0
#define SX1278_POWER_17DBM 1
#define SX1278_POWER_14DBM 2
#define SX1278_POWER_11DBM 3

static const uint8_t SX1278_Power[4] = { 0xFF, /* 20dbm */
0xFC, /* 17dbm */
0xF9, /* 14dbm */
0xF6, /* 11dbm */
};

#define SX1278_LORA_SF_6 0
#define SX1278_LORA_SF_7 1
#define SX1278_LORA_SF_8 2
#define SX1278_LORA_SF_9 3
#define SX1278_LORA_SF_10 4
#define SX1278_LORA_SF_11 5
#define SX1278_LORA_SF_12 6

static const uint8_t SX1278_SpreadFactor[7] = { 6, 7, 8, 9, 10, 11, 12 };

#define SX1278_LORA_BW_7_8KHZ 0
#define SX1278_LORA_BW_10_4KHZ 1
#define SX1278_LORA_BW_15_6KHZ 2
#define SX1278_LORA_BW_20_8KHZ 3
#define SX1278_LORA_BW_31_2KHZ 4
#define SX1278_LORA_BW_41_7KHZ 5
#define SX1278_LORA_BW_62_5KHZ 6
#define SX1278_LORA_BW_125KHZ 7
#define SX1278_LORA_BW_250KHZ 8
#define SX1278_LORA_BW_500KHZ 9

static const uint8_t SX1278_LoRaBandwidth[10] = { 0, /* 7.8KHz, */
1, /* 10.4KHz, */
2, /* 15.6KHz, */
3, /* 20.8KHz, */
4, /* 31.2KHz, */
5, /* 41.7KHz, */
6, /* 62.5KHz, */
7, /* 125.0KHz, */
8, /* 250.0KHz, */
9 /* 500.0KHz */
};

/* Coding rate */
#define SX1278_LORA_CR_4_5 0
#define SX1278_LORA_CR_4_6 1
#define SX1278_LORA_CR_4_7 2
#define SX1278_LORA_CR_4_8 3

static const uint8_t SX1278_CodingRate[4] = { 0x01, 0x02, 0x03, 0x04 };

/* CRC Enable */
#define SX1278_LORA_CRC_EN 0
#define SX1278_LORA_CRC_DIS 1

static const uint8_t SX1278_CRC_Sum[2] = { 0x01, 0x00 };

typedef enum _SX1278_STATUS {
SLEEP, STANDBY, TX, RX
} SX1278_Status_t;

typedef struct {
SX1278_hw_t *hw;

uint64_t frequency;
uint8_t power;
uint8_t LoRa_SF;
uint8_t LoRa_BW;
uint8_t LoRa_CR;
uint8_t LoRa_CRC_sum;
uint8_t packetLength;

SX1278_Status_t status;

uint8_t rxBuffer[SX1278_MAX_PACKET];
uint8_t readBytes;
} SX1278_t;

/**
* \brief Read byte from LoRa module
*
* Reads data from LoRa module from given address.
*
* \param[in] module Pointer to LoRa structure
* \param[in] addr Address from which data will be read
*
* \return Read data
*/
uint8_t SX1278_SPIRead(SX1278_t *module, uint8_t addr);

/**
* \brief Write byte to LoRa module
*
* Writes data to LoRa module under given address.
*
* \param[in] module Pointer to LoRa structure
* \param[in] addr Address under which data will be written
* \param[in] cmd Data to write
*/
void SX1278_SPIWrite(SX1278_t *module, uint8_t addr, uint8_t cmd);

/**
* \brief Read data from LoRa module
*
* Reads data from LoRa module from given address.
*
* \param[in] module Pointer to LoRa structure
* \param[in] addr Address from which data will be read
* \param[out] rxBuf Pointer to store read data
* \param[in] length Number of bytes to read
*/
void SX1278_SPIBurstRead(SX1278_t *module, uint8_t addr, uint8_t *rxBuf,
uint8_t length);

/**
* \brief Write data to LoRa module
*
* Writes data to LoRa module under given address.
*
* \param[in] module Pointer to LoRa structure
* \param[in] addr Address under which data will be written
* \param[in] txBuf Pointer to data
* \param[in] length Number of bytes to write
*/
void SX1278_SPIBurstWrite(SX1278_t *module, uint8_t addr, uint8_t *txBuf,
uint8_t length);

/**
* \brief Configure LoRa module
*
* Configure LoRa module according to parameters stored in
* module structure.
*
* \param[in] module Pointer to LoRa structure
*/
void SX1278_config(SX1278_t *module);

/**
* \brief Entry LoRa mode
*
* Module supports different operation mode.
* To use LoRa operation mode one has to enter this
* particular mode to transmit and receive data
* using LoRa.
*
* \param[in] module Pointer to LoRa structure
*/
void SX1278_entryLoRa(SX1278_t *module);

/**
* \brief Clear IRQ
*
* Clears interrupt flags.
*
* \param[in] module Pointer to LoRa structure
*/
void SX1278_clearLoRaIrq(SX1278_t *module);

/**
* \brief Entry reception mode
*
* Entry reception mode
*
* \param[in] module Pointer to LoRa structure
* \param[in] length Length of message to be received
* \param[in] timeout Timeout in [ms]
*
* \return 1 if entering reception mode
* 0 if timeout was exceeded
*/
int SX1278_LoRaEntryRx(SX1278_t *module, uint8_t length, uint32_t timeout);

/**
* \brief Read data
*
* Read data and store it in module's RX buffer
*
* \param[in] module Pointer to LoRa structure
*
* \return returns number of read bytes
*/
uint8_t SX1278_LoRaRxPacket(SX1278_t *module);

/**
* \brief Entry transmitter mode
*
* Entry transmitter mode
*
* \param[in] module Pointer to LoRa structure
* \param[in] length Length of message to be sent
* \param[in] timeout Timeout in [ms]
*
* \return 1 if entering reception mode
* 0 if timeout was exceeded
*/
int SX1278_LoRaEntryTx(SX1278_t *module, uint8_t length, uint32_t timeout);

/**
* \brief Send data
*
* Transmit data
*
* \param[in] module Pointer to LoRa structure
* \param[in] txBuf Data buffer with data to be sent
* \param[in] length Length of message to be sent
* \param[in] timeout Timeout in [ms]
*
* \return 1 if entering reception mode
* 0 if timeout was exceeded
*/
int SX1278_LoRaTxPacket(SX1278_t *module, uint8_t *txBuf, uint8_t length,
uint32_t timeout);

/**
* \brief Initialize LoRa module
*
* Initialize LoRa module and initialize LoRa structure.
*
* \param[in] module Pointer to LoRa structure
* \param[in] frequency Frequency in [Hz]
* \param[in] power Power level, accepts SX1278_POWER_*
* \param[in] LoRa_SF LoRa spread rate, accepts SX1278_LORA_SF_*
* \param[in] LoRa_BW LoRa bandwidth, accepts SX1278_LORA_BW_*
* \param[in] LoRa_CR LoRa coding rate, accepts SX1278_LORA_CR_*
* \param[in] LoRa_CRC_sum Hardware CRC check, SX1278_LORA_CRC_EN or
* SX1278_LORA_CRC_DIS
* \param[in] packetLength Package length, no more than 256 bytes
*/
void SX1278_init(SX1278_t *module, uint64_t frequency, uint8_t power,
uint8_t LoRa_SF, uint8_t LoRa_BW, uint8_t LoRa_CR,
uint8_t LoRa_CRC_sum, uint8_t packetLength);

/**
* \brief Entry transmitter mode and send data
*
* Entry transmitter mode and send data.
* Combination of SX1278_LoRaEntryTx() and SX1278_LoRaTxPacket().
*
* \param[in] module Pointer to LoRa structure
* \param[in] txBuf Data buffer with data to be sent
* \param[in] length Length of message to be sent
* \param[in] timeout Timeout in [ms]
*
* \return 1 if entered TX mode and sent data
* 0 if timeout was exceeded
*/
int SX1278_transmit(SX1278_t *module, uint8_t *txBuf, uint8_t length,
uint32_t timeout);

/**
* \brief Entry reception mode
*
* Same as SX1278_LoRaEntryRx()
*
* \param[in] module Pointer to LoRa structure
* \param[in] length Length of message to be received
* \param[in] timeout Timeout in [ms]
*
* \return 1 if entering reception mode
* 0 if timeout was exceeded
*/
int SX1278_receive(SX1278_t *module, uint8_t length, uint32_t timeout);

/**
* \brief Returns number of received data
*
* Returns the number of received data which are
* held in internal buffer.
* Same as SX1278_LoRaRxPacket().
*
* \param[in] module Pointer to LoRa structure
*
* \return returns number of read bytes
*/
uint8_t SX1278_available(SX1278_t *module);

/**
* \brief Read received data to buffer
*
* Reads data from internal buffer to external
* buffer. Reads exactly number of bytes which are stored in
* internal buffer.
*
* \param[in] module Pointer to LoRa structure
* \param[out] rxBuf External buffer to store data.
* External buffer is terminated with '\0'
* character
* \param[in] length Length of message to be received
*
* \return returns number of read bytes
*/
uint8_t SX1278_read(SX1278_t *module, uint8_t *rxBuf, uint8_t length);

/**
* \brief Returns RSSI (LoRa)
*
* Returns RSSI in LoRa mode.
*
* \param[in] module Pointer to LoRa structure
*
* \return RSSI value
*/
uint8_t SX1278_RSSI_LoRa(SX1278_t *module);

/**
* \brief Returns RSSI
*
* Returns RSSI (general mode).
*
* \param[in] module Pointer to LoRa structure
*
* \return RSSI value
*/
uint8_t SX1278_RSSI(SX1278_t *module);

/**
* \brief Enter standby mode
*
* Enters standby mode.
*
* \param[in] module Pointer to LoRa structure
*/
void SX1278_standby(SX1278_t *module);

/**
* \brief Enter sleep mode
*
* Enters sleep mode.
*
* \param[in] module Pointer to LoRa structure
*/
void SX1278_sleep(SX1278_t *module);
#ifdef __cplusplus
}
#endif

#endif

+ 95
- 0
STM32/Core/Inc/SX1278_hw.h View File

@@ -0,0 +1,95 @@
/**
* Author Wojciech Domski <Wojciech.Domski@gmail.com>
* www: www.Domski.pl
*
* Hardware layer for SX1278 LoRa module
*/

#ifndef __SX1278_HW_HEADER
#define __SX1278_HW_HEADER

#include <stdint.h>

typedef struct {
int pin;
void *port;
} SX1278_hw_dio_t;

typedef struct {
SX1278_hw_dio_t reset;
SX1278_hw_dio_t dio0;
SX1278_hw_dio_t nss;
void *spi;
} SX1278_hw_t;

/**
* \brief Initialize hardware layer
*
* Clears NSS and resets LoRa module.
*
* \param[in] hw Pointer to hardware structure
*/
void SX1278_hw_init(SX1278_hw_t *hw);

/**
* \brief Control NSS
*
* Clears and sets NSS according to passed value.
*
* \param[in] hw Pointer to hardware structure.
* \param[in] value 1 sets NSS high, other value sets NSS low.
*/
void SX1278_hw_SetNSS(SX1278_hw_t *hw, int value);

/**
* \brief Resets LoRa module
*
* Resets LoRa module.
*
* \param[in] hw Pointer to hardware structure
*/
void SX1278_hw_Reset(SX1278_hw_t *hw);

/**
* \brief Send command via SPI.
*
* Send single byte via SPI interface.
*
* \param[in] hw Pointer to hardware structure
* \param[in] cmd Command
*/
void SX1278_hw_SPICommand(SX1278_hw_t *hw, uint8_t cmd);

/**
* \brief Reads data via SPI
*
* Reads data via SPI interface.
*
* \param[in] hw Pointer to hardware structure
*
* \return Read value
*/
uint8_t SX1278_hw_SPIReadByte(SX1278_hw_t *hw);

/**
* \brief ms delay
*
* Milisecond delay.
*
* \param[in] msec Number of milliseconds to wait
*/
void SX1278_hw_DelayMs(uint32_t msec);

/**
* \brief Reads DIO0 state
*
* Reads LoRa DIO0 state using GPIO.
*
* \param[in] hw Pointer to hardware structure
*
* \return 0 if DIO0 low, 1 if DIO high
*/
int SX1278_hw_GetDIO0(SX1278_hw_t *hw);

#endif


+ 102
- 0
STM32/Core/Inc/arduinoFFT.h View File

@@ -0,0 +1,102 @@
/*

FFT libray
Copyright (C) 2010 Didier Longueville
Copyright (C) 2014 Enrique Condes

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef arduinoFFT_h /* Prevent loading library twice */
#define arduinoFFT_h

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <defs.h>
#include <types.h>

#define FFT_LIB_REV 0x14
/* Custom constants */
#define FFT_FORWARD 0x01
#define FFT_REVERSE 0x00

/* Windowing type */
#define FFT_WIN_TYP_RECTANGLE 0x00 /* rectangle (Box car) */
#define FFT_WIN_TYP_HAMMING 0x01 /* hamming */
#define FFT_WIN_TYP_HANN 0x02 /* hann */
#define FFT_WIN_TYP_TRIANGLE 0x03 /* triangle (Bartlett) */
#define FFT_WIN_TYP_NUTTALL 0x04 /* nuttall */
#define FFT_WIN_TYP_BLACKMAN 0x05 /* blackman */
#define FFT_WIN_TYP_BLACKMAN_NUTTALL 0x06 /* blackman nuttall */
#define FFT_WIN_TYP_BLACKMAN_HARRIS 0x07 /* blackman harris*/
#define FFT_WIN_TYP_FLT_TOP 0x08 /* flat top */
#define FFT_WIN_TYP_WELCH 0x09 /* welch */
/*Mathematial constants*/
#define twoPi 6.28318531
#define fourPi 12.56637061
#define sixPi 18.84955593

#ifdef __AVR__
static const double _c1[]PROGMEM = {0.0000000000, 0.7071067812, 0.9238795325, 0.9807852804,
0.9951847267, 0.9987954562, 0.9996988187, 0.9999247018,
0.9999811753, 0.9999952938, 0.9999988235, 0.9999997059,
0.9999999265, 0.9999999816, 0.9999999954, 0.9999999989,
0.9999999997};
static const double _c2[]PROGMEM = {1.0000000000, 0.7071067812, 0.3826834324, 0.1950903220,
0.0980171403, 0.0490676743, 0.0245412285, 0.0122715383,
0.0061358846, 0.0030679568, 0.0015339802, 0.0007669903,
0.0003834952, 0.0001917476, 0.0000958738, 0.0000479369,
0.0000239684};
#endif
class arduinoFFT {
public:
/* Constructor */
arduinoFFT(void);
arduinoFFT(double *vReal, double *vImag, uint16_t samples, double samplingFrequency);
/* Destructor */
~arduinoFFT(void);
/* Functions */
uint8_t Revision(void);
uint8_t Exponent(uint16_t value);

void ComplexToMagnitude(double *vReal, double *vImag, uint16_t samples);
void Compute(double *vReal, double *vImag, uint16_t samples, uint8_t dir);
void Compute(double *vReal, double *vImag, uint16_t samples, uint8_t power, uint8_t dir);
void DCRemoval(double *vData, uint16_t samples);
double MajorPeak(double *vD, uint16_t samples, double samplingFrequency);
void MajorPeak(double *vD, uint16_t samples, double samplingFrequency, double *f, double *v);
void Windowing(double *vData, uint16_t samples, uint8_t windowType, uint8_t dir);

void ComplexToMagnitude();
void Compute(uint8_t dir);
void DCRemoval();
void MajorPeakAndMagnitude(double *freq_interpolated, double *mag_interpolated); // Added by me
double MajorPeak();
void MajorPeak(double *f, double *v);
void Windowing(uint8_t windowType, uint8_t dir);

private:
/* Variables */
uint16_t _samples;
double _samplingFrequency;
double *_vReal;
double *_vImag;
uint8_t _power;
/* Functions */
void Swap(double *x, double *y);
};

#endif

+ 70
- 0
STM32/Core/Inc/correction_values.h View File

@@ -0,0 +1,70 @@
/*
* correction_values.h
*
* Created on: Feb 9, 2021
* Author: lukas
*/

#ifndef INC_CORRECTION_VALUES_H_
#define INC_CORRECTION_VALUES_H_


// 512
const float CORRECTION_VALUES[] = {
0.0,7.172883405795546e-05,0.001059260037457216,0.004035324283915964,0.009791360415459789,0.018498869351727586,0.030546600767073013,0.04524773389537198,0.06312054701195031,0.0818440680984944,
0.10352075045215836,0.12794679745582618,0.15361517704862274,0.18018801058837586,0.20776632685999466,0.2361873442322523,0.2662140944595638,0.29695041847073594,0.3277827886445909,0.3580006456478009,
0.38819916054721165,0.41863074980816084,0.4497257525325588,0.48058178703131293,0.5111063487591285,0.540273642354577,0.5688382594591064,0.5966645337998011,0.6238340240825409,0.650461303550153,
0.6760130904406626,0.7005557204194303,0.7243886261300616,0.7475183358403319,0.7702629396190269,0.7934428767121573,0.8159057164363238,0.83765511467948,0.8586975316368711,0.8790418017204933,
0.8986987470894034,0.9176808323845598,0.9360018579822185,0.9536766889327459,0.9707210167012957,0.9871511508509416,1.002983837888662,1.0182361046144601,1.0329251234610313,1.0470680974755222,
1.0602946965518625,1.0724771806307554,1.084112679028229,1.0954249967970877,1.1062127253016834,1.1164601096616837,1.1262787299321142,1.1356828651092872,1.1446880245538988,1.1534899388049804,
1.1618281005985902,1.1697256639380633,1.1772808683020228,1.1853230604969849,1.1930901650986656,1.200548562786553,1.2077092521697683,1.2145828226528632,1.2211794644283986,1.2275089791593923,
1.233580791171737,1.239403959003114,1.2449871871781069,1.2503388380993885,1.2554669439624755,1.2603792186167753,1.2650830693089457,1.2695856082560306,1.2738936640057226,1.2780137925496329,
1.281952288162757,1.2857151939485687,1.2893083120745448,1.2927372136874369,1.2960072485014562,1.299123554055786,1.302091064640536,1.3049145198925178,1.3075984730641015,1.310147298969909,
1.312565201617383,1.3148562215282158,1.3170242427584278,1.3190729996254622,1.3210060831510961,1.3228269472292884,1.3245389145282596,1.3261451821362016,1.3275735193179066,1.328161505203354,
1.3285398211716795,1.3287473180657905,1.328876681296295,1.3289243905292003,1.3288923767080048,1.3287901131795625,1.3286800462793598,1.3286206632764501,1.3283542876698091,1.3279692139632036,
1.3275238780381797,1.3270914179034223,1.3267004615342253,1.3267742840600314,1.3269720219576617,1.3271058942040632,1.3271774931790798,1.3271883585907676,1.3271399796126981,1.3270337969259807,
1.326871204670443,1.3266535523092335,1.3263821464108725,1.3260582523526088,1.325683095948776,1.3252578650076263,1.324783710819993,1.3242617495829616,1.3236930637615634,1.3230787033913824,
1.3224196873248222,1.3215309348732716,1.3201781465447535,1.3185602835081423,1.3163904842879137,1.3141893621392133,1.3119670779440011,1.3096840698031207,1.3072689997800968,1.3048394979963558,
1.3025223698494062,1.3001736478759265,1.297812936334551,1.2954224586250285,1.292906161704599,1.2903412289884622,1.2878459557081685,1.2853801395396072,1.2828950815618145,1.2803948353940793,
1.27777957135956,1.2746077621705787,1.2714147493381687,1.2675862401083555,1.2636317991342418,1.259681618525803,1.2557347984475775,1.2517793495297105,1.2478413582417982,1.2438900981136651,
1.2400406226929348,1.2362165300229944,1.232354706654204,1.2284250662791136,1.22448436484387,1.2205615750396235,1.216634218026872,1.2127424750817724,1.208938199345932,1.2051240799926874,
1.2012427190574988,1.1973350238874958,1.193766945882658,1.1918536415473437,1.1899231600400093,1.1880319977373104,1.186171811026769,1.1842950731404265,1.1824020894198684,1.1804931596695738,
1.1785685783139235,1.176628634548578,1.1746736124864576,1.1727037912985276,1.1707194453495953,1.1687208443293127,1.1667082533785722,1.1646819332114742,1.162642140233034,1.1605891266527948,
1.1585231405945051,1.1564444262020073,1.1543532237414862,1.152249769700208,1.1501342968818975,1.1474145580599013,1.1446559746057992,1.141888721417447,1.1383561989203028,1.1348039410645114,
1.1312480180104145,1.1277901215883568,1.1243324312370409,1.1208711116653496,1.1173492415138613,1.1138180334445404,1.1102842515562992,1.1067636375534724,1.1032449775042512,1.099724242527613,
1.0962631335953248,1.0928363396942997,1.089407443005215,1.0859517683562654,1.0824603596773055,1.078967789595708,1.075489552291985,1.0720881299386718,1.0686854859892996,1.065281793892197,
1.0618290706808384,1.0583680033848966,1.054906755249069,1.0514542211699252,1.0480104341003997,1.0445668330653837,1.041131592378115,1.0377747729878009,1.0344180356505863,1.0310615288945382,
1.0276725904710695,1.0242653926527339,1.020859198973952,1.0174560644651591,1.0140683195464366,1.0106818841727532,1.007296891850679,1.0039573374229547,1.0006546969914412,0.9973533593246692,
0.9940534505011709,0.9907106437180979,0.9873664712382778,0.9840244150151416,0.9806883405331283,0.9773656430518435,0.9740453115792655,0.9707274595859758,0.9674501559810466,0.9642103774628765,
0.9609729138627312,0.9577378726892607,0.9545564840044283,0.9513964276555934,0.948238637378326,0.9450832151686782,0.9419407183887651,0.9388021546127084,0.9356661769737245,0.9325328819103722,
0.9294135961284578,0.9262974399922136,0.9231841700256103,0.9200739143089076,0.916977930551638,0.9138850266969418,0.9107952902167624,0.9077088073388642,0.9046363093514975,0.9015674367782348,
0.8985019950572375,0.8954400657137611,0.8923911122002267,0.8893469886097733,0.8863065426299345,0.8832698513238463,0.8802445319215023,0.8772258250367256,0.874211026676025,0.8712002096626809,
0.8681985991470822,0.8652059148496944,0.8622173550516091,0.8592329885421919,0.8562657641464899,0.8533448443389925,0.850427939355407,0.8475151148168408,0.8446064353885903,0.8417876394416499,
0.8389834032676171,0.8361828473707709,0.8333860340955348,0.8305762098807065,0.8277517492352842,0.8249314524510548,0.822115377874059,0.8193035829935283,0.8165036662847402,0.8137081440239708,
0.8109170169074323,0.8081303392044807,0.8053514344607194,0.8025811546506798,0.7998154314964251,0.7970543161834435,0.7942978591151272,0.7915520023789957,0.7888121145484682,0.786076982113828,
0.7833466525539204,0.7806271655659783,0.777951087501187,0.7752796419982264,0.7726128744290972,0.7699508294586495,0.7672414237348727,0.7644496291093685,0.7616636780322027,0.7588836094529752,
0.7561094616166246,0.7532506657758349,0.7503208967572872,0.7473984288821756,0.744483293146494,0.7415755198454969,0.73870316728899,0.7358545058279665,0.7330129481929062,0.7301785232708123,
0.7273512592898264,0.7245161159298864,0.7216800334451033,0.7188513743019934,0.7160301634466695,0.713216425195918,0.7104158820999209,0.7076268517510362,0.7048452867996134,0.7020712094194204,
0.6993046411878778,0.6965635326785661,0.6938519786386481,0.6911476810253259,0.6884506603779014,0.6857609366740617,0.6830736909915721,0.6803776743686955,0.6776891762880255,0.6750082138487741,
0.6723348036147564,0.6696689616199956,0.6670188652997536,0.6643768832722908,0.661742445367839,0.6591155658552638,0.6564962585017369,0.6538892323652762,0.6512935055358983,0.648705322270668,
0.6461246946770429,0.6435516343875753,0.6409971344595664,0.6385534046263793,0.6361163822449369,0.6336860809419324,0.6312625139023003,0.6288456938737227,0.626453252376109,0.6240816837909854,
0.6217166555265382,0.6193581796459204,0.6170062677993668,0.6146609312284136,0.6123046285177839,0.6099536101425693,0.607609343101918,0.6052718364211899,0.6029410987366184,0.6006183582768324,
0.598306997444908,0.5960023843516674,0.5937045263154322,0.5914134302859362,0.5891291028482787,0.5868631609716286,0.5846207941704108,0.5823849947162417,0.5801557687503681,0.5779331220697975,
0.5757170601310062,0.5734988242308056,0.5712790410252068,0.5690659875651222,0.5668596673882982,0.564660083709719,0.5624672394252177,0.5602839171567512,0.5581097346242566,0.5559422579961837,
0.5537814891149292,0.5516274295214653,0.5494800804587907,0.5473511723382107,0.5452425513179093,0.5431404463056002,0.5410448583090187,0.5389557880548492,0.5368732359919627,0.5348681346367996,
0.5330380540201975,0.5312127430431234,0.5293922086719108,0.5275764576164956,0.5257654963329431,0.5239613159108583,0.5222175631853987,0.5204782279743697,0.5187433172719041,0.5170128378333307,
0.5152867961774786,0.5135651985889782,0.5118480511205437,0.5101353595952403,0.5084271296087454,0.5067233665315937,0.5050240755114073,0.5033292614751171,0.5016389291311685,0.49995308297171603,
0.49827172727480323,0.49659486610653314,0.49492250332322274,0.4932546425735472,0.49159128730066814,0.4899324407443539,0.4882781059430834,0.4866282857361377,0.48498298276568175,0.48334219947883056,
0.4817059381297021,0.4800742007814626,0.47844698930835344,0.4768243053977078,0.47520615055195664,0.47359252609061886,0.4719834331522799,0.47037887269656137,0.46877884550607196,0.46718335218834955,
0.4655923931777925,0.464005968737574,0.4624240789615473,0.4608467237761388,0.45927390294222453,0.4577056160570006,0.4561418625558357,0.4545826417141148,0.45302795264906914,0.4514777943215931,
0.4499321655380505,0.44839106495206904,0.4468737749345353,0.4453851733641605,0.4439008009704048,0.44242065709570616,0.4409447409379821,0.43947305155228067,0.4380055878524199,0.4365837314106429,
0.43523560843876913,0.43389099318539354,0.43254988696998853,0.4312122909785673,0.4298782062650867,0.4285476337528458,0.4272175283220949,0.4258782697200807,0.42454262333177084,0.4232105891769857,
0.42188216715172827,0.42055735702955016,0.4192361584629108,0.4179185709845266,0.4166145251963689,0.41531506916996963,0.4140191536360333,0.41272677794409274,0.41143794133045397,0.410152642919478,
0.4088708817248545,0.40758529052778536,0.4062960742923718,0.4050104831515799,0.40372851530466675,0.40245016884669893,0.4011754417697965,0.399904331964362,0.39863683722030263,0.39738302448490076,
0.39613284633852,0.3948862121360839,0.3936431195515306,0.39240356616402244,0.3911675494591046,0.38993506682985646,0.3887012156015032,0.38746234792929096,0.3862270912837194,0.38499544232782434,
0.38376739763825213,0.3825429537063741
};



#endif /* INC_CORRECTION_VALUES_H_ */

+ 79
- 0
STM32/Core/Inc/defs.h View File

@@ -0,0 +1,79 @@
/*! \file avrlibdefs.h \brief AVRlib global defines and macros. */
//*****************************************************************************
//
// File Name : 'avrlibdefs.h'
// Title : AVRlib global defines and macros include file
// Author : Pascal Stang
// Created : 7/12/2001
// Revised : 9/30/2002
// Version : 1.1
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// Description : This include file is designed to contain items useful to all
// code files and projects, regardless of specific implementation.
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************


#ifndef AVRLIBDEFS_H
#define AVRLIBDEFS_H

//#define F_CPU 4000000
#define MEM_TYPE 1

// Code compatibility to new AVR-libc
// outb(), inb(), inw(), outw(), BV(), sbi(), cbi(), sei(), cli()
#ifndef outb
#define outb(addr, data) addr = (data)
#endif
#ifndef inb
#define inb(addr) (addr)
#endif
#ifndef outw
#define outw(addr, data) addr = (data)
#endif
#ifndef inw
#define inw(addr) (addr)
#endif
#ifndef BV
#define BV(bit) (1<<(bit))
#endif
//#ifndef cbi
// #define cbi(reg,bit) reg &= ~(BV(bit))
//#endif
//#ifndef sbi
// #define sbi(reg,bit) reg |= (BV(bit))
//#endif
#ifndef cli
#define cli() __asm__ __volatile__ ("cli" ::)
#endif
#ifndef sei
#define sei() __asm__ __volatile__ ("sei" ::)
#endif

// use this for packed structures
// (this is seldom necessary on an 8-bit architecture like AVR,
// but can assist in code portability to AVR)
#define GNUC_PACKED __attribute__((packed))

// port address helpers
#define DDR(x) ((x)-1) // address of data direction register of port x
#define PIN(x) ((x)-2) // address of input register of port x

// MIN/MAX/ABS macros
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a>b)?(a):(b))
#define ABS(x) ((x>0)?(x):(-x))

// constants
#define PI 3.14159265359

//Math
#define sq(x) ((x)*(x))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))

#endif

+ 84
- 0
STM32/Core/Inc/main.h View File

@@ -0,0 +1,84 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g0xx_hal.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define Device_ID_Pin GPIO_PIN_2
#define Device_ID_GPIO_Port GPIOA
#define NSS_Pin GPIO_PIN_5
#define NSS_GPIO_Port GPIOA
#define LED_Pin GPIO_PIN_6
#define LED_GPIO_Port GPIOA
#define RESET_Pin GPIO_PIN_7
#define RESET_GPIO_Port GPIOA
#define BAT_Monitor_Pin GPIO_PIN_1
#define BAT_Monitor_GPIO_Port GPIOB
#define I2C_Address_Pin GPIO_PIN_6
#define I2C_Address_GPIO_Port GPIOC
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 352
- 0
STM32/Core/Inc/stm32g0xx_hal_conf.h View File

@@ -0,0 +1,352 @@
/**
******************************************************************************
* @file stm32g0xx_hal_conf.h
* @author MCD Application Team
* @brief HAL configuration file.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32G0xx_HAL_CONF_H
#define STM32G0xx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
#define HAL_ADC_MODULE_ENABLED
/* #define HAL_CEC_MODULE_ENABLED */
/* #define HAL_COMP_MODULE_ENABLED */
/* #define HAL_CRC_MODULE_ENABLED */
/* #define HAL_CRYP_MODULE_ENABLED */
/* #define HAL_DAC_MODULE_ENABLED */
/* #define HAL_EXTI_MODULE_ENABLED */
/* #define HAL_FDCAN_MODULE_ENABLED */
/* #define HAL_HCD_MODULE_ENABLED */
#define HAL_I2C_MODULE_ENABLED
#define HAL_I2S_MODULE_ENABLED
/* #define HAL_IWDG_MODULE_ENABLED */
/* #define HAL_IRDA_MODULE_ENABLED */
/* #define HAL_LPTIM_MODULE_ENABLED */
/* #define HAL_PCD_MODULE_ENABLED */
/* #define HAL_RNG_MODULE_ENABLED */
/* #define HAL_RTC_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */
/* #define HAL_SMBUS_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */
/* #define HAL_WWDG_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
/* ########################## Register Callbacks selection ############################## */
/**
* @brief This is the list of modules where register callback can be used
*/
#define USE_HAL_ADC_REGISTER_CALLBACKS 1u
#define USE_HAL_CEC_REGISTER_CALLBACKS 0u
#define USE_HAL_COMP_REGISTER_CALLBACKS 0u
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u
#define USE_HAL_DAC_REGISTER_CALLBACKS 0u
#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0u
#define USE_HAL_HCD_REGISTER_CALLBACKS 0u
#define USE_HAL_I2C_REGISTER_CALLBACKS 1u
#define USE_HAL_I2S_REGISTER_CALLBACKS 1u
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0u
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0u
#define USE_HAL_PCD_REGISTER_CALLBACKS 0u
#define USE_HAL_RNG_REGISTER_CALLBACKS 0u
#define USE_HAL_RTC_REGISTER_CALLBACKS 0u
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u
#define USE_HAL_SPI_REGISTER_CALLBACKS 0u
#define USE_HAL_TIM_REGISTER_CALLBACKS 0u
#define USE_HAL_UART_REGISTER_CALLBACKS 0u
#define USE_HAL_USART_REGISTER_CALLBACKS 0u
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0u
/* ########################## Oscillator Values adaptation ####################*/
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE (8000000UL) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
#if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
/**
* @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC and RNG.
* This internal oscillator is mainly dedicated to provide a high precision clock to
* the USB peripheral by means of a special Clock Recovery System (CRS) circuitry.
* When the CRS is not used, the HSI48 RC oscillator runs on it default frequency
* which is subject to manufacturing process variations.
*/
#if !defined (HSI48_VALUE)
#define HSI48_VALUE 48000000U /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
The real value my vary depending on manufacturing process variations.*/
#endif /* HSI48_VALUE */
#endif
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature.*/
/**
* @brief External Low Speed oscillator (LSE) value.
* This value is used by the UART, RTC HAL module to compute the system frequency
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE (32768UL) /*!< Value of the External oscillator in Hz*/
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */
/**
* @brief External clock source for I2S1 peripheral
* This value is used by the RCC HAL module to compute the I2S1 clock source
* frequency.
*/
#if !defined (EXTERNAL_I2S1_CLOCK_VALUE)
#define EXTERNAL_I2S1_CLOCK_VALUE (48000UL) /*!< Value of the I2S1 External clock source in Hz*/
#endif /* EXTERNAL_I2S1_CLOCK_VALUE */
#if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
/**
* @brief External clock source for I2S2 peripheral
* This value is used by the RCC HAL module to compute the I2S2 clock source
* frequency.
*/
#if !defined (EXTERNAL_I2S2_CLOCK_VALUE)
#define EXTERNAL_I2S2_CLOCK_VALUE 48000U /*!< Value of the I2S2 External clock source in Hz*/
#endif /* EXTERNAL_I2S2_CLOCK_VALUE */
#endif
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY 0U /*!< tick interrupt priority */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 1U
#define INSTRUCTION_CACHE_ENABLE 1U
/* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver
*/
#define USE_SPI_CRC 0U
/* ################## CRYP peripheral configuration ########################## */
#define USE_HAL_CRYP_SUSPEND_RESUME 1U
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1U */
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include modules header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32g0xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32g0xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32g0xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32g0xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32g0xx_hal_adc.h"
#include "stm32g0xx_hal_adc_ex.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_CEC_MODULE_ENABLED
#include "stm32g0xx_hal_cec.h"
#endif /* HAL_CEC_MODULE_ENABLED */
#ifdef HAL_COMP_MODULE_ENABLED
#include "stm32g0xx_hal_comp.h"
#endif /* HAL_COMP_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32g0xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_CRYP_MODULE_ENABLED
#include "stm32g0xx_hal_cryp.h"
#endif /* HAL_CRYP_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32g0xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32g0xx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32g0xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_FDCAN_MODULE_ENABLED
#include "stm32g0xx_hal_fdcan.h"
#endif /* HAL_FDCAN_MODULE_ENABLED */
#ifdef HAL_HCD_MODULE_ENABLED
#include "stm32g0xx_hal_hcd.h"
#endif /* HAL_HCD_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32g0xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED
#include "stm32g0xx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32g0xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32g0xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_LPTIM_MODULE_ENABLED
#include "stm32g0xx_hal_lptim.h"
#endif /* HAL_LPTIM_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32g0xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32g0xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_RNG_MODULE_ENABLED
#include "stm32g0xx_hal_rng.h"
#endif /* HAL_RNG_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32g0xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32g0xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_SMBUS_MODULE_ENABLED
#include "stm32g0xx_hal_smbus.h"
#endif /* HAL_SMBUS_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32g0xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32g0xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32g0xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32g0xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32g0xx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for functions parameters check.
* @param expr If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t *file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* STM32G0xx_HAL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 69
- 0
STM32/Core/Inc/stm32g0xx_it.h View File

@@ -0,0 +1,69 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g0xx_it.h
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32G0xx_IT_H
#define __STM32G0xx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void NMI_Handler(void);
void HardFault_Handler(void);
void SVC_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA1_Channel1_IRQHandler(void);
void DMA1_Channel2_3_IRQHandler(void);
void ADC1_COMP_IRQHandler(void);
void I2C2_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __STM32G0xx_IT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 69
- 0
STM32/Core/Inc/types.h View File

@@ -0,0 +1,69 @@
//useful things to include in code

#ifndef TYPES_H
#define TYPES_H

#ifndef WIN32
// true/false defines
#define FALSE 0
#define TRUE -1
#endif

// datatype definitions macros
typedef unsigned char u08;
typedef signed char s08;
typedef unsigned short u16;
typedef signed short s16;
typedef unsigned long u32;
typedef signed long s32;
typedef unsigned long long u64;
typedef signed long long s64;

// #ifndef __AVR__
#ifdef __MBED__
// use inttypes.h instead
// C99 standard integer type definitions
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
/*typedef unsigned long uint32_t;
typedef signed long int32_t;
typedef unsigned long uint64_t;
typedef signed long int64_t;
*/
#endif

// maximum value that can be held
// by unsigned data types (8,16,32bits)
#define MAX_U08 255
#define MAX_U16 65535
#define MAX_U32 4294967295

// maximum values that can be held
// by signed data types (8,16,32bits)
#define MIN_S08 -128
#define MAX_S08 127
#define MIN_S16 -32768
#define MAX_S16 32767
#define MIN_S32 -2147483648
#define MAX_S32 2147483647

#ifndef WIN32
// more type redefinitions
typedef unsigned char BOOL;
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;

typedef unsigned char UCHAR;
typedef unsigned int UINT;
typedef unsigned short USHORT;
typedef unsigned long ULONG;

typedef char CHAR;
typedef int INT;
typedef long LONG;
#endif

#endif

+ 293
- 0
STM32/Core/Src/SX1278.c View File

@@ -0,0 +1,293 @@
/**
* Author Wojciech Domski <Wojciech.Domski@gmail.com>
* www: www.Domski.pl
*
* work based on DORJI.COM sample code and
* https://github.com/realspinner/SX1278_LoRa
*/

#include <string.h>
#include <SX1278.h>

uint8_t SX1278_SPIRead(SX1278_t *module, uint8_t addr) {
uint8_t tmp;
SX1278_hw_SPICommand(module->hw, addr);
tmp = SX1278_hw_SPIReadByte(module->hw);
SX1278_hw_SetNSS(module->hw, 1);
return tmp;
}

void SX1278_SPIWrite(SX1278_t *module, uint8_t addr, uint8_t cmd) {
SX1278_hw_SetNSS(module->hw, 0);
SX1278_hw_SPICommand(module->hw, addr | 0x80);
SX1278_hw_SPICommand(module->hw, cmd);
SX1278_hw_SetNSS(module->hw, 1);
}

void SX1278_SPIBurstRead(SX1278_t *module, uint8_t addr, uint8_t *rxBuf,
uint8_t length) {
uint8_t i;
if (length <= 1) {
return;
} else {
SX1278_hw_SetNSS(module->hw, 0);
SX1278_hw_SPICommand(module->hw, addr);
for (i = 0; i < length; i++) {
*(rxBuf + i) = SX1278_hw_SPIReadByte(module->hw);
}
SX1278_hw_SetNSS(module->hw, 1);
}
}

void SX1278_SPIBurstWrite(SX1278_t *module, uint8_t addr, uint8_t *txBuf,
uint8_t length) {
unsigned char i;
if (length <= 1) {
return;
} else {
SX1278_hw_SetNSS(module->hw, 0);
SX1278_hw_SPICommand(module->hw, addr | 0x80);
for (i = 0; i < length; i++) {
SX1278_hw_SPICommand(module->hw, *(txBuf + i));
}
SX1278_hw_SetNSS(module->hw, 1);
}
}

void SX1278_config(SX1278_t *module) {
SX1278_sleep(module); //Change modem mode Must in Sleep mode
SX1278_hw_DelayMs(15);

SX1278_entryLoRa(module);
//SX1278_SPIWrite(module, 0x5904); //?? Change digital regulator form 1.6V to 1.47V: see errata note

uint64_t freq = ((uint64_t) module->frequency << 19) / 32000000;
uint8_t freq_reg[3];
freq_reg[0] = (uint8_t) (freq >> 16);
freq_reg[1] = (uint8_t) (freq >> 8);
freq_reg[2] = (uint8_t) (freq >> 0);
SX1278_SPIBurstWrite(module, LR_RegFrMsb, (uint8_t*) freq_reg, 3); //setting frequency parameter

/* According to Semtech syncWord doesn't really work all that well. I'll set it anyway; for completeness' sake */
SX1278_SPIWrite(module, RegSyncWord, 0xff);

//setting base parameter
SX1278_SPIWrite(module, LR_RegPaConfig, SX1278_Power[module->power]); //Setting output power parameter

SX1278_SPIWrite(module, LR_RegOcp, 0x0B); //RegOcp,Close Ocp
SX1278_SPIWrite(module, LR_RegLna, 0x23); //RegLNA,High & LNA Enable
if (SX1278_SpreadFactor[module->LoRa_SF] == 6) { //SFactor=6
uint8_t tmp;
SX1278_SPIWrite(module,
LR_RegModemConfig1,
((SX1278_LoRaBandwidth[module->LoRa_BW] << 4)
+ (SX1278_CodingRate[module->LoRa_CR] << 1) + 0x01)); //Implicit Enable CRC Enable(0x02) & Error Coding rate 4/5(0x01), 4/6(0x02), 4/7(0x03), 4/8(0x04)

SX1278_SPIWrite(module,
LR_RegModemConfig2,
((SX1278_SpreadFactor[module->LoRa_SF] << 4)
+ (SX1278_CRC_Sum[module->LoRa_CRC_sum] << 2) + 0x03));

tmp = SX1278_SPIRead(module, 0x31);
tmp &= 0xF8;
tmp |= 0x05;
SX1278_SPIWrite(module, 0x31, tmp);
SX1278_SPIWrite(module, 0x37, 0x0C);
} else {
SX1278_SPIWrite(module,
LR_RegModemConfig1,
((SX1278_LoRaBandwidth[module->LoRa_BW] << 4)
+ (SX1278_CodingRate[module->LoRa_CR] << 1) + 0x00)); //Explicit Enable CRC Enable(0x02) & Error Coding rate 4/5(0x01), 4/6(0x02), 4/7(0x03), 4/8(0x04)

SX1278_SPIWrite(module,
LR_RegModemConfig2,
((SX1278_SpreadFactor[module->LoRa_SF] << 4)
+ (SX1278_CRC_Sum[module->LoRa_CRC_sum] << 2) + 0x00)); //SFactor & LNA gain set by the internal AGC loop
}

SX1278_SPIWrite(module, LR_RegModemConfig3, 0x04);
SX1278_SPIWrite(module, LR_RegSymbTimeoutLsb, 0x08); //RegSymbTimeoutLsb Timeout = 0x3FF(Max)
SX1278_SPIWrite(module, LR_RegPreambleMsb, 0x00); //RegPreambleMsb
SX1278_SPIWrite(module, LR_RegPreambleLsb, 8); //RegPreambleLsb 8+4=12byte Preamble
SX1278_SPIWrite(module, REG_LR_DIOMAPPING2, 0x01); //RegDioMapping2 DIO5=00, DIO4=01
module->readBytes = 0;
SX1278_standby(module); //Entry standby mode
}

void SX1278_standby(SX1278_t *module) {
SX1278_SPIWrite(module, LR_RegOpMode, 0x09);
module->status = STANDBY;
}

void SX1278_sleep(SX1278_t *module) {
SX1278_SPIWrite(module, LR_RegOpMode, 0x08);
module->status = SLEEP;
}

void SX1278_entryLoRa(SX1278_t *module) {
SX1278_SPIWrite(module, LR_RegOpMode, 0x88);
}

void SX1278_clearLoRaIrq(SX1278_t *module) {
SX1278_SPIWrite(module, LR_RegIrqFlags, 0xFF);
}

int SX1278_LoRaEntryRx(SX1278_t *module, uint8_t length, uint32_t timeout) {
uint8_t addr;

module->packetLength = length;

SX1278_config(module); //Setting base parameter
SX1278_SPIWrite(module, REG_LR_PADAC, 0x84); //Normal and RX
SX1278_SPIWrite(module, LR_RegHopPeriod, 0xFF); //No FHSS
SX1278_SPIWrite(module, REG_LR_DIOMAPPING1, 0x01);//DIO=00,DIO1=00,DIO2=00, DIO3=01
SX1278_SPIWrite(module, LR_RegIrqFlagsMask, 0x3F);//Open RxDone interrupt & Timeout
SX1278_clearLoRaIrq(module);
SX1278_SPIWrite(module, LR_RegPayloadLength, length);//Payload Length 21byte(this register must difine when the data long of one byte in SF is 6)
addr = SX1278_SPIRead(module, LR_RegFifoRxBaseAddr); //Read RxBaseAddr
SX1278_SPIWrite(module, LR_RegFifoAddrPtr, addr); //RxBaseAddr->FiFoAddrPtr
SX1278_SPIWrite(module, LR_RegOpMode, 0x8d); //Mode//Low Frequency Mode
//SX1278_SPIWrite(module, LR_RegOpMode,0x05); //Continuous Rx Mode //High Frequency Mode
module->readBytes = 0;

while (1) {
if ((SX1278_SPIRead(module, LR_RegModemStat) & 0x04) == 0x04) { //Rx-on going RegModemStat
module->status = RX;
return 1;
}
if (--timeout == 0) {
SX1278_hw_Reset(module->hw);
SX1278_config(module);
return 0;
}
SX1278_hw_DelayMs(1);
}
}

uint8_t SX1278_LoRaRxPacket(SX1278_t *module) {
unsigned char addr;
unsigned char packet_size;

if (SX1278_hw_GetDIO0(module->hw)) {
memset(module->rxBuffer, 0x00, SX1278_MAX_PACKET);

addr = SX1278_SPIRead(module, LR_RegFifoRxCurrentaddr); //last packet addr
SX1278_SPIWrite(module, LR_RegFifoAddrPtr, addr); //RxBaseAddr -> FiFoAddrPtr

if (module->LoRa_SF == SX1278_LORA_SF_6) { //When SpreadFactor is six,will used Implicit Header mode(Excluding internal packet length)
packet_size = module->packetLength;
} else {
packet_size = SX1278_SPIRead(module, LR_RegRxNbBytes); //Number for received bytes
}

SX1278_SPIBurstRead(module, 0x00, module->rxBuffer, packet_size);
module->readBytes = packet_size;
SX1278_clearLoRaIrq(module);
}
return module->readBytes;
}

int SX1278_LoRaEntryTx(SX1278_t *module, uint8_t length, uint32_t timeout) {
uint8_t addr;
uint8_t temp;

module->packetLength = length;

SX1278_config(module); //setting base parameter
SX1278_SPIWrite(module, REG_LR_PADAC, 0x87); //Tx for 20dBm
SX1278_SPIWrite(module, LR_RegHopPeriod, 0x00); //RegHopPeriod NO FHSS
SX1278_SPIWrite(module, REG_LR_DIOMAPPING1, 0x41); //DIO0=01, DIO1=00,DIO2=00, DIO3=01
SX1278_clearLoRaIrq(module);
SX1278_SPIWrite(module, LR_RegIrqFlagsMask, 0xF7); //Open TxDone interrupt
SX1278_SPIWrite(module, LR_RegPayloadLength, length); //RegPayloadLength 21byte
addr = SX1278_SPIRead(module, LR_RegFifoTxBaseAddr); //RegFiFoTxBaseAddr
SX1278_SPIWrite(module, LR_RegFifoAddrPtr, addr); //RegFifoAddrPtr

while (1) {
temp = SX1278_SPIRead(module, LR_RegPayloadLength);
if (temp == length) {
module->status = TX;
return 1;
}

if (--timeout == 0) {
SX1278_hw_Reset(module->hw);
SX1278_config(module);
return 0;
}
}
}

int SX1278_LoRaTxPacket(SX1278_t *module, uint8_t *txBuffer, uint8_t length,
uint32_t timeout) {
SX1278_SPIBurstWrite(module, 0x00, txBuffer, length);
SX1278_SPIWrite(module, LR_RegOpMode, 0x8b); //Tx Mode
while (1) {
if (SX1278_hw_GetDIO0(module->hw)) { //if(Get_NIRQ()) //Packet send over
SX1278_SPIRead(module, LR_RegIrqFlags);
SX1278_clearLoRaIrq(module); //Clear irq
SX1278_standby(module); //Entry Standby mode
return 1;
}

if (--timeout == 0) {
SX1278_hw_Reset(module->hw);
SX1278_config(module);
return 0;
}
SX1278_hw_DelayMs(1);
}
}

void SX1278_init(SX1278_t *module, uint64_t frequency, uint8_t power,
uint8_t LoRa_SF, uint8_t LoRa_BW, uint8_t LoRa_CR,
uint8_t LoRa_CRC_sum, uint8_t packetLength) {
SX1278_hw_init(module->hw);
module->frequency = frequency;
module->power = power;
module->LoRa_SF = LoRa_SF;
module->LoRa_BW = LoRa_BW;
module->LoRa_CR = LoRa_CR;
module->LoRa_CRC_sum = LoRa_CRC_sum;
module->packetLength = packetLength;
SX1278_config(module);
}

int SX1278_transmit(SX1278_t *module, uint8_t *txBuf, uint8_t length,
uint32_t timeout) {
if (SX1278_LoRaEntryTx(module, length, timeout)) {
return SX1278_LoRaTxPacket(module, txBuf, length, timeout);
}
return 0;
}

int SX1278_receive(SX1278_t *module, uint8_t length, uint32_t timeout) {
return SX1278_LoRaEntryRx(module, length, timeout);
}

uint8_t SX1278_available(SX1278_t *module) {
return SX1278_LoRaRxPacket(module);
}

uint8_t SX1278_read(SX1278_t *module, uint8_t *rxBuf, uint8_t length) {
if (length != module->readBytes)
length = module->readBytes;
memcpy(rxBuf, module->rxBuffer, length);
rxBuf[length] = '\0';
module->readBytes = 0;
return length;
}

uint8_t SX1278_RSSI_LoRa(SX1278_t *module) {
uint32_t temp = 10;
temp = SX1278_SPIRead(module, LR_RegRssiValue); //Read RegRssiValue, Rssi value
temp = temp + 127 - 137; //127:Max RSSI, 137:RSSI offset
return (uint8_t) temp;
}

uint8_t SX1278_RSSI(SX1278_t *module) {
uint8_t temp = 0xff;
temp = SX1278_SPIRead(module, RegRssiValue);
temp = 127 - (temp >> 1); //127:Max RSSI
return temp;
}

+ 60
- 0
STM32/Core/Src/SX1278_hw.c View File

@@ -0,0 +1,60 @@
/**
* Author Wojciech Domski <Wojciech.Domski@gmail.com>
* www: www.Domski.pl
*
* Hardware layer for SX1278 LoRa module
*/

#include <string.h>
#include <SX1278_hw.h>
#include "main.h"
//#include "gpio.h"
//#include "spi.h"

__weak void SX1278_hw_init(SX1278_hw_t *hw) {
SX1278_hw_SetNSS(hw, 1);
HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_SET);
}

__weak void SX1278_hw_SetNSS(SX1278_hw_t *hw, int value) {
HAL_GPIO_WritePin(hw->nss.port, hw->nss.pin,
(value == 1) ? GPIO_PIN_SET : GPIO_PIN_RESET);
}

__weak void SX1278_hw_Reset(SX1278_hw_t *hw) {
SX1278_hw_SetNSS(hw, 1);
HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_RESET);

SX1278_hw_DelayMs(1);

HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_SET);

SX1278_hw_DelayMs(100);
}

__weak void SX1278_hw_SPICommand(SX1278_hw_t *hw, uint8_t cmd) {
SX1278_hw_SetNSS(hw, 0);
HAL_SPI_Transmit(hw->spi, &cmd, 1, 1000);
while (HAL_SPI_GetState(hw->spi) != HAL_SPI_STATE_READY)
;
}

__weak uint8_t SX1278_hw_SPIReadByte(SX1278_hw_t *hw) {
uint8_t txByte = 0x00;
uint8_t rxByte = 0x00;

SX1278_hw_SetNSS(hw, 0);
HAL_SPI_TransmitReceive(hw->spi, &txByte, &rxByte, 1, 1000);
while (HAL_SPI_GetState(hw->spi) != HAL_SPI_STATE_READY)
;
return rxByte;
}

__weak void SX1278_hw_DelayMs(uint32_t msec) {
HAL_Delay(msec);
}

__weak int SX1278_hw_GetDIO0(SX1278_hw_t *hw) {
return (HAL_GPIO_ReadPin(hw->dio0.port, hw->dio0.pin) == GPIO_PIN_SET);
}


+ 280
- 0
STM32/Core/Src/arduinoFFT.cpp View File

@@ -0,0 +1,280 @@
/*

FFT libray
Copyright (C) 2010 Didier Longueville
Copyright (C) 2014 Enrique Condes

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

*/

#include <arduinoFFT.h>

arduinoFFT::arduinoFFT(double *vReal, double *vImag, uint16_t samples, double samplingFrequency)
{// Constructor
this->_vReal = vReal;
this->_vImag = vImag;
this->_samples = samples;
this->_samplingFrequency = samplingFrequency;
this->_power = Exponent(samples);
}

arduinoFFT::~arduinoFFT(void)
{
// Destructor
}

uint8_t arduinoFFT::Revision(void)
{
return(FFT_LIB_REV);
}

void arduinoFFT::Compute(uint8_t dir)
{// Computes in-place complex-to-complex FFT /
// Reverse bits /
uint16_t j = 0;
for (uint16_t i = 0; i < (this->_samples - 1); i++) {
if (i < j) {
Swap(&this->_vReal[i], &this->_vReal[j]);
if(dir==FFT_REVERSE)
Swap(&this->_vImag[i], &this->_vImag[j]);
}
uint16_t k = (this->_samples >> 1);
while (k <= j) {
j -= k;
k >>= 1;
}
j += k;
}
// Compute the FFT /
#ifdef __AVR__
uint8_t index = 0;
#endif
double c1 = -1.0;
double c2 = 0.0;
uint16_t l2 = 1;
for (uint8_t l = 0; (l < this->_power); l++) {
uint16_t l1 = l2;
l2 <<= 1;
double u1 = 1.0;
double u2 = 0.0;
for (j = 0; j < l1; j++) {
for (uint16_t i = j; i < this->_samples; i += l2) {
uint16_t i1 = i + l1;
double t1 = u1 * this->_vReal[i1] - u2 * this->_vImag[i1];
double t2 = u1 * this->_vImag[i1] + u2 * this->_vReal[i1];
this->_vReal[i1] = this->_vReal[i] - t1;
this->_vImag[i1] = this->_vImag[i] - t2;
this->_vReal[i] += t1;
this->_vImag[i] += t2;
}
double z = ((u1 * c1) - (u2 * c2));
u2 = ((u1 * c2) + (u2 * c1));
u1 = z;
}
#ifdef __AVR__
c2 = pgm_read_float_near(&(_c2[index]));
c1 = pgm_read_float_near(&(_c1[index]));
index++;
#else
c2 = sqrt((1.0 - c1) / 2.0);
c1 = sqrt((1.0 + c1) / 2.0);
#endif
if (dir == FFT_FORWARD) {
c2 = -c2;
}
}
// Scaling for reverse transform /
if (dir != FFT_FORWARD) {
for (uint16_t i = 0; i < this->_samples; i++) {
this->_vReal[i] /= this->_samples;
this->_vImag[i] /= this->_samples;
}
}
}

void arduinoFFT::ComplexToMagnitude()
{ // vM is half the size of vReal and vImag
for (uint16_t i = 0; i < this->_samples; i++) {
this->_vReal[i] = sqrt(sq(this->_vReal[i]) + sq(this->_vImag[i]));
}
}

void arduinoFFT::DCRemoval()
{
// calculate the mean of vData
double mean = 0;
for (uint16_t i = 0; i < this->_samples; i++)
{
mean += this->_vReal[i];
}
mean /= this->_samples;
// Subtract the mean from vData
for (uint16_t i = 0; i < this->_samples; i++)
{
this->_vReal[i] -= mean;
}
}

void arduinoFFT::Windowing(uint8_t windowType, uint8_t dir)
{// Weighing factors are computed once before multiple use of FFT
// The weighing function is symetric; half the weighs are recorded
double samplesMinusOne = (double(this->_samples) - 1.0);
for (uint16_t i = 0; i < (this->_samples >> 1); i++) {
double indexMinusOne = double(i);
double ratio = (indexMinusOne / samplesMinusOne);
double weighingFactor = 1.0;
// TODO Make this only calculate once
// Compute and record weighting factor
switch (windowType) {
case FFT_WIN_TYP_RECTANGLE: // rectangle (box car)
weighingFactor = 1.0;
break;
case FFT_WIN_TYP_HAMMING: // hamming
weighingFactor = 0.54 - (0.46 * cos(twoPi * ratio));
//weighingFactor = 0.080000000000000016;
break;
case FFT_WIN_TYP_HANN: // hann
weighingFactor = 0.54 * (1.0 - cos(twoPi * ratio));
break;
case FFT_WIN_TYP_TRIANGLE: // triangle (Bartlett)
#if defined(ESP8266) || defined(ESP32)
weighingFactor = 1.0 - ((2.0 * fabs(indexMinusOne - (samplesMinusOne / 2.0))) / samplesMinusOne);
#else
weighingFactor = 1.0 - ((2.0 * abs(indexMinusOne - (samplesMinusOne / 2.0))) / samplesMinusOne);
#endif
break;
case FFT_WIN_TYP_NUTTALL: // nuttall
weighingFactor = 0.355768 - (0.487396 * (cos(twoPi * ratio))) + (0.144232 * (cos(fourPi * ratio))) - (0.012604 * (cos(sixPi * ratio)));
break;
case FFT_WIN_TYP_BLACKMAN: // blackman
weighingFactor = 0.42323 - (0.49755 * (cos(twoPi * ratio))) + (0.07922 * (cos(fourPi * ratio)));
break;
case FFT_WIN_TYP_BLACKMAN_NUTTALL: // blackman nuttall
weighingFactor = 0.3635819 - (0.4891775 * (cos(twoPi * ratio))) + (0.1365995 * (cos(fourPi * ratio))) - (0.0106411 * (cos(sixPi * ratio)));
break;
case FFT_WIN_TYP_BLACKMAN_HARRIS: // blackman harris
weighingFactor = 0.35875 - (0.48829 * (cos(twoPi * ratio))) + (0.14128 * (cos(fourPi * ratio))) - (0.01168 * (cos(sixPi * ratio)));
break;
case FFT_WIN_TYP_FLT_TOP: // flat top
weighingFactor = 0.2810639 - (0.5208972 * cos(twoPi * ratio)) + (0.1980399 * cos(fourPi * ratio));
break;
case FFT_WIN_TYP_WELCH: // welch
weighingFactor = 1.0 - sq((indexMinusOne - samplesMinusOne / 2.0) / (samplesMinusOne / 2.0));
break;
}
if (dir == FFT_FORWARD) {
this->_vReal[i] *= weighingFactor;
this->_vReal[this->_samples - (i + 1)] *= weighingFactor;
}
else {
this->_vReal[i] /= weighingFactor;
this->_vReal[this->_samples - (i + 1)] /= weighingFactor;
}
}
}

double arduinoFFT::MajorPeak()
{
double maxY = 0;
uint16_t IndexOfMaxY = 0;
//If sampling_frequency = 2 * max_frequency in signal,
//value would be stored at position samples/2
for (uint16_t i = 1; i < ((this->_samples >> 1) + 1); i++) {
if ((this->_vReal[i-1] < this->_vReal[i]) && (this->_vReal[i] > this->_vReal[i+1])) {
if (this->_vReal[i] > maxY) {
maxY = this->_vReal[i];
IndexOfMaxY = i;
}
}
}
double delta = 0.5 * ((this->_vReal[IndexOfMaxY-1] - this->_vReal[IndexOfMaxY+1]) / (this->_vReal[IndexOfMaxY-1] - (2.0 * this->_vReal[IndexOfMaxY]) + this->_vReal[IndexOfMaxY+1]));
double interpolatedX = ((IndexOfMaxY + delta) * this->_samplingFrequency) / (this->_samples-1);
if(IndexOfMaxY==(this->_samples >> 1)) //To improve calculation on edge values
interpolatedX = ((IndexOfMaxY + delta) * this->_samplingFrequency) / (this->_samples);
// returned value: interpolated frequency peak apex
return(interpolatedX);
}

void arduinoFFT::MajorPeakAndMagnitude(double *freq_interpolated, double *mag_interpolated)
// Added by me
{
double maxY = 0;
uint16_t IndexOfMaxY = 0;
//If sampling_frequency = 2 * max_frequency in signal,
//value would be stored at position samples/2
for (uint16_t i = 1; i < ((this->_samples >> 1) + 1); i++) {
if ((this->_vReal[i-1] < this->_vReal[i]) && (this->_vReal[i] > this->_vReal[i+1])) {
if (this->_vReal[i] > maxY) {
maxY = this->_vReal[i];
IndexOfMaxY = i;
}
}
}
double delta = 0.5 * ((this->_vReal[IndexOfMaxY-1] - this->_vReal[IndexOfMaxY+1]) / (this->_vReal[IndexOfMaxY-1] - (2.0 * this->_vReal[IndexOfMaxY]) + this->_vReal[IndexOfMaxY+1]));
*freq_interpolated = ((IndexOfMaxY + delta) * this->_samplingFrequency) / (this->_samples-1);
if(IndexOfMaxY==(this->_samples >> 1)) //To improve calculation on edge values
*freq_interpolated = ((IndexOfMaxY + delta) * this->_samplingFrequency) / (this->_samples);

if (delta <= 0) { // We can add the equals check here as well as a delta of zero has no effect.
*mag_interpolated = ( this->_vReal[IndexOfMaxY] + (delta * (this->_vReal[IndexOfMaxY] - this->_vReal[IndexOfMaxY-1])) );
} else if (delta > 0) {
*mag_interpolated = ( this->_vReal[IndexOfMaxY] - (delta * (this->_vReal[IndexOfMaxY] - this->_vReal[IndexOfMaxY+1])) );
}
}

void arduinoFFT::MajorPeak(double *f, double *v)
{
double maxY = 0;
uint16_t IndexOfMaxY = 0;
//If sampling_frequency = 2 * max_frequency in signal,
//value would be stored at position samples/2
for (uint16_t i = 1; i < ((this->_samples >> 1) + 1); i++) {
if ((this->_vReal[i - 1] < this->_vReal[i]) && (this->_vReal[i] > this->_vReal[i + 1])) {
if (this->_vReal[i] > maxY) {
maxY = this->_vReal[i];
IndexOfMaxY = i;
}
}
}
double delta = 0.5 * ((this->_vReal[IndexOfMaxY - 1] - this->_vReal[IndexOfMaxY + 1]) / (this->_vReal[IndexOfMaxY - 1] - (2.0 * this->_vReal[IndexOfMaxY]) + this->_vReal[IndexOfMaxY + 1]));
double interpolatedX = ((IndexOfMaxY + delta) * this->_samplingFrequency) / (this->_samples - 1);
if (IndexOfMaxY == (this->_samples >> 1)) //To improve calculation on edge values
interpolatedX = ((IndexOfMaxY + delta) * this->_samplingFrequency) / (this->_samples);
// returned value: interpolated frequency peak apex
*f = interpolatedX;
#if defined(ESP8266) || defined(ESP32)
*v = fabs(this->_vReal[IndexOfMaxY - 1] - (2.0 * this->_vReal[IndexOfMaxY]) + this->_vReal[IndexOfMaxY + 1]);
#else
*v = abs(this->_vReal[IndexOfMaxY - 1] - (2.0 * this->_vReal[IndexOfMaxY]) + this->_vReal[IndexOfMaxY + 1]);
#endif
}

uint8_t arduinoFFT::Exponent(uint16_t value)
{
#warning("This method may not be accessible on future revisions.")
// Calculates the base 2 logarithm of a value
uint8_t result = 0;
while (((value >> result) & 1) != 1) result++;
return(result);
}

// Private functions

void arduinoFFT::Swap(double *x, double *y)
{
double temp = *x;
*x = *y;
*y = temp;
}

+ 1135
- 0
STM32/Core/Src/main.cpp
File diff suppressed because it is too large
View File


+ 550
- 0
STM32/Core/Src/stm32g0xx_hal_msp.c View File

@@ -0,0 +1,550 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : stm32g0xx_hal_msp.c
* Description : This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern DMA_HandleTypeDef hdma_adc1;
extern DMA_HandleTypeDef hdma_spi1_rx;
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
/* USER CODE END ExternalFunctions */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
/* System interrupt init*/
/** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
*/
HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE);
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/**
* @brief ADC MSP Initialization
* This function configures the hardware resources used in this example
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hadc->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspInit 0 */
/* USER CODE END ADC1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_ADC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**ADC1 GPIO Configuration
PA2 ------> ADC1_IN2
PB1 ------> ADC1_IN9
*/
GPIO_InitStruct.Pin = Device_ID_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(Device_ID_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = BAT_Monitor_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(BAT_Monitor_GPIO_Port, &GPIO_InitStruct);
/* ADC1 DMA Init */
/* ADC1 Init */
hdma_adc1.Instance = DMA1_Channel2;
hdma_adc1.Init.Request = DMA_REQUEST_ADC1;
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
hdma_adc1.Init.Mode = DMA_CIRCULAR;
hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
/* ADC1 interrupt Init */
HAL_NVIC_SetPriority(ADC1_COMP_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC1_COMP_IRQn);
/* USER CODE BEGIN ADC1_MspInit 1 */
/* USER CODE END ADC1_MspInit 1 */
}
}
/**
* @brief ADC MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
{
if(hadc->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspDeInit 0 */
/* USER CODE END ADC1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_ADC_CLK_DISABLE();
/**ADC1 GPIO Configuration
PA2 ------> ADC1_IN2
PB1 ------> ADC1_IN9
*/
HAL_GPIO_DeInit(Device_ID_GPIO_Port, Device_ID_Pin);
HAL_GPIO_DeInit(BAT_Monitor_GPIO_Port, BAT_Monitor_Pin);
/* ADC1 DMA DeInit */
HAL_DMA_DeInit(hadc->DMA_Handle);
/* ADC1 interrupt DeInit */
HAL_NVIC_DisableIRQ(ADC1_COMP_IRQn);
/* USER CODE BEGIN ADC1_MspDeInit 1 */
/* USER CODE END ADC1_MspDeInit 1 */
}
}
/**
* @brief I2C MSP Initialization
* This function configures the hardware resources used in this example
* @param hi2c: I2C handle pointer
* @retval None
*/
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hi2c->Instance==I2C2)
{
/* USER CODE BEGIN I2C2_MspInit 0 */
/* USER CODE END I2C2_MspInit 0 */
__HAL_RCC_GPIOA_CLK_ENABLE();
/**I2C2 GPIO Configuration
PA11 [PA9] ------> I2C2_SCL
PA12 [PA10] ------> I2C2_SDA
*/
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF6_I2C2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_I2C2_CLK_ENABLE();
/* I2C2 interrupt Init */
HAL_NVIC_SetPriority(I2C2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(I2C2_IRQn);
/* USER CODE BEGIN I2C2_MspInit 1 */
/* USER CODE END I2C2_MspInit 1 */
}
}
/**
* @brief I2C MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hi2c: I2C handle pointer
* @retval None
*/
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
{
if(hi2c->Instance==I2C2)
{
/* USER CODE BEGIN I2C2_MspDeInit 0 */
/* USER CODE END I2C2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_I2C2_CLK_DISABLE();
/**I2C2 GPIO Configuration
PA11 [PA9] ------> I2C2_SCL
PA12 [PA10] ------> I2C2_SDA
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12);
/* I2C2 interrupt DeInit */
HAL_NVIC_DisableIRQ(I2C2_IRQn);
/* USER CODE BEGIN I2C2_MspDeInit 1 */
/* USER CODE END I2C2_MspDeInit 1 */
}
}
/**
* @brief I2S MSP Initialization
* This function configures the hardware resources used in this example
* @param hi2s: I2S handle pointer
* @retval None
*/
void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hi2s->Instance==SPI1)
{
/* USER CODE BEGIN SPI1_MspInit 0 */
/* USER CODE END SPI1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**I2S1 GPIO Configuration
PA15 ------> I2S1_WS
PB3 ------> I2S1_CK
PB5 ------> I2S1_SD
*/
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* I2S1 DMA Init */
/* SPI1_RX Init */
hdma_spi1_rx.Instance = DMA1_Channel1;
hdma_spi1_rx.Init.Request = DMA_REQUEST_SPI1_RX;
hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_spi1_rx.Init.Mode = DMA_CIRCULAR;
hdma_spi1_rx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hi2s,hdmarx,hdma_spi1_rx);
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */
}
}
/**
* @brief I2S MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hi2s: I2S handle pointer
* @retval None
*/
void HAL_I2S_MspDeInit(I2S_HandleTypeDef* hi2s)
{
if(hi2s->Instance==SPI1)
{
/* USER CODE BEGIN SPI1_MspDeInit 0 */
/* USER CODE END SPI1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SPI1_CLK_DISABLE();
/**I2S1 GPIO Configuration
PA15 ------> I2S1_WS
PB3 ------> I2S1_CK
PB5 ------> I2S1_SD
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_15);
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_5);
/* I2S1 DMA DeInit */
HAL_DMA_DeInit(hi2s->hdmarx);
/* USER CODE BEGIN SPI1_MspDeInit 1 */
/* USER CODE END SPI1_MspDeInit 1 */
}
}
/**
* @brief SPI MSP Initialization
* This function configures the hardware resources used in this example
* @param hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hspi->Instance==SPI2)
{
/* USER CODE BEGIN SPI2_MspInit 0 */
/* USER CODE END SPI2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_SPI2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**SPI2 GPIO Configuration
PA3 ------> SPI2_MISO
PA4 ------> SPI2_MOSI
PB8 ------> SPI2_SCK
*/
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_SPI2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_SPI2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_SPI2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN SPI2_MspInit 1 */
/* USER CODE END SPI2_MspInit 1 */
}
}
/**
* @brief SPI MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
{
if(hspi->Instance==SPI2)
{
/* USER CODE BEGIN SPI2_MspDeInit 0 */
/* USER CODE END SPI2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SPI2_CLK_DISABLE();
/**SPI2 GPIO Configuration
PA3 ------> SPI2_MISO
PA4 ------> SPI2_MOSI
PB8 ------> SPI2_SCK
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3|GPIO_PIN_4);
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8);
/* USER CODE BEGIN SPI2_MspDeInit 1 */
/* USER CODE END SPI2_MspDeInit 1 */
}
}
/**
* @brief TIM_Base MSP Initialization
* This function configures the hardware resources used in this example
* @param htim_base: TIM_Base handle pointer
* @retval None
*/
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
{
if(htim_base->Instance==TIM2)
{
/* USER CODE BEGIN TIM2_MspInit 0 */
/* USER CODE END TIM2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_TIM2_CLK_ENABLE();
/* USER CODE BEGIN TIM2_MspInit 1 */
/* USER CODE END TIM2_MspInit 1 */
}
}
/**
* @brief TIM_Base MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param htim_base: TIM_Base handle pointer
* @retval None
*/
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
{
if(htim_base->Instance==TIM2)
{
/* USER CODE BEGIN TIM2_MspDeInit 0 */
/* USER CODE END TIM2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM2_CLK_DISABLE();
/* USER CODE BEGIN TIM2_MspDeInit 1 */
/* USER CODE END TIM2_MspDeInit 1 */
}
}
/**
* @brief UART MSP Initialization
* This function configures the hardware resources used in this example
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(huart->Instance==USART4)
{
/* USER CODE BEGIN USART4_MspInit 0 */
/* USER CODE END USART4_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART4_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART4 GPIO Configuration
PA0 ------> USART4_TX
PA1 ------> USART4_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF4_USART4;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE BEGIN USART4_MspInit 1 */
/* USER CODE END USART4_MspInit 1 */
}
}
/**
* @brief UART MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==USART4)
{
/* USER CODE BEGIN USART4_MspDeInit 0 */
/* USER CODE END USART4_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART4_CLK_DISABLE();
/**USART4 GPIO Configuration
PA0 ------> USART4_TX
PA1 ------> USART4_RX
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1);
/* USER CODE BEGIN USART4_MspDeInit 1 */
/* USER CODE END USART4_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 208
- 0
STM32/Core/Src/stm32g0xx_it.c View File

@@ -0,0 +1,208 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g0xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32g0xx_it.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern DMA_HandleTypeDef hdma_adc1;
extern ADC_HandleTypeDef hadc1;
extern I2C_HandleTypeDef hi2c2;
extern DMA_HandleTypeDef hdma_spi1_rx;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M0+ Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
/* USER CODE END NonMaskableInt_IRQn 0 */
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
/* USER CODE END NonMaskableInt_IRQn 1 */
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
/* USER CODE BEGIN SVC_IRQn 0 */
/* USER CODE END SVC_IRQn 0 */
/* USER CODE BEGIN SVC_IRQn 1 */
/* USER CODE END SVC_IRQn 1 */
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
/* USER CODE BEGIN PendSV_IRQn 0 */
/* USER CODE END PendSV_IRQn 0 */
/* USER CODE BEGIN PendSV_IRQn 1 */
/* USER CODE END PendSV_IRQn 1 */
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
/* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */
}
/******************************************************************************/
/* STM32G0xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32g0xx.s). */
/******************************************************************************/
/**
* @brief This function handles DMA1 channel 1 interrupt.
*/
void DMA1_Channel1_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel1_IRQn 0 */
/* USER CODE END DMA1_Channel1_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_spi1_rx);
/* USER CODE BEGIN DMA1_Channel1_IRQn 1 */
/* USER CODE END DMA1_Channel1_IRQn 1 */
}
/**
* @brief This function handles DMA1 channel 2 and channel 3 interrupts.
*/
void DMA1_Channel2_3_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel2_3_IRQn 0 */
/* USER CODE END DMA1_Channel2_3_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_adc1);
/* USER CODE BEGIN DMA1_Channel2_3_IRQn 1 */
/* USER CODE END DMA1_Channel2_3_IRQn 1 */
}
/**
* @brief This function handles ADC1, COMP1 and COMP2 interrupts (COMP interrupts through EXTI lines 17 and 18).
*/
void ADC1_COMP_IRQHandler(void)
{
/* USER CODE BEGIN ADC1_COMP_IRQn 0 */
/* USER CODE END ADC1_COMP_IRQn 0 */
HAL_ADC_IRQHandler(&hadc1);
/* USER CODE BEGIN ADC1_COMP_IRQn 1 */
/* USER CODE END ADC1_COMP_IRQn 1 */
}
/**
* @brief This function handles I2C2 global interrupt.
*/
void I2C2_IRQHandler(void)
{
/* USER CODE BEGIN I2C2_IRQn 0 */
/* USER CODE END I2C2_IRQn 0 */
if (hi2c2.Instance->ISR & (I2C_FLAG_BERR | I2C_FLAG_ARLO | I2C_FLAG_OVR)) {
HAL_I2C_ER_IRQHandler(&hi2c2);
} else {
HAL_I2C_EV_IRQHandler(&hi2c2);
}
/* USER CODE BEGIN I2C2_IRQn 1 */
/* USER CODE END I2C2_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 159
- 0
STM32/Core/Src/syscalls.c View File

@@ -0,0 +1,159 @@
/**
******************************************************************************
* @file syscalls.c
* @author Auto-generated by STM32CubeIDE
* @brief STM32CubeIDE Minimal System calls file
*
* For more information about which c-functions
* need which of these lowlevel functions
* please consult the Newlib libc-manual
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/

/* Includes */
#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>


/* Variables */
//#undef errno
extern int errno;
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));

register char * stack_ptr asm("sp");

char *__env[1] = { 0 };
char **environ = __env;


/* Functions */
void initialise_monitor_handles()
{
}

int _getpid(void)
{
return 1;
}

int _kill(int pid, int sig)
{
errno = EINVAL;
return -1;
}

void _exit (int status)
{
_kill(status, -1);
while (1) {} /* Make sure we hang here */
}

__attribute__((weak)) int _read(int file, char *ptr, int len)
{
int DataIdx;

for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = __io_getchar();
}

return len;
}

__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;

for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}

int _close(int file)
{
return -1;
}


int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}

int _isatty(int file)
{
return 1;
}

int _lseek(int file, int ptr, int dir)
{
return 0;
}

int _open(char *path, int flags, ...)
{
/* Pretend like we always fail */
return -1;
}

int _wait(int *status)
{
errno = ECHILD;
return -1;
}

int _unlink(char *name)
{
errno = ENOENT;
return -1;
}

int _times(struct tms *buf)
{
return -1;
}

int _stat(char *file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}

int _link(char *old, char *new)
{
errno = EMLINK;
return -1;
}

int _fork(void)
{
errno = EAGAIN;
return -1;
}

int _execve(char *name, char **argv, char **env)
{
errno = ENOMEM;
return -1;
}

+ 80
- 0
STM32/Core/Src/sysmem.c View File

@@ -0,0 +1,80 @@
/**
******************************************************************************
* @file sysmem.c
* @author Generated by STM32CubeIDE
* @brief STM32CubeIDE System Memory calls file
*
* For more information about which C functions
* need which of these lowlevel functions
* please consult the newlib libc manual
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/

/* Includes */
#include <errno.h>
#include <stdint.h>

/**
* Pointer to the current high watermark of the heap usage
*/
static uint8_t *__sbrk_heap_end = NULL;

/**
* @brief _sbrk() allocates memory to the newlib heap and is used by malloc
* and others from the C library
*
* @verbatim
* ############################################################################
* # .data # .bss # newlib heap # MSP stack #
* # # # # Reserved by _Min_Stack_Size #
* ############################################################################
* ^-- RAM start ^-- _end _estack, RAM end --^
* @endverbatim
*
* This implementation starts allocating at the '_end' linker symbol
* The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
* The implementation considers '_estack' linker symbol to be RAM end
* NOTE: If the MSP stack, at any point during execution, grows larger than the
* reserved size, please increase the '_Min_Stack_Size'.
*
* @param incr Memory size
* @return Pointer to allocated memory
*/
void *_sbrk(ptrdiff_t incr)
{
extern uint8_t _end; /* Symbol defined in the linker script */
extern uint8_t _estack; /* Symbol defined in the linker script */
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
const uint8_t *max_heap = (uint8_t *)stack_limit;
uint8_t *prev_heap_end;

/* Initalize heap end at first call */
if (NULL == __sbrk_heap_end)
{
__sbrk_heap_end = &_end;
}

/* Protect heap from growing into the reserved MSP stack */
if (__sbrk_heap_end + incr > max_heap)
{
errno = ENOMEM;
return (void *)-1;
}

prev_heap_end = __sbrk_heap_end;
__sbrk_heap_end += incr;

return (void *)prev_heap_end;
}

+ 290
- 0
STM32/Core/Src/system_stm32g0xx.c View File

@@ -0,0 +1,290 @@
/**
******************************************************************************
* @file system_stm32g0xx.c
* @author MCD Application Team
* @brief CMSIS Cortex-M0+ Device Peripheral Access Layer System Source File
*
* This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32g0xx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
* After each device reset the HSI (8 MHz then 16 MHz) is used as system clock source.
* Then SystemInit() function is called, in "startup_stm32g0xx.s" file, to
* configure the system clock before to branch to main program.
*
* This file configures the system clock as follows:
*=============================================================================
*-----------------------------------------------------------------------------
* System Clock source | HSI
*-----------------------------------------------------------------------------
* SYSCLK(Hz) | 16000000
*-----------------------------------------------------------------------------
* HCLK(Hz) | 16000000
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB Prescaler | 1
*-----------------------------------------------------------------------------
* HSI Division factor | 1
*-----------------------------------------------------------------------------
* PLL_M | 1
*-----------------------------------------------------------------------------
* PLL_N | 8
*-----------------------------------------------------------------------------
* PLL_P | 7
*-----------------------------------------------------------------------------
* PLL_Q | 2
*-----------------------------------------------------------------------------
* PLL_R | 2
*-----------------------------------------------------------------------------
* Require 48MHz for RNG | Disabled
*-----------------------------------------------------------------------------
*=============================================================================
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32g0xx_system
* @{
*/
/** @addtogroup STM32G0xx_System_Private_Includes
* @{
*/
#include "stm32g0xx.h"
#if !defined (HSE_VALUE)
#define HSE_VALUE (8000000UL) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSI_VALUE)
#define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
#if !defined (LSI_VALUE)
#define LSI_VALUE (32000UL) /*!< Value of LSI in Hz*/
#endif /* LSI_VALUE */
#if !defined (LSE_VALUE)
#define LSE_VALUE (32768UL) /*!< Value of LSE in Hz*/
#endif /* LSE_VALUE */
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_Defines
* @{
*/
/************************* Miscellaneous Configuration ************************/
/*!< Uncomment the following line if you need to relocate your vector Table in
Internal SRAM. */
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET 0x0U /*!< Vector Table base offset field.
This value must be a multiple of 0x100. */
/******************************************************************************/
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_Variables
* @{
*/
/* The SystemCoreClock variable is updated in three ways:
1) by calling CMSIS function SystemCoreClockUpdate()
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
Note: If you use this function to configure the system clock; then there
is no need to call the 2 first functions listed above, since SystemCoreClock
variable is updated automatically.
*/
uint32_t SystemCoreClock = 16000000UL;
const uint32_t AHBPrescTable[16UL] = {0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL, 6UL, 7UL, 8UL, 9UL};
const uint32_t APBPrescTable[8UL] = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL};
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_Functions
* @{
*/
/**
* @brief Setup the microcontroller system.
* @param None
* @retval None
*/
void SystemInit(void)
{
/* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif
}
/**
* @brief Update SystemCoreClock variable according to Clock Register Values.
* The SystemCoreClock variable contains the core clock (HCLK), it can
* be used by the user application to setup the SysTick timer or configure
* other parameters.
*
* @note Each time the core clock (HCLK) changes, this function must be called
* to update SystemCoreClock variable value. Otherwise, any configuration
* based on this variable will be incorrect.
*
* @note - The system frequency computed by this function is not the real
* frequency in the chip. It is calculated based on the predefined
* constant and the selected clock source:
*
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**) / HSI division factor
*
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
*
* - If SYSCLK source is LSI, SystemCoreClock will contain the LSI_VALUE
*
* - If SYSCLK source is LSE, SystemCoreClock will contain the LSE_VALUE
*
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
* or HSI_VALUE(*) multiplied/divided by the PLL factors.
*
* (**) HSI_VALUE is a constant defined in stm32g0xx_hal_conf.h file (default value
* 16 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (***) HSE_VALUE is a constant defined in stm32g0xx_hal_conf.h file (default value
* 8 MHz), user has to ensure that HSE_VALUE is same as the real
* frequency of the crystal used. Otherwise, this function may
* have wrong result.
*
* - The result of this function could be not correct when using fractional
* value for HSE crystal.
*
* @param None
* @retval None
*/
//void SystemCoreClockUpdate(void)
//{
// uint32_t tmp;
// uint32_t pllvco;
// uint32_t pllr;
// uint32_t pllsource;
// uint32_t pllm;
// uint32_t hsidiv;
//
// /* Get SYSCLK source -------------------------------------------------------*/
// switch (RCC->CFGR & RCC_CFGR_SWS)
// {
// case RCC_CFGR_SWS_HSE: /* HSE used as system clock */ RCC_
// SystemCoreClock = HSE_VALUE;
// break;
//
// case RCC_CFGR_SWS_LSI: /* LSI used as system clock */
// SystemCoreClock = LSI_VALUE;
// break;
//
// case RCC_CFGR_SWS_LSE: /* LSE used as system clock */
// SystemCoreClock = LSE_VALUE;
// break;
//
// case RCC_CFGR_SWS_PLL: /* PLL used as system clock */
// /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
// SYSCLK = PLL_VCO / PLLR
// */
// pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
// pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1UL;
//
// if(pllsource == 0x03UL) /* HSE used as PLL clock source */
// {
// pllvco = (HSE_VALUE / pllm);
// }
// else /* HSI used as PLL clock source */
// {
// pllvco = (HSI_VALUE / pllm);
// }
// pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos);
// pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> RCC_PLLCFGR_PLLR_Pos) + 1UL);
//
// SystemCoreClock = pllvco/pllr;
// break;
//
// case RCC_CFGR_SWS_HSI: /* HSI used as system clock */
// default: /* HSI used as system clock */
// hsidiv = (1UL << ((READ_BIT(RCC->CR, RCC_CR_HSIDIV))>> RCC_CR_HSIDIV_Pos));
// SystemCoreClock = (HSI_VALUE/hsidiv);
// break;
// }
// /* Compute HCLK clock frequency --------------------------------------------*/
// /* Get HCLK prescaler */
// tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)];
// /* HCLK clock frequency */
// SystemCoreClock >>= tmp;
//}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 271
- 0
STM32/noise_sensor.ioc View File

@@ -0,0 +1,271 @@
#MicroXplorer Configuration settings - do not modify
ADC1.Channel-1\#ChannelRegularConversion=ADC_CHANNEL_2
ADC1.Channel-2\#ChannelRegularConversion=ADC_CHANNEL_9
ADC1.Channel-4\#ChannelRegularConversion=ADC_CHANNEL_VREFINT
ADC1.ChannelVREF=ADC_CHANNEL_VREFINT
ADC1.DMAContinuousRequests=ENABLE
ADC1.IPParameters=Rank-1\#ChannelRegularConversion,Channel-1\#ChannelRegularConversion,SamplingTime-1\#ChannelRegularConversion,NbrOfConversionFlag,Rank-2\#ChannelRegularConversion,Channel-2\#ChannelRegularConversion,SamplingTime-2\#ChannelRegularConversion,NbrOfConversion,DMAContinuousRequests,master,SelectedChannel,Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion,ChannelVREF
ADC1.NbrOfConversion=3
ADC1.NbrOfConversionFlag=1
ADC1.Rank-1\#ChannelRegularConversion=1
ADC1.Rank-2\#ChannelRegularConversion=2
ADC1.Rank-4\#ChannelRegularConversion=3
ADC1.SamplingTime-1\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1
ADC1.SamplingTime-2\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1
ADC1.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1
ADC1.SelectedChannel=ADC_CHANNEL_2|ADC_CHANNEL_9|ADC_CHANNEL_VREFINT
ADC1.master=1
Dma.ADC1.1.Direction=DMA_PERIPH_TO_MEMORY
Dma.ADC1.1.EventEnable=DISABLE
Dma.ADC1.1.Instance=DMA1_Channel2
Dma.ADC1.1.MemDataAlignment=DMA_MDATAALIGN_WORD
Dma.ADC1.1.MemInc=DMA_MINC_ENABLE
Dma.ADC1.1.Mode=DMA_CIRCULAR
Dma.ADC1.1.PeriphDataAlignment=DMA_PDATAALIGN_WORD
Dma.ADC1.1.PeriphInc=DMA_PINC_DISABLE
Dma.ADC1.1.Polarity=HAL_DMAMUX_REQ_GEN_RISING
Dma.ADC1.1.Priority=DMA_PRIORITY_LOW
Dma.ADC1.1.RequestNumber=1
Dma.ADC1.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber
Dma.ADC1.1.SignalID=NONE
Dma.ADC1.1.SyncEnable=DISABLE
Dma.ADC1.1.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT
Dma.ADC1.1.SyncRequestNumber=1
Dma.ADC1.1.SyncSignalID=NONE
Dma.Request0=SPI1_RX
Dma.Request1=ADC1
Dma.RequestsNb=2
Dma.SPI1_RX.0.Direction=DMA_PERIPH_TO_MEMORY
Dma.SPI1_RX.0.EventEnable=DISABLE
Dma.SPI1_RX.0.Instance=DMA1_Channel1
Dma.SPI1_RX.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
Dma.SPI1_RX.0.MemInc=DMA_MINC_ENABLE
Dma.SPI1_RX.0.Mode=DMA_CIRCULAR
Dma.SPI1_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
Dma.SPI1_RX.0.PeriphInc=DMA_PINC_DISABLE
Dma.SPI1_RX.0.Polarity=HAL_DMAMUX_REQ_GEN_RISING
Dma.SPI1_RX.0.Priority=DMA_PRIORITY_LOW
Dma.SPI1_RX.0.RequestNumber=1
Dma.SPI1_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber
Dma.SPI1_RX.0.SignalID=NONE
Dma.SPI1_RX.0.SyncEnable=DISABLE
Dma.SPI1_RX.0.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT
Dma.SPI1_RX.0.SyncRequestNumber=1
Dma.SPI1_RX.0.SyncSignalID=NONE
File.Version=6
GPIO.groupedBy=Group By Peripherals
I2C2.I2C_Speed_Mode=I2C_Fast
I2C2.IPParameters=I2C_Speed_Mode,OwnAddress,Timing
I2C2.OwnAddress=0x3C
I2C2.Timing=0x0010061A
I2S1.AudioFreq=I2S_AUDIOFREQ_22K
I2S1.DataFormat=I2S_DATAFORMAT_24B
I2S1.ErrorAudioFreq=3.3 %
I2S1.FullDuplexMode=I2S_FULLDUPLEXMODE_DISABLE
I2S1.IPParameters=Instance,VirtualMode,FullDuplexMode,RealAudioFreq,ErrorAudioFreq,Mode,DataFormat,AudioFreq
I2S1.Instance=SPI$Index
I2S1.Mode=I2S_MODE_MASTER_RX
I2S1.RealAudioFreq=22.727 KHz
I2S1.VirtualMode=I2S_MODE_MASTER
KeepUserPlacement=false
Mcu.Family=STM32G0
Mcu.IP0=ADC1
Mcu.IP1=DMA
Mcu.IP2=I2C2
Mcu.IP3=I2S1
Mcu.IP4=NVIC
Mcu.IP5=RCC
Mcu.IP6=SPI2
Mcu.IP7=SYS
Mcu.IP8=TIM2
Mcu.IP9=USART4
Mcu.IPNb=10
Mcu.Name=STM32G071K(6-8-B)Tx
Mcu.Package=LQFP32
Mcu.Pin0=PA0
Mcu.Pin1=PA1
Mcu.Pin10=PC6
Mcu.Pin11=PA11 [PA9]
Mcu.Pin12=PA12 [PA10]
Mcu.Pin13=PA13
Mcu.Pin14=PA14-BOOT0
Mcu.Pin15=PA15
Mcu.Pin16=PB3
Mcu.Pin17=PB5
Mcu.Pin18=PB8
Mcu.Pin19=VP_ADC1_Vref_Input
Mcu.Pin2=PA2
Mcu.Pin20=VP_SYS_VS_Systick
Mcu.Pin21=VP_SYS_VS_DBSignals
Mcu.Pin22=VP_TIM2_VS_ClockSourceINT
Mcu.Pin3=PA3
Mcu.Pin4=PA4
Mcu.Pin5=PA5
Mcu.Pin6=PA6
Mcu.Pin7=PA7
Mcu.Pin8=PB0
Mcu.Pin9=PB1
Mcu.PinsNb=23
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32G071KBTx
MxCube.Version=6.1.1
MxDb.Version=DB.6.0.10
NVIC.ADC1_COMP_IRQn=true\:0\:0\:false\:false\:true\:true\:true
NVIC.DMA1_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false\:true
NVIC.DMA1_Channel2_3_IRQn=true\:0\:0\:false\:false\:true\:false\:true
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
NVIC.I2C2_IRQn=true\:0\:0\:false\:false\:true\:true\:true
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false
NVIC.SVC_IRQn=true\:0\:0\:false\:false\:true\:false\:false
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true
PA0.Locked=true
PA0.Mode=Asynchronous
PA0.Signal=USART4_TX
PA1.Locked=true
PA1.Mode=Asynchronous
PA1.Signal=USART4_RX
PA11\ [PA9].Mode=I2C
PA11\ [PA9].Signal=I2C2_SCL
PA12\ [PA10].Locked=true
PA12\ [PA10].Mode=I2C
PA12\ [PA10].Signal=I2C2_SDA
PA13.Mode=Serial_Wire
PA13.Signal=SYS_SWDIO
PA14-BOOT0.Mode=Serial_Wire
PA14-BOOT0.Signal=SYS_SWCLK
PA15.Locked=true
PA15.Mode=Half_Duplex_Master
PA15.Signal=I2S1_WS
PA2.GPIOParameters=GPIO_Label
PA2.GPIO_Label=Device_ID
PA2.Locked=true
PA2.Mode=IN2
PA2.Signal=ADC1_IN2
PA3.Locked=true
PA3.Mode=Full_Duplex_Master
PA3.Signal=SPI2_MISO
PA4.Mode=Full_Duplex_Master
PA4.Signal=SPI2_MOSI
PA5.GPIOParameters=PinState,GPIO_Label
PA5.GPIO_Label=NSS
PA5.Locked=true
PA5.PinState=GPIO_PIN_SET
PA5.Signal=GPIO_Output
PA6.GPIOParameters=GPIO_Label
PA6.GPIO_Label=LED
PA6.Locked=true
PA6.Signal=GPIO_Output
PA7.GPIOParameters=GPIO_Label
PA7.GPIO_Label=RESET
PA7.Locked=true
PA7.Signal=GPIO_Output
PB0.GPIOParameters=GPIO_PuPd
PB0.GPIO_PuPd=GPIO_NOPULL
PB0.Locked=true
PB0.Signal=GPIO_Input
PB1.GPIOParameters=GPIO_Label
PB1.GPIO_Label=BAT_Monitor
PB1.Locked=true
PB1.Mode=IN9
PB1.Signal=ADC1_IN9
PB3.Locked=true
PB3.Mode=Half_Duplex_Master
PB3.Signal=I2S1_CK
PB5.Locked=true
PB5.Mode=Half_Duplex_Master
PB5.Signal=I2S1_SD
PB8.Mode=Full_Duplex_Master
PB8.Signal=SPI2_SCK
PC6.GPIOParameters=GPIO_PuPd,GPIO_Label
PC6.GPIO_Label=I2C_Address
PC6.GPIO_PuPd=GPIO_PULLUP
PC6.Locked=true
PC6.Signal=GPIO_Input
PinOutPanel.RotationAngle=0
ProjectManager.AskForMigrate=true
ProjectManager.BackupPrevious=false
ProjectManager.CompilerOptimize=6
ProjectManager.ComputerToolchain=false
ProjectManager.CoupleFile=false
ProjectManager.CustomerFirmwarePackage=
ProjectManager.DefaultFWLocation=true
ProjectManager.DeletePrevious=true
ProjectManager.DeviceId=STM32G071KBTx
ProjectManager.FirmwarePackage=STM32Cube FW_G0 V1.4.0
ProjectManager.FreePins=false
ProjectManager.HalAssertFull=false
ProjectManager.HeapSize=0x200
ProjectManager.KeepUserCode=true
ProjectManager.LastFirmware=true
ProjectManager.LibraryCopy=1
ProjectManager.MainLocation=Core/Src
ProjectManager.NoMain=false
ProjectManager.PreviousToolchain=
ProjectManager.ProjectBuild=false
ProjectManager.ProjectFileName=noise_sensor.ioc
ProjectManager.ProjectName=noise_sensor
ProjectManager.RegisterCallBack=ADC,I2C,I2S
ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_I2S1_Init-I2S1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_I2C2_Init-I2C2-false-HAL-true,8-MX_USART4_UART_Init-USART4-false-HAL-true,9-MX_TIM2_Init-TIM2-false-HAL-true
RCC.ADCFreq_Value=16000000
RCC.AHBFreq_Value=16000000
RCC.APBFreq_Value=16000000
RCC.APBTimFreq_Value=16000000
RCC.CECFreq_Value=32786.88524590164
RCC.CortexFreq_Value=16000000
RCC.EXTERNAL_CLOCK_VALUE=48000
RCC.FCLKCortexFreq_Value=16000000
RCC.FamilyName=M
RCC.HCLKFreq_Value=16000000
RCC.HSE_VALUE=8000000
RCC.HSI_VALUE=16000000
RCC.I2C1Freq_Value=16000000
RCC.I2S1Freq_Value=16000000
RCC.IPParameters=ADCFreq_Value,AHBFreq_Value,APBFreq_Value,APBTimFreq_Value,CECFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2S1Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLR,PLLRCLKFreq_Value,PWRFreq_Value,SYSCLKFreq_VALUE,TIM15Freq_Value,TIM1Freq_Value,USART1Freq_Value,USART2Freq_Value,VCOInputFreq_Value,VCOOutputFreq_Value
RCC.LPTIM1Freq_Value=16000000
RCC.LPTIM2Freq_Value=16000000
RCC.LPUART1Freq_Value=16000000
RCC.LSCOPinFreq_Value=32000
RCC.LSE_VALUE=32768
RCC.LSI_VALUE=32000
RCC.MCO1PinFreq_Value=16000000
RCC.PLLPoutputFreq_Value=64000000
RCC.PLLQoutputFreq_Value=64000000
RCC.PLLR=RCC_PLLR_DIV4
RCC.PLLRCLKFreq_Value=32000000
RCC.PWRFreq_Value=16000000
RCC.SYSCLKFreq_VALUE=16000000
RCC.TIM15Freq_Value=16000000
RCC.TIM1Freq_Value=16000000
RCC.USART1Freq_Value=16000000
RCC.USART2Freq_Value=16000000
RCC.VCOInputFreq_Value=16000000
RCC.VCOOutputFreq_Value=128000000
SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_2
SPI2.CalculateBaudRate=8.0 MBits/s
SPI2.DataSize=SPI_DATASIZE_8BIT
SPI2.Direction=SPI_DIRECTION_2LINES
SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,BaudRatePrescaler
SPI2.Mode=SPI_MODE_MASTER
SPI2.VirtualType=VM_MASTER
TIM2.IPParameters=Prescaler
TIM2.Prescaler=16-1
USART4.IPParameters=VirtualMode-Asynchronous,Mode
USART4.Mode=MODE_TX
USART4.VirtualMode-Asynchronous=VM_ASYNC
VP_ADC1_Vref_Input.Mode=IN-Vrefint
VP_ADC1_Vref_Input.Signal=ADC1_Vref_Input
VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals
VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
VP_TIM2_VS_ClockSourceINT.Mode=Internal
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
board=custom
isbadioc=false

Loading…
Cancel
Save