├── BMS-Schematic ├── BMS.pretty │ ├── 2178710-4_1.kicad_mod │ ├── 744242471.kicad_mod │ ├── ACT45B-101-2P.kicad_mod │ ├── Connector_5.08mm_1x2.kicad_mod │ ├── DO-214AB.kicad_mod │ ├── LQFP-32_7x7mm_P0.8mm_STM32custom.kicad_mod │ ├── README │ └── SOT-6.kicad_mod ├── GERBERS │ ├── BMSmodul0_GERBERS.zip │ ├── README │ ├── Sintaksa-stm32g031-BMSmodul-B_Cu.gbr │ ├── Sintaksa-stm32g031-BMSmodul-B_Mask.gbr │ ├── Sintaksa-stm32g031-BMSmodul-B_SilkS.gbr │ ├── Sintaksa-stm32g031-BMSmodul-Edge_Cuts.gbr │ ├── Sintaksa-stm32g031-BMSmodul-F_Cu.gbr │ ├── Sintaksa-stm32g031-BMSmodul-F_Mask.gbr │ ├── Sintaksa-stm32g031-BMSmodul-F_SilkS.gbr │ ├── Sintaksa-stm32g031-BMSmodul-NPTH.drl │ ├── Sintaksa-stm32g031-BMSmodul-PTH.drl │ └── Sintaksa-stm32g031-BMSmodul-job.gbrjob ├── README └── STM32G031-BMS.pdf ├── BMS-layer-design-3Dview ├── BMS-3d view smaller.png ├── BMS-layerView1.png ├── BMS-layerView2.png ├── BMS-layerView3.png ├── README ├── STM32_BMS(2).png └── STM32_BMS.png ├── BMS-stm32f407vg-code ├── README ├── main.c └── main2.c ├── BMS-stm32g0-code ├── FreeRTOS-main.c ├── README ├── adc_temp_testing.c ├── adc_testing.c ├── adc_testing2.c ├── statusLED_test.c ├── temp_data_sending.c ├── transistor_test.c └── uart1_testing.c ├── BMSv2.0-Layout ├── BMSv2.0-3D-view.png ├── BMSv2.0-PCBLayout-view.png └── README ├── KiCad-zip-file ├── README └── Sintaksa-stm32g031-BMSmodul.zip └── README.md /BMS-Schematic/BMS.pretty/2178710-4_1.kicad_mod: -------------------------------------------------------------------------------- 1 | (module "21787-4 connector:2178710-4_1" (layer F.Cu) (tedit 5F196B82) 2 | (fp_text reference REF** (at 0.7 -0.05) (layer F.SilkS) 3 | (effects (font (size 1 1) (thickness 0.15))) 4 | ) 5 | (fp_text value 2178710-4_1 (at 0 -4.55) (layer F.Fab) 6 | (effects (font (size 1 1) (thickness 0.15))) 7 | ) 8 | (fp_line (start -3.07 2.075) (end -2.575 2.75) (layer F.SilkS) (width 0.12)) 9 | (fp_line (start -4 -3.6) (end -4 -2) (layer F.CrtYd) (width 0.12)) 10 | (fp_line (start 5.25 -3.6) (end -4 -3.6) (layer F.CrtYd) (width 0.12)) 11 | (fp_line (start 5.25 3.75) (end 5.25 -3.6) (layer F.CrtYd) (width 0.12)) 12 | (fp_line (start 5 3.75) (end 5.25 3.75) (layer F.CrtYd) (width 0.12)) 13 | (fp_line (start -4 3.75) (end 5 3.75) (layer F.CrtYd) (width 0.12)) 14 | (fp_line (start -4 -2) (end -4 3.75) (layer F.CrtYd) (width 0.12)) 15 | (fp_line (start -2.92 -1.98) (end -2.92 2) (layer F.Fab) (width 0.12)) 16 | (fp_line (start -2.92 2) (end -2.425 2.675) (layer F.Fab) (width 0.12)) 17 | (fp_line (start -2.425 2.675) (end 4.24 2.67) (layer F.Fab) (width 0.12)) 18 | (fp_line (start -2.92 -1.98) (end -2.92 -2.65) (layer F.Fab) (width 0.12)) 19 | (fp_line (start -2.92 -2.65) (end 4.24 -2.65) (layer F.Fab) (width 0.12)) 20 | (fp_line (start 4.24 -2.65) (end 4.24 -1.98) (layer F.Fab) (width 0.12)) 21 | (fp_line (start 4.24 -1.98) (end 4.24 1.98) (layer F.Fab) (width 0.12)) 22 | (fp_line (start 4.24 1.98) (end 4.24 2.67) (layer F.Fab) (width 0.12)) 23 | (pad 4 thru_hole circle (at 2.54 -1.27) (size 1.4 1.4) (drill 0.9) (layers *.Cu *.Mask)) 24 | (pad 3 thru_hole circle (at 1.27 1.27) (size 1.4 1.4) (drill 0.9) (layers *.Cu *.Mask)) 25 | (pad 2 thru_hole circle (at 0 -1.27) (size 1.4 1.4) (drill 0.9) (layers *.Cu *.Mask)) 26 | (pad 1 thru_hole circle (at -1.27 1.27) (size 1.4 1.4) (drill 0.9) (layers *.Cu *.Mask)) 27 | ) 28 | -------------------------------------------------------------------------------- /BMS-Schematic/BMS.pretty/744242471.kicad_mod: -------------------------------------------------------------------------------- 1 | (module LQFP-32_7x7mm_P0.8mm_STM32custom:744242471 (layer F.Cu) (tedit 5F0D80EF) 2 | (fp_text reference REF** (at 0.04 -2.92) (layer F.SilkS) 3 | (effects (font (size 1 1) (thickness 0.15))) 4 | ) 5 | (fp_text value 744242471 (at -0.02 -4.17) (layer F.Fab) 6 | (effects (font (size 1 1) (thickness 0.15))) 7 | ) 8 | (fp_text user 3 (at 2.97 2.24) (layer F.Fab) 9 | (effects (font (size 1 1) (thickness 0.15))) 10 | ) 11 | (fp_text user 4 (at 2.97 -1.76) (layer F.Fab) 12 | (effects (font (size 1 1) (thickness 0.15))) 13 | ) 14 | (fp_text user 2 (at -3.06 2.26) (layer F.Fab) 15 | (effects (font (size 1 1) (thickness 0.15))) 16 | ) 17 | (fp_text user 1 (at -3.07 -1.73) (layer F.Fab) 18 | (effects (font (size 1 1) (thickness 0.15))) 19 | ) 20 | (fp_line (start 2.49 -1.42) (end 2.49 1.36) (layer F.Fab) (width 0.12)) 21 | (fp_line (start 2.49 -1.42) (end 2.49 1.36) (layer F.CrtYd) (width 0.12)) 22 | (fp_line (start 2.49 1.36) (end -2.46 1.36) (layer F.Fab) (width 0.12)) 23 | (fp_line (start 2.49 1.36) (end -2.46 1.36) (layer F.CrtYd) (width 0.12)) 24 | (fp_line (start -2.46 -1.42) (end -2.46 1.36) (layer F.Fab) (width 0.12)) 25 | (fp_line (start -2.46 -1.42) (end -2.46 1.36) (layer F.CrtYd) (width 0.12)) 26 | (fp_line (start -2.46 -1.42) (end 2.49 -1.42) (layer F.Fab) (width 0.12)) 27 | (fp_line (start -2.46 -1.42) (end 2.49 -1.42) (layer F.CrtYd) (width 0.12)) 28 | (fp_line (start -2.46 -1.42) (end 2.49 -1.42) (layer F.SilkS) (width 0.12)) 29 | (fp_line (start 2.49 1.36) (end -2.46 1.36) (layer F.SilkS) (width 0.12)) 30 | (fp_line (start 2.49 -1.42) (end 2.49 1.36) (layer F.SilkS) (width 0.12)) 31 | (fp_line (start -2.46 -1.42) (end -2.46 1.36) (layer F.SilkS) (width 0.12)) 32 | (pad 4 smd rect (at 2.275 -0.635) (size 1.85 0.6) (layers F.Cu F.Paste F.Mask)) 33 | (pad 3 smd rect (at 2.275 0.635) (size 1.85 0.6) (layers F.Cu F.Paste F.Mask)) 34 | (pad 2 smd rect (at -2.275 0.635) (size 1.85 0.6) (layers F.Cu F.Paste F.Mask)) 35 | (pad 1 smd rect (at -2.275 -0.635) (size 1.85 0.6) (layers F.Cu F.Paste F.Mask)) 36 | ) 37 | -------------------------------------------------------------------------------- /BMS-Schematic/BMS.pretty/ACT45B-101-2P.kicad_mod: -------------------------------------------------------------------------------- 1 | (module LQFP-32_7x7mm_P0.8mm_STM32custom:ACT45B-101-2P (layer F.Cu) (tedit 5F0D8DC9) 2 | (fp_text reference REF** (at 0.03 -3.56) (layer F.SilkS) 3 | (effects (font (size 1 1) (thickness 0.15))) 4 | ) 5 | (fp_text value ACT45B-101-2P (at -0.02 -5.05) (layer F.Fab) 6 | (effects (font (size 1 1) (thickness 0.15))) 7 | ) 8 | (fp_text user 4 (at 4.16 -1.34) (layer F.Fab) 9 | (effects (font (size 1 1) (thickness 0.15))) 10 | ) 11 | (fp_text user 3 (at 4.18 1.39) (layer F.Fab) 12 | (effects (font (size 1 1) (thickness 0.15))) 13 | ) 14 | (fp_text user 2 (at -4.18 1.38) (layer F.Fab) 15 | (effects (font (size 1 1) (thickness 0.15))) 16 | ) 17 | (fp_text user 1 (at -4.09 -1.35) (layer F.Fab) 18 | (effects (font (size 1 1) (thickness 0.15))) 19 | ) 20 | (fp_line (start 3.18 -1.9) (end -2.59 -1.9) (layer F.Fab) (width 0.12)) 21 | (fp_line (start 3.17 -1.9) (end -2.6 -1.9) (layer F.CrtYd) (width 0.12)) 22 | (fp_line (start 3.18 1.94) (end 3.18 -1.9) (layer F.Fab) (width 0.12)) 23 | (fp_line (start 3.18 1.94) (end 3.18 -1.9) (layer F.CrtYd) (width 0.12)) 24 | (fp_line (start -3.19 1.94) (end 3.18 1.94) (layer F.Fab) (width 0.12)) 25 | (fp_line (start -3.19 1.94) (end 3.18 1.94) (layer F.CrtYd) (width 0.12)) 26 | (fp_line (start -3.19 -1.32) (end -3.19 1.94) (layer F.Fab) (width 0.12)) 27 | (fp_line (start -3.19 -1.32) (end -3.19 1.94) (layer F.CrtYd) (width 0.12)) 28 | (fp_line (start 3.18 -1.9) (end -2.59 -1.9) (layer F.SilkS) (width 0.12)) 29 | (fp_line (start 3.18 1.94) (end 3.18 -1.9) (layer F.SilkS) (width 0.12)) 30 | (fp_line (start -3.19 1.94) (end 3.18 1.94) (layer F.SilkS) (width 0.12)) 31 | (fp_line (start -3.19 -1.32) (end -3.19 1.94) (layer F.SilkS) (width 0.12)) 32 | (pad 4 smd rect (at 2.275 -1.25) (size 1.35 0.9) (layers F.Cu F.Paste F.Mask)) 33 | (pad 3 smd rect (at 2.275 1.25) (size 1.35 0.9) (layers F.Cu F.Paste F.Mask)) 34 | (pad 2 smd rect (at -2.275 1.25) (size 1.35 0.9) (layers F.Cu F.Paste F.Mask)) 35 | (pad 1 smd rect (at -2.275 -1.25) (size 1.35 0.9) (layers F.Cu F.Paste F.Mask)) 36 | ) 37 | -------------------------------------------------------------------------------- /BMS-Schematic/BMS.pretty/Connector_5.08mm_1x2.kicad_mod: -------------------------------------------------------------------------------- 1 | (module "1x2 5.08mm connector:Connector_5.08mm_1x2" (layer F.Cu) (tedit 5F2BC745) 2 | (fp_text reference J1 (at 0 3.1 -180) (layer F.SilkS) 3 | (effects (font (size 1 1) (thickness 0.15))) 4 | ) 5 | (fp_text value "Battery Conn" (at 0.03 -4.11 -180) (layer F.Fab) 6 | (effects (font (size 1 1) (thickness 0.15))) 7 | ) 8 | (fp_arc (start -2.49 0.03) (end -3.429999 -0.959999) (angle -359.4) (layer Eco2.User) (width 0.05)) 9 | (fp_arc (start 2.53 0) (end 1.590001 -0.989999) (angle -359.4) (layer Eco2.User) (width 0.05)) 10 | (fp_line (start 4.11 -2) (end -4 -2) (layer F.CrtYd) (width 0.12)) 11 | (fp_line (start 4.11 1.99) (end 4.11 -2) (layer F.CrtYd) (width 0.12)) 12 | (fp_line (start -4 1.99) (end 4.11 1.99) (layer F.CrtYd) (width 0.12)) 13 | (fp_line (start -4 -2) (end -4 1.99) (layer F.CrtYd) (width 0.12)) 14 | (fp_line (start -4 -1.99) (end -4 1.99) (layer F.CrtYd) (width 0.05)) 15 | (fp_line (start -4 -1.99) (end 4.11 -1.99) (layer F.CrtYd) (width 0.05)) 16 | (fp_line (start 4.11 -1.99) (end 4.11 1.99) (layer F.CrtYd) (width 0.05)) 17 | (fp_line (start 4.11 1.99) (end -4 1.99) (layer F.CrtYd) (width 0.05)) 18 | (fp_line (start 1 -1.5) (end 4 -1.5) (layer F.SilkS) (width 0.05)) 19 | (fp_line (start 4 -1.5) (end 4 1.5) (layer F.SilkS) (width 0.05)) 20 | (fp_line (start 4 1.5) (end 1 1.5) (layer F.SilkS) (width 0.05)) 21 | (fp_line (start 1 1.5) (end 1 -1.5) (layer F.SilkS) (width 0.05)) 22 | (fp_line (start 1 1.5) (end 1 -1.5) (layer F.CrtYd) (width 0.05)) 23 | (fp_line (start 1 1.5) (end 1 -1.5) (layer F.Fab) (width 0.05)) 24 | (fp_line (start 1 -1.5) (end 4 -1.5) (layer F.Fab) (width 0.05)) 25 | (fp_line (start 1 -1.5) (end 4 -1.5) (layer F.CrtYd) (width 0.05)) 26 | (fp_line (start 4 -1.5) (end 4 1.5) (layer F.Fab) (width 0.05)) 27 | (fp_line (start 4 -1.5) (end 4 1.5) (layer F.CrtYd) (width 0.05)) 28 | (fp_line (start 4 1.5) (end 1 1.5) (layer F.Fab) (width 0.05)) 29 | (fp_line (start 4 1.5) (end 1 1.5) (layer F.CrtYd) (width 0.05)) 30 | (fp_line (start -4 -1.99) (end 4.11 -1.99) (layer F.CrtYd) (width 0.05)) 31 | (fp_line (start -4 -2) (end -4 1.98) (layer F.Fab) (width 0.05)) 32 | (fp_line (start 4.11 1.98) (end -4 1.98) (layer F.Fab) (width 0.05)) 33 | (fp_line (start 4.11 -2) (end 4.11 1.98) (layer F.Fab) (width 0.05)) 34 | (pad 2 thru_hole rect (at 2.54 0) (size 1.7 1.7) (drill 1.1) (layers *.Cu *.Mask)) 35 | (pad 1 thru_hole rect (at -2.54 0) (size 1.7 1.7) (drill 1.1) (layers *.Cu *.Mask)) 36 | ) 37 | -------------------------------------------------------------------------------- /BMS-Schematic/BMS.pretty/DO-214AB.kicad_mod: -------------------------------------------------------------------------------- 1 | (module SS34:DO-214AB (layer F.Cu) (tedit 5F0EFBF8) 2 | (fp_text reference REF** (at 0 -2.96) (layer F.SilkS) 3 | (effects (font (size 1 1) (thickness 0.15))) 4 | ) 5 | (fp_text value DO-214AB (at 0 -4.3) (layer F.Fab) 6 | (effects (font (size 1 1) (thickness 0.15))) 7 | ) 8 | (fp_text user K (at -4.82 0.06) (layer F.SilkS) 9 | (effects (font (size 1 1) (thickness 0.15))) 10 | ) 11 | (fp_line (start -3.16 -2.2) (end -4.22 -1.19) (layer F.SilkS) (width 0.12)) 12 | (fp_line (start 3.94 -2.18) (end -3.16 -2.2) (layer F.SilkS) (width 0.12)) 13 | (fp_line (start -4.21 1.96) (end -4.22 -1.19) (layer F.SilkS) (width 0.12)) 14 | (fp_line (start 3.94 1.96) (end 3.94 -2.18) (layer F.SilkS) (width 0.12)) 15 | (fp_line (start -4.21 1.96) (end 3.94 1.96) (layer F.SilkS) (width 0.12)) 16 | (pad 2 smd rect (at 2.545 0) (size 1.52 3.2) (layers F.Cu F.Paste F.Mask)) 17 | (pad 1 smd rect (at -2.545 0) (size 1.52 3.2) (layers F.Cu F.Paste F.Mask)) 18 | ) 19 | -------------------------------------------------------------------------------- /BMS-Schematic/BMS.pretty/LQFP-32_7x7mm_P0.8mm_STM32custom.kicad_mod: -------------------------------------------------------------------------------- 1 | (module Package_QFP:LQFP-32_7x7mm_P0.8mm_STM32custom (layer F.Cu) (tedit 5F05BC30) 2 | (fp_text reference REF** (at 0.05 7.9) (layer F.SilkS) 3 | (effects (font (size 1 1) (thickness 0.15))) 4 | ) 5 | (fp_text value LQFP-32_7x7mm_P0.8mm_STM32custom (at 0 -9.5) (layer F.Fab) 6 | (effects (font (size 1 1) (thickness 0.15))) 7 | ) 8 | (fp_line (start 3.1 -3.9) (end 3.1 -5) (layer F.CrtYd) (width 0.05)) 9 | (fp_line (start 3.6 -3.9) (end 3.1 -3.9) (layer F.CrtYd) (width 0.05)) 10 | (fp_line (start 3.6 -3.1) (end 3.6 -3.9) (layer F.CrtYd) (width 0.05)) 11 | (fp_line (start 5.2 -3.1) (end 3.6 -3.1) (layer F.CrtYd) (width 0.05)) 12 | (fp_line (start 5.2 3.15) (end 5.2 -3.1) (layer F.CrtYd) (width 0.05)) 13 | (fp_line (start 3.6 3.15) (end 5.2 3.15) (layer F.CrtYd) (width 0.05)) 14 | (fp_line (start 3.6 5.1) (end 3.6 3.15) (layer F.CrtYd) (width 0.05)) 15 | (fp_line (start 3.15 5.1) (end 3.6 5.1) (layer F.CrtYd) (width 0.05)) 16 | (fp_line (start -3.3 -3.85) (end -3.3 -5) (layer F.CrtYd) (width 0.05)) 17 | (fp_line (start -3.65 -3.85) (end -3.3 -3.85) (layer F.CrtYd) (width 0.05)) 18 | (fp_line (start -3.65 -3.15) (end -3.65 -3.85) (layer F.CrtYd) (width 0.05)) 19 | (fp_line (start -5 -3.15) (end -3.65 -3.15) (layer F.CrtYd) (width 0.05)) 20 | (fp_line (start -5 3.15) (end -5 -3.15) (layer F.CrtYd) (width 0.05)) 21 | (fp_line (start -3.7 3.15) (end -5 3.15) (layer F.CrtYd) (width 0.05)) 22 | (fp_line (start -3.7 5.1) (end -3.7 3.15) (layer F.CrtYd) (width 0.05)) 23 | (fp_line (start -3.25 5.1) (end -3.7 5.1) (layer F.CrtYd) (width 0.05)) 24 | (fp_line (start -3.3 5.1) (end 3.2 5.1) (layer F.CrtYd) (width 0.05)) 25 | (fp_line (start -3.3 -5) (end 3.1 -5) (layer F.CrtYd) (width 0.05)) 26 | (fp_text user 1 (at -6.95 -3.15) (layer F.Fab) 27 | (effects (font (size 1 1) (thickness 0.15))) 28 | ) 29 | (fp_line (start -3.55 -3.75) (end -3.15 -3.75) (layer F.SilkS) (width 0.12)) 30 | (fp_line (start -3.55 -3.15) (end -3.55 -3.75) (layer F.SilkS) (width 0.12)) 31 | (fp_line (start -3.6 -3.15) (end -3.55 -3.15) (layer F.SilkS) (width 0.12)) 32 | (fp_line (start -3.6 -3.15) (end -4.9 -3.15) (layer F.SilkS) (width 0.12)) 33 | (fp_line (start -3.55 3.65) (end -3.15 3.65) (layer F.SilkS) (width 0.12)) 34 | (fp_line (start -3.55 3.15) (end -3.55 3.65) (layer F.SilkS) (width 0.12)) 35 | (fp_line (start 3.45 3.65) (end 3.1 3.65) (layer F.SilkS) (width 0.12)) 36 | (fp_line (start 3.45 3.6) (end 3.45 3.65) (layer F.SilkS) (width 0.12)) 37 | (fp_line (start 3.45 3.2) (end 3.45 3.6) (layer F.SilkS) (width 0.12)) 38 | (fp_line (start 3.45 -3.75) (end 3.45 -3.3) (layer F.SilkS) (width 0.12)) 39 | (fp_line (start 3.1 -3.75) (end 3.45 -3.75) (layer F.SilkS) (width 0.12)) 40 | (fp_line (start -3.35 3.5) (end -3.35 -2.6) (layer F.Fab) (width 0.09)) 41 | (fp_line (start 3.3 3.5) (end -3.35 3.5) (layer F.Fab) (width 0.09)) 42 | (fp_line (start 3.3 -3.55) (end 3.3 3.5) (layer F.Fab) (width 0.09)) 43 | (fp_line (start -2.5 -3.55) (end 3.3 -3.55) (layer F.Fab) (width 0.09)) 44 | (fp_line (start -3.35 -2.6) (end -2.5 -3.55) (layer F.Fab) (width 0.09)) 45 | (pad 32 smd rect (at -2.8 -4.685 270) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 46 | (pad 31 smd rect (at -2 -4.685 270) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 47 | (pad 30 smd rect (at -1.2 -4.685 270) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 48 | (pad 29 smd rect (at -0.4 -4.685 270) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 49 | (pad 28 smd rect (at 0.4 -4.685 270) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 50 | (pad 27 smd rect (at 1.2 -4.685 270) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 51 | (pad 26 smd rect (at 2 -4.685 270) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 52 | (pad 25 smd rect (at 2.8 -4.685 270) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 53 | (pad 24 smd rect (at 4.685 -2.8 180) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 54 | (pad 23 smd rect (at 4.685 -2 180) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 55 | (pad 22 smd rect (at 4.685 -1.2 180) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 56 | (pad 21 smd rect (at 4.685 -0.4 180) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 57 | (pad 20 smd rect (at 4.685 0.4 180) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 58 | (pad 19 smd rect (at 4.685 1.2 180) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 59 | (pad 18 smd rect (at 4.685 2 180) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 60 | (pad 17 smd rect (at 4.685 2.8 180) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 61 | (pad 16 smd rect (at 2.8 4.685 90) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 62 | (pad 15 smd rect (at 2 4.685 90) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 63 | (pad 14 smd rect (at 1.2 4.685 90) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 64 | (pad 13 smd rect (at 0.4 4.685 90) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 65 | (pad 12 smd rect (at -0.4 4.685 90) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 66 | (pad 11 smd rect (at -1.2 4.685 90) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 67 | (pad 10 smd rect (at -2 4.685 90) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 68 | (pad 9 smd rect (at -2.8 4.685 90) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 69 | (pad 8 smd rect (at -4.685 2.8) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 70 | (pad 7 smd rect (at -4.685 2) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 71 | (pad 6 smd rect (at -4.685 1.2) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 72 | (pad 5 smd rect (at -4.685 0.4) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 73 | (pad 4 smd rect (at -4.685 -0.4) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 74 | (pad 3 smd rect (at -4.685 -1.2) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 75 | (pad 2 smd rect (at -4.685 -2) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 76 | (pad 1 smd rect (at -4.685 -2.8) (size 3 0.37) (layers F.Cu F.Paste F.Mask)) 77 | ) 78 | -------------------------------------------------------------------------------- /BMS-Schematic/BMS.pretty/README: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /BMS-Schematic/BMS.pretty/SOT-6.kicad_mod: -------------------------------------------------------------------------------- 1 | (module LQFP-32_7x7mm_P0.8mm_STM32custom:SOT-6 (layer F.Cu) (tedit 5F0D5E25) 2 | (fp_text reference REF** (at 0 -5.08) (layer F.SilkS) 3 | (effects (font (size 1 1) (thickness 0.15))) 4 | ) 5 | (fp_text value SOT-6 (at 0 -3.81) (layer F.Fab) 6 | (effects (font (size 1 1) (thickness 0.15))) 7 | ) 8 | (fp_text user 1 (at -2.59 -0.96) (layer F.CrtYd) 9 | (effects (font (size 0.4 0.4) (thickness 0.08))) 10 | ) 11 | (fp_line (start -0.83 1.39) (end 0.78 1.39) (layer F.SilkS) (width 0.12)) 12 | (fp_line (start 0.78 1.39) (end 0.78 -1.39) (layer F.SilkS) (width 0.12)) 13 | (fp_line (start -0.83 1.39) (end -0.83 -0.92) (layer F.SilkS) (width 0.12)) 14 | (fp_line (start -0.83 -0.92) (end -0.83 -1.01) (layer F.SilkS) (width 0.12)) 15 | (fp_line (start -0.83 -1.01) (end -0.83 -1.08) (layer F.SilkS) (width 0.12)) 16 | (fp_line (start -0.83 -1.08) (end -0.58 -1.39) (layer F.SilkS) (width 0.12)) 17 | (fp_line (start -0.58 -1.39) (end 0.78 -1.39) (layer F.SilkS) (width 0.12)) 18 | (fp_line (start -0.58 -1.39) (end 0.78 -1.39) (layer F.CrtYd) (width 0.12)) 19 | (fp_line (start 0.78 1.39) (end 0.78 -1.39) (layer F.CrtYd) (width 0.12)) 20 | (fp_line (start -0.82 1.39) (end 0.78 1.39) (layer F.CrtYd) (width 0.12)) 21 | (fp_line (start -0.82 1.39) (end -0.82 -1.08) (layer F.CrtYd) (width 0.12)) 22 | (fp_line (start -0.82 -1.08) (end -0.58 -1.39) (layer F.CrtYd) (width 0.12)) 23 | (fp_line (start -0.82 -1.09) (end -0.59 -1.39) (layer F.Fab) (width 0.12)) 24 | (fp_line (start -0.59 -1.39) (end 0.77 -1.39) (layer F.Fab) (width 0.12)) 25 | (fp_line (start 0.78 1.38) (end 0.78 -1.39) (layer F.Fab) (width 0.12)) 26 | (fp_line (start -0.83 1.38) (end 0.78 1.38) (layer F.Fab) (width 0.12)) 27 | (fp_line (start -0.82 1.38) (end -0.82 -1.09) (layer F.Fab) (width 0.12)) 28 | (pad 6 smd roundrect (at 1.55 -0.95) (size 1.5 0.6) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.1)) 29 | (pad 5 smd roundrect (at 1.55 0) (size 1.5 0.6) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.1)) 30 | (pad 4 smd roundrect (at 1.55 0.95) (size 1.5 0.6) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.1)) 31 | (pad 3 smd roundrect (at -1.55 0.95) (size 1.5 0.6) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.1)) 32 | (pad 2 smd roundrect (at -1.55 0) (size 1.5 0.6) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.1)) 33 | (pad 1 smd roundrect (at -1.55 -0.95) (size 1.5 0.6) (layers F.Cu F.Paste F.Mask) (roundrect_rratio 0.1)) 34 | ) 35 | -------------------------------------------------------------------------------- /BMS-Schematic/GERBERS/BMSmodul0_GERBERS.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/BMS-Schematic/GERBERS/BMSmodul0_GERBERS.zip -------------------------------------------------------------------------------- /BMS-Schematic/GERBERS/README: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /BMS-Schematic/GERBERS/Sintaksa-stm32g031-BMSmodul-B_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,(5.1.6)-1*% 2 | %TF.CreationDate,2020-08-06T11:36:23+02:00*% 3 | %TF.ProjectId,Sintaksa-stm32g031-BMSmodul,53696e74-616b-4736-912d-73746d333267,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L2,Bot*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW (5.1.6)-1) date 2020-08-06 11:36:23* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ComponentPad*% 15 | %ADD10R,1.700000X1.700000*% 16 | %TD*% 17 | %TA.AperFunction,ComponentPad*% 18 | %ADD11C,1.400000*% 19 | %TD*% 20 | %TA.AperFunction,ComponentPad*% 21 | %ADD12O,1.700000X1.700000*% 22 | %TD*% 23 | %TA.AperFunction,ComponentPad*% 24 | %ADD13C,1.500000*% 25 | %TD*% 26 | %TA.AperFunction,ComponentPad*% 27 | %ADD14O,1.600000X1.600000*% 28 | %TD*% 29 | %TA.AperFunction,ComponentPad*% 30 | %ADD15C,1.600000*% 31 | %TD*% 32 | %TA.AperFunction,ComponentPad*% 33 | %ADD16C,2.000000*% 34 | %TD*% 35 | %TA.AperFunction,ComponentPad*% 36 | %ADD17O,2.400000X2.400000*% 37 | %TD*% 38 | %TA.AperFunction,ComponentPad*% 39 | %ADD18C,2.400000*% 40 | %TD*% 41 | %TA.AperFunction,ViaPad*% 42 | %ADD19C,0.800000*% 43 | %TD*% 44 | %TA.AperFunction,Conductor*% 45 | %ADD20C,0.250000*% 46 | %TD*% 47 | G04 APERTURE END LIST* 48 | D10* 49 | %TO.P,J1,2*% 50 | %TO.N,BATT+RAW*% 51 | X65300000Y-60400000D03* 52 | %TO.P,J1,1*% 53 | %TO.N,GND*% 54 | X65300000Y-55320000D03* 55 | %TD*% 56 | D11* 57 | %TO.P,U8,1*% 58 | %TO.N,Net-(U8-Pad1)*% 59 | X186690000Y-111506000D03* 60 | %TO.P,U8,2*% 61 | %TO.N,Y_COMM*% 62 | X184150000Y-110236000D03* 63 | %TO.P,U8,3*% 64 | %TO.N,Z_COMM*% 65 | X186690000Y-108966000D03* 66 | %TO.P,U8,4*% 67 | %TO.N,Net-(U8-Pad4)*% 68 | X184150000Y-107696000D03* 69 | %TD*% 70 | %TO.P,U6,1*% 71 | %TO.N,Net-(U6-Pad1)*% 72 | X186690000Y-81280000D03* 73 | %TO.P,U6,2*% 74 | %TO.N,B1_COMM*% 75 | X184150000Y-80010000D03* 76 | %TO.P,U6,3*% 77 | %TO.N,A1_COMM*% 78 | X186690000Y-78740000D03* 79 | %TO.P,U6,4*% 80 | %TO.N,Net-(U6-Pad4)*% 81 | X184150000Y-77470000D03* 82 | %TD*% 83 | %TO.P,U7,1*% 84 | %TO.N,Net-(U7-Pad1)*% 85 | X186690000Y-96774000D03* 86 | %TO.P,U7,2*% 87 | %TO.N,B2_COMM*% 88 | X184150000Y-95504000D03* 89 | %TO.P,U7,3*% 90 | %TO.N,A2_COMM*% 91 | X186690000Y-94234000D03* 92 | %TO.P,U7,4*% 93 | %TO.N,Net-(U7-Pad4)*% 94 | X184150000Y-92964000D03* 95 | %TD*% 96 | D12* 97 | %TO.P,J12,2*% 98 | %TO.N,UART2_RX*% 99 | X128270000Y-89662000D03* 100 | D10* 101 | %TO.P,J12,1*% 102 | %TO.N,UART2_TX*% 103 | X125730000Y-89662000D03* 104 | %TD*% 105 | D13* 106 | %TO.P,Y1,2*% 107 | %TO.N,OCS32_IN*% 108 | X115624000Y-67818000D03* 109 | %TO.P,Y1,1*% 110 | %TO.N,OSC32_OUT*% 111 | X110744000Y-67818000D03* 112 | %TD*% 113 | D14* 114 | %TO.P,TH2,2*% 115 | %TO.N,ADC_TEMP_2*% 116 | X85852000Y-92710000D03* 117 | D15* 118 | %TO.P,TH2,1*% 119 | %TO.N,3.3V*% 120 | X85852000Y-90170000D03* 121 | %TD*% 122 | D14* 123 | %TO.P,TH1,2*% 124 | %TO.N,ADC_TEMP_1*% 125 | X78232000Y-92710000D03* 126 | D15* 127 | %TO.P,TH1,1*% 128 | %TO.N,3.3V*% 129 | X78232000Y-90170000D03* 130 | %TD*% 131 | D16* 132 | %TO.P,SW1,1*% 133 | %TO.N,NRST*% 134 | X140358000Y-60706000D03* 135 | %TO.P,SW1,2*% 136 | %TO.N,GND*% 137 | X140358000Y-65206000D03* 138 | %TO.P,SW1,1*% 139 | %TO.N,NRST*% 140 | X133858000Y-60706000D03* 141 | %TO.P,SW1,2*% 142 | %TO.N,GND*% 143 | X133858000Y-65206000D03* 144 | %TD*% 145 | D17* 146 | %TO.P,R5,2*% 147 | %TO.N,BATT+RAW*% 148 | X67818000Y-66548000D03* 149 | D18* 150 | %TO.P,R5,1*% 151 | %TO.N,Net-(Q1-Pad3)*% 152 | X67818000Y-97028000D03* 153 | %TD*% 154 | D12* 155 | %TO.P,J11,2*% 156 | %TO.N,UART1_RX*% 157 | X128270000Y-75692000D03* 158 | D10* 159 | %TO.P,J11,1*% 160 | %TO.N,UART1_TX*% 161 | X125730000Y-75692000D03* 162 | %TD*% 163 | D12* 164 | %TO.P,J10,2*% 165 | %TO.N,BATT+RAW*% 166 | X78232000Y-81280000D03* 167 | D10* 168 | %TO.P,J10,1*% 169 | X78232000Y-78740000D03* 170 | %TD*% 171 | D12* 172 | %TO.P,J9,2*% 173 | %TO.N,ADC_VOLT*% 174 | X116586000Y-113284000D03* 175 | D10* 176 | %TO.P,J9,1*% 177 | X116586000Y-110744000D03* 178 | %TD*% 179 | D12* 180 | %TO.P,J8,2*% 181 | %TO.N,ADC_VOLT_IN*% 182 | X65024000Y-104140000D03* 183 | D10* 184 | %TO.P,J8,1*% 185 | X65024000Y-106680000D03* 186 | %TD*% 187 | D12* 188 | %TO.P,J7,2*% 189 | %TO.N,GND*% 190 | X94488000Y-81026000D03* 191 | D10* 192 | %TO.P,J7,1*% 193 | X94488000Y-78486000D03* 194 | %TD*% 195 | D12* 196 | %TO.P,J6,2*% 197 | %TO.N,3.3V*% 198 | X85852000Y-81026000D03* 199 | D10* 200 | %TO.P,J6,1*% 201 | X85852000Y-78486000D03* 202 | %TD*% 203 | D12* 204 | %TO.P,J5,2*% 205 | %TO.N,Y*% 206 | X152654000Y-109982000D03* 207 | D10* 208 | %TO.P,J5,1*% 209 | %TO.N,Z*% 210 | X152654000Y-107442000D03* 211 | %TD*% 212 | D12* 213 | %TO.P,J4,2*% 214 | %TO.N,B2*% 215 | X152654000Y-98298000D03* 216 | D10* 217 | %TO.P,J4,1*% 218 | %TO.N,A2*% 219 | X152654000Y-95758000D03* 220 | %TD*% 221 | D12* 222 | %TO.P,J3,2*% 223 | %TO.N,B1*% 224 | X152908000Y-81534000D03* 225 | D10* 226 | %TO.P,J3,1*% 227 | %TO.N,A1*% 228 | X152908000Y-84074000D03* 229 | %TD*% 230 | D12* 231 | %TO.P,J2,5*% 232 | %TO.N,NRST*% 233 | X157988000Y-60706000D03* 234 | %TO.P,J2,4*% 235 | %TO.N,SWDIO*% 236 | X155448000Y-60706000D03* 237 | %TO.P,J2,3*% 238 | %TO.N,SWCLK*% 239 | X152908000Y-60706000D03* 240 | %TO.P,J2,2*% 241 | %TO.N,GND*% 242 | X150368000Y-60706000D03* 243 | D10* 244 | %TO.P,J2,1*% 245 | %TO.N,3.3V*% 246 | X147828000Y-60706000D03* 247 | %TD*% 248 | D19* 249 | %TO.N,G*% 250 | X136800000Y-110000000D03* 251 | X134000000Y-100800000D03* 252 | %TO.N,UART2_TX*% 253 | X123400000Y-103450000D03* 254 | X129350000Y-103250000D03* 255 | %TO.N,GND*% 256 | X97536000Y-89408000D03* 257 | X140716000Y-86360000D03* 258 | X140716000Y-81026000D03* 259 | X130810000Y-112776000D03* 260 | X140716000Y-106680000D03* 261 | X140716000Y-100076000D03* 262 | X140716000Y-94234000D03* 263 | X140716000Y-113030000D03* 264 | X111252000Y-78232000D03* 265 | %TO.N,3.3V*% 266 | X120396000Y-114300000D03* 267 | X133096000Y-79756000D03* 268 | X125476000Y-92456000D03* 269 | X130556000Y-63246000D03* 270 | X100838000Y-56388000D03* 271 | X113030000Y-78232000D03* 272 | X120396000Y-107404000D03* 273 | %TO.N,ADC_VOLT_IN*% 274 | X97536000Y-97282000D03* 275 | X103124000Y-80010000D03* 276 | %TO.N,STATUS_PIN*% 277 | X115062000Y-96012000D03* 278 | X103124000Y-89662000D03* 279 | %TO.N,NRST*% 280 | X107442000Y-80010000D03* 281 | %TO.N,SWDIO*% 282 | X118618000Y-96012000D03* 283 | %TO.N,SWCLK*% 284 | X120650000Y-90424000D03* 285 | %TO.N,ADC_VOLT*% 286 | X105156000Y-80010000D03* 287 | %TO.N,UART1_RX*% 288 | X120396000Y-85598000D03* 289 | %TO.N,UART1_TX*% 290 | X122682000Y-80010000D03* 291 | X122682000Y-84074000D03* 292 | %TO.N,UART2_RX*% 293 | X122682000Y-109220000D03* 294 | X123444000Y-102362000D03* 295 | X105200000Y-85600000D03* 296 | %TO.N,UART2_TX*% 297 | X105200000Y-83750000D03* 298 | %TO.N,ON-OFF*% 299 | X89916000Y-72136000D03* 300 | X117348000Y-78232000D03* 301 | %TO.N,ADC_TEMP_1*% 302 | X98806000Y-86360000D03* 303 | %TO.N,PWM_OUT*% 304 | X86600000Y-115950000D03* 305 | X110998000Y-96012000D03* 306 | %TO.N,Net-(R22-Pad2)*% 307 | X94234000Y-95250000D03* 308 | X100838000Y-113030000D03* 309 | %TO.N,TXEN*% 310 | X128000000Y-107300000D03* 311 | X112268000Y-97282000D03* 312 | %TO.N,RXEN*% 313 | X113792000Y-97282000D03* 314 | %TO.N,Net-(R24-Pad1)*% 315 | X106060000Y-113010000D03* 316 | X106040000Y-105620000D03* 317 | %TD*% 318 | D20* 319 | %TO.N,GND*% 320 | X140716000Y-94234000D02* 321 | X140716000Y-100076000D01* 322 | X140716000Y-100076000D02* 323 | X140716000Y-106680000D01* 324 | X140716000Y-106680000D02* 325 | X140716000Y-113030000D01* 326 | X140462000Y-112776000D02* 327 | X140716000Y-113030000D01* 328 | X130810000Y-112776000D02* 329 | X140462000Y-112776000D01* 330 | X140716000Y-81026000D02* 331 | X140716000Y-86360000D01* 332 | X140716000Y-86360000D02* 333 | X140716000Y-94234000D01* 334 | X140716000Y-68834000D02* 335 | X140716000Y-81026000D01* 336 | X141224000Y-68326000D02* 337 | X140716000Y-68834000D01* 338 | X160100000Y-68100000D02* 339 | X159874000Y-68326000D01* 340 | X150368000Y-60706000D02* 341 | X150368000Y-59436000D01* 342 | X159874000Y-68326000D02* 343 | X141224000Y-68326000D01* 344 | X150876000Y-58928000D02* 345 | X159928000Y-58928000D01* 346 | X150368000Y-59436000D02* 347 | X150876000Y-58928000D01* 348 | X159928000Y-58928000D02* 349 | X160100000Y-59100000D01* 350 | X160100000Y-59100000D02* 351 | X160100000Y-68100000D01* 352 | X94488000Y-84582000D02* 353 | X94488000Y-81026000D01* 354 | X94996000Y-85090000D02* 355 | X94488000Y-84582000D01* 356 | X98905002Y-85090000D02* 357 | X94996000Y-85090000D01* 358 | X99731001Y-85915999D02* 359 | X98905002Y-85090000D01* 360 | X99731001Y-86668999D02* 361 | X99731001Y-89218999D01* 362 | X99731001Y-86668999D02* 363 | X99731001Y-85915999D01* 364 | X99731001Y-86804001D02* 365 | X99731001Y-86668999D01* 366 | X99542000Y-89408000D02* 367 | X97536000Y-89408000D01* 368 | X99731001Y-89218999D02* 369 | X99542000Y-89408000D01* 370 | %TO.N,BATT+RAW*% 371 | X78232000Y-78740000D02* 372 | X69088000Y-78740000D01* 373 | X67818000Y-77470000D02* 374 | X67818000Y-66548000D01* 375 | X69088000Y-78740000D02* 376 | X67818000Y-77470000D01* 377 | X65300000Y-60400000D02* 378 | X65300000Y-66000000D01* 379 | X65848000Y-66548000D02* 380 | X67818000Y-66548000D01* 381 | X65300000Y-66000000D02* 382 | X65848000Y-66548000D01* 383 | %TO.N,3.3V*% 384 | X147828000Y-60706000D02* 385 | X147828000Y-57150000D01* 386 | X147066000Y-56388000D02* 387 | X100838000Y-56388000D01* 388 | X147828000Y-57150000D02* 389 | X147066000Y-56388000D01* 390 | X130556000Y-63246000D02* 391 | X130556000Y-79502000D01* 392 | X130810000Y-79756000D02* 393 | X133096000Y-79756000D01* 394 | X130556000Y-79502000D02* 395 | X130810000Y-79756000D01* 396 | X133096000Y-79756000D02* 397 | X133096000Y-91948000D01* 398 | X132588000Y-92456000D02* 399 | X125476000Y-92456000D01* 400 | X133096000Y-91948000D02* 401 | X132588000Y-92456000D01* 402 | X122682000Y-92456000D02* 403 | X125476000Y-92456000D01* 404 | X121920000Y-89154000D02* 405 | X122428000Y-89662000D01* 406 | X122428000Y-92202000D02* 407 | X122682000Y-92456000D01* 408 | X117094000Y-89154000D02* 409 | X121920000Y-89154000D01* 410 | X116840000Y-89408000D02* 411 | X117094000Y-89154000D01* 412 | X120396000Y-97790000D02* 413 | X119888000Y-97282000D01* 414 | X116840000Y-97028000D02* 415 | X116840000Y-89408000D01* 416 | X120396000Y-111252000D02* 417 | X120396000Y-107404000D01* 418 | X122428000Y-89662000D02* 419 | X122428000Y-92202000D01* 420 | X117094000Y-97282000D02* 421 | X116840000Y-97028000D01* 422 | X119888000Y-97282000D02* 423 | X117094000Y-97282000D01* 424 | X120396000Y-111252000D02* 425 | X120396000Y-114300000D01* 426 | X120396000Y-107404000D02* 427 | X120396000Y-97790000D01* 428 | X83400000Y-56800000D02* 429 | X83400000Y-78200000D01* 430 | X83686000Y-78486000D02* 431 | X85852000Y-78486000D01* 432 | X100838000Y-56388000D02* 433 | X83812000Y-56388000D01* 434 | X83400000Y-78200000D02* 435 | X83686000Y-78486000D01* 436 | X83812000Y-56388000D02* 437 | X83400000Y-56800000D01* 438 | X130556000Y-63246000D02* 439 | X130556000Y-63244000D01* 440 | X130556000Y-63244000D02* 441 | X131000000Y-62800000D01* 442 | X131000000Y-62800000D02* 443 | X147500000Y-62800000D01* 444 | X147828000Y-62472000D02* 445 | X147828000Y-60706000D01* 446 | X147500000Y-62800000D02* 447 | X147828000Y-62472000D01* 448 | X113030000Y-75430000D02* 449 | X113030000Y-78232000D01* 450 | X112750000Y-75150000D02* 451 | X113030000Y-75430000D01* 452 | X85852000Y-76652000D02* 453 | X85850000Y-76650000D01* 454 | X85852000Y-78486000D02* 455 | X85852000Y-76652000D01* 456 | X85850000Y-76650000D02* 457 | X85850000Y-75450000D01* 458 | X85850000Y-75450000D02* 459 | X86150000Y-75150000D01* 460 | X86150000Y-75150000D02* 461 | X112750000Y-75150000D01* 462 | %TO.N,ADC_VOLT_IN*% 463 | X97536000Y-97282000D02* 464 | X97536000Y-103378000D01* 465 | X96774000Y-104140000D02* 466 | X65024000Y-104140000D01* 467 | X97536000Y-103378000D02* 468 | X96774000Y-104140000D01* 469 | X102775001Y-79661001D02* 470 | X103124000Y-80010000D01* 471 | X102775001Y-76975001D02* 472 | X102775001Y-79661001D01* 473 | X102000000Y-76200000D02* 474 | X102775001Y-76975001D01* 475 | X89550000Y-76200000D02* 476 | X102000000Y-76200000D01* 477 | X91300000Y-95150000D02* 478 | X91100000Y-94950000D01* 479 | X91300000Y-96750000D02* 480 | X91300000Y-95150000D01* 481 | X97536000Y-97282000D02* 482 | X91832000Y-97282000D01* 483 | X74750000Y-94700000D02* 484 | X74750000Y-85250000D01* 485 | X91832000Y-97282000D02* 486 | X91300000Y-96750000D01* 487 | X91100000Y-94950000D02* 488 | X75000000Y-94950000D01* 489 | X75000000Y-94950000D02* 490 | X74750000Y-94700000D01* 491 | X74750000Y-85250000D02* 492 | X75500000Y-84500000D01* 493 | X75500000Y-84500000D02* 494 | X88700000Y-84500000D01* 495 | X88950000Y-76800000D02* 496 | X89550000Y-76200000D01* 497 | X88700000Y-84500000D02* 498 | X88950000Y-84250000D01* 499 | X88950000Y-84250000D02* 500 | X88950000Y-76800000D01* 501 | %TO.N,STATUS_PIN*% 502 | X103124000Y-89662000D02* 503 | X114808000Y-89662000D01* 504 | X115062000Y-89916000D02* 505 | X115062000Y-96012000D01* 506 | X114808000Y-89662000D02* 507 | X115062000Y-89916000D01* 508 | %TO.N,NRST*% 509 | X116939002Y-80010000D02* 510 | X118364000Y-78585002D01* 511 | X107442000Y-80010000D02* 512 | X116939002Y-80010000D01* 513 | X118364000Y-78585002D02* 514 | X118364000Y-59182000D01* 515 | X118364000Y-59182000D02* 516 | X118872000Y-58674000D01* 517 | X118872000Y-58674000D02* 518 | X133350000Y-58674000D01* 519 | X133858000Y-59182000D02* 520 | X133858000Y-60706000D01* 521 | X133350000Y-58674000D02* 522 | X133858000Y-59182000D01* 523 | %TO.N,SWDIO*% 524 | X118618000Y-94682000D02* 525 | X118618000Y-96012000D01* 526 | X136500000Y-94400000D02* 527 | X118900000Y-94400000D01* 528 | X136906000Y-93994000D02* 529 | X136500000Y-94400000D01* 530 | X155448000Y-66802000D02* 531 | X154940000Y-67310000D01* 532 | X155448000Y-60706000D02* 533 | X155448000Y-66802000D01* 534 | X118900000Y-94400000D02* 535 | X118618000Y-94682000D01* 536 | X137668000Y-67310000D02* 537 | X136906000Y-68072000D01* 538 | X154940000Y-67310000D02* 539 | X137668000Y-67310000D01* 540 | X136906000Y-68072000D02* 541 | X136906000Y-93994000D01* 542 | %TO.N,SWCLK*% 543 | X135382000Y-64118000D02* 544 | X135800000Y-63700000D01* 545 | X135800000Y-63700000D02* 546 | X152708000Y-63700000D01* 547 | X120650000Y-93472000D02* 548 | X120904000Y-93726000D01* 549 | X120650000Y-90424000D02* 550 | X120650000Y-93472000D01* 551 | X152708000Y-63700000D02* 552 | X152908000Y-63500000D01* 553 | X120904000Y-93726000D02* 554 | X133350000Y-93726000D01* 555 | X152908000Y-63500000D02* 556 | X152908000Y-60706000D01* 557 | X133350000Y-93726000D02* 558 | X135382000Y-91694000D01* 559 | X135382000Y-91694000D02* 560 | X135382000Y-64118000D01* 561 | %TO.N,ADC_VOLT*% 562 | X116078000Y-112776000D02* 563 | X116586000Y-113284000D01* 564 | X104420999Y-80745001D02* 565 | X105156000Y-80010000D01* 566 | X115900000Y-110058000D02* 567 | X115900000Y-89100000D01* 568 | X116586000Y-110744000D02* 569 | X115900000Y-110058000D01* 570 | X103450000Y-86700000D02* 571 | X103450000Y-81716000D01* 572 | X115900000Y-89100000D02* 573 | X115350000Y-88550000D01* 574 | X103450000Y-81716000D02* 575 | X104420999Y-80745001D01* 576 | X115350000Y-88550000D02* 577 | X105250000Y-88550000D01* 578 | X105250000Y-88550000D02* 579 | X104420999Y-87720999D01* 580 | X104420999Y-87670999D02* 581 | X103450000Y-86700000D01* 582 | X104420999Y-87720999D02* 583 | X104420999Y-87670999D01* 584 | %TO.N,UART1_RX*% 585 | X120396000Y-85598000D02* 586 | X120396000Y-77978000D01* 587 | X120396000Y-77978000D02* 588 | X120396000Y-78486000D01* 589 | X128270000Y-73420000D02* 590 | X128270000Y-75692000D01* 591 | X120900000Y-73150000D02* 592 | X128000000Y-73150000D01* 593 | X120396000Y-77978000D02* 594 | X120396000Y-73654000D01* 595 | X128000000Y-73150000D02* 596 | X128270000Y-73420000D01* 597 | X120396000Y-73654000D02* 598 | X120900000Y-73150000D01* 599 | %TO.N,UART1_TX*% 600 | X122682000Y-84074000D02* 601 | X122682000Y-80010000D01* 602 | %TO.N,UART2_RX*% 603 | X127925001Y-86523001D02* 604 | X106123001Y-86523001D01* 605 | X128270000Y-89662000D02* 606 | X128270000Y-86868000D01* 607 | X106123001Y-86523001D02* 608 | X105200000Y-85600000D01* 609 | X128270000Y-86868000D02* 610 | X127925001Y-86523001D01* 611 | X122682000Y-109220000D02* 612 | X122070000Y-109220000D01* 613 | X122070000Y-109220000D02* 614 | X121700000Y-108850000D01* 615 | X121700000Y-108850000D02* 616 | X121700000Y-102650000D01* 617 | X121988000Y-102362000D02* 618 | X123444000Y-102362000D01* 619 | X121700000Y-102650000D02* 620 | X121988000Y-102362000D01* 621 | %TO.N,UART2_TX*% 622 | X104420999Y-84529001D02* 623 | X105200000Y-83750000D01* 624 | X125730000Y-89662000D02* 625 | X125730000Y-87630000D01* 626 | X104420999Y-85973921D02* 627 | X104420999Y-84529001D01* 628 | X125476000Y-87376000D02* 629 | X105823078Y-87376000D01* 630 | X125730000Y-87630000D02* 631 | X125476000Y-87376000D01* 632 | X105823078Y-87376000D02* 633 | X104420999Y-85973921D01* 634 | X123600000Y-103250000D02* 635 | X123400000Y-103450000D01* 636 | X129350000Y-103250000D02* 637 | X123600000Y-103250000D01* 638 | %TO.N,ON-OFF*% 639 | X89916000Y-72136000D02* 640 | X117094000Y-72136000D01* 641 | X117348000Y-72390000D02* 642 | X117348000Y-78232000D01* 643 | X117094000Y-72136000D02* 644 | X117348000Y-72390000D01* 645 | %TO.N,ADC_TEMP_1*% 646 | X76708000Y-92710000D02* 647 | X78232000Y-92710000D01* 648 | X76454000Y-92456000D02* 649 | X76708000Y-92710000D01* 650 | X76454000Y-86360000D02* 651 | X76454000Y-92456000D01* 652 | X76708000Y-86106000D02* 653 | X76454000Y-86360000D01* 654 | X98552000Y-86106000D02* 655 | X98806000Y-86360000D01* 656 | X76708000Y-86106000D02* 657 | X98552000Y-86106000D01* 658 | %TO.N,PWM_OUT*% 659 | X110550000Y-115950000D02* 660 | X86600000Y-115950000D01* 661 | X110998000Y-96012000D02* 662 | X110998000Y-115502000D01* 663 | X110998000Y-115502000D02* 664 | X110550000Y-115950000D01* 665 | %TO.N,Net-(R22-Pad2)*% 666 | X100838000Y-113030000D02* 667 | X100838000Y-95758000D01* 668 | X100330000Y-95250000D02* 669 | X94234000Y-95250000D01* 670 | X100838000Y-95758000D02* 671 | X100330000Y-95250000D01* 672 | %TO.N,G*% 673 | X136800000Y-110000000D02* 674 | X136800000Y-101100000D01* 675 | X136500000Y-100800000D02* 676 | X134000000Y-100800000D01* 677 | X136800000Y-101100000D02* 678 | X136500000Y-100800000D01* 679 | %TO.N,Net-(R24-Pad1)*% 680 | X106060000Y-105640000D02* 681 | X106040000Y-105620000D01* 682 | X106060000Y-113010000D02* 683 | X106060000Y-105640000D01* 684 | %TD*% 685 | M02* 686 | -------------------------------------------------------------------------------- /BMS-Schematic/GERBERS/Sintaksa-stm32g031-BMSmodul-B_Mask.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,(5.1.6)-1*% 2 | %TF.CreationDate,2020-08-06T11:36:23+02:00*% 3 | %TF.ProjectId,Sintaksa-stm32g031-BMSmodul,53696e74-616b-4736-912d-73746d333267,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Soldermask,Bot*% 6 | %TF.FilePolarity,Negative*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW (5.1.6)-1) date 2020-08-06 11:36:23* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %ADD10C,3.200000*% 15 | %ADD11R,1.700000X1.700000*% 16 | %ADD12C,1.400000*% 17 | %ADD13O,1.700000X1.700000*% 18 | %ADD14C,1.500000*% 19 | %ADD15O,1.600000X1.600000*% 20 | %ADD16C,1.600000*% 21 | %ADD17C,2.000000*% 22 | %ADD18O,2.400000X2.400000*% 23 | %ADD19C,2.400000*% 24 | G04 APERTURE END LIST* 25 | D10* 26 | %TO.C,H4*% 27 | X187960000Y-116840000D03* 28 | %TD*% 29 | %TO.C,H3*% 30 | X60960000Y-116840000D03* 31 | %TD*% 32 | %TO.C,H2*% 33 | X60960000Y-66040000D03* 34 | %TD*% 35 | %TO.C,H1*% 36 | X187960000Y-55880000D03* 37 | %TD*% 38 | D11* 39 | %TO.C,J1*% 40 | X65300000Y-60400000D03* 41 | X65300000Y-55320000D03* 42 | %TD*% 43 | D12* 44 | %TO.C,U8*% 45 | X186690000Y-111506000D03* 46 | X184150000Y-110236000D03* 47 | X186690000Y-108966000D03* 48 | X184150000Y-107696000D03* 49 | %TD*% 50 | %TO.C,U6*% 51 | X186690000Y-81280000D03* 52 | X184150000Y-80010000D03* 53 | X186690000Y-78740000D03* 54 | X184150000Y-77470000D03* 55 | %TD*% 56 | %TO.C,U7*% 57 | X186690000Y-96774000D03* 58 | X184150000Y-95504000D03* 59 | X186690000Y-94234000D03* 60 | X184150000Y-92964000D03* 61 | %TD*% 62 | D13* 63 | %TO.C,J12*% 64 | X128270000Y-89662000D03* 65 | D11* 66 | X125730000Y-89662000D03* 67 | %TD*% 68 | D14* 69 | %TO.C,Y1*% 70 | X115624000Y-67818000D03* 71 | X110744000Y-67818000D03* 72 | %TD*% 73 | D15* 74 | %TO.C,TH2*% 75 | X85852000Y-92710000D03* 76 | D16* 77 | X85852000Y-90170000D03* 78 | %TD*% 79 | D15* 80 | %TO.C,TH1*% 81 | X78232000Y-92710000D03* 82 | D16* 83 | X78232000Y-90170000D03* 84 | %TD*% 85 | D17* 86 | %TO.C,SW1*% 87 | X140358000Y-60706000D03* 88 | X140358000Y-65206000D03* 89 | X133858000Y-60706000D03* 90 | X133858000Y-65206000D03* 91 | %TD*% 92 | D18* 93 | %TO.C,R5*% 94 | X67818000Y-66548000D03* 95 | D19* 96 | X67818000Y-97028000D03* 97 | %TD*% 98 | D13* 99 | %TO.C,J11*% 100 | X128270000Y-75692000D03* 101 | D11* 102 | X125730000Y-75692000D03* 103 | %TD*% 104 | D13* 105 | %TO.C,J10*% 106 | X78232000Y-81280000D03* 107 | D11* 108 | X78232000Y-78740000D03* 109 | %TD*% 110 | D13* 111 | %TO.C,J9*% 112 | X116586000Y-113284000D03* 113 | D11* 114 | X116586000Y-110744000D03* 115 | %TD*% 116 | D13* 117 | %TO.C,J8*% 118 | X65024000Y-104140000D03* 119 | D11* 120 | X65024000Y-106680000D03* 121 | %TD*% 122 | D13* 123 | %TO.C,J7*% 124 | X94488000Y-81026000D03* 125 | D11* 126 | X94488000Y-78486000D03* 127 | %TD*% 128 | D13* 129 | %TO.C,J6*% 130 | X85852000Y-81026000D03* 131 | D11* 132 | X85852000Y-78486000D03* 133 | %TD*% 134 | D13* 135 | %TO.C,J5*% 136 | X152654000Y-109982000D03* 137 | D11* 138 | X152654000Y-107442000D03* 139 | %TD*% 140 | D13* 141 | %TO.C,J4*% 142 | X152654000Y-98298000D03* 143 | D11* 144 | X152654000Y-95758000D03* 145 | %TD*% 146 | D13* 147 | %TO.C,J3*% 148 | X152908000Y-81534000D03* 149 | D11* 150 | X152908000Y-84074000D03* 151 | %TD*% 152 | D13* 153 | %TO.C,J2*% 154 | X157988000Y-60706000D03* 155 | X155448000Y-60706000D03* 156 | X152908000Y-60706000D03* 157 | X150368000Y-60706000D03* 158 | D11* 159 | X147828000Y-60706000D03* 160 | %TD*% 161 | M02* 162 | -------------------------------------------------------------------------------- /BMS-Schematic/GERBERS/Sintaksa-stm32g031-BMSmodul-B_SilkS.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,(5.1.6)-1*% 2 | %TF.CreationDate,2020-08-06T11:36:23+02:00*% 3 | %TF.ProjectId,Sintaksa-stm32g031-BMSmodul,53696e74-616b-4736-912d-73746d333267,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Legend,Bot*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW (5.1.6)-1) date 2020-08-06 11:36:23* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | G04 APERTURE END LIST* 15 | M02* 16 | -------------------------------------------------------------------------------- /BMS-Schematic/GERBERS/Sintaksa-stm32g031-BMSmodul-Edge_Cuts.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,(5.1.6)-1*% 2 | %TF.CreationDate,2020-08-06T11:36:23+02:00*% 3 | %TF.ProjectId,Sintaksa-stm32g031-BMSmodul,53696e74-616b-4736-912d-73746d333267,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Profile,NP*% 6 | %FSLAX46Y46*% 7 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 8 | G04 Created by KiCad (PCBNEW (5.1.6)-1) date 2020-08-06 11:36:23* 9 | %MOMM*% 10 | %LPD*% 11 | G01* 12 | G04 APERTURE LIST* 13 | %TA.AperFunction,Profile*% 14 | %ADD10C,0.100000*% 15 | %TD*% 16 | G04 APERTURE END LIST* 17 | D10* 18 | X193040000Y-121920000D02* 19 | X55880000Y-121920000D01* 20 | X193040000Y-50800000D02* 21 | X193040000Y-121920000D01* 22 | X55880000Y-50800000D02* 23 | X193040000Y-50800000D01* 24 | X55880000Y-50800000D02* 25 | X55880000Y-121920000D01* 26 | M02* 27 | -------------------------------------------------------------------------------- /BMS-Schematic/GERBERS/Sintaksa-stm32g031-BMSmodul-NPTH.drl: -------------------------------------------------------------------------------- 1 | M48 2 | ; DRILL file {KiCad (5.1.6)-1} date 08/06/20 11:36:17 3 | ; FORMAT={-:-/ absolute / inch / decimal} 4 | ; #@! TF.CreationDate,2020-08-06T11:36:17+02:00 5 | ; #@! TF.GenerationSoftware,Kicad,Pcbnew,(5.1.6)-1 6 | ; #@! TF.FileFunction,NonPlated,1,2,NPTH 7 | FMAT,2 8 | INCH 9 | T1C0.1260 10 | % 11 | G90 12 | G05 13 | T1 14 | X7.4Y-4.6 15 | X2.4Y-2.6 16 | X7.4Y-2.2 17 | X2.4Y-4.6 18 | T0 19 | M30 20 | -------------------------------------------------------------------------------- /BMS-Schematic/GERBERS/Sintaksa-stm32g031-BMSmodul-PTH.drl: -------------------------------------------------------------------------------- 1 | M48 2 | ; DRILL file {KiCad (5.1.6)-1} date 08/06/20 11:36:17 3 | ; FORMAT={-:-/ absolute / inch / decimal} 4 | ; #@! TF.CreationDate,2020-08-06T11:36:17+02:00 5 | ; #@! TF.GenerationSoftware,Kicad,Pcbnew,(5.1.6)-1 6 | ; #@! TF.FileFunction,Plated,1,2,PTH 7 | FMAT,2 8 | INCH 9 | T1C0.0157 10 | T2C0.0315 11 | T3C0.0354 12 | T4C0.0394 13 | T5C0.0433 14 | T6C0.0472 15 | % 16 | G90 17 | G05 18 | T1 19 | X3.4094Y-4.565 20 | X3.54Y-2.84 21 | X3.71Y-3.75 22 | X3.84Y-3.52 23 | X3.84Y-3.83 24 | X3.89Y-3.4 25 | X3.97Y-2.22 26 | X3.97Y-4.45 27 | X4.06Y-3.15 28 | X4.06Y-3.53 29 | X4.14Y-3.15 30 | X4.1417Y-3.2972 31 | X4.1417Y-3.3701 32 | X4.1748Y-4.1583 33 | X4.1756Y-4.4492 34 | X4.23Y-3.15 35 | X4.37Y-3.78 36 | X4.38Y-3.08 37 | X4.42Y-3.83 38 | X4.45Y-3.08 39 | X4.48Y-3.83 40 | X4.53Y-3.78 41 | X4.62Y-3.08 42 | X4.67Y-3.78 43 | X4.74Y-3.37 44 | X4.74Y-4.2285 45 | X4.74Y-4.5 46 | X4.75Y-3.56 47 | X4.83Y-3.15 48 | X4.83Y-3.31 49 | X4.83Y-4.3 50 | X4.8583Y-4.0728 51 | X4.86Y-4.03 52 | X4.94Y-3.64 53 | X5.0394Y-4.2244 54 | X5.0925Y-4.065 55 | X5.14Y-2.49 56 | X5.15Y-4.44 57 | X5.24Y-3.14 58 | X5.2756Y-3.9685 59 | X5.3858Y-4.3307 60 | X5.54Y-3.19 61 | X5.54Y-3.4 62 | X5.54Y-3.71 63 | X5.54Y-3.94 64 | X5.54Y-4.2 65 | X5.54Y-4.45 66 | T2 67 | X3.08Y-3.55 68 | X3.08Y-3.65 69 | X4.36Y-2.67 70 | X4.5521Y-2.67 71 | X3.38Y-3.55 72 | X3.38Y-3.65 73 | T3 74 | X7.25Y-3.05 75 | X7.25Y-3.15 76 | X7.35Y-3.1 77 | X7.35Y-3.2 78 | X7.25Y-4.24 79 | X7.25Y-4.34 80 | X7.35Y-4.29 81 | X7.35Y-4.39 82 | X7.25Y-3.66 83 | X7.25Y-3.76 84 | X7.35Y-3.71 85 | X7.35Y-3.81 86 | T4 87 | X4.95Y-2.98 88 | X5.05Y-2.98 89 | X6.02Y-3.21 90 | X6.02Y-3.31 91 | X4.95Y-3.53 92 | X5.05Y-3.53 93 | X2.56Y-4.1 94 | X2.56Y-4.2 95 | X6.01Y-3.77 96 | X6.01Y-3.87 97 | X6.01Y-4.23 98 | X6.01Y-4.33 99 | X4.59Y-4.36 100 | X4.59Y-4.46 101 | X5.82Y-2.39 102 | X5.92Y-2.39 103 | X6.02Y-2.39 104 | X6.12Y-2.39 105 | X6.22Y-2.39 106 | X3.38Y-3.09 107 | X3.38Y-3.19 108 | X3.08Y-3.1 109 | X3.08Y-3.2 110 | X3.72Y-3.09 111 | X3.72Y-3.19 112 | T5 113 | X5.27Y-2.39 114 | X5.27Y-2.5672 115 | X5.5259Y-2.39 116 | X5.5259Y-2.5672 117 | X2.5709Y-2.178 118 | X2.5709Y-2.378 119 | T6 120 | X2.67Y-2.62 121 | X2.67Y-3.82 122 | T0 123 | M30 124 | -------------------------------------------------------------------------------- /BMS-Schematic/GERBERS/Sintaksa-stm32g031-BMSmodul-job.gbrjob: -------------------------------------------------------------------------------- 1 | { 2 | "Header": 3 | { 4 | "GenerationSoftware": 5 | { 6 | "Vendor": "KiCad", 7 | "Application": "Pcbnew", 8 | "Version": "(5.1.6)-1" 9 | }, 10 | "CreationDate": "2020-08-06T11:36:23+02:00" 11 | }, 12 | "GeneralSpecs": 13 | { 14 | "ProjectId": 15 | { 16 | "Name": "Sintaksa-stm32g031-BMSmodul", 17 | "GUID": "53696e74-616b-4736-912d-73746d333267", 18 | "Revision": "rev?" 19 | }, 20 | "Size": 21 | { 22 | "X": 137.260, 23 | "Y": 71.220 24 | }, 25 | "LayerNumber": 2, 26 | "BoardThickness": 1.600 27 | }, 28 | "DesignRules": 29 | [ 30 | { 31 | "Layers": "Outer", 32 | "PadToPad": 0.254, 33 | "PadToTrack": 0.254, 34 | "TrackToTrack": 0.254, 35 | "MinLineWidth": 0.250, 36 | "TrackToRegion": 0.254, 37 | "RegionToRegion": 0.254 38 | } 39 | ], 40 | "FilesAttributes": 41 | [ 42 | { 43 | "Path": "Sintaksa-stm32g031-BMSmodul-F_Cu.gbr", 44 | "FileFunction": "Copper,L1,Top", 45 | "FilePolarity": "Positive" 46 | }, 47 | { 48 | "Path": "Sintaksa-stm32g031-BMSmodul-B_Cu.gbr", 49 | "FileFunction": "Copper,L2,Bot", 50 | "FilePolarity": "Positive" 51 | }, 52 | { 53 | "Path": "Sintaksa-stm32g031-BMSmodul-F_SilkS.gbr", 54 | "FileFunction": "Legend,Top", 55 | "FilePolarity": "Positive" 56 | }, 57 | { 58 | "Path": "Sintaksa-stm32g031-BMSmodul-B_SilkS.gbr", 59 | "FileFunction": "Legend,Bot", 60 | "FilePolarity": "Positive" 61 | }, 62 | { 63 | "Path": "Sintaksa-stm32g031-BMSmodul-F_Mask.gbr", 64 | "FileFunction": "SolderMask,Top", 65 | "FilePolarity": "Negative" 66 | }, 67 | { 68 | "Path": "Sintaksa-stm32g031-BMSmodul-B_Mask.gbr", 69 | "FileFunction": "SolderMask,Bot", 70 | "FilePolarity": "Negative" 71 | }, 72 | { 73 | "Path": "Sintaksa-stm32g031-BMSmodul-Edge_Cuts.gbr", 74 | "FileFunction": "Profile", 75 | "FilePolarity": "Positive" 76 | } 77 | ], 78 | "MaterialStackup": 79 | [ 80 | { 81 | "Type": "Legend", 82 | "Notes": "Layer F.SilkS" 83 | }, 84 | { 85 | "Type": "SolderMask", 86 | "Notes": "Layer F.Mask" 87 | }, 88 | { 89 | "Type": "Copper", 90 | "Notes": "Layer F.Cu" 91 | }, 92 | { 93 | "Type": "Dielectric", 94 | "Material": "FR4", 95 | "Notes": "Layers L1/L2" 96 | }, 97 | { 98 | "Type": "Copper", 99 | "Notes": "Layer B.Cu" 100 | }, 101 | { 102 | "Type": "SolderMask", 103 | "Notes": "Layer B.Mask" 104 | }, 105 | { 106 | "Type": "Legend", 107 | "Notes": "Layer B.SilkS" 108 | } 109 | ] 110 | } 111 | -------------------------------------------------------------------------------- /BMS-Schematic/README: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /BMS-Schematic/STM32G031-BMS.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/BMS-Schematic/STM32G031-BMS.pdf -------------------------------------------------------------------------------- /BMS-layer-design-3Dview/BMS-3d view smaller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/BMS-layer-design-3Dview/BMS-3d view smaller.png -------------------------------------------------------------------------------- /BMS-layer-design-3Dview/BMS-layerView1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/BMS-layer-design-3Dview/BMS-layerView1.png -------------------------------------------------------------------------------- /BMS-layer-design-3Dview/BMS-layerView2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/BMS-layer-design-3Dview/BMS-layerView2.png -------------------------------------------------------------------------------- /BMS-layer-design-3Dview/BMS-layerView3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/BMS-layer-design-3Dview/BMS-layerView3.png -------------------------------------------------------------------------------- /BMS-layer-design-3Dview/README: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /BMS-layer-design-3Dview/STM32_BMS(2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/BMS-layer-design-3Dview/STM32_BMS(2).png -------------------------------------------------------------------------------- /BMS-layer-design-3Dview/STM32_BMS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/BMS-layer-design-3Dview/STM32_BMS.png -------------------------------------------------------------------------------- /BMS-stm32f407vg-code/README: -------------------------------------------------------------------------------- 1 | /--------------------------ADC peripheral explanation-------------------------------------- 2 | //PA0 and PA1 are analog input pins connected to measure battery voltage 3 | //We assume that at PA0 pin (ADC_VOLT point) will be 16 bit battery voltage value 4 | //at PA1 (ADC_VOLT_IN) will be 12 bit battery voltage value 5 | //PA4 pin (ADC_TEMP1 point) is connected to voltage divider made by 10k resistor and thermistor in series 6 | //PA5 pin (ADC_TEMP2 point) is connected aslo to simmilar voltage divider 7 | //F_CPU is 16 MHz and we need to divide that value to cca 125 kHz to form ADCCLK 8 | //for this purpose, we will use ADCx_SMPRx register (SMPx [2:0]) that holds the value how many cycles will th system sample 9 | //any value and ADCx_CCR register (ADCPRE[17:16]) SMPx = 001 (15 cycles), ADCPRE = 11 ( PCK2 / 8) 10 | //ADCCLK -> 16 MHz / (15*8) = 133.3 kHz 11 | //We will allign data to the right so ALIGH bit in ADCx_CR2 will be cleared to 0, VREF is 2.56 V internally 12 | 13 | //--------------------------System Nofitications---------------------------------------------- 14 | //type 0 for false ondition and 1 for true condition 15 | 16 | //--------------------------TIM1 peripheral explanation--------------------------------------- 17 | //TIM1 is used to generate clock signal with frquency about 8 Hz, timer mode will be clear at compare match 18 | 19 | -------------------------------------------------------------------------------- /BMS-stm32f407vg-code/main.c: -------------------------------------------------------------------------------- 1 | //--------------------------ADC peripheral explanation-------------------------------------- 2 | //PA0 and PA1 are analog input pins connected to measure battery voltage 3 | //We assume that at PA0 pin (ADC_VOLT point) will be 16 bit battery voltage value 4 | //at PA1 (ADC_VOLT_IN) will be 12 bit battery voltage value 5 | //PA4 pin (ADC_TEMP1 point) is connected to voltage divider made by 10k resistor and thermistor in series 6 | //PA5 pin (ADC_TEMP2 point) is connected aslo to simmilar voltage divider 7 | //F_CPU is 16 MHz and we need to divide that value to cca 125 kHz to form ADCCLK 8 | //for this purpose, we will use ADCx_SMPRx register (SMPx [2:0]) that holds the value how many cycles will th system sample 9 | //any value and ADCx_CCR register (ADCPRE[17:16]) SMPx = 001 (15 cycles), ADCPRE = 11 ( PCK2 / 8) 10 | //ADCCLK -> 16 MHz / (15*8) = 133.3 kHz 11 | //We will allign data to the right so ALIGH bit in ADCx_CR2 will be cleared to 0, VREF is 2.56 V internally 12 | 13 | //--------------------------System Nofitications---------------------------------------------- 14 | //type 0 for false ondition and 1 for true condition 15 | 16 | //--------------------------TIM1 peripheral explanation--------------------------------------- 17 | //TIM1 is used to generate clock signal with frquency about 8 Hz, timer mode will be clear at compare match 18 | 19 | #include "stm32f4xx.h" // Device header 20 | #include "RTE_Components.h" // Component selection 21 | 22 | //system predirectives 23 | //Number of voltage readings to take before we take a temperature reading 24 | #define TEMP_READING_LOOP_FREQ 16 25 | #define OVERSAMPLE_LOOP 32 26 | #define PIN0 0x1 27 | #define PIN1 0x2 28 | #define PIN4 0x4 29 | #define PIN5 0x5 30 | uint8_t PINS [4] = {PIN0, PIN1, PIN4, PIN5}; 31 | 32 | //forward method declarations 33 | void initADC(void); 34 | void ADC1_IRQHandler(void); 35 | void initTimer1(void); 36 | 37 | //system global variable definitions 38 | volatile uint32_t analogVal[OVERSAMPLE_LOOP]; 39 | volatile uint8_t analogValIndex; 40 | volatile uint8_t buffer_ready = 0; 41 | volatile int skipNextADC = 0; 42 | volatile uint8_t reading_count = 0; 43 | volatile uint32_t temperature_probe = 0; 44 | volatile uint32_t last_raw_adc = 0; 45 | 46 | void initADC(void){ 47 | //Enable clock acces to GPIOA module 48 | RCC->AHB1ENR |= 0x1; 49 | //Declare PA0, PA1, PA4 and PA5 as analog input mode pins 50 | GPIOA->MODER |= 0xF0F; 51 | //Enable clock access to ADC1 module (represented by 8th bit in APB2ENR reg) 52 | RCC->APB2ENR |= 0x100; 53 | //Disable the ADC module 54 | ADC1->CR2 = 0; 55 | //Set the ADCCLK value, 133.3 kHz 56 | ADC1->SMPR1 |= 0x1; 57 | ADC->CCR |= 0x30000; 58 | //Channel number CH1 assigned as the 1st in the sequence to be converted 59 | //PA0 is connected to ADC1 input module 60 | ADC1->SQR3 = PINS[0]; 61 | //Interrupt enable for ADC1 end of conversion 62 | ADC1->CR1 |= 0x10; 63 | //Enable ADC1 module and set continouns sequence mode 64 | ADC1->CR2 |= 0x3; 65 | } 66 | 67 | void ADC1_IRQHandler(void){ 68 | //Interrupt servie routine for ADC completion 69 | uint32_t value = 0; 70 | //If we skip this ADC reading, quit ISR here 71 | if (skipNextADC) { 72 | skipNextADC = 0; 73 | return; 74 | } 75 | if (reading_count == TEMP_READING_LOOP_FREQ ) { 76 | reading_count = 0; 77 | 78 | //We reduce the value by 512 as we have a DC offset we need to remove 79 | temperature_probe = value; 80 | 81 | //Connect the next pin to take the value 82 | //ADMUX = B10010011 83 | //Connect GPIOA PIN 0 to th ADC1 module input 84 | ADC1->SQR3 = PINS[0]; 85 | 86 | /*if(ADC1->SQR3 == PINS[0]){ 87 | ADC1->SQR3 = PINS[1]; 88 | } 89 | else if(ADC1->SQR3 == PINS[1]){ 90 | ADC1->SQR3 = PINS[2]; 91 | } 92 | else if(ADC1->SQR3 == PINS[2]){ 93 | ADC1->SQR3 = PINS[3]; 94 | } 95 | else if(ADC1->SQR3 == PINS[3]){ 96 | ADC1->SQR3 = PINS[0]; 97 | } 98 | */ 99 | 100 | //Set skipNextADC to delay the next TIMER2 call to ADC reading to allow the ADC to settle after changing MUX 101 | skipNextADC = 1; 102 | 103 | } 104 | else { 105 | 106 | //Populate the rolling buffer with values from the ADC 107 | last_raw_adc = value; 108 | analogVal[analogValIndex] = value; 109 | 110 | analogValIndex++; 111 | 112 | if (analogValIndex == OVERSAMPLE_LOOP) { 113 | analogValIndex = 0; 114 | buffer_ready = 1; 115 | } 116 | 117 | reading_count++; 118 | 119 | if (reading_count == TEMP_READING_LOOP_FREQ) { 120 | //use ADC0 for temp probe input on next ADC loop 121 | 122 | 123 | //ADMUX = B10010000; 124 | //Assuming PA0 is connected to ADC1 module input and we need to connect PA1 to the input and so on 125 | ADC1->SQR3 = PINS[2]; 126 | 127 | /* 128 | if(ADC1->SQR3 == PINS[0]){ 129 | ADC1->SQR3 = PINS[1]; 130 | } 131 | else if(ADC1->SQR3 == PINS[1]){ 132 | ADC1->SQR3 = PINS[2]; 133 | } 134 | else if(ADC1->SQR3 == PINS[2]){ 135 | ADC1->SQR3 = PINS[3]; 136 | } 137 | else if(ADC1->SQR3 == PINS[3]){ 138 | ADC1->SQR3 = PINS[0]; 139 | } 140 | */ 141 | 142 | //Set skipNextADC to delay the next TIMER1 call to ADC reading to allow the ADC to settle after changing MUX 143 | skipNextADC = 1; 144 | } 145 | } 146 | } 147 | 148 | void initTimer1(void){ 149 | //Enable clock access to TIM1 150 | RCC->APB2ENR |= 0x1; 151 | //Define clock signal prescaler, generate 8 Hz signal 152 | //F_OSC = 16 MHz, prescaler = 16000 * 125 = 2 MHz equals 8 ticks per second 153 | TIM1->PSC = 16000 - 1; 154 | TIM1->ARR = 125 - 1; 155 | } 156 | 157 | -------------------------------------------------------------------------------- /BMS-stm32f407vg-code/main2.c: -------------------------------------------------------------------------------- 1 | //--------------------------ADC peripheral explanation-------------------------------------- 2 | //PA0 and PA1 are analog input pins connected to measure battery voltage 3 | //We assume that at PA0 pin (ADC_VOLT point) will be 16 bit battery voltage value 4 | //at PA1 (ADC_VOLT_IN) will be 12 bit battery voltage value 5 | //PA4 pin (ADC_TEMP1 point) is connected to voltage divider made by 10k resistor and thermistor in series 6 | //PA5 pin (ADC_TEMP2 point) is connected aslo to simmilar voltage divider 7 | //F_CPU is 16 MHz and we need to divide that value to cca 125 kHz to form ADCCLK 8 | //for this purpose, we will use ADCx_SMPRx register (SMPx [2:0]) that holds the value how many cycles will th system sample 9 | //any value and ADCx_CCR register (ADCPRE[17:16]) SMPx = 001 (15 cycles), ADCPRE = 11 ( PCK2 / 8) 10 | //ADCCLK -> 16 MHz / (15*8) = 133.3 kHz 11 | //We will allign data to the right so ALIGH bit in ADCx_CR2 will be cleared to 0, VREF is 2.56 V internally 12 | 13 | //--------------------------System Nofitications---------------------------------------------- 14 | //type 0 for false ondition and 1 for true condition 15 | 16 | //--------------------------TIM1 peripheral explanation--------------------------------------- 17 | //TIM1 is used to generate clock signal with frquency about 8 Hz, timer mode will be clear at compare match 18 | 19 | #include "stm32f4xx.h" // Device header 20 | #include "RTE_Components.h" // Component selection 21 | 22 | //system predirectives 23 | //Number of voltage readings to take before we take a temperature reading 24 | #define TEMP_READING_LOOP_FREQ 16 25 | #define OVERSAMPLE_LOOP 32 26 | #define PIN0 0x1 27 | #define PIN1 0x2 28 | #define PIN4 0x4 29 | #define PIN5 0x5 30 | //Number of TIMER1 cycles between voltage reading checks (240 = approx 30 seconds) 31 | #define BYPASS_COUNTER_MAX 240 32 | uint8_t PINS [4] = {PIN0, PIN1, PIN4, PIN5}; 33 | 34 | //LED light patterns 35 | #define GREEN_LED_PATTERN_STANDARD 0b00000000 36 | #define GREEN_LED_PATTERN_BYPASS 0b01101100 37 | #define GREEN_LED_PANIC 0b01010101 38 | #define GREEN_LED_PATTERN_UNCONFIGURED 0b11101111 39 | 40 | //forward method declarations 41 | void initADC(void); 42 | void ADC1_IRQHandler(void); 43 | void initTimer1(void); 44 | void TIM1_IRQHanlder(void); 45 | inline void ledGreen(void); 46 | inline void ledOff(void); 47 | void bypass_off(void); 48 | uint16_t Update_VCCMillivolts(void); 49 | 50 | //system global variable definitions 51 | volatile uint32_t analogVal[OVERSAMPLE_LOOP]; 52 | volatile uint8_t analogValIndex; 53 | volatile uint8_t buffer_ready = 0; 54 | volatile int skipNextADC = 0; 55 | volatile uint8_t reading_count = 0; 56 | volatile uint32_t temperature_probe = 0; 57 | volatile uint32_t last_raw_adc = 0; 58 | volatile uint8_t green_pattern = GREEN_LED_PATTERN_STANDARD; 59 | volatile int flash_green = 0; 60 | volatile int ByPassEnabled = 0; 61 | volatile uint16_t ByPassVCCMillivolts = 0; 62 | volatile uint8_t ByPassCounter = 0; 63 | volatile uint16_t targetByPassVoltage = 0; 64 | 65 | void initADC(void){ 66 | //Enable clock acces to GPIOA module 67 | RCC->AHB1ENR |= 0x1; 68 | //Declare PA0, PA1, PA4 and PA5 as analog input mode pins 69 | GPIOA->MODER |= 0xF0F; 70 | //Enable clock access to ADC1 module (represented by 8th bit in APB2ENR reg) 71 | RCC->APB2ENR |= 0x100; 72 | //Disable the ADC module 73 | ADC1->CR2 = 0; 74 | //Set the ADCCLK value, 133.3 kHz 75 | ADC1->SMPR1 |= 0x1; 76 | ADC->CCR |= 0x30000; 77 | //Channel number CH1 assigned as the 1st in the sequence to be converted 78 | //PA0 is connected to ADC1 input module 79 | ADC1->SQR3 = PINS[0]; 80 | //Interrupt enable for ADC1 end of conversion 81 | ADC1->CR1 |= 0x10; 82 | //Enable ADC1 module and set continouns sequence mode 83 | ADC1->CR2 |= 0x3; 84 | } 85 | 86 | void ADC1_IRQHandler(void){ 87 | //Interrupt servie routine for ADC completion 88 | uint32_t value = 0; 89 | //If we skip this ADC reading, quit ISR here 90 | if (skipNextADC) { 91 | skipNextADC = 0; 92 | return; 93 | } 94 | if (reading_count == TEMP_READING_LOOP_FREQ ) { 95 | reading_count = 0; 96 | 97 | //We reduce the value by 512 as we have a DC offset we need to remove 98 | temperature_probe = value; 99 | 100 | //Connect the next pin to take the value 101 | //ADMUX = B10010011 102 | //Connect GPIOA PIN 0 to th ADC1 module input 103 | ADC1->SQR3 = PINS[0]; 104 | 105 | /*if(ADC1->SQR3 == PINS[0]){ 106 | ADC1->SQR3 = PINS[1]; 107 | } 108 | else if(ADC1->SQR3 == PINS[1]){ 109 | ADC1->SQR3 = PINS[2]; 110 | } 111 | else if(ADC1->SQR3 == PINS[2]){ 112 | ADC1->SQR3 = PINS[3]; 113 | } 114 | else if(ADC1->SQR3 == PINS[3]){ 115 | ADC1->SQR3 = PINS[0]; 116 | } 117 | */ 118 | 119 | //Set skipNextADC to delay the next TIMER2 call to ADC reading to allow the ADC to settle after changing MUX 120 | skipNextADC = 1; 121 | 122 | } 123 | else { 124 | 125 | //Populate the rolling buffer with values from the ADC 126 | last_raw_adc = value; 127 | analogVal[analogValIndex] = value; 128 | 129 | analogValIndex++; 130 | 131 | if (analogValIndex == OVERSAMPLE_LOOP) { 132 | analogValIndex = 0; 133 | buffer_ready = 1; 134 | } 135 | 136 | reading_count++; 137 | 138 | if (reading_count == TEMP_READING_LOOP_FREQ) { 139 | //use ADC0 for temp probe input on next ADC loop 140 | 141 | 142 | //ADMUX = B10010000; 143 | //Assuming PA0 is connected to ADC1 module input and we need to connect PA1 to the input and so on 144 | ADC1->SQR3 = PINS[2]; 145 | 146 | /* 147 | if(ADC1->SQR3 == PINS[0]){ 148 | ADC1->SQR3 = PINS[1]; 149 | } 150 | else if(ADC1->SQR3 == PINS[1]){ 151 | ADC1->SQR3 = PINS[2]; 152 | } 153 | else if(ADC1->SQR3 == PINS[2]){ 154 | ADC1->SQR3 = PINS[3]; 155 | } 156 | else if(ADC1->SQR3 == PINS[3]){ 157 | ADC1->SQR3 = PINS[0]; 158 | } 159 | */ 160 | 161 | //Set skipNextADC to delay the next TIMER1 call to ADC reading to allow the ADC to settle after changing MUX 162 | skipNextADC = 1; 163 | } 164 | } 165 | } 166 | 167 | void initTimer1(void){ 168 | //Enable clock access to TIM1 169 | RCC->APB2ENR |= 0x1; 170 | //Define clock signal prescaler, generate 8 Hz signal 171 | //F_OSC = 16 MHz, prescaler = 16000 * 125 = 2 MHz equals 8 ticks per second 172 | TIM1->PSC = 16000 - 1; 173 | TIM1->ARR = 125 - 1; 174 | //Set the value to be compared with counter register 175 | TIM1->CCR1 = 64; 176 | //Interrupt request is to be generated 177 | TIM1->DIER |= 0x1; 178 | //Toggle OCx pin when CNT reg reaches CCR reg 179 | TIM1->CCMR1 |= 0x30; 180 | //Select active high polarity and enable the output 181 | TIM1->CCER |= 0x1; 182 | //Enable the timer 183 | TIM1->CR1 |= 0x1; 184 | } 185 | 186 | void TIM1_IRQHanlder(void){ 187 | if (green_pattern == 0) { 188 | if (flash_green) { 189 | ledGreen(); 190 | } 191 | flash_green = 0; 192 | } else { 193 | ///Rotate pattern 194 | green_pattern = (uint8_t)(green_pattern << 1) | (green_pattern >> 7); 195 | } 196 | if (green_pattern & 0x01) { 197 | ledGreen(); 198 | } else { 199 | ledOff(); 200 | } 201 | if (ByPassEnabled) { 202 | 203 | //TODO: We need to add in code here to check we don't overheat 204 | 205 | //This must go above the following "if (ByPassCounter > 0)" statement... 206 | if (ByPassCounter == 0 && analogValIndex == 0) { 207 | //We are in bypass and just finished an in-cycle voltage measurement 208 | ByPassVCCMillivolts = Update_VCCMillivolts(); 209 | 210 | if (targetByPassVoltage >= ByPassVCCMillivolts) { 211 | //We reached the goal 212 | bypass_off(); 213 | } else { 214 | //Try again 215 | ByPassCounter = BYPASS_COUNTER_MAX; 216 | } 217 | } 218 | 219 | if (ByPassCounter > 0) 220 | { 221 | //We are in ACTIVE BYPASS mode - the RESISTOR will be ACTIVE + BURNING ENERGY 222 | ByPassCounter--; 223 | //digitalWrite(PB4, HIGH); 224 | //ON-OFF pin at PB9 pin 225 | //Enable clock access to GPIOB 226 | RCC->AHB1ENR |= 0x2; 227 | //Declare PB9 as output mode pin 228 | GPIOB->MODER |= 0x40000; 229 | //Set PB9 at HIGH state 230 | GPIOB->BSRR |= 0x200; 231 | if (ByPassCounter == 0) 232 | { 233 | //We have just finished this timed ACTIVE BYPASS mode, disable resistor 234 | //and measure resting voltage now before possible re-enable. 235 | //digitalWrite(PB4, LOW); 236 | //Enable clock access to GPIOB 237 | RCC->AHB1ENR |= 0x2; 238 | //Declare PB9 as output mode pin 239 | GPIOB->MODER |= 0x40000; 240 | //Set PB9 at LOW state 241 | GPIOB->BSRR |= 0x2000000; 242 | //Reset voltage ADC buffer 243 | analogValIndex = 0; 244 | } 245 | } 246 | 247 | } else { 248 | //Safety check we ensure bypass is always off if not enabled 249 | //digitalWrite(PB4, LOW); 250 | //Enable clock access to GPIOB 251 | RCC->AHB1ENR |= 0x2; 252 | //Declare PB9 as output mode pin 253 | GPIOB->MODER |= 0x40000; 254 | //Set PB9 at LOW state 255 | GPIOB->BSRR |= 0x2000000; 256 | } 257 | 258 | if (green_pattern == 0) { 259 | ledOff(); 260 | } 261 | 262 | 263 | //trigger ADC reading 264 | //ADCSRA |= (1 << ADSC); 265 | //Enable clock access to GPIOA module 266 | RCC->AHB1ENR |= 0x1; 267 | //Enable clock access to ADC1 module (represented by 8th bit in APB2ENR reg) 268 | RCC->APB2ENR |= 0x100; 269 | //Trigger ADC1 module 270 | ADC1->CR2 |= 0x40000000; 271 | } 272 | inline void ledGreen() { 273 | //DDRB |= (1 << DDB1); 274 | //PORTB |= (1 << PB1); 275 | //Enable clock access to GPIOA 276 | RCC->AHB1ENR |= 0x1; 277 | //Define PA12 as output mode pin 278 | GPIOA->MODER |= 0x1000000; 279 | //Set PA12 at HIGH state 280 | GPIOA->BSRR |= 0x1000; 281 | } 282 | 283 | inline void ledOff() { 284 | //Low 285 | //DDRB |= (1 << DDB1); 286 | //PORTB &= ~(1 << PB1); 287 | //Enable clock access to GPIOA 288 | RCC->AHB1ENR |= 0x1; 289 | //Define PA12 as output mode pin 290 | GPIOA->MODER |= 0x1000000; 291 | //Set PA12 at LOW state 292 | GPIOA->BSRR |= 0x10000000; 293 | } 294 | void bypass_off(void){ 295 | targetByPassVoltage = 0; 296 | ByPassCounter = 0; 297 | ByPassEnabled = 0; 298 | green_pattern = GREEN_LED_PATTERN_STANDARD; 299 | } 300 | -------------------------------------------------------------------------------- /BMS-stm32g0-code/FreeRTOS-main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2020 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | #include "cmsis_os.h" 23 | #include "freertos.h" 24 | #include "stdio.h" 25 | #include "stdint.h" 26 | /* Private includes ----------------------------------------------------------*/ 27 | /* USER CODE BEGIN Includes */ 28 | 29 | /* USER CODE END Includes */ 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* USER CODE BEGIN PTD */ 33 | 34 | /* USER CODE END PTD */ 35 | 36 | /* Private define ------------------------------------------------------------*/ 37 | /* USER CODE BEGIN PD */ 38 | /* USER CODE END PD */ 39 | 40 | /* Private macro -------------------------------------------------------------*/ 41 | /* USER CODE BEGIN PM */ 42 | 43 | /* USER CODE END PM */ 44 | 45 | /* Private variables ---------------------------------------------------------*/ 46 | ADC_HandleTypeDef hadc1; 47 | UART_HandleTypeDef huart1; 48 | UART_HandleTypeDef huart2; 49 | osThreadId Task1Handle; 50 | osThreadId Task2Handle; 51 | osThreadId Task3Handle; 52 | osSemaphoreId BinarySemHandle; 53 | uint16_t voltageValue = 0; 54 | uint16_t temperatureValue = 0; 55 | uint8_t system_default_address = 0x20; 56 | uint16_t voltage = 0; 57 | uint16_t temperature = 0; 58 | /* USER CODE BEGIN PV */ 59 | 60 | /* USER CODE END PV */ 61 | 62 | /* Private function prototypes -----------------------------------------------*/ 63 | void SystemClock_Config(void); 64 | static void MX_GPIO_Init(void); 65 | static void MX_USART2_UART_Init(void); 66 | static void MX_ADC1_Init(void); 67 | static void MX_USART1_UART_Init(void); 68 | void UART_Task(void const * argument); 69 | void ADC_Volt_Task(void const * argument); 70 | void ADC_Temp_Task(void const * argument); 71 | 72 | /* USER CODE BEGIN PFP */ 73 | /* USER CODE END PFP */ 74 | 75 | /* Private user code ---------------------------------------------------------*/ 76 | /* USER CODE BEGIN 0 */ 77 | 78 | /* USER CODE END 0 */ 79 | 80 | /** 81 | * @brief The application entry point. 82 | * @retval int 83 | */ 84 | int main(void) 85 | { 86 | /* USER CODE BEGIN 1 */ 87 | 88 | /* USER CODE END 1 */ 89 | 90 | /* MCU Configuration--------------------------------------------------------*/ 91 | 92 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 93 | HAL_Init(); 94 | 95 | /* USER CODE BEGIN Init */ 96 | 97 | /* USER CODE END Init */ 98 | 99 | /* Configure the system clock */ 100 | SystemClock_Config(); 101 | 102 | /* USER CODE BEGIN SysInit */ 103 | 104 | /* USER CODE END SysInit */ 105 | 106 | /* Initialize all configured peripherals */ 107 | MX_GPIO_Init(); 108 | MX_USART2_UART_Init(); 109 | MX_ADC1_Init(); 110 | MX_USART1_UART_Init(); 111 | /* USER CODE BEGIN 2 */ 112 | 113 | /* USER CODE END 2 */ 114 | 115 | /* USER CODE BEGIN RTOS_MUTEX */ 116 | /* add mutexes, ... */ 117 | /* USER CODE END RTOS_MUTEX */ 118 | 119 | /* Create the semaphores(s) */ 120 | /* definition and creation of BinarySem */ 121 | osSemaphoreDef(BinarySem); 122 | BinarySemHandle = osSemaphoreCreate(osSemaphore(BinarySem), 1); 123 | 124 | /* USER CODE BEGIN RTOS_SEMAPHORES */ 125 | /* add semaphores, ... */ 126 | /* USER CODE END RTOS_SEMAPHORES */ 127 | 128 | /* USER CODE BEGIN RTOS_TIMERS */ 129 | /* start timers, add new ones, ... */ 130 | /* USER CODE END RTOS_TIMERS */ 131 | 132 | /* USER CODE BEGIN RTOS_QUEUES */ 133 | /* add queues, ... */ 134 | /* USER CODE END RTOS_QUEUES */ 135 | 136 | /* Create the thread(s) */ 137 | /* definition and creation of Task1 */ 138 | osThreadDef(Task1, UART_Task, osPriorityNormal, 0, 128); 139 | Task1Handle = osThreadCreate(osThread(Task1), NULL); 140 | 141 | /* definition and creation of Task2 */ 142 | osThreadDef(Task2, ADC_Volt_Task, osPriorityNormal, 0, 128); 143 | Task2Handle = osThreadCreate(osThread(Task2), NULL); 144 | 145 | /* definition and creation of Task3 */ 146 | osThreadDef(Task3, ADC_Temp_Task, osPriorityNormal, 0, 128); 147 | Task3Handle = osThreadCreate(osThread(Task3), NULL); 148 | 149 | /* USER CODE BEGIN RTOS_THREADS */ 150 | /* add threads, ... */ 151 | /* USER CODE END RTOS_THREADS */ 152 | 153 | /* Start scheduler */ 154 | osKernelStart(); 155 | 156 | /* We should never get here as control is now taken by the scheduler */ 157 | /* Infinite loop */ 158 | /* USER CODE BEGIN WHILE */ 159 | while (1) 160 | { 161 | /* USER CODE END WHILE */ 162 | 163 | /* USER CODE BEGIN 3 */ 164 | } 165 | /* USER CODE END 3 */ 166 | } 167 | 168 | /** 169 | * @brief System Clock Configuration 170 | * @retval None 171 | */ 172 | void SystemClock_Config(void) 173 | { 174 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 175 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 176 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; 177 | 178 | /** Configure the main internal regulator output voltage 179 | */ 180 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 181 | /** Initializes the RCC Oscillators according to the specified parameters 182 | * in the RCC_OscInitTypeDef structure. 183 | */ 184 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 185 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 186 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; 187 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 188 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 189 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 190 | { 191 | Error_Handler(); 192 | } 193 | /** Initializes the CPU, AHB and APB buses clocks 194 | */ 195 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 196 | |RCC_CLOCKTYPE_PCLK1; 197 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; 198 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 199 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 200 | 201 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) 202 | { 203 | Error_Handler(); 204 | } 205 | /** Initializes the peripherals clocks 206 | */ 207 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_ADC; 208 | PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; 209 | PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; 210 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) 211 | { 212 | Error_Handler(); 213 | } 214 | } 215 | 216 | /** 217 | * @brief ADC1 Initialization Function 218 | * @param None 219 | * @retval None 220 | */ 221 | static void MX_ADC1_Init(void) 222 | { 223 | 224 | /* USER CODE BEGIN ADC1_Init 0 */ 225 | 226 | /* USER CODE END ADC1_Init 0 */ 227 | 228 | ADC_ChannelConfTypeDef sConfig = {0}; 229 | 230 | /* USER CODE BEGIN ADC1_Init 1 */ 231 | 232 | /* USER CODE END ADC1_Init 1 */ 233 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 234 | */ 235 | hadc1.Instance = ADC1; 236 | hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; 237 | hadc1.Init.Resolution = ADC_RESOLUTION_12B; 238 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; 239 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; 240 | hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 241 | hadc1.Init.LowPowerAutoWait = DISABLE; 242 | hadc1.Init.LowPowerAutoPowerOff = DISABLE; 243 | hadc1.Init.ContinuousConvMode = DISABLE; 244 | hadc1.Init.NbrOfConversion = 1; 245 | hadc1.Init.DiscontinuousConvMode = DISABLE; 246 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; 247 | hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; 248 | hadc1.Init.DMAContinuousRequests = DISABLE; 249 | hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; 250 | hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5; 251 | hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5; 252 | hadc1.Init.OversamplingMode = DISABLE; 253 | hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH; 254 | if (HAL_ADC_Init(&hadc1) != HAL_OK) 255 | { 256 | Error_Handler(); 257 | } 258 | /** Configure Regular Channel 259 | */ 260 | sConfig.Channel = ADC_CHANNEL_1; 261 | sConfig.Rank = ADC_REGULAR_RANK_1; 262 | sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; 263 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 264 | { 265 | Error_Handler(); 266 | } 267 | /* USER CODE BEGIN ADC1_Init 2 */ 268 | 269 | /* USER CODE END ADC1_Init 2 */ 270 | 271 | } 272 | 273 | /** 274 | * @brief USART1 Initialization Function 275 | * @param None 276 | * @retval None 277 | */ 278 | static void MX_USART1_UART_Init(void) 279 | { 280 | 281 | /* USER CODE BEGIN USART1_Init 0 */ 282 | 283 | /* USER CODE END USART1_Init 0 */ 284 | 285 | /* USER CODE BEGIN USART1_Init 1 */ 286 | 287 | /* USER CODE END USART1_Init 1 */ 288 | huart1.Instance = USART1; 289 | huart1.Init.BaudRate = 115200; 290 | huart1.Init.WordLength = UART_WORDLENGTH_8B; 291 | huart1.Init.StopBits = UART_STOPBITS_1; 292 | huart1.Init.Parity = UART_PARITY_NONE; 293 | huart1.Init.Mode = UART_MODE_TX_RX; 294 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 295 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; 296 | huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 297 | huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; 298 | huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 299 | if (HAL_UART_Init(&huart1) != HAL_OK) 300 | { 301 | Error_Handler(); 302 | } 303 | if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) 304 | { 305 | Error_Handler(); 306 | } 307 | if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) 308 | { 309 | Error_Handler(); 310 | } 311 | if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) 312 | { 313 | Error_Handler(); 314 | } 315 | /* USER CODE BEGIN USART1_Init 2 */ 316 | 317 | /* USER CODE END USART1_Init 2 */ 318 | 319 | } 320 | 321 | /** 322 | * @brief USART2 Initialization Function 323 | * @param None 324 | * @retval None 325 | */ 326 | static void MX_USART2_UART_Init(void) 327 | { 328 | 329 | /* USER CODE BEGIN USART2_Init 0 */ 330 | 331 | /* USER CODE END USART2_Init 0 */ 332 | 333 | /* USER CODE BEGIN USART2_Init 1 */ 334 | 335 | /* USER CODE END USART2_Init 1 */ 336 | huart2.Instance = USART2; 337 | huart2.Init.BaudRate = 230400; 338 | huart2.Init.WordLength = UART_WORDLENGTH_8B; 339 | huart2.Init.StopBits = UART_STOPBITS_1; 340 | huart2.Init.Parity = UART_PARITY_NONE; 341 | huart2.Init.Mode = UART_MODE_TX_RX; 342 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 343 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 344 | huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 345 | huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; 346 | huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 347 | if (HAL_UART_Init(&huart2) != HAL_OK) 348 | { 349 | Error_Handler(); 350 | } 351 | /* USER CODE BEGIN USART2_Init 2 */ 352 | 353 | /* USER CODE END USART2_Init 2 */ 354 | 355 | } 356 | 357 | /** 358 | * @brief GPIO Initialization Function 359 | * @param None 360 | * @retval None 361 | */ 362 | static void MX_GPIO_Init(void) 363 | { 364 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 365 | 366 | /* GPIO Ports Clock Enable */ 367 | __HAL_RCC_GPIOB_CLK_ENABLE(); 368 | __HAL_RCC_GPIOC_CLK_ENABLE(); 369 | __HAL_RCC_GPIOF_CLK_ENABLE(); 370 | __HAL_RCC_GPIOA_CLK_ENABLE(); 371 | 372 | /*Configure GPIO pin Output Level */ 373 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET); 374 | 375 | /*Configure GPIO pin Output Level */ 376 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_RESET); 377 | 378 | /*Configure GPIO pin : PB9 */ 379 | GPIO_InitStruct.Pin = GPIO_PIN_9; 380 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 381 | GPIO_InitStruct.Pull = GPIO_NOPULL; 382 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 383 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 384 | 385 | /*Configure GPIO pin : T_NRST_Pin */ 386 | GPIO_InitStruct.Pin = T_NRST_Pin; 387 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 388 | GPIO_InitStruct.Pull = GPIO_NOPULL; 389 | HAL_GPIO_Init(T_NRST_GPIO_Port, &GPIO_InitStruct); 390 | 391 | /*Configure GPIO pins : PA10 PA11 PA12 */ 392 | GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; 393 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 394 | GPIO_InitStruct.Pull = GPIO_NOPULL; 395 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 396 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 397 | 398 | /* EXTI interrupt init*/ 399 | HAL_NVIC_SetPriority(EXTI2_3_IRQn, 0, 0); 400 | HAL_NVIC_EnableIRQ(EXTI2_3_IRQn); 401 | 402 | } 403 | 404 | /* USER CODE BEGIN 4 */ 405 | 406 | /* USER CODE END 4 */ 407 | 408 | /* USER CODE BEGIN Header_UART_Task */ 409 | /** 410 | * @brief Function implementing the Task1 thread. 411 | * @param argument: Not used 412 | * @retval None 413 | */ 414 | /* USER CODE END Header_UART_Task */ 415 | void UART_Task(void const * argument) 416 | { 417 | /* USER CODE BEGIN 5 */ 418 | /* Infinite loop */ 419 | while(1) 420 | { 421 | //priting the entry string 422 | printf("The system is sending the packets...\n"); 423 | //Enable transmission 424 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); 425 | //wait for 1ms 426 | osDelay(1); 427 | //Send the system address 428 | HAL_UART_Transmit(&huart2, &system_default_address, sizeof(system_default_address), HAL_MAX_DELAY); 429 | //wait for 1ms 430 | //HAL_Delay(1); 431 | //Send the system voltage value 432 | HAL_UART_Transmit(&huart2, &voltage, sizeof(voltage), HAL_MAX_DELAY); 433 | //wait for 1ms 434 | //HAL_Delay(1); 435 | //Send the system temperature value 436 | HAL_UART_Transmit(&huart2, &temperature, sizeof(temperature), HAL_MAX_DELAY); 437 | //Disable transmission 438 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); 439 | //10000 ms delay 440 | osDelay(10000); 441 | } 442 | /* USER CODE END 5 */ 443 | } 444 | 445 | /* USER CODE BEGIN Header_ADC_Volt_Task */ 446 | /** 447 | * @brief Function implementing the Task2 thread. 448 | * @param argument: Not used 449 | * @retval None 450 | */ 451 | /* USER CODE END Header_ADC_Volt_Task */ 452 | void ADC_Volt_Task(void const * argument) 453 | { 454 | /* USER CODE BEGIN ADC_Volt_Task */ 455 | /* Infinite loop */ 456 | while(1) 457 | { 458 | //priting the entry string 459 | printf("The system is taking voltage value...\n"); 460 | //Define ADC parameters 461 | hadc1.Instance = ADC1; 462 | ADC_ChannelConfTypeDef sConfig = {0}; 463 | sConfig.Channel = ADC_CHANNEL_1; 464 | //Start ADC 465 | HAL_ADC_Start(&hadc1); 466 | //Poll ADC 467 | HAL_ADC_PollForConversion(&hadc1, 100); 468 | //calculate analog and decimal values 469 | voltage = (HAL_ADC_GetValue(&hadc1)); 470 | //5000 ms delay 471 | osDelay(5000); 472 | } 473 | /* USER CODE END ADC_Volt_Task */ 474 | } 475 | 476 | /* USER CODE BEGIN Header_ADC_Temp_Task */ 477 | /** 478 | * @brief Function implementing the Task3 thread. 479 | * @param argument: Not used 480 | * @retval None 481 | */ 482 | /* USER CODE END Header_ADC_Temp_Task */ 483 | void ADC_Temp_Task(void const * argument) 484 | { 485 | /* USER CODE BEGIN ADC_Temp_Task */ 486 | /* Infinite loop */ 487 | while(1) 488 | { 489 | //priting the entry string 490 | printf("The system is taking temperature value...\n"); 491 | //Define ADC parameters 492 | hadc1.Instance = ADC1; 493 | ADC_ChannelConfTypeDef sConfig = {0}; 494 | sConfig.Channel = ADC_CHANNEL_4; 495 | //Start ADC 496 | HAL_ADC_Start(&hadc1); 497 | //Poll ADC 498 | HAL_ADC_PollForConversion(&hadc1, 100); 499 | //calculate analog and decimal values 500 | temperature = (HAL_ADC_GetValue(&hadc1)); 501 | //5000 ms delay 502 | osDelay(5000); 503 | } 504 | /* USER CODE END ADC_Temp_Task */ 505 | } 506 | 507 | /** 508 | * @brief Period elapsed callback in non blocking mode 509 | * @note This function is called when TIM1 interrupt took place, inside 510 | * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment 511 | * a global variable "uwTick" used as application time base. 512 | * @param htim : TIM handle 513 | * @retval None 514 | */ 515 | void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) 516 | { 517 | /* USER CODE BEGIN Callback 0 */ 518 | 519 | /* USER CODE END Callback 0 */ 520 | if (htim->Instance == TIM1) { 521 | HAL_IncTick(); 522 | } 523 | /* USER CODE BEGIN Callback 1 */ 524 | 525 | /* USER CODE END Callback 1 */ 526 | } 527 | 528 | /** 529 | * @brief This function is executed in case of error occurrence. 530 | * @retval None 531 | */ 532 | void Error_Handler(void) 533 | { 534 | /* USER CODE BEGIN Error_Handler_Debug */ 535 | /* User can add his own implementation to report the HAL error return state */ 536 | 537 | /* USER CODE END Error_Handler_Debug */ 538 | } 539 | 540 | #ifdef USE_FULL_ASSERT 541 | /** 542 | * @brief Reports the name of the source file and the source line number 543 | * where the assert_param error has occurred. 544 | * @param file: pointer to the source file name 545 | * @param line: assert_param error line source number 546 | * @retval None 547 | */ 548 | void assert_failed(uint8_t *file, uint32_t line) 549 | { 550 | /* USER CODE BEGIN 6 */ 551 | /* User can add his own implementation to report the file name and line number, 552 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 553 | /* USER CODE END 6 */ 554 | } 555 | #endif /* USE_FULL_ASSERT */ 556 | 557 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 558 | -------------------------------------------------------------------------------- /BMS-stm32g0-code/README: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /BMS-stm32g0-code/adc_temp_testing.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2020 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | #include "stdlib.h" 23 | #include "math.h" 24 | #include "stdio.h" 25 | #include "stdint.h" 26 | 27 | /* Private includes ----------------------------------------------------------*/ 28 | /* USER CODE BEGIN Includes */ 29 | 30 | /* USER CODE END Includes */ 31 | 32 | /* Private typedef -----------------------------------------------------------*/ 33 | /* USER CODE BEGIN PTD */ 34 | 35 | /* USER CODE END PTD */ 36 | 37 | /* Private define ------------------------------------------------------------*/ 38 | /* USER CODE BEGIN PD */ 39 | /* USER CODE END PD */ 40 | 41 | /* Private macro -------------------------------------------------------------*/ 42 | /* USER CODE BEGIN PM */ 43 | 44 | /* USER CODE END PM */ 45 | 46 | /* Private variables ---------------------------------------------------------*/ 47 | ADC_HandleTypeDef hadc1; 48 | //ADC test variables 49 | /* 50 | double adcResult = 0; 51 | double voltageResult = 0; 52 | //double voltageValue[OVERSAMPLE_VALUE]; 53 | double voltageMax = 0; 54 | int count = 0; 55 | //Temperature test variables 56 | double analogValue = 0; 57 | double tempValue = 0; 58 | double voltageVal = 0; 59 | double R1 = 10000; 60 | double logR2, R2, T, Tc, Tf; 61 | float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07; 62 | */ 63 | //float variables 64 | /* 65 | float Vin = 3.3; // [V] 66 | float Rt = 10000; // Resistor t [ohm] 67 | float R0 = 10000; // value of rct in T0 [ohm] 68 | float T0 = 298.15; // use T0 in Kelvin [K] 69 | float Vout = 0.0; // Vout in A0 70 | float Rout = 0.0; // Rout in A0 71 | 72 | float T1 = 273.15; // [K] in datasheet 0º C 73 | float T2 = 373.15; // [K] in datasheet 100° C 74 | float RT1 = 32014; // [ohms] resistence in T1 75 | float RT2 = 697; // [ohms] resistence in T2 76 | float beta = 0.0; // initial parameters [K] 77 | float Rinf = 0.0; // initial parameters [ohm] 78 | float TempK = 0.0; // variable output 79 | float TempC = 0.0; // variable output 80 | */ 81 | UART_HandleTypeDef huart2; 82 | 83 | /* USER CODE BEGIN PV */ 84 | 85 | /* USER CODE END PV */ 86 | 87 | /* Private function prototypes -----------------------------------------------*/ 88 | void SystemClock_Config(void); 89 | static void MX_GPIO_Init(void); 90 | static void MX_USART2_UART_Init(void); 91 | static void MX_ADC1_Init(void); 92 | /* USER CODE BEGIN PFP */ 93 | 94 | /* USER CODE END PFP */ 95 | 96 | /* Private user code ---------------------------------------------------------*/ 97 | /* USER CODE BEGIN 0 */ 98 | 99 | /* USER CODE END 0 */ 100 | 101 | /** 102 | * @brief The application entry point. 103 | * @retval int 104 | */ 105 | int main(void) 106 | { 107 | 108 | /*while(count < OVERSAMPLE_VALUE){ 109 | voltageResult = (adcResult * 3.3) / 4096; 110 | voltageValue[count] = voltageResult; 111 | voltageMax += voltageResult; 112 | count++; 113 | } 114 | voltageMax /= OVERSAMPLE_VALUE; 115 | */ 116 | 117 | /* USER CODE END 1 */ 118 | 119 | /* MCU Configuration--------------------------------------------------------*/ 120 | 121 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 122 | HAL_Init(); 123 | 124 | /* USER CODE BEGIN Init */ 125 | 126 | /* USER CODE END Init */ 127 | 128 | /* Configure the system clock */ 129 | SystemClock_Config(); 130 | 131 | /* USER CODE BEGIN SysInit */ 132 | 133 | /* USER CODE END SysInit */ 134 | 135 | /* Initialize all configured peripherals */ 136 | MX_GPIO_Init(); 137 | MX_USART2_UART_Init(); 138 | MX_ADC1_Init(); 139 | /* USER CODE BEGIN 2 */ 140 | 141 | //system varaibles 142 | const float invBeta = 1.00 / 3950.00; 143 | const float adcMax = 4095.00; 144 | const float invT0 = 1.00 / 298.15; 145 | double adcVal; 146 | 147 | //Rinf = R0*exp(-beta/T0); 148 | /* USER CODE END 2 */ 149 | 150 | /* Infinite loop */ 151 | /* USER CODE BEGIN WHILE */ 152 | while(1){ 153 | //USER CODE BEGIN 1 154 | HAL_ADC_Start(&hadc1); 155 | HAL_ADC_PollForConversion(&hadc1, 100); 156 | adcVal = (HAL_ADC_GetValue(&hadc1)); 157 | T = 1.00 / (invT0 + invBeta*(log ( adcMax / (float) adcVal - 1.00))); 158 | Tc = T - 273.15; 159 | /* 160 | HAL_ADC_Start(&hadc1); 161 | HAL_ADC_PollForConversion(&hadc1, 100); 162 | analogValue = (HAL_ADC_GetValue(&hadc1)); 163 | tempValue = analogValue * 3.3 / 4096; 164 | R2 = R1 * (4095.0 / (double)analogValue - 1.0); 165 | logR2 = log10(R2); 166 | T = (1.0 / ((double)c1 + (double)c2*logR2 + (double)c3*logR2*logR2*logR2)); 167 | Tc = T - 273; 168 | HAL_ADC_Stop(&hadc1);*/ 169 | } 170 | //USER CODE END 3 171 | /*HAL_ADC_Start(&hadc1); 172 | HAL_ADC_PollForConversion(&hadc1, 100); 173 | analogValue = (HAL_ADC_GetValue(&hadc1)); 174 | voltageVal = analogValue * 3.3 / 4096; 175 | Rout=(Rt*(float)voltageVal/(Vin-(float)voltageVal)); 176 | TempK=(beta/log10(Rout/Rinf)); // calc for temperature 177 | TempC=TempK-273.15;*/ 178 | } 179 | 180 | /** 181 | * @brief System Clock Configuration 182 | * @retval None 183 | */ 184 | void SystemClock_Config(void) 185 | { 186 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 187 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 188 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; 189 | 190 | /** Configure the main internal regulator output voltage 191 | */ 192 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 193 | /** Initializes the RCC Oscillators according to the specified parameters 194 | * in the RCC_OscInitTypeDef structure. 195 | */ 196 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 197 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 198 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; 199 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 200 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 201 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 202 | { 203 | Error_Handler(); 204 | } 205 | /** Initializes the CPU, AHB and APB buses clocks 206 | */ 207 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 208 | |RCC_CLOCKTYPE_PCLK1; 209 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; 210 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 211 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 212 | 213 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) 214 | { 215 | Error_Handler(); 216 | } 217 | /** Initializes the peripherals clocks 218 | */ 219 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; 220 | PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; 221 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) 222 | { 223 | Error_Handler(); 224 | } 225 | } 226 | 227 | /** 228 | * @brief ADC1 Initialization Function 229 | * @param None 230 | * @retval None 231 | */ 232 | static void MX_ADC1_Init(void) 233 | { 234 | 235 | /* USER CODE BEGIN ADC1_Init 0 */ 236 | 237 | /* USER CODE END ADC1_Init 0 */ 238 | 239 | ADC_ChannelConfTypeDef sConfig = {0}; 240 | 241 | /* USER CODE BEGIN ADC1_Init 1 */ 242 | 243 | /* USER CODE END ADC1_Init 1 */ 244 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 245 | */ 246 | hadc1.Instance = ADC1; 247 | hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; 248 | hadc1.Init.Resolution = ADC_RESOLUTION_12B; 249 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; 250 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; 251 | hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 252 | hadc1.Init.LowPowerAutoWait = DISABLE; 253 | hadc1.Init.LowPowerAutoPowerOff = DISABLE; 254 | hadc1.Init.ContinuousConvMode = DISABLE; 255 | hadc1.Init.NbrOfConversion = 1; 256 | hadc1.Init.DiscontinuousConvMode = DISABLE; 257 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; 258 | hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; 259 | hadc1.Init.DMAContinuousRequests = DISABLE; 260 | hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; 261 | hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5; 262 | hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5; 263 | hadc1.Init.OversamplingMode = DISABLE; 264 | hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH; 265 | if (HAL_ADC_Init(&hadc1) != HAL_OK) 266 | { 267 | Error_Handler(); 268 | } 269 | /** Configure Regular Channel 270 | */ 271 | sConfig.Channel = ADC_CHANNEL_4; 272 | sConfig.Rank = ADC_REGULAR_RANK_1; 273 | sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; 274 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 275 | { 276 | Error_Handler(); 277 | } 278 | /* USER CODE BEGIN ADC1_Init 2 */ 279 | 280 | /* USER CODE END ADC1_Init 2 */ 281 | 282 | } 283 | 284 | /** 285 | * @brief USART2 Initialization Function 286 | * @param None 287 | * @retval None 288 | */ 289 | static void MX_USART2_UART_Init(void) 290 | { 291 | 292 | /* USER CODE BEGIN USART2_Init 0 */ 293 | 294 | /* USER CODE END USART2_Init 0 */ 295 | 296 | /* USER CODE BEGIN USART2_Init 1 */ 297 | 298 | /* USER CODE END USART2_Init 1 */ 299 | huart2.Instance = USART2; 300 | huart2.Init.BaudRate = 115200; 301 | huart2.Init.WordLength = UART_WORDLENGTH_7B; 302 | huart2.Init.StopBits = UART_STOPBITS_1; 303 | huart2.Init.Parity = UART_PARITY_NONE; 304 | huart2.Init.Mode = UART_MODE_TX_RX; 305 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 306 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 307 | huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 308 | huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; 309 | huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 310 | if (HAL_UART_Init(&huart2) != HAL_OK) 311 | { 312 | Error_Handler(); 313 | } 314 | /* USER CODE BEGIN USART2_Init 2 */ 315 | 316 | /* USER CODE END USART2_Init 2 */ 317 | 318 | } 319 | 320 | /** 321 | * @brief GPIO Initialization Function 322 | * @param None 323 | * @retval None 324 | */ 325 | static void MX_GPIO_Init(void) 326 | { 327 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 328 | 329 | /* GPIO Ports Clock Enable */ 330 | __HAL_RCC_GPIOC_CLK_ENABLE(); 331 | __HAL_RCC_GPIOF_CLK_ENABLE(); 332 | __HAL_RCC_GPIOA_CLK_ENABLE(); 333 | 334 | /*Configure GPIO pin Output Level */ 335 | HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET); 336 | 337 | /*Configure GPIO pin : T_NRST_Pin */ 338 | GPIO_InitStruct.Pin = T_NRST_Pin; 339 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 340 | GPIO_InitStruct.Pull = GPIO_NOPULL; 341 | HAL_GPIO_Init(T_NRST_GPIO_Port, &GPIO_InitStruct); 342 | 343 | /*Configure GPIO pin : LD3_Pin */ 344 | GPIO_InitStruct.Pin = LD3_Pin; 345 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 346 | GPIO_InitStruct.Pull = GPIO_NOPULL; 347 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 348 | HAL_GPIO_Init(LD3_GPIO_Port, &GPIO_InitStruct); 349 | 350 | } 351 | 352 | /* USER CODE BEGIN 4 */ 353 | 354 | /* USER CODE END 4 */ 355 | 356 | /** 357 | * @brief This function is executed in case of error occurrence. 358 | * @retval None 359 | */ 360 | void Error_Handler(void) 361 | { 362 | /* USER CODE BEGIN Error_Handler_Debug */ 363 | /* User can add his own implementation to report the HAL error return state */ 364 | 365 | /* USER CODE END Error_Handler_Debug */ 366 | } 367 | 368 | #ifdef USE_FULL_ASSERT 369 | /** 370 | * @brief Reports the name of the source file and the source line number 371 | * where the assert_param error has occurred. 372 | * @param file: pointer to the source file name 373 | * @param line: assert_param error line source number 374 | * @retval None 375 | */ 376 | void assert_failed(uint8_t *file, uint32_t line) 377 | { 378 | /* USER CODE BEGIN 6 */ 379 | /* User can add his own implementation to report the file name and line number, 380 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 381 | /* USER CODE END 6 */ 382 | } 383 | #endif /* USE_FULL_ASSERT */ 384 | 385 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 386 | -------------------------------------------------------------------------------- /BMS-stm32g0-code/adc_testing.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "stdlib.h" 3 | #include "stdio.h" 4 | #include "stdint.h" 5 | 6 | 7 | /* Private includes ----------------------------------------------------------*/ 8 | /* USER CODE BEGIN Includes */ 9 | 10 | /* USER CODE END Includes */ 11 | 12 | /* Private typedef -----------------------------------------------------------*/ 13 | /* USER CODE BEGIN PTD */ 14 | 15 | /* USER CODE END PTD */ 16 | 17 | /* Private define ------------------------------------------------------------*/ 18 | /* USER CODE BEGIN PD */ 19 | #define ADC_0V_VALUE 0 20 | #define ADC_1V_VALUE 1241 21 | #define ADC_2V_VALUE 2482 22 | #define ADC_3V_VALUE 3723 23 | #define OVERSAMPLE_VALUE 16 24 | /* USER CODE END PD */ 25 | 26 | /* Private macro -------------------------------------------------------------*/ 27 | /* USER CODE BEGIN PM */ 28 | 29 | /* USER CODE END PM */ 30 | 31 | /* Private variables ---------------------------------------------------------*/ 32 | ADC_HandleTypeDef hadc1; 33 | 34 | UART_HandleTypeDef huart2; 35 | 36 | /* USER CODE BEGIN PV */ 37 | double adcResult = 0; 38 | double voltageResult = 0; 39 | double voltageValue[OVERSAMPLE_VALUE]; 40 | double voltageMax = 0; 41 | int count = 0; 42 | /* USER CODE END PV */ 43 | 44 | /* Private function prototypes -----------------------------------------------*/ 45 | void SystemClock_Config(void); 46 | static void MX_GPIO_Init(void); 47 | static void MX_USART2_UART_Init(void); 48 | static void MX_ADC1_Init(void); 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* Private user code ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN 0 */ 55 | 56 | /* USER CODE END 0 */ 57 | 58 | /** 59 | * @brief The application entry point. 60 | * @retval int 61 | */ 62 | int main(void) 63 | { 64 | /* USER CODE BEGIN 1 */ 65 | 66 | /* USER CODE END 1 */ 67 | 68 | /* MCU Configuration--------------------------------------------------------*/ 69 | 70 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 71 | HAL_Init(); 72 | 73 | /* USER CODE BEGIN Init */ 74 | 75 | /* USER CODE END Init */ 76 | 77 | /* Configure the system clock */ 78 | SystemClock_Config(); 79 | 80 | /* USER CODE BEGIN SysInit */ 81 | 82 | /* USER CODE END SysInit */ 83 | 84 | /* Initialize all configured peripherals */ 85 | MX_GPIO_Init(); 86 | MX_USART2_UART_Init(); 87 | MX_ADC1_Init(); 88 | /* USER CODE BEGIN 2 */ 89 | 90 | /* USER CODE END 2 */ 91 | 92 | /* Infinite loop */ 93 | /* USER CODE BEGIN WHILE */ 94 | /* USER CODE END WHILE */ 95 | while(count < OVERSAMPLE_VALUE){ 96 | HAL_ADC_Start(&hadc1); 97 | HAL_ADC_PollForConversion(&hadc1, 100); 98 | adcResult = 18.335 * (HAL_ADC_GetValue(&hadc1) - 1950); 99 | voltageResult = (adcResult * 3.3) / 4096; 100 | voltageValue[count] = voltageResult; 101 | voltageMax += voltageResult; 102 | count++; 103 | } 104 | voltageMax /= OVERSAMPLE_VALUE; 105 | HAL_ADC_Stop(&hadc1); 106 | /* USER CODE BEGIN 3 */ 107 | /* USER CODE END 3 */ 108 | } 109 | 110 | /** 111 | * @brief System Clock Configuration 112 | * @retval None 113 | */ 114 | void SystemClock_Config(void) 115 | { 116 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 117 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 118 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; 119 | 120 | /** Configure the main internal regulator output voltage 121 | */ 122 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 123 | /** Initializes the RCC Oscillators according to the specified parameters 124 | * in the RCC_OscInitTypeDef structure. 125 | */ 126 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 127 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 128 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; 129 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 130 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 131 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 132 | { 133 | Error_Handler(); 134 | } 135 | /** Initializes the CPU, AHB and APB buses clocks 136 | */ 137 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 138 | |RCC_CLOCKTYPE_PCLK1; 139 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; 140 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 141 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 142 | 143 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) 144 | { 145 | Error_Handler(); 146 | } 147 | /** Initializes the peripherals clocks 148 | */ 149 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; 150 | PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; 151 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) 152 | { 153 | Error_Handler(); 154 | } 155 | } 156 | 157 | /** 158 | * @brief ADC1 Initialization Function 159 | * @param None 160 | * @retval None 161 | */ 162 | static void MX_ADC1_Init(void) 163 | { 164 | 165 | /* USER CODE BEGIN ADC1_Init 0 */ 166 | 167 | /* USER CODE END ADC1_Init 0 */ 168 | 169 | ADC_ChannelConfTypeDef sConfig = {0}; 170 | 171 | /* USER CODE BEGIN ADC1_Init 1 */ 172 | 173 | /* USER CODE END ADC1_Init 1 */ 174 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 175 | */ 176 | hadc1.Instance = ADC1; 177 | hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; 178 | hadc1.Init.Resolution = ADC_RESOLUTION_12B; 179 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; 180 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; 181 | hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 182 | hadc1.Init.LowPowerAutoWait = DISABLE; 183 | hadc1.Init.LowPowerAutoPowerOff = DISABLE; 184 | hadc1.Init.ContinuousConvMode = DISABLE; 185 | hadc1.Init.NbrOfConversion = 1; 186 | hadc1.Init.DiscontinuousConvMode = DISABLE; 187 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; 188 | hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; 189 | hadc1.Init.DMAContinuousRequests = DISABLE; 190 | hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; 191 | hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5; 192 | hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5; 193 | hadc1.Init.OversamplingMode = DISABLE; 194 | hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH; 195 | if (HAL_ADC_Init(&hadc1) != HAL_OK) 196 | { 197 | Error_Handler(); 198 | } 199 | /** Configure Regular Channel 200 | */ 201 | sConfig.Channel = ADC_CHANNEL_1; 202 | sConfig.Rank = ADC_REGULAR_RANK_1; 203 | sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; 204 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 205 | { 206 | Error_Handler(); 207 | } 208 | /* USER CODE BEGIN ADC1_Init 2 */ 209 | 210 | /* USER CODE END ADC1_Init 2 */ 211 | 212 | } 213 | 214 | /** 215 | * @brief USART2 Initialization Function 216 | * @param None 217 | * @retval None 218 | */ 219 | static void MX_USART2_UART_Init(void) 220 | { 221 | 222 | /* USER CODE BEGIN USART2_Init 0 */ 223 | 224 | /* USER CODE END USART2_Init 0 */ 225 | 226 | /* USER CODE BEGIN USART2_Init 1 */ 227 | 228 | /* USER CODE END USART2_Init 1 */ 229 | huart2.Instance = USART2; 230 | huart2.Init.BaudRate = 115200; 231 | huart2.Init.WordLength = UART_WORDLENGTH_7B; 232 | huart2.Init.StopBits = UART_STOPBITS_1; 233 | huart2.Init.Parity = UART_PARITY_NONE; 234 | huart2.Init.Mode = UART_MODE_TX_RX; 235 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 236 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 237 | huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 238 | huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; 239 | huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 240 | if (HAL_UART_Init(&huart2) != HAL_OK) 241 | { 242 | Error_Handler(); 243 | } 244 | /* USER CODE BEGIN USART2_Init 2 */ 245 | 246 | /* USER CODE END USART2_Init 2 */ 247 | 248 | } 249 | 250 | /** 251 | * @brief GPIO Initialization Function 252 | * @param None 253 | * @retval None 254 | */ 255 | static void MX_GPIO_Init(void) 256 | { 257 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 258 | 259 | /* GPIO Ports Clock Enable */ 260 | __HAL_RCC_GPIOC_CLK_ENABLE(); 261 | __HAL_RCC_GPIOF_CLK_ENABLE(); 262 | __HAL_RCC_GPIOA_CLK_ENABLE(); 263 | 264 | /*Configure GPIO pin : T_NRST_Pin */ 265 | GPIO_InitStruct.Pin = T_NRST_Pin; 266 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 267 | GPIO_InitStruct.Pull = GPIO_NOPULL; 268 | HAL_GPIO_Init(T_NRST_GPIO_Port, &GPIO_InitStruct); 269 | 270 | } 271 | 272 | /* USER CODE BEGIN 4 */ 273 | 274 | /* USER CODE END 4 */ 275 | 276 | /** 277 | * @brief This function is executed in case of error occurrence. 278 | * @retval None 279 | */ 280 | void Error_Handler(void) 281 | { 282 | /* USER CODE BEGIN Error_Handler_Debug */ 283 | /* User can add his own implementation to report the HAL error return state */ 284 | 285 | /* USER CODE END Error_Handler_Debug */ 286 | } 287 | 288 | #ifdef USE_FULL_ASSERT 289 | /** 290 | * @brief Reports the name of the source file and the source line number 291 | * where the assert_param error has occurred. 292 | * @param file: pointer to the source file name 293 | * @param line: assert_param error line source number 294 | * @retval None 295 | */ 296 | void assert_failed(uint8_t *file, uint32_t line) 297 | { 298 | /* USER CODE BEGIN 6 */ 299 | /* User can add his own implementation to report the file name and line number, 300 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 301 | /* USER CODE END 6 */ 302 | } 303 | #endif /* USE_FULL_ASSERT */ 304 | 305 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 306 | -------------------------------------------------------------------------------- /BMS-stm32g0-code/adc_testing2.c: -------------------------------------------------------------------------------- 1 | /* Includes ------------------------------------------------------------------*/ 2 | #include "main.h" 3 | #include "stdlib.h" 4 | #include "stdio.h" 5 | #include "stdint.h" 6 | 7 | 8 | /* Private includes ----------------------------------------------------------*/ 9 | /* USER CODE BEGIN Includes */ 10 | 11 | /* USER CODE END Includes */ 12 | 13 | /* Private typedef -----------------------------------------------------------*/ 14 | /* USER CODE BEGIN PTD */ 15 | 16 | /* USER CODE END PTD */ 17 | 18 | /* Private define ------------------------------------------------------------*/ 19 | /* USER CODE BEGIN PD */ 20 | #define ADC_0V_VALUE 0 21 | #define ADC_1V_VALUE 1241 22 | #define ADC_2V_VALUE 2482 23 | #define ADC_3V_VALUE 3723 24 | #define OVERSAMPLE_VALUE 16 25 | /* USER CODE END PD */ 26 | 27 | /* Private macro -------------------------------------------------------------*/ 28 | /* USER CODE BEGIN PM */ 29 | 30 | /* USER CODE END PM */ 31 | 32 | /* Private variables --------------------------------------------------------*/ 33 | ADC_HandleTypeDef hadc1; 34 | 35 | UART_HandleTypeDef huart2; 36 | 37 | /* USER CODE BEGIN PV */ 38 | double adcResult = 0; 39 | double voltageResult = 0; 40 | double voltageValue[OVERSAMPLE_VALUE]; 41 | double voltageMax = 0; 42 | int count = 0; 43 | /* USER CODE END PV */ 44 | 45 | /* Private function prototypes -----------------------------------------------*/ 46 | void SystemClock_Config(void); 47 | static void MX_GPIO_Init(void); 48 | static void MX_USART2_UART_Init(void); 49 | static void MX_ADC1_Init(void); 50 | /* USER CODE BEGIN PFP */ 51 | 52 | /* USER CODE END PFP */ 53 | 54 | /* Private user code ---------------------------------------------------------*/ 55 | /* USER CODE BEGIN 0 */ 56 | 57 | /* USER CODE END 0 */ 58 | 59 | /** 60 | * @brief The application entry point. 61 | * @retval int 62 | */ 63 | int main(void) 64 | { 65 | /* USER CODE BEGIN 1 */ 66 | 67 | /* USER CODE END 1 */ 68 | 69 | /* MCU Configuration--------------------------------------------------------*/ 70 | 71 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 72 | HAL_Init(); 73 | 74 | /* USER CODE BEGIN Init */ 75 | 76 | /* USER CODE END Init */ 77 | 78 | /* Configure the system clock */ 79 | SystemClock_Config(); 80 | 81 | /* USER CODE BEGIN SysInit */ 82 | 83 | /* USER CODE END SysInit */ 84 | 85 | /* Initialize all configured peripherals */ 86 | MX_GPIO_Init(); 87 | MX_USART2_UART_Init(); 88 | MX_ADC1_Init(); 89 | /* USER CODE BEGIN 2 */ 90 | 91 | /* USER CODE END 2 */ 92 | 93 | /* Infinite loop */ 94 | /* USER CODE BEGIN WHILE */ 95 | /* USER CODE END WHILE */ 96 | while(count < OVERSAMPLE_VALUE){ 97 | HAL_ADC_Start(&hadc1); 98 | HAL_ADC_PollForConversion(&hadc1, 100); 99 | adcResult = 1.74 * (HAL_ADC_GetValue(&hadc1)); 100 | voltageResult = (adcResult * 3.3) / 4096; 101 | voltageValue[count] = voltageResult; 102 | voltageMax += voltageResult; 103 | count++; 104 | } 105 | voltageMax /= OVERSAMPLE_VALUE; 106 | HAL_ADC_Stop(&hadc1); 107 | /* USER CODE BEGIN 3 */ 108 | /* USER CODE END 3 */ 109 | } 110 | 111 | /** 112 | * @brief System Clock Configuration 113 | * @retval None 114 | */ 115 | void SystemClock_Config(void) 116 | { 117 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 118 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 119 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; 120 | 121 | /** Configure the main internal regulator output voltage 122 | */ 123 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 124 | /** Initializes the RCC Oscillators according to the specified parameters 125 | * in the RCC_OscInitTypeDef structure. 126 | */ 127 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 128 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 129 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; 130 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 131 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 132 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 133 | { 134 | Error_Handler(); 135 | } 136 | /** Initializes the CPU, AHB and APB buses clocks 137 | */ 138 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 139 | |RCC_CLOCKTYPE_PCLK1; 140 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; 141 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 142 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 143 | 144 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) 145 | { 146 | Error_Handler(); 147 | } 148 | /** Initializes the peripherals clocks 149 | */ 150 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; 151 | PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; 152 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) 153 | { 154 | Error_Handler(); 155 | } 156 | } 157 | 158 | /** 159 | * @brief ADC1 Initialization Function 160 | * @param None 161 | * @retval None 162 | */ 163 | static void MX_ADC1_Init(void) 164 | { 165 | 166 | /* USER CODE BEGIN ADC1_Init 0 */ 167 | 168 | /* USER CODE END ADC1_Init 0 */ 169 | 170 | ADC_ChannelConfTypeDef sConfig = {0}; 171 | 172 | /* USER CODE BEGIN ADC1_Init 1 */ 173 | 174 | /* USER CODE END ADC1_Init 1 */ 175 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 176 | */ 177 | hadc1.Instance = ADC1; 178 | hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; 179 | hadc1.Init.Resolution = ADC_RESOLUTION_12B; 180 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; 181 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; 182 | hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 183 | hadc1.Init.LowPowerAutoWait = DISABLE; 184 | hadc1.Init.LowPowerAutoPowerOff = DISABLE; 185 | hadc1.Init.ContinuousConvMode = DISABLE; 186 | hadc1.Init.NbrOfConversion = 1; 187 | hadc1.Init.DiscontinuousConvMode = DISABLE; 188 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; 189 | hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; 190 | hadc1.Init.DMAContinuousRequests = DISABLE; 191 | hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; 192 | hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5; 193 | hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5; 194 | hadc1.Init.OversamplingMode = DISABLE; 195 | hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH; 196 | if (HAL_ADC_Init(&hadc1) != HAL_OK) 197 | { 198 | Error_Handler(); 199 | } 200 | /** Configure Regular Channel 201 | */ 202 | sConfig.Channel = ADC_CHANNEL_1; 203 | sConfig.Rank = ADC_REGULAR_RANK_1; 204 | sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; 205 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 206 | { 207 | Error_Handler(); 208 | } 209 | /* USER CODE BEGIN ADC1_Init 2 */ 210 | 211 | /* USER CODE END ADC1_Init 2 */ 212 | 213 | } 214 | 215 | /** 216 | * @brief USART2 Initialization Function 217 | * @param None 218 | * @retval None 219 | */ 220 | static void MX_USART2_UART_Init(void) 221 | { 222 | 223 | /* USER CODE BEGIN USART2_Init 0 */ 224 | 225 | /* USER CODE END USART2_Init 0 */ 226 | 227 | /* USER CODE BEGIN USART2_Init 1 */ 228 | 229 | /* USER CODE END USART2_Init 1 */ 230 | huart2.Instance = USART2; 231 | huart2.Init.BaudRate = 115200; 232 | huart2.Init.WordLength = UART_WORDLENGTH_7B; 233 | huart2.Init.StopBits = UART_STOPBITS_1; 234 | huart2.Init.Parity = UART_PARITY_NONE; 235 | huart2.Init.Mode = UART_MODE_TX_RX; 236 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 237 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 238 | huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 239 | huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; 240 | huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 241 | if (HAL_UART_Init(&huart2) != HAL_OK) 242 | { 243 | Error_Handler(); 244 | } 245 | /* USER CODE BEGIN USART2_Init 2 */ 246 | 247 | /* USER CODE END USART2_Init 2 */ 248 | 249 | } 250 | 251 | /** 252 | * @brief GPIO Initialization Function 253 | * @param None 254 | * @retval None 255 | */ 256 | static void MX_GPIO_Init(void) 257 | { 258 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 259 | 260 | /* GPIO Ports Clock Enable */ 261 | __HAL_RCC_GPIOC_CLK_ENABLE(); 262 | __HAL_RCC_GPIOF_CLK_ENABLE(); 263 | __HAL_RCC_GPIOA_CLK_ENABLE(); 264 | 265 | /*Configure GPIO pin : T_NRST_Pin */ 266 | GPIO_InitStruct.Pin = T_NRST_Pin; 267 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 268 | GPIO_InitStruct.Pull = GPIO_NOPULL; 269 | HAL_GPIO_Init(T_NRST_GPIO_Port, &GPIO_InitStruct); 270 | 271 | } 272 | 273 | /* USER CODE BEGIN 4 */ 274 | 275 | /* USER CODE END 4 */ 276 | 277 | /** 278 | * @brief This function is executed in case of error occurrence. 279 | * @retval None 280 | */ 281 | void Error_Handler(void) 282 | { 283 | /* USER CODE BEGIN Error_Handler_Debug */ 284 | /* User can add his own implementation to report the HAL error return state */ 285 | 286 | /* USER CODE END Error_Handler_Debug */ 287 | } 288 | 289 | #ifdef USE_FULL_ASSERT 290 | /** 291 | * @brief Reports the name of the source file and the source line number 292 | * where the assert_param error has occurred. 293 | * @param file: pointer to the source file name 294 | * @param line: assert_param error line source number 295 | * @retval None 296 | */ 297 | void assert_failed(uint8_t *file, uint32_t line) 298 | { 299 | /* USER CODE BEGIN 6 */ 300 | /* User can add his own implementation to report the file name and line number, 301 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 302 | /* USER CODE END 6 */ 303 | } 304 | #endif /* USE_FULL_ASSERT */ 305 | 306 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 307 | -------------------------------------------------------------------------------- /BMS-stm32g0-code/statusLED_test.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /* Private includes ----------------------------------------------------------*/ 4 | /* USER CODE BEGIN Includes */ 5 | 6 | /* USER CODE END Includes */ 7 | 8 | /* Private typedef -----------------------------------------------------------*/ 9 | /* USER CODE BEGIN PTD */ 10 | 11 | /* USER CODE END PTD */ 12 | 13 | /* Private define ------------------------------------------------------------*/ 14 | /* USER CODE BEGIN PD */ 15 | /* USER CODE END PD */ 16 | 17 | /* Private macro -------------------------------------------------------------*/ 18 | /* USER CODE BEGIN PM */ 19 | 20 | /* USER CODE END PM */ 21 | 22 | /* Private variables ---------------------------------------------------------*/ 23 | UART_HandleTypeDef huart2; 24 | unsigned char panic [8] = {0,1,0,1,0,1,0,1}; 25 | unsigned char configured [8] = {1,1,1,1,1,1,1,1}; 26 | unsigned char unconfigured [8] = {0,0,0,0,0,0,0,0}; 27 | /* USER CODE BEGIN PV */ 28 | 29 | /* USER CODE END PV */ 30 | 31 | /* Private function prototypes -----------------------------------------------*/ 32 | void SystemClock_Config(void); 33 | static void MX_GPIO_Init(void); 34 | static void MX_USART2_UART_Init(void); 35 | void ledBlink(unsigned char* t); 36 | /* USER CODE BEGIN PFP */ 37 | 38 | /* USER CODE END PFP */ 39 | 40 | /* Private user code ---------------------------------------------------------*/ 41 | /* USER CODE BEGIN 0 */ 42 | 43 | /* USER CODE END 0 */ 44 | 45 | /** 46 | * @brief The application entry point. 47 | * @retval int 48 | */ 49 | int main(void) 50 | { 51 | /* USER CODE BEGIN 1 */ 52 | 53 | /* USER CODE END 1 */ 54 | 55 | /* MCU Configuration--------------------------------------------------------*/ 56 | 57 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 58 | HAL_Init(); 59 | 60 | /* USER CODE BEGIN Init */ 61 | 62 | /* USER CODE END Init */ 63 | 64 | /* Configure the system clock */ 65 | SystemClock_Config(); 66 | 67 | /* USER CODE BEGIN SysInit */ 68 | 69 | /* USER CODE END SysInit */ 70 | 71 | /* Initialize all configured peripherals */ 72 | MX_GPIO_Init(); 73 | MX_USART2_UART_Init(); 74 | /* USER CODE BEGIN 2 */ 75 | 76 | /* USER CODE END 2 */ 77 | 78 | /* Infinite loop */ 79 | /* USER CODE BEGIN WHILE */ 80 | while (1) 81 | { 82 | /* USER CODE END WHILE */ 83 | //HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_12); 84 | //HAL_Delay(500); 85 | //ledBlink(panic); 86 | //ledBlink(unconfigured); 87 | ledBlink(configured); 88 | /* USER CODE BEGIN 3 */ 89 | } 90 | /* USER CODE END 3 */ 91 | } 92 | 93 | /** 94 | * @brief System Clock Configuration 95 | * @retval None 96 | */ 97 | void SystemClock_Config(void) 98 | { 99 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 100 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 101 | 102 | /** Configure the main internal regulator output voltage 103 | */ 104 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 105 | /** Initializes the RCC Oscillators according to the specified parameters 106 | * in the RCC_OscInitTypeDef structure. 107 | */ 108 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 109 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 110 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; 111 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 112 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 113 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 114 | { 115 | Error_Handler(); 116 | } 117 | /** Initializes the CPU, AHB and APB buses clocks 118 | */ 119 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 120 | |RCC_CLOCKTYPE_PCLK1; 121 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; 122 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 123 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 124 | 125 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) 126 | { 127 | Error_Handler(); 128 | } 129 | } 130 | 131 | /** 132 | * @brief USART2 Initialization Function 133 | * @param None 134 | * @retval None 135 | */ 136 | static void MX_USART2_UART_Init(void) 137 | { 138 | 139 | /* USER CODE BEGIN USART2_Init 0 */ 140 | 141 | /* USER CODE END USART2_Init 0 */ 142 | 143 | /* USER CODE BEGIN USART2_Init 1 */ 144 | 145 | /* USER CODE END USART2_Init 1 */ 146 | huart2.Instance = USART2; 147 | huart2.Init.BaudRate = 115200; 148 | huart2.Init.WordLength = UART_WORDLENGTH_7B; 149 | huart2.Init.StopBits = UART_STOPBITS_1; 150 | huart2.Init.Parity = UART_PARITY_NONE; 151 | huart2.Init.Mode = UART_MODE_TX_RX; 152 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 153 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 154 | huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 155 | huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; 156 | huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 157 | if (HAL_UART_Init(&huart2) != HAL_OK) 158 | { 159 | Error_Handler(); 160 | } 161 | /* USER CODE BEGIN USART2_Init 2 */ 162 | 163 | /* USER CODE END USART2_Init 2 */ 164 | 165 | } 166 | 167 | /** 168 | * @brief GPIO Initialization Function 169 | * @param None 170 | * @retval None 171 | */ 172 | static void MX_GPIO_Init(void) 173 | { 174 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 175 | 176 | /* GPIO Ports Clock Enable */ 177 | __HAL_RCC_GPIOC_CLK_ENABLE(); 178 | __HAL_RCC_GPIOF_CLK_ENABLE(); 179 | __HAL_RCC_GPIOA_CLK_ENABLE(); 180 | 181 | /*Configure GPIO pin Output Level */ 182 | HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET); 183 | 184 | /*Configure GPIO pin Output Level */ 185 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); 186 | 187 | /*Configure GPIO pin : T_NRST_Pin */ 188 | GPIO_InitStruct.Pin = T_NRST_Pin; 189 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 190 | GPIO_InitStruct.Pull = GPIO_NOPULL; 191 | HAL_GPIO_Init(T_NRST_GPIO_Port, &GPIO_InitStruct); 192 | 193 | /*Configure GPIO pin : LD3_Pin */ 194 | GPIO_InitStruct.Pin = LD3_Pin; 195 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 196 | GPIO_InitStruct.Pull = GPIO_NOPULL; 197 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 198 | HAL_GPIO_Init(LD3_GPIO_Port, &GPIO_InitStruct); 199 | 200 | /*Configure GPIO pin : PA12 */ 201 | GPIO_InitStruct.Pin = GPIO_PIN_12; 202 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 203 | GPIO_InitStruct.Pull = GPIO_NOPULL; 204 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 205 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 206 | 207 | } 208 | 209 | /* USER CODE BEGIN 4 */ 210 | 211 | /* USER CODE END 4 */ 212 | 213 | /** 214 | * @brief This function is executed in case of error occurrence. 215 | * @retval None 216 | */ 217 | void Error_Handler(void) 218 | { 219 | /* USER CODE BEGIN Error_Handler_Debug */ 220 | /* User can add his own implementation to report the HAL error return state */ 221 | 222 | /* USER CODE END Error_Handler_Debug */ 223 | } 224 | 225 | void ledBlink(unsigned char t[]){ 226 | for(int k = 0; k < 8; k++){ 227 | if(t[k] == 1) 228 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12,GPIO_PIN_SET); 229 | else 230 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12,GPIO_PIN_RESET); 231 | HAL_Delay(200); 232 | } 233 | } 234 | #ifdef USE_FULL_ASSERT 235 | /** 236 | * @brief Reports the name of the source file and the source line number 237 | * where the assert_param error has occurred. 238 | * @param file: pointer to the source file name 239 | * @param line: assert_param error line source number 240 | * @retval None 241 | */ 242 | void assert_failed(uint8_t *file, uint32_t line) 243 | { 244 | /* USER CODE BEGIN 6 */ 245 | /* User can add his own implementation to report the file name and line number, 246 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 247 | /* USER CODE END 6 */ 248 | } 249 | #endif /* USE_FULL_ASSERT */ 250 | 251 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 252 | -------------------------------------------------------------------------------- /BMS-stm32g0-code/temp_data_sending.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2020 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | 23 | /* Private includes ----------------------------------------------------------*/ 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN PTD */ 30 | 31 | /* USER CODE END PTD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN PD */ 35 | /* USER CODE END PD */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN PM */ 39 | 40 | /* USER CODE END PM */ 41 | 42 | /* Private variables ---------------------------------------------------------*/ 43 | ADC_HandleTypeDef hadc1; 44 | UART_HandleTypeDef huart1; 45 | UART_HandleTypeDef huart2; 46 | uint16_t analogVal = 0; 47 | uint16_t voltVal = 0; 48 | /* USER CODE BEGIN PV */ 49 | 50 | /* USER CODE END PV */ 51 | 52 | /* Private function prototypes -----------------------------------------------*/ 53 | void SystemClock_Config(void); 54 | static void MX_GPIO_Init(void); 55 | static void MX_USART2_UART_Init(void); 56 | static void MX_ADC1_Init(void); 57 | static void MX_USART1_UART_Init(void); 58 | uint16_t byte2halfWord(uint8_t byte); 59 | /* USER CODE BEGIN PFP */ 60 | 61 | /* USER CODE END PFP */ 62 | 63 | /* Private user code ---------------------------------------------------------*/ 64 | /* USER CODE BEGIN 0 */ 65 | 66 | /* USER CODE END 0 */ 67 | 68 | /** 69 | * @brief The application entry point. 70 | * @retval int 71 | */ 72 | int main(void) 73 | { 74 | /* USER CODE BEGIN 1 */ 75 | 76 | /* USER CODE END 1 */ 77 | 78 | /* MCU Configuration--------------------------------------------------------*/ 79 | 80 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 81 | HAL_Init(); 82 | 83 | /* USER CODE BEGIN Init */ 84 | 85 | /* USER CODE END Init */ 86 | 87 | /* Configure the system clock */ 88 | SystemClock_Config(); 89 | 90 | /* USER CODE BEGIN SysInit */ 91 | 92 | /* USER CODE END SysInit */ 93 | 94 | /* Initialize all configured peripherals */ 95 | MX_GPIO_Init(); 96 | MX_USART2_UART_Init(); 97 | MX_ADC1_Init(); 98 | MX_USART1_UART_Init(); 99 | //Set PA10 and PA11 to low state, enabling data receiving and disabling transmission 100 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); 101 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET); 102 | 103 | /* Infinite loop */ 104 | /* USER CODE BEGIN WHILE */ 105 | while (1) 106 | { 107 | //Start ADC conversion 108 | HAL_ADC_Start(&hadc1); 109 | //measure adc1 channel 4 with timeout value 100 110 | HAL_ADC_PollForConversion(&hadc1, 100); 111 | //calculate analog value and voltage value to represent the temperature 112 | analogVal = 1.34 * (HAL_ADC_GetValue(&hadc1)); 113 | voltVal = (analogVal * 3.3) / 4096; 114 | //stop adc conversion 115 | HAL_ADC_Stop(&hadc1); 116 | //Write lower byte and higher byte into two uint8_t variables 117 | uint8_t lowByte = analogVal; 118 | uint8_t highByte = analogVal >> 8; 119 | //change lower byte and higher byte patterns using method 120 | //0 -> 10, 1 -> 01 121 | uint16_t lowHWord = byte2halfWord(lowByte); 122 | uint16_t highHWord = byte2halfWord(highByte); 123 | //set PA10 to HIGH state enabling transmission 124 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); 125 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); 126 | //wait for 1000 ms 127 | HAL_Delay(1000); 128 | //Transmit lowHWord variable 129 | HAL_UART_Transmit(&huart2, &lowHWord, sizeof(lowHWord), HAL_MAX_DELAY); 130 | //HAL_Delay(100); 131 | //Transmit highHWord variable 132 | HAL_UART_Transmit(&huart2, &highHWord, sizeof(highHWord), HAL_MAX_DELAY); 133 | //Set PA10 to LOW state disabling the transmission 134 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); 135 | //wait for 1000 ms 136 | HAL_Delay(1000); 137 | } 138 | /* USER CODE END 3 */ 139 | } 140 | 141 | uint16_t byte2halfWord(uint8_t byte){ 142 | //declare output 16bit variable and 8bit mask variable 143 | uint16_t halfWord = 0; 144 | uint8_t mask = 0b00000001; 145 | //initialise the base variable 146 | int base = 1; 147 | //for every bit in input 8bit variable, check if it is 0 or 1 148 | //and add the number to output variable depend on what bit in byte 149 | //you look for 150 | for(int i = 0; i < 8; i++){ 151 | if(byte & mask){ 152 | halfWord += base; 153 | } 154 | else{ 155 | halfWord += 2 * base; 156 | } 157 | mask <<= 1; 158 | base *= 4; 159 | } 160 | return halfWord; 161 | } 162 | 163 | /** 164 | * @brief System Clock Configuration 165 | * @retval None 166 | */ 167 | void SystemClock_Config(void) 168 | { 169 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 170 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 171 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; 172 | 173 | /** Configure the main internal regulator output voltage 174 | */ 175 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 176 | /** Initializes the RCC Oscillators according to the specified parameters 177 | * in the RCC_OscInitTypeDef structure. 178 | */ 179 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 180 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 181 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; 182 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 183 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 184 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 185 | { 186 | Error_Handler(); 187 | } 188 | /** Initializes the CPU, AHB and APB buses clocks 189 | */ 190 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 191 | |RCC_CLOCKTYPE_PCLK1; 192 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; 193 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 194 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 195 | 196 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) 197 | { 198 | Error_Handler(); 199 | } 200 | /** Initializes the peripherals clocks 201 | */ 202 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_ADC; 203 | PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; 204 | PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; 205 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) 206 | { 207 | Error_Handler(); 208 | } 209 | } 210 | 211 | /** 212 | * @brief ADC1 Initialization Function 213 | * @param None 214 | * @retval None 215 | */ 216 | static void MX_ADC1_Init(void) 217 | { 218 | 219 | /* USER CODE BEGIN ADC1_Init 0 */ 220 | 221 | /* USER CODE END ADC1_Init 0 */ 222 | 223 | ADC_ChannelConfTypeDef sConfig = {0}; 224 | 225 | /* USER CODE BEGIN ADC1_Init 1 */ 226 | 227 | /* USER CODE END ADC1_Init 1 */ 228 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 229 | */ 230 | hadc1.Instance = ADC1; 231 | hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; 232 | hadc1.Init.Resolution = ADC_RESOLUTION_12B; 233 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; 234 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; 235 | hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 236 | hadc1.Init.LowPowerAutoWait = DISABLE; 237 | hadc1.Init.LowPowerAutoPowerOff = DISABLE; 238 | hadc1.Init.ContinuousConvMode = DISABLE; 239 | hadc1.Init.NbrOfConversion = 1; 240 | hadc1.Init.DiscontinuousConvMode = DISABLE; 241 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; 242 | hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; 243 | hadc1.Init.DMAContinuousRequests = DISABLE; 244 | hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; 245 | hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5; 246 | hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5; 247 | hadc1.Init.OversamplingMode = DISABLE; 248 | hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH; 249 | if (HAL_ADC_Init(&hadc1) != HAL_OK) 250 | { 251 | Error_Handler(); 252 | } 253 | /** Configure Regular Channel 254 | */ 255 | sConfig.Channel = ADC_CHANNEL_4; 256 | sConfig.Rank = ADC_REGULAR_RANK_1; 257 | sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; 258 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 259 | { 260 | Error_Handler(); 261 | } 262 | /* USER CODE BEGIN ADC1_Init 2 */ 263 | 264 | /* USER CODE END ADC1_Init 2 */ 265 | 266 | } 267 | 268 | /** 269 | * @brief USART1 Initialization Function 270 | * @param None 271 | * @retval None 272 | */ 273 | static void MX_USART1_UART_Init(void) 274 | { 275 | 276 | /* USER CODE BEGIN USART1_Init 0 */ 277 | 278 | /* USER CODE END USART1_Init 0 */ 279 | 280 | /* USER CODE BEGIN USART1_Init 1 */ 281 | 282 | /* USER CODE END USART1_Init 1 */ 283 | huart1.Instance = USART1; 284 | huart1.Init.BaudRate = 115200; 285 | huart1.Init.WordLength = UART_WORDLENGTH_8B; 286 | huart1.Init.StopBits = UART_STOPBITS_1; 287 | huart1.Init.Parity = UART_PARITY_NONE; 288 | huart1.Init.Mode = UART_MODE_TX_RX; 289 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 290 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; 291 | huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 292 | huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; 293 | huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 294 | if (HAL_UART_Init(&huart1) != HAL_OK) 295 | { 296 | Error_Handler(); 297 | } 298 | if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) 299 | { 300 | Error_Handler(); 301 | } 302 | if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) 303 | { 304 | Error_Handler(); 305 | } 306 | if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) 307 | { 308 | Error_Handler(); 309 | } 310 | /* USER CODE BEGIN USART1_Init 2 */ 311 | 312 | /* USER CODE END USART1_Init 2 */ 313 | 314 | } 315 | 316 | /** 317 | * @brief USART2 Initialization Function 318 | * @param None 319 | * @retval None 320 | */ 321 | static void MX_USART2_UART_Init(void) 322 | { 323 | 324 | /* USER CODE BEGIN USART2_Init 0 */ 325 | 326 | /* USER CODE END USART2_Init 0 */ 327 | 328 | /* USER CODE BEGIN USART2_Init 1 */ 329 | 330 | /* USER CODE END USART2_Init 1 */ 331 | huart2.Instance = USART2; 332 | huart2.Init.BaudRate = 115200; 333 | huart2.Init.WordLength = UART_WORDLENGTH_8B; 334 | huart2.Init.StopBits = UART_STOPBITS_1; 335 | huart2.Init.Parity = UART_PARITY_NONE; 336 | huart2.Init.Mode = UART_MODE_TX_RX; 337 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 338 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 339 | huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 340 | huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; 341 | huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 342 | if (HAL_UART_Init(&huart2) != HAL_OK) 343 | { 344 | Error_Handler(); 345 | } 346 | /* USER CODE BEGIN USART2_Init 2 */ 347 | 348 | /* USER CODE END USART2_Init 2 */ 349 | 350 | } 351 | 352 | /** 353 | * @brief GPIO Initialization Function 354 | * @param None 355 | * @retval None 356 | */ 357 | static void MX_GPIO_Init(void) 358 | { 359 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 360 | 361 | /* GPIO Ports Clock Enable */ 362 | __HAL_RCC_GPIOB_CLK_ENABLE(); 363 | __HAL_RCC_GPIOC_CLK_ENABLE(); 364 | __HAL_RCC_GPIOF_CLK_ENABLE(); 365 | __HAL_RCC_GPIOA_CLK_ENABLE(); 366 | 367 | /*Configure GPIO pin Output Level */ 368 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET); 369 | 370 | /*Configure GPIO pin Output Level */ 371 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_RESET); 372 | 373 | /*Configure GPIO pin : PB9 */ 374 | GPIO_InitStruct.Pin = GPIO_PIN_9; 375 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 376 | GPIO_InitStruct.Pull = GPIO_NOPULL; 377 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 378 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 379 | 380 | /*Configure GPIO pin : T_NRST_Pin */ 381 | GPIO_InitStruct.Pin = T_NRST_Pin; 382 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 383 | GPIO_InitStruct.Pull = GPIO_NOPULL; 384 | HAL_GPIO_Init(T_NRST_GPIO_Port, &GPIO_InitStruct); 385 | 386 | /*Configure GPIO pins : PA10 PA11 PA12 */ 387 | GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; 388 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 389 | GPIO_InitStruct.Pull = GPIO_NOPULL; 390 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 391 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 392 | 393 | } 394 | 395 | /* USER CODE BEGIN 4 */ 396 | 397 | /* USER CODE END 4 */ 398 | 399 | /** 400 | * @brief This function is executed in case of error occurrence. 401 | * @retval None 402 | */ 403 | void Error_Handler(void) 404 | { 405 | /* USER CODE BEGIN Error_Handler_Debug */ 406 | /* User can add his own implementation to report the HAL error return state */ 407 | 408 | /* USER CODE END Error_Handler_Debug */ 409 | } 410 | 411 | #ifdef USE_FULL_ASSERT 412 | /** 413 | * @brief Reports the name of the source file and the source line number 414 | * where the assert_param error has occurred. 415 | * @param file: pointer to the source file name 416 | * @param line: assert_param error line source number 417 | * @retval None 418 | */ 419 | void assert_failed(uint8_t *file, uint32_t line) 420 | { 421 | /* USER CODE BEGIN 6 */ 422 | /* User can add his own implementation to report the file name and line number, 423 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 424 | /* USER CODE END 6 */ 425 | } 426 | #endif /* USE_FULL_ASSERT */ 427 | 428 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 429 | -------------------------------------------------------------------------------- /BMS-stm32g0-code/transistor_test.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2020 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | 23 | /* Private includes ----------------------------------------------------------*/ 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN PTD */ 30 | 31 | /* USER CODE END PTD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN PD */ 35 | /* USER CODE END PD */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN PM */ 39 | 40 | /* USER CODE END PM */ 41 | 42 | /* Private variables ---------------------------------------------------------*/ 43 | UART_HandleTypeDef huart2; 44 | 45 | /* USER CODE BEGIN PV */ 46 | 47 | /* USER CODE END PV */ 48 | 49 | /* Private function prototypes -----------------------------------------------*/ 50 | void SystemClock_Config(void); 51 | static void MX_GPIO_Init(void); 52 | static void MX_USART2_UART_Init(void); 53 | /* USER CODE BEGIN PFP */ 54 | 55 | /* USER CODE END PFP */ 56 | 57 | /* Private user code ---------------------------------------------------------*/ 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | 62 | /** 63 | * @brief The application entry point. 64 | * @retval int 65 | */ 66 | int main(void) 67 | { 68 | /* USER CODE BEGIN 1 */ 69 | 70 | /* USER CODE END 1 */ 71 | 72 | /* MCU Configuration--------------------------------------------------------*/ 73 | 74 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 75 | HAL_Init(); 76 | 77 | /* USER CODE BEGIN Init */ 78 | 79 | /* USER CODE END Init */ 80 | 81 | /* Configure the system clock */ 82 | SystemClock_Config(); 83 | 84 | /* USER CODE BEGIN SysInit */ 85 | 86 | /* USER CODE END SysInit */ 87 | 88 | /* Initialize all configured peripherals */ 89 | MX_GPIO_Init(); 90 | MX_USART2_UART_Init(); 91 | /* USER CODE BEGIN 2 */ 92 | 93 | /* USER CODE END 2 */ 94 | 95 | /* Infinite loop */ 96 | /* USER CODE BEGIN WHILE */ 97 | while (1) 98 | { 99 | /* USER CODE END WHILE */ 100 | HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_9); 101 | HAL_Delay(1000); 102 | /* USER CODE BEGIN 3 */ 103 | } 104 | /* USER CODE END 3 */ 105 | } 106 | 107 | /** 108 | * @brief System Clock Configuration 109 | * @retval None 110 | */ 111 | void SystemClock_Config(void) 112 | { 113 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 114 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 115 | 116 | /** Configure the main internal regulator output voltage 117 | */ 118 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 119 | /** Initializes the RCC Oscillators according to the specified parameters 120 | * in the RCC_OscInitTypeDef structure. 121 | */ 122 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 123 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 124 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; 125 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 126 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 127 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 128 | { 129 | Error_Handler(); 130 | } 131 | /** Initializes the CPU, AHB and APB buses clocks 132 | */ 133 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 134 | |RCC_CLOCKTYPE_PCLK1; 135 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; 136 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 137 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 138 | 139 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) 140 | { 141 | Error_Handler(); 142 | } 143 | } 144 | 145 | /** 146 | * @brief USART2 Initialization Function 147 | * @param None 148 | * @retval None 149 | */ 150 | static void MX_USART2_UART_Init(void) 151 | { 152 | 153 | /* USER CODE BEGIN USART2_Init 0 */ 154 | 155 | /* USER CODE END USART2_Init 0 */ 156 | 157 | /* USER CODE BEGIN USART2_Init 1 */ 158 | 159 | /* USER CODE END USART2_Init 1 */ 160 | huart2.Instance = USART2; 161 | huart2.Init.BaudRate = 115200; 162 | huart2.Init.WordLength = UART_WORDLENGTH_7B; 163 | huart2.Init.StopBits = UART_STOPBITS_1; 164 | huart2.Init.Parity = UART_PARITY_NONE; 165 | huart2.Init.Mode = UART_MODE_TX_RX; 166 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 167 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 168 | huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 169 | huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; 170 | huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 171 | if (HAL_UART_Init(&huart2) != HAL_OK) 172 | { 173 | Error_Handler(); 174 | } 175 | /* USER CODE BEGIN USART2_Init 2 */ 176 | 177 | /* USER CODE END USART2_Init 2 */ 178 | 179 | } 180 | 181 | /** 182 | * @brief GPIO Initialization Function 183 | * @param None 184 | * @retval None 185 | */ 186 | static void MX_GPIO_Init(void) 187 | { 188 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 189 | 190 | /* GPIO Ports Clock Enable */ 191 | __HAL_RCC_GPIOB_CLK_ENABLE(); 192 | __HAL_RCC_GPIOC_CLK_ENABLE(); 193 | __HAL_RCC_GPIOF_CLK_ENABLE(); 194 | __HAL_RCC_GPIOA_CLK_ENABLE(); 195 | 196 | /*Configure GPIO pin Output Level */ 197 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET); 198 | 199 | /*Configure GPIO pin Output Level */ 200 | HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET); 201 | 202 | /*Configure GPIO pin : PB9 */ 203 | GPIO_InitStruct.Pin = GPIO_PIN_9; 204 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 205 | GPIO_InitStruct.Pull = GPIO_NOPULL; 206 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 207 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 208 | 209 | /*Configure GPIO pin : T_NRST_Pin */ 210 | GPIO_InitStruct.Pin = T_NRST_Pin; 211 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 212 | GPIO_InitStruct.Pull = GPIO_NOPULL; 213 | HAL_GPIO_Init(T_NRST_GPIO_Port, &GPIO_InitStruct); 214 | 215 | /*Configure GPIO pin : LD3_Pin */ 216 | GPIO_InitStruct.Pin = LD3_Pin; 217 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 218 | GPIO_InitStruct.Pull = GPIO_NOPULL; 219 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 220 | HAL_GPIO_Init(LD3_GPIO_Port, &GPIO_InitStruct); 221 | 222 | } 223 | 224 | /* USER CODE BEGIN 4 */ 225 | 226 | /* USER CODE END 4 */ 227 | 228 | /** 229 | * @brief This function is executed in case of error occurrence. 230 | * @retval None 231 | */ 232 | void Error_Handler(void) 233 | { 234 | /* USER CODE BEGIN Error_Handler_Debug */ 235 | /* User can add his own implementation to report the HAL error return state */ 236 | 237 | /* USER CODE END Error_Handler_Debug */ 238 | } 239 | 240 | #ifdef USE_FULL_ASSERT 241 | /** 242 | * @brief Reports the name of the source file and the source line number 243 | * where the assert_param error has occurred. 244 | * @param file: pointer to the source file name 245 | * @param line: assert_param error line source number 246 | * @retval None 247 | */ 248 | void assert_failed(uint8_t *file, uint32_t line) 249 | { 250 | /* USER CODE BEGIN 6 */ 251 | /* User can add his own implementation to report the file name and line number, 252 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 253 | /* USER CODE END 6 */ 254 | } 255 | #endif /* USE_FULL_ASSERT */ 256 | 257 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 258 | -------------------------------------------------------------------------------- /BMS-stm32g0-code/uart1_testing.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2020 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | #include "stdlib.h" 23 | #include "math.h" 24 | #include "stdio.h" 25 | #include "stdint.h" 26 | 27 | /* Private includes ----------------------------------------------------------*/ 28 | /* USER CODE BEGIN Includes */ 29 | 30 | /* USER CODE END Includes */ 31 | 32 | /* Private typedef -----------------------------------------------------------*/ 33 | /* USER CODE BEGIN PTD */ 34 | /* USER CODE END PTD */ 35 | 36 | /* Private define ------------------------------------------------------------*/ 37 | /* USER CODE BEGIN PD */ 38 | #define OVERSAMPLE_VALUE 4 39 | /* USER CODE END PD */ 40 | 41 | /* Private macro -------------------------------------------------------------*/ 42 | /* USER CODE BEGIN PM */ 43 | 44 | /* USER CODE END PM */ 45 | 46 | /* Private variables ---------------------------------------------------------*/ 47 | ADC_HandleTypeDef hadc1; 48 | 49 | UART_HandleTypeDef huart1; 50 | UART_HandleTypeDef huart2; 51 | 52 | /* USER CODE BEGIN PV */ 53 | double adcResult = 0; 54 | double voltageResult = 0; 55 | double voltageValue[OVERSAMPLE_VALUE]; 56 | double voltageMax = 0; 57 | int count = 0; 58 | uint8_t buffer_tx [4]= {10, 11, 12, 13}; 59 | uint8_t buffer_rx [4]; 60 | 61 | /* USER CODE END PV */ 62 | 63 | /* Private function prototypes -----------------------------------------------*/ 64 | void SystemClock_Config(void); 65 | static void MX_GPIO_Init(void); 66 | static void MX_USART2_UART_Init(void); 67 | static void MX_ADC1_Init(void); 68 | static void MX_USART1_UART_Init(void); 69 | void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){ 70 | 71 | } 72 | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){ 73 | while(1); 74 | } 75 | /* USER CODE BEGIN PFP */ 76 | 77 | /* USER CODE END PFP */ 78 | 79 | /* Private user code ---------------------------------------------------------*/ 80 | /* USER CODE BEGIN 0 */ 81 | 82 | /* USER CODE END 0 */ 83 | 84 | /** 85 | * @brief The application entry point. 86 | * @retval int 87 | */ 88 | int main(void) 89 | { 90 | /* USER CODE BEGIN 1 */ 91 | 92 | /* USER CODE END 1 */ 93 | 94 | /* MCU Configuration--------------------------------------------------------*/ 95 | 96 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 97 | HAL_Init(); 98 | 99 | /* USER CODE BEGIN Init */ 100 | 101 | /* USER CODE END Init */ 102 | 103 | /* Configure the system clock */ 104 | SystemClock_Config(); 105 | 106 | /* USER CODE BEGIN SysInit */ 107 | 108 | /* USER CODE END SysInit */ 109 | 110 | /* Initialize all configured peripherals */ 111 | MX_GPIO_Init(); 112 | MX_USART2_UART_Init(); 113 | MX_ADC1_Init(); 114 | MX_USART1_UART_Init(); 115 | /* USER CODE BEGIN 2 */ 116 | //HAL_UART_Receive_IT(&huart1, buffer_rx, 4); 117 | //HAL_UART_Transmit_IT(&huart1, buffer_tx, 4); 118 | /* USER CODE END 2 */ 119 | HAL_UART_Init(&huart1); 120 | /* Infinite loop */ 121 | /* USER CODE BEGIN WHILE */ 122 | while (1) 123 | { 124 | uint8_t buffer[4]; 125 | HAL_UART_Receive(&huart1, buffer, sizeof(buffer), HAL_MAX_DELAY); 126 | //HAL_UART_Transmit(&huart1, buffer, sizeof(buffer), HAL_MAX_DELAY); 127 | } 128 | /* USER CODE END WHILE 129 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); 130 | HAL_Delay(500); 131 | 132 | HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_9); 133 | HAL_Delay(500); 134 | 135 | HAL_ADC_Start(&hadc1); 136 | HAL_ADC_PollForConversion(&hadc1, 100); 137 | adcVal = (HAL_ADC_GetValue(&hadc1)); 138 | T = 1.00 / (invT0 + invBeta*(log ( adcMax / (float) adcVal - 1.00))); 139 | Tc = T - 273.15; 140 | 141 | while(count < OVERSAMPLE_VALUE){ 142 | HAL_ADC_Start(&hadc1); 143 | HAL_ADC_PollForConversion(&hadc1, 100); 144 | adcResult = 1.8 * (HAL_ADC_GetValue(&hadc1)); 145 | voltageResult = (adcResult * 3.3) / 4096; 146 | voltageValue[count] = voltageResult; 147 | voltageMax += voltageResult; 148 | count++; 149 | } 150 | voltageMax /= OVERSAMPLE_VALUE; 151 | HAL_ADC_Stop(&hadc1); 152 | if(voltageMax > 3.00){ 153 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET); 154 | HAL_Delay(500); 155 | } 156 | USER CODE BEGIN 3 */ 157 | /* USER CODE END 3 */ 158 | } 159 | 160 | /** 161 | * @brief System Clock Configuration 162 | * @retval None 163 | */ 164 | void SystemClock_Config(void) 165 | { 166 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 167 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 168 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; 169 | 170 | /** Configure the main internal regulator output voltage 171 | */ 172 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 173 | /** Initializes the RCC Oscillators according to the specified parameters 174 | * in the RCC_OscInitTypeDef structure. 175 | */ 176 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 177 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 178 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; 179 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 180 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 181 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 182 | { 183 | Error_Handler(); 184 | } 185 | /** Initializes the CPU, AHB and APB buses clocks 186 | */ 187 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 188 | |RCC_CLOCKTYPE_PCLK1; 189 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; 190 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 191 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 192 | 193 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) 194 | { 195 | Error_Handler(); 196 | } 197 | /** Initializes the peripherals clocks 198 | */ 199 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_ADC; 200 | PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; 201 | PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; 202 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) 203 | { 204 | Error_Handler(); 205 | } 206 | } 207 | 208 | /** 209 | * @brief ADC1 Initialization Function 210 | * @param None 211 | * @retval None 212 | */ 213 | static void MX_ADC1_Init(void) 214 | { 215 | 216 | /* USER CODE BEGIN ADC1_Init 0 */ 217 | 218 | /* USER CODE END ADC1_Init 0 */ 219 | 220 | ADC_ChannelConfTypeDef sConfig = {0}; 221 | 222 | /* USER CODE BEGIN ADC1_Init 1 */ 223 | 224 | /* USER CODE END ADC1_Init 1 */ 225 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 226 | */ 227 | hadc1.Instance = ADC1; 228 | hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; 229 | hadc1.Init.Resolution = ADC_RESOLUTION_12B; 230 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; 231 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; 232 | hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 233 | hadc1.Init.LowPowerAutoWait = DISABLE; 234 | hadc1.Init.LowPowerAutoPowerOff = DISABLE; 235 | hadc1.Init.ContinuousConvMode = DISABLE; 236 | hadc1.Init.NbrOfConversion = 1; 237 | hadc1.Init.DiscontinuousConvMode = DISABLE; 238 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; 239 | hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; 240 | hadc1.Init.DMAContinuousRequests = DISABLE; 241 | hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; 242 | hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5; 243 | hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5; 244 | hadc1.Init.OversamplingMode = DISABLE; 245 | hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH; 246 | if (HAL_ADC_Init(&hadc1) != HAL_OK) 247 | { 248 | Error_Handler(); 249 | } 250 | /** Configure Regular Channel 251 | */ 252 | sConfig.Channel = ADC_CHANNEL_1; 253 | sConfig.Rank = ADC_REGULAR_RANK_1; 254 | sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; 255 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 256 | { 257 | Error_Handler(); 258 | } 259 | /* USER CODE BEGIN ADC1_Init 2 */ 260 | 261 | /* USER CODE END ADC1_Init 2 */ 262 | 263 | } 264 | 265 | /** 266 | * @brief USART1 Initialization Function 267 | * @param None 268 | * @retval None 269 | */ 270 | static void MX_USART1_UART_Init(void) 271 | { 272 | 273 | /* USER CODE BEGIN USART1_Init 0 */ 274 | 275 | /* USER CODE END USART1_Init 0 */ 276 | 277 | /* USER CODE BEGIN USART1_Init 1 */ 278 | 279 | /* USER CODE END USART1_Init 1 */ 280 | huart1.Instance = USART1; 281 | huart1.Init.BaudRate = 115200; 282 | huart1.Init.WordLength = UART_WORDLENGTH_8B; 283 | huart1.Init.StopBits = UART_STOPBITS_1; 284 | huart1.Init.Parity = UART_PARITY_NONE; 285 | huart1.Init.Mode = UART_MODE_TX_RX; 286 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 287 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; 288 | huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 289 | huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; 290 | huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 291 | if (HAL_UART_Init(&huart1) != HAL_OK) 292 | { 293 | Error_Handler(); 294 | } 295 | if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) 296 | { 297 | Error_Handler(); 298 | } 299 | if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) 300 | { 301 | Error_Handler(); 302 | } 303 | if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) 304 | { 305 | Error_Handler(); 306 | } 307 | /* USER CODE BEGIN USART1_Init 2 */ 308 | 309 | /* USER CODE END USART1_Init 2 */ 310 | 311 | } 312 | 313 | /** 314 | * @brief USART2 Initialization Function 315 | * @param None 316 | * @retval None 317 | */ 318 | static void MX_USART2_UART_Init(void) 319 | { 320 | 321 | /* USER CODE BEGIN USART2_Init 0 */ 322 | 323 | /* USER CODE END USART2_Init 0 */ 324 | 325 | /* USER CODE BEGIN USART2_Init 1 */ 326 | 327 | /* USER CODE END USART2_Init 1 */ 328 | huart2.Instance = USART2; 329 | huart2.Init.BaudRate = 115200; 330 | huart2.Init.WordLength = UART_WORDLENGTH_8B; 331 | huart2.Init.StopBits = UART_STOPBITS_1; 332 | huart2.Init.Parity = UART_PARITY_NONE; 333 | huart2.Init.Mode = UART_MODE_TX_RX; 334 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 335 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 336 | huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 337 | huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; 338 | huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 339 | if (HAL_UART_Init(&huart2) != HAL_OK) 340 | { 341 | Error_Handler(); 342 | } 343 | /* USER CODE BEGIN USART2_Init 2 */ 344 | 345 | /* USER CODE END USART2_Init 2 */ 346 | 347 | } 348 | 349 | /** 350 | * @brief GPIO Initialization Function 351 | * @param None 352 | * @retval None 353 | */ 354 | static void MX_GPIO_Init(void) 355 | { 356 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 357 | 358 | /* GPIO Ports Clock Enable */ 359 | __HAL_RCC_GPIOB_CLK_ENABLE(); 360 | __HAL_RCC_GPIOC_CLK_ENABLE(); 361 | __HAL_RCC_GPIOF_CLK_ENABLE(); 362 | __HAL_RCC_GPIOA_CLK_ENABLE(); 363 | 364 | /*Configure GPIO pin Output Level */ 365 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET); 366 | 367 | /*Configure GPIO pin Output Level */ 368 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); 369 | 370 | /*Configure GPIO pin : PB9 */ 371 | GPIO_InitStruct.Pin = GPIO_PIN_9; 372 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 373 | GPIO_InitStruct.Pull = GPIO_NOPULL; 374 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 375 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 376 | 377 | /*Configure GPIO pin : T_NRST_Pin */ 378 | GPIO_InitStruct.Pin = T_NRST_Pin; 379 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 380 | GPIO_InitStruct.Pull = GPIO_NOPULL; 381 | HAL_GPIO_Init(T_NRST_GPIO_Port, &GPIO_InitStruct); 382 | 383 | /*Configure GPIO pin : PA12 */ 384 | GPIO_InitStruct.Pin = GPIO_PIN_12; 385 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 386 | GPIO_InitStruct.Pull = GPIO_NOPULL; 387 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 388 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 389 | 390 | } 391 | 392 | /* USER CODE BEGIN 4 */ 393 | 394 | /* USER CODE END 4 */ 395 | 396 | /** 397 | * @brief This function is executed in case of error occurrence. 398 | * @retval None 399 | */ 400 | void Error_Handler(void) 401 | { 402 | /* USER CODE BEGIN Error_Handler_Debug */ 403 | /* User can add his own implementation to report the HAL error return state */ 404 | 405 | /* USER CODE END Error_Handler_Debug */ 406 | } 407 | 408 | #ifdef USE_FULL_ASSERT 409 | /** 410 | * @brief Reports the name of the source file and the source line number 411 | * where the assert_param error has occurred. 412 | * @param file: pointer to the source file name 413 | * @param line: assert_param error line source number 414 | * @retval None 415 | */ 416 | void assert_failed(uint8_t *file, uint32_t line) 417 | { 418 | /* USER CODE BEGIN 6 */ 419 | /* User can add his own implementation to report the file name and line number, 420 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 421 | /* USER CODE END 6 */ 422 | } 423 | #endif /* USE_FULL_ASSERT */ 424 | 425 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 426 | -------------------------------------------------------------------------------- /BMSv2.0-Layout/BMSv2.0-3D-view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/BMSv2.0-Layout/BMSv2.0-3D-view.png -------------------------------------------------------------------------------- /BMSv2.0-Layout/BMSv2.0-PCBLayout-view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/BMSv2.0-Layout/BMSv2.0-PCBLayout-view.png -------------------------------------------------------------------------------- /BMSv2.0-Layout/README: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /KiCad-zip-file/README: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /KiCad-zip-file/Sintaksa-stm32g031-BMSmodul.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quanhengwen/STM32G031-BMS/265e20eb5f85cc7e3995c7fa96c035f456db41fc/KiCad-zip-file/Sintaksa-stm32g031-BMSmodul.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## STM32Gx31 BMS Board 2 | ----------------------------------------------------- 3 | 4 | ### Problem 5 | ------- 6 | A DIY Powerwall is the DIY construction of a pack of battery cells to create an energy store which can be used via inverters to power electrical items in the home. Generally cells are salvaged/second hand. 7 | 8 | Lithium batteries need to be kept at the same voltage level across a parallel pack. This is done by balancing each cell in the pack to raise or lower its voltage to match the others. 9 | 10 | Existing balancing solutions are available in the market place, but at a relatively high cost compared to the cost of the battery bank, so this project is to design a low-cost, simple featured BMS. 11 | 12 | ### Circuit explanation 13 | ------------------ 14 | Battery management system controlled by STM32G031K6 32bit microcontroller, the system has three separated units, power supply, analog digital conversion peripheral 15 | and communication unit. 16 | 17 | Power supply is connected directly to batteries meaning that we do not need additional external power source. Power supply main part is Texas Instruments integrated 18 | circuit TPS6107x which stands as a buck/boost converter generating stable 600 mA and 3.3 V at the output. All 4.7 uF capacitors connceted to TPS6107x chip are used to give the 19 | maximum power at the output. Two 4.7 uF X7R capacitors instead of one 10uF capacitor are better solution due to less value noise generation. 20 | 21 | The output voltage of the TPS6107x dc/dc converter can be adjusted with an external resistor divider. The typical value of the voltage at the FB pin is 500 mV. The maximum 22 | recommended value for the output voltage is 5.5 V. The current through the resistive divider should be about 100 times greater than the current into the FB pin. 23 | 24 | The typical current into the FB pin is 0.01 µA, and the voltage across R2 is typically 500 mV. Based on those two values, the recommended value for R2 should be lower than 500 kΩ, in 25 | order to set the divider current at 1 µA or higher. Because of internal compensation circuitry, the value for this resistor should be in the range of 200 kΩ. The second parameter for 26 | choosing the inductor is the desired current ripple in the inductor. Normally, it is advisable to work with a ripple of less than 20% of the average inductor current. A smaller 27 | ripple reduces the magnetic hysteresis losses in the inductor, as well as output voltage ripple and EMI. 28 | 29 | But in the same way, regulation time rises at load changes. Parameter f is the switching frequency and ΔIL is the ripple current in the inductor, i.e., 30 | 40% ΔIL. In this example,the desired inductor has the value of 4 µH. With this calculated value and the calculated currents, it is possible to choose a suitable inductor. In typical 31 | applications, a 4.7-µH inductance is recommended. The device has been optimized to operate with inductance values between 2.2 µH and 10 µH. 32 | 33 | Analog to digital conversion peripheral is used to take analog values from various sources, like NTC thermistors and batteries. These sources give us battery voltage and 34 | battery temperature directly from battery connector and from the battery side. These two temperature points are added to calculate the temperature change between battery 35 | connector and battery body. ADC peripheral has an ability to generate 12 bit and 16 bit battery voltage value due to operational amplifier circuit that generates triangle shape 36 | signal making it better for microcontroller to take measurements with 4 extra bits. LMV321 is used as a main operational amplifier. 37 | 38 | Devices are communicating in series, sharing measured values between each other. Main CPU is collecting voltage and temperature values from every unit and posting it to 39 | the PLC. System testing unit is using both half duplex and full duplex communication method. Half duplex method allows the system to communicate with another one but not 40 | in the same time whereas full duplex is making that possible. 41 | 42 | Half and full duplex communication main elements are Texas Instruments SN65HVD10 and SN65HVD73 transreceivers 43 | circuits. ICs datasheets recommend 10 kOhms pull up resistors for receiver input line and 10 kOhms pull down resistor for transmitter line. All outputs must be protected 44 | from electrostatic discharge. ESD protection is made using 10 Ohms resistors and zener diodes with Vz = 5 V disallowing signals to have values greater than 5 V. 45 | 46 | ### Project Documents 47 | 48 | [STM32G0 NUCLEO User Manual 1](https://www.st.com/resource/en/user_manual/dm00622380-stm32g0-nucleo-32-board-mb1455-stmicroelectronics.pdf) 49 | 50 | [STM32G0 NUCLEO User Manual 2](https://www.st.com/resource/en/user_manual/dm00231744-stm32-nucleo32-boards-mb1180-stmicroelectronics.pdf) 51 | 52 | [STM32G0 NUCLEO Reference Manual](https://www.st.com/resource/en/reference_manual/dm00371828-stm32g0x1-advanced-armbased-32bit-mcus-stmicroelectronics.pdf) 53 | 54 | ### KiCad Design 55 | 56 | _BMSv2.0 PCB Layout Design_ 57 | 58 | ![GitHub Logo](/BMSv2.0-Layout/BMSv2.0-PCBLayout-view.png) 59 | 60 | _BMSv2.0 PCB 3D View_ 61 | 62 | ![GitHub Logo](/BMSv2.0-Layout/BMSv2.0-3D-view.png) 63 | 64 | ### Shortcomings and footnotes 65 | 66 | 1. Replace the boost converter with the buck/boost converter 67 | 2. Make the hole in the footprint for communication connector header 68 | 3. Replace 200k resistor with 180k resistor in the power supply block to generate correct voltage reference 69 | 4. Move the cooper pour layer from the output connectors 70 | 5. Put the interface to connect the board with PC 71 | 6. Change PWM output pin to TIM2_CH1 72 | 7. Move ADC pin from ADC1_IN1 pin (PA1) to clear the conflict with UART2 configuration 73 | 8. Using FreeRTOS, one task will take analog voltage and temperature values every milisecond, another task will send the data after it gets the request 74 | --------------------------------------------------------------------------------