diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/proj/amcbldc-application.uvoptx b/emBODY/eBcode/arch-arm/board/amcbldc/application/proj/amcbldc-application.uvoptx index 475e06d37..7f13f21ee 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/proj/amcbldc-application.uvoptx +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/proj/amcbldc-application.uvoptx @@ -22,7 +22,7 @@ - amcbldc-app-osal-ulpro + amcbldc-app 0x4 ARM-ADS @@ -75,7 +75,7 @@ 1 0 - 1 + 0 18 @@ -120,7 +120,7 @@ 0 ULP2CM3 - -UP0948193 -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65555 -TC168000000 -TT10000000 -TP18 -TDX0 -TDD0 -TDS8000 -TDT0 -TDC1F -TIE80000001 -TIP9 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32G47x-8x_512.FLM -FS08000000 -FL080000 -FP0($$Device:STM32G474QETx$CMSIS\Flash\STM32G47x-8x_512.FLM) + -UP0948199 -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65555 -TC168000000 -TT10000000 -TP18 -TDX0 -TDD0 -TDS8000 -TDT0 -TDC1F -TIE80000001 -TIP9 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32G47x-8x_512.FLM -FS08000000 -FL080000 -FP0($$Device:STM32G474QETx$CMSIS\Flash\STM32G47x-8x_512.FLM) 0 @@ -217,7 +217,7 @@ 0 0 0 - 0 + 1 0 0 0 @@ -247,7 +247,7 @@ - amcbldc-app-osal-ulpro-v122 + amcbldc-app-motorhal2 0x4 ARM-ADS @@ -300,7 +300,7 @@ 1 0 - 0 + 1 18 @@ -328,7 +328,7 @@ 1 0 0 - 0 + 1 @@ -339,18 +339,13 @@ - BIN\UL2CM3.DLL + BIN\ULP2CM3.DLL - - 0 - UL2CM3 - UL2CM3(-S0 -C0 -P0 ) -FN1 -FC1000 -FD20000000 -FF0STM32G47x-8x_256 -FL040000 -FS08000000 -FP0($$Device:STM32G474CCUx$CMSIS\Flash\STM32G47x-8x_256.FLM) - 0 ULP2CM3 - UL2CM3(-S0 -C0 -P0 ) -FN1 -FC1000 -FD20000000 -FF0STM32G47x-8x_256 -FL040000 -FS08000000 -FP0($$Device:STM32G474CCUx$CMSIS\Flash\STM32G47x-8x_256.FLM) + -UP0948199 -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65555 -TC168000000 -TT10000000 -TP18 -TDX0 -TDD0 -TDS8000 -TDT0 -TDC1F -TIE80000001 -TIP9 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32G47x-8x_512.FLM -FS08000000 -FL080000 -FP0($$Device:STM32G474QETx$CMSIS\Flash\STM32G47x-8x_512.FLM) 0 @@ -372,45 +367,45 @@ DLGUARM + + 0 + JL2CM3 + -U932000551 -O78 -S8 -ZTIFSpeedSel50000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32G47x-8x_512.FLM -FS08000000 -FL080000 -FP0($$Device:STM32G474QETx$CMSIS\Flash\STM32G47x-8x_512.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32G47x-8x_512 -FS08000000 -FL080000 -FP0($$Device:STM32G474QETx$CMSIS\Flash\STM32G47x-8x_512.FLM)) + 0 1 - SupervisorFSM_RX_DW + faultvalues 1 1 - SupervisorFSM_RX_B + s_analog_raw_cphases 2 1 - AMC_BLDC_Y.ConfigurationParameters_p + currents 3 1 - AMC_BLDC_B.RTBInsertedForAdapter_InsertedF - - - 4 - 1 - rtb_SupervisorFSM_RX_o2 - - - 5 - 1 - AMC_BLDC_Y.ConfigurationParameters_p + filter 1 0 - rtb_SupervisorFSM_RX_o2 + myuID 0 @@ -437,7 +432,7 @@ 0 0 0 - 0 + 1 0 0 0 @@ -466,288 +461,6 @@ - - amcbldc-app01-osal-stlink - 0x4 - ARM-ADS - - 12000000 - - 0 - 1 - 1 - 0 - 0 - - - 1 - 65535 - 0 - 0 - 0 - - - 79 - 66 - 8 - .\lst\ - - - 1 - 1 - 1 - 0 - 1 - 1 - 0 - 1 - 0 - 0 - 0 - 0 - - - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - - - 0 - 0 - 0 - - 18 - - 1 - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 1 - 1 - 1 - 0 - 1 - 1 - 1 - 1 - 0 - 0 - 1 - 0 - 0 - -1 - - - - - - - - - - - - - - - 0 - - - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - - - - 0 - 0 - 0 - - - - - - - - - - - - - amcbldc-app01-cmsisos2-ulpro - 0x4 - ARM-ADS - - 12000000 - - 0 - 1 - 1 - 0 - 0 - - - 1 - 65535 - 0 - 0 - 0 - - - 79 - 66 - 8 - .\lstcmsisos2\ - - - 1 - 1 - 1 - 0 - 1 - 1 - 0 - 1 - 0 - 0 - 0 - 0 - - - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - - - 0 - 0 - 0 - - 18 - - 1 - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 1 - 1 - 1 - 0 - 1 - 1 - 1 - 1 - 0 - 0 - 1 - 0 - 0 - -1 - - - - - - - - - - - - - - - 0 - - - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - - - - 0 - 0 - 0 - - - - - - - - - - - main 1 @@ -780,45 +493,33 @@ 4 0 0 - 0 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib - stm32hal.g4.amcbldc.v120.lib - 0 - 0 - - - 2 - 3 - 2 - 0 - 0 - 0 - ..\cfg\stm32hal.startup.amcbldc.s - stm32hal.startup.amcbldc.s + 0 + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v120.amcbldc.lib + stm32hal.g4.v120.amcbldc.lib 0 0 2 - 4 + 3 4 0 0 0 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib - stm32hal.g4.amcbldc.v122.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v122.amcbldc.lib + stm32hal.g4.v122.amcbldc.lib 0 0 2 - 5 + 4 2 0 0 0 - ..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s - stm32hal.startup.amcbldc.v122.template.s + ..\cfg\stm32hal.startup.amcbldc.s + stm32hal.startup.amcbldc.s 0 0 @@ -832,7 +533,7 @@ 0 3 - 6 + 5 4 0 0 @@ -844,7 +545,7 @@ 3 - 7 + 6 1 0 0 @@ -856,7 +557,7 @@ 3 - 8 + 7 4 0 0 @@ -876,7 +577,7 @@ 0 4 - 9 + 8 8 0 0 @@ -888,7 +589,7 @@ 4 - 10 + 9 8 0 0 @@ -908,7 +609,7 @@ 0 5 - 11 + 10 8 0 0 @@ -922,13 +623,13 @@ embot::hw - 1 + 0 0 0 0 6 - 12 + 11 8 0 0 @@ -940,7 +641,7 @@ 6 - 13 + 12 8 0 0 @@ -952,7 +653,7 @@ 6 - 14 + 13 8 0 0 @@ -964,7 +665,7 @@ 6 - 15 + 14 8 0 0 @@ -976,7 +677,7 @@ 6 - 16 + 15 8 0 0 @@ -988,7 +689,7 @@ 6 - 17 + 16 8 0 0 @@ -1000,7 +701,7 @@ 6 - 18 + 17 8 0 0 @@ -1012,7 +713,7 @@ 6 - 19 + 18 8 0 0 @@ -1024,7 +725,7 @@ 6 - 20 + 19 8 0 0 @@ -1036,7 +737,7 @@ 6 - 21 + 20 8 0 0 @@ -1048,7 +749,7 @@ 6 - 22 + 21 8 0 0 @@ -1060,7 +761,7 @@ 6 - 23 + 22 8 0 0 @@ -1072,7 +773,7 @@ 6 - 24 + 23 8 0 0 @@ -1084,7 +785,7 @@ 6 - 25 + 24 8 0 0 @@ -1096,7 +797,7 @@ 6 - 26 + 25 8 0 0 @@ -1109,14 +810,14 @@ - embot::hw::lowlevel - 0 + embot::hw::lowlevel-0optimized + 1 0 0 0 7 - 27 + 26 8 0 0 @@ -1130,13 +831,13 @@ embot::hw::bsp - 0 + 1 0 0 0 8 - 28 + 27 8 0 0 @@ -1156,7 +857,7 @@ 0 9 - 29 + 28 8 0 0 @@ -1168,7 +869,7 @@ 9 - 30 + 29 8 0 0 @@ -1180,7 +881,7 @@ 9 - 31 + 30 8 0 0 @@ -1192,7 +893,7 @@ 9 - 32 + 31 8 0 0 @@ -1204,7 +905,7 @@ 9 - 33 + 32 8 0 0 @@ -1216,7 +917,7 @@ 9 - 34 + 33 8 0 0 @@ -1228,7 +929,7 @@ 9 - 35 + 34 8 0 0 @@ -1240,7 +941,7 @@ 9 - 36 + 35 8 0 0 @@ -1252,7 +953,7 @@ 9 - 37 + 36 8 0 0 @@ -1272,7 +973,7 @@ 0 10 - 38 + 37 8 0 0 @@ -1284,7 +985,7 @@ 10 - 39 + 38 8 0 0 @@ -1296,7 +997,7 @@ 10 - 40 + 39 8 0 0 @@ -1308,7 +1009,7 @@ 10 - 41 + 40 8 0 0 @@ -1320,7 +1021,7 @@ 10 - 42 + 41 8 0 0 @@ -1332,7 +1033,7 @@ 10 - 43 + 42 8 0 0 @@ -1344,7 +1045,7 @@ 10 - 44 + 43 8 0 0 @@ -1356,7 +1057,7 @@ 10 - 45 + 44 8 0 0 @@ -1368,7 +1069,7 @@ 10 - 46 + 45 8 0 0 @@ -1388,7 +1089,7 @@ 0 11 - 47 + 46 8 0 0 @@ -1400,7 +1101,7 @@ 11 - 48 + 47 8 0 0 @@ -1412,7 +1113,7 @@ 11 - 49 + 48 8 0 0 @@ -1424,7 +1125,7 @@ 11 - 50 + 49 8 0 0 @@ -1436,7 +1137,7 @@ 11 - 51 + 50 8 0 0 @@ -1448,7 +1149,7 @@ 11 - 52 + 51 8 0 0 @@ -1468,7 +1169,7 @@ 0 12 - 53 + 52 8 0 0 @@ -1480,7 +1181,7 @@ 12 - 54 + 53 8 0 0 @@ -1500,7 +1201,7 @@ 0 13 - 55 + 54 8 0 0 @@ -1512,7 +1213,7 @@ 13 - 56 + 55 8 0 0 @@ -1532,7 +1233,7 @@ 0 14 - 57 + 56 4 0 0 @@ -1552,7 +1253,7 @@ 0 15 - 58 + 57 1 0 0 @@ -1564,7 +1265,7 @@ 15 - 59 + 58 8 0 0 @@ -1576,7 +1277,7 @@ 15 - 60 + 59 8 0 0 @@ -1588,7 +1289,7 @@ 15 - 61 + 60 8 0 0 @@ -1601,11 +1302,23 @@ - mbd - 1 + others::motorhal2 + 0 0 0 0 + + 16 + 61 + 8 + 0 + 0 + 0 + ..\src\motorhal2\motorhal_config.c + motorhal_config.c + 0 + 0 + 16 62 @@ -1613,8 +1326,8 @@ 0 0 0 - ..\src\model-based-design\sharedutils\rt_hypotf_snf.cpp - rt_hypotf_snf.cpp + ..\src\motorhal2\encoder.c + encoder.c 0 0 @@ -1625,8 +1338,8 @@ 0 0 0 - ..\src\model-based-design\sharedutils\rt_nonfinite.cpp - rt_nonfinite.cpp + ..\src\motorhal2\pwm.c + pwm.c 0 0 @@ -1637,14 +1350,58 @@ 0 0 0 + ..\src\motorhal2\analog.c + analog.c + 0 + 0 + + + + + mbd + 0 + 0 + 0 + 0 + + 17 + 65 + 8 + 0 + 0 + 0 + ..\src\model-based-design\sharedutils\rt_hypotf_snf.cpp + rt_hypotf_snf.cpp + 0 + 0 + + + 17 + 66 + 8 + 0 + 0 + 0 + ..\src\model-based-design\sharedutils\rt_nonfinite.cpp + rt_nonfinite.cpp + 0 + 0 + + + 17 + 67 + 8 + 0 + 0 + 0 ..\src\model-based-design\sharedutils\rtGetInf.cpp rtGetInf.cpp 0 0 - 16 - 65 + 17 + 68 8 0 0 @@ -1655,8 +1412,8 @@ 0 - 16 - 66 + 17 + 69 8 0 0 @@ -1667,8 +1424,8 @@ 0 - 16 - 67 + 17 + 70 8 0 0 @@ -1679,8 +1436,8 @@ 0 - 16 - 68 + 17 + 71 8 0 0 @@ -1691,8 +1448,8 @@ 0 - 16 - 69 + 17 + 72 8 0 0 @@ -1703,8 +1460,8 @@ 0 - 16 - 70 + 17 + 73 8 0 0 @@ -1715,8 +1472,8 @@ 0 - 16 - 71 + 17 + 74 8 0 0 @@ -1735,8 +1492,8 @@ 0 0 - 17 - 72 + 18 + 75 8 0 0 @@ -1755,8 +1512,8 @@ 0 0 - 18 - 73 + 19 + 76 8 0 0 @@ -1775,8 +1532,8 @@ 0 0 - 19 - 74 + 20 + 77 8 0 0 @@ -1795,8 +1552,8 @@ 0 0 - 20 - 75 + 21 + 78 8 0 0 @@ -1815,8 +1572,8 @@ 0 0 - 21 - 76 + 22 + 79 8 0 0 @@ -1835,8 +1592,8 @@ 0 0 - 22 - 77 + 23 + 80 8 0 0 @@ -1847,8 +1604,8 @@ 0 - 22 - 78 + 23 + 81 8 0 0 @@ -1859,8 +1616,8 @@ 0 - 22 - 79 + 23 + 82 8 0 0 @@ -1879,8 +1636,8 @@ 0 0 - 23 - 80 + 24 + 83 8 0 0 @@ -1899,8 +1656,8 @@ 0 0 - 24 - 81 + 25 + 84 8 0 0 @@ -1919,8 +1676,8 @@ 0 0 - 25 - 82 + 26 + 85 8 0 0 diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/proj/amcbldc-application.uvprojx b/emBODY/eBcode/arch-arm/board/amcbldc/application/proj/amcbldc-application.uvprojx index ff517642d..b9585bac0 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/proj/amcbldc-application.uvprojx +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/proj/amcbldc-application.uvprojx @@ -7,7 +7,7 @@ - amcbldc-app-osal-ulpro + amcbldc-app 0x4 ARM-ADS 6190000::V6.19::ARMCLANG @@ -395,19 +395,14 @@ stm32hal - stm32hal.g4.amcbldc.v120.lib + stm32hal.g4.v120.amcbldc.lib 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v120.amcbldc.lib - stm32hal.startup.amcbldc.s - 2 - ..\cfg\stm32hal.startup.amcbldc.s - - - stm32hal.g4.amcbldc.v122.lib + stm32hal.g4.v122.amcbldc.lib 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v122.amcbldc.lib 2 @@ -429,47 +424,9 @@ - stm32hal.startup.amcbldc.v122.template.s + stm32hal.startup.amcbldc.s 2 - ..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - - - - - - - - - + ..\cfg\stm32hal.startup.amcbldc.s @@ -618,12 +575,132 @@ - embot::hw::lowlevel + embot::hw::lowlevel-0optimized + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 1 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + embot_hw_lowlevel.cpp 8 ..\..\..\..\embot\hw\embot_hw_lowlevel.cpp + + + 2 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 1 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + @@ -837,6 +914,100 @@ + + others::motorhal2 + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + motorhal_config.c + 8 + ..\src\motorhal2\motorhal_config.c + + + encoder.c + 8 + ..\src\motorhal2\encoder.c + + + pwm.c + 8 + ..\src\motorhal2\pwm.c + + + analog.c + 8 + ..\src\motorhal2\analog.c + + + mbd @@ -1067,23 +1238,23 @@ - amcbldc-app-osal-ulpro-v122 + amcbldc-app-motorhal2 0x4 ARM-ADS - 6180000::V6.18::ARMCLANG + 6190000::V6.19::ARMCLANG 1 - STM32G474CCUx + STM32G474QETx STMicroelectronics Keil.STM32G4xx_DFP.1.4.0 http://www.keil.com/pack/ - IRAM(0x20000000,0x00020000) IROM(0x08000000,0x00040000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE + IRAM(0x20000000,0x00020000) IROM(0x08000000,0x00080000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE - UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32G47x-8x_256 -FS08000000 -FL040000 -FP0($$Device:STM32G474CCUx$CMSIS\Flash\STM32G47x-8x_256.FLM)) + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32G47x-8x_512 -FS08000000 -FL080000 -FP0($$Device:STM32G474QETx$CMSIS\Flash\STM32G47x-8x_512.FLM)) 0 - $$Device:STM32G474CCUx$Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g4xx.h + $$Device:STM32G474QETx$Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g4xx.h @@ -1093,7 +1264,7 @@ - $$Device:STM32G474CCUx$CMSIS\SVD\STM32G474xx.svd + $$Device:STM32G474QETx$CMSIS\SVD\STM32G474xx.svd 0 0 @@ -1198,7 +1369,7 @@ 1 BIN\UL2CM3.DLL - + "" () @@ -1312,7 +1483,7 @@ 1 0x8000000 - 0x40000 + 0x80000 0 @@ -1337,7 +1508,7 @@ 1 0x8000000 - 0x40000 + 0x80000 1 @@ -1400,7 +1571,7 @@ -Wno-pragma-pack -Wno-deprecated-register -DEMBOT_USE_rtos_osal -DEMBOT_AMCBLDC_APP05 USE_STM32HAL STM32HAL_BOARD_AMCBLDC STM32HAL_DRIVER_V122 - ..\..\bsp;..\..\..\..\libs\highlevel\abslayer\osal\api;..\..\..\..\libs\midware\eventviewer\api;..\..\..\..\libs\lowlevel\stm32hal\api;..\..\..\..\embot\app;..\..\..\..\embot\i2h;..\..\..\..\embot\hw;..\..\..\..\embot\os;..\..\..\..\embot;..\..\..\..\embot\app\dsp;..\..\..\..\embot\app\skeleton;..\..\..\..\embot\prot\can;..\..\..\..\..\..\..\..\icub-firmware-shared\can\canProtocolLib;..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core;..\..\..\..\..\..\..\..\icub-firmware-shared\embot\tools;..\..\..\..\libs\lowlevel\cmsis\dsp\v160\Include;..\..\..\..\libs\highlevel\abslayer\hal2\api;..\src\motorhal;..\src\model-based-design\sharedutils;..\src\model-based-design\can-decoder;..\src\model-based-design\can-raw2struct;..\src\model-based-design\supervisor-rx;..\src\model-based-design\supervisor-tx;..\src\model-based-design\can-encoder;..\src\model-based-design\control-outer;..\src\model-based-design\control-foc;..\src\model-based-design\estimator;..\src\model-based-design\amc-bldc;..\src\model-based-design\filter-current + ..\..\bsp;..\..\..\..\libs\highlevel\abslayer\osal\api;..\..\..\..\libs\midware\eventviewer\api;..\..\..\..\libs\lowlevel\stm32hal\api;..\..\..\..\embot\app;..\..\..\..\embot\i2h;..\..\..\..\embot\hw;..\..\..\..\embot\os;..\..\..\..\embot;..\..\..\..\embot\app\dsp;..\..\..\..\embot\app\skeleton;..\..\..\..\embot\prot\can;..\..\..\..\..\..\..\..\icub-firmware-shared\can\canProtocolLib;..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core;..\..\..\..\..\..\..\..\icub-firmware-shared\embot\tools;..\..\..\..\libs\lowlevel\cmsis\dsp\v160\Include;..\..\..\..\libs\highlevel\abslayer\hal2\api;..\src\motorhal2;..\src\model-based-design\sharedutils;..\src\model-based-design\can-decoder;..\src\model-based-design\can-raw2struct;..\src\model-based-design\supervisor-rx;..\src\model-based-design\supervisor-tx;..\src\model-based-design\can-encoder;..\src\model-based-design\control-outer;..\src\model-based-design\control-foc;..\src\model-based-design\estimator;..\src\model-based-design\amc-bldc;..\src\model-based-design\filter-current @@ -1455,9 +1626,9 @@ stm32hal - stm32hal.g4.amcbldc.v120.lib + stm32hal.g4.v120.amcbldc.lib 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v120.amcbldc.lib 2 @@ -1479,2115 +1650,15 @@ - stm32hal.startup.amcbldc.s - 2 - ..\cfg\stm32hal.startup.amcbldc.s - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - - - - - - - - - - - - stm32hal.g4.amcbldc.v122.lib - 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib - - - stm32hal.startup.amcbldc.v122.template.s - 2 - ..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s - - - - - rtos - - - osal.cm4.dbg.lib - 4 - ..\..\..\..\..\..\eBcode\arch-arm\libs\highlevel\abslayer\osal\lib\osal.cm4.dbg.lib - - - eventviewer.c - 1 - ..\..\..\..\..\..\eBcode\arch-arm\libs\midware\eventviewer\src\eventviewer.c - - - cmsisos2.lib - 4 - ..\..\..\..\libs\highlevel\abslayer\cmsisos2\lib\cmsisos2.lib - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - - - - - embot::core - - - embot_core.cpp - 8 - ..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core\embot_core.cpp - - - embot_core_binary.cpp - 8 - ..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core\embot_core_binary.cpp - - - - - embot::tools - - - embot_tools.cpp - 8 - ..\..\..\..\..\..\..\..\icub-firmware-shared\embot\tools\embot_tools.cpp - - - - - embot::hw - - - embot_hw.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw.cpp - - - embot_hw_bsp.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_bsp.cpp - - - embot_hw_sys.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_sys.cpp - - - embot_hw_FlashStorage.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_FlashStorage.cpp - - - embot_hw_FlashBurner.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_FlashBurner.cpp - - - embot_hw_can.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_can.cpp - - - embot_hw_flash.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_flash.cpp - - - embot_hw_timer.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_timer.cpp - - - embot_hw_gpio.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_gpio.cpp - - - embot_hw_led.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_led.cpp - - - embot_hw_button.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_button.cpp - - - embot_hw_i2c.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_i2c.cpp - - - embot_hw_tlv493d.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_tlv493d.cpp - - - embot_hw_types.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_types.cpp - - - embot_hw_motor.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_motor.cpp - - - - - embot::hw::lowlevel - - - embot_hw_lowlevel.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_lowlevel.cpp - - - - - embot::hw::bsp - - - embot_hw_bsp_amcbldc.cpp - 8 - ..\..\bsp\embot_hw_bsp_amcbldc.cpp - - - - - embot::os - - - embot_os.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os.cpp - - - embot_os_Thread.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_Thread.cpp - - - embot_os_theCallbackManager.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_theCallbackManager.cpp - - - embot_app_theJumper.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_theJumper.cpp - - - embot_os_theScheduler.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_theScheduler.cpp - - - embot_os_theTimerManager.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_theTimerManager.cpp - - - embot_os_Timer.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_Timer.cpp - - - embot_os_Action.cpp - 8 - ..\..\..\..\embot\os\embot_os_Action.cpp - - - embot_os_rtos.cpp - 8 - ..\..\..\..\embot\os\embot_os_rtos.cpp - - - - - embot::prot::can - - - embot_app_application_theCANparserBasic.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_application_theCANparserBasic.cpp - - - embot_prot_can.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can.cpp - - - embot_prot_can_skin_periodic.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_skin_periodic.cpp - - - embot_prot_can_inertial_periodic.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_inertial_periodic.cpp - - - embot_prot_can_motor_polling.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_motor_polling.cpp - - - embot_prot_can_motor_periodic.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_motor_periodic.cpp - - - embot_prot_can_bootloader.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_bootloader.cpp - - - embot_prot_can_analog_polling.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_analog_polling.cpp - - - embot_prot_can_analog_periodic.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_analog_periodic.cpp - - - - - embot::app-required - - - embot_app_skeleton_os_evthreadcan.cpp - 8 - ..\..\..\..\embot\app\skeleton\embot_app_skeleton_os_evthreadcan.cpp - - - embot_app_skeleton_os_basic.cpp - 8 - ..\..\..\..\embot\app\skeleton\embot_app_skeleton_os_basic.cpp - - - embot_app_theApplication.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_theApplication.cpp - - - embot_app_theCANboardInfo.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_theCANboardInfo.cpp - - - embot_app_application_theCANtracer.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_application_theCANtracer.cpp - - - embot_app_theStorage.cpp - 8 - ..\..\..\..\embot\app\embot_app_theStorage.cpp - - - - - embot::app-others - - - embot_app_scope.cpp - 8 - ..\..\..\..\embot\app\embot_app_scope.cpp - - - embot_app_theLEDmanager.cpp - 8 - ..\..\..\..\embot\app\embot_app_theLEDmanager.cpp - - - - - others - - - embot_app_application_theCANparserMBD.cpp - 8 - ..\src\embot_app_application_theCANparserMBD.cpp - - - embot_app_application_theMBDagent.cpp - 8 - ..\src\embot_app_application_theMBDagent.cpp - - - - - others::foc - - - arm_cortexM4lf_math.lib - 4 - ..\..\..\..\libs\lowlevel\cmsis\dsp\v160\Lib\ARM\arm_cortexM4lf_math.lib - - - - - others::motorhal - - - motorhal_config.c - 1 - ..\src\motorhal\motorhal_config.c - - - encoder.c - 8 - ..\src\motorhal\encoder.c - - - pwm.c - 8 - ..\src\motorhal\pwm.c - - - analog.c - 8 - ..\src\motorhal\analog.c - - - - - mbd - - - rt_hypotf_snf.cpp - 8 - ..\src\model-based-design\sharedutils\rt_hypotf_snf.cpp - - - rt_nonfinite.cpp - 8 - ..\src\model-based-design\sharedutils\rt_nonfinite.cpp - - - rtGetInf.cpp - 8 - ..\src\model-based-design\sharedutils\rtGetInf.cpp - - - rtGetNaN.cpp - 8 - ..\src\model-based-design\sharedutils\rtGetNaN.cpp - - - rtw_enable_disable_motors.c - 8 - ..\src\model-based-design\sharedutils\rtw_enable_disable_motors.c - - - const_params.cpp - 8 - ..\src\model-based-design\sharedutils\const_params.cpp - - - uMultiWord2Double.cpp - 8 - ..\src\model-based-design\sharedutils\uMultiWord2Double.cpp - - - uMultiWordShl.cpp - 8 - ..\src\model-based-design\sharedutils\uMultiWordShl.cpp - - - rt_roundd_snf.cpp - 8 - ..\src\model-based-design\sharedutils\rt_roundd_snf.cpp - - - rtw_motor_config.c - 8 - ..\src\model-based-design\sharedutils\rtw_motor_config.c - - - - - mbd::can-encoder - - - can_encoder.cpp - 8 - ..\src\model-based-design\can-encoder\can_encoder.cpp - - - - - mbd::can-decoder - - - can_decoder.cpp - 8 - ..\src\model-based-design\can-decoder\can_decoder.cpp - - - - - mbd::supervisor-rx - - - SupervisorFSM_RX.cpp - 8 - ..\src\model-based-design\supervisor-rx\SupervisorFSM_RX.cpp - - - - - mbd::supervisor-tx - - - SupervisorFSM_TX.cpp - 8 - ..\src\model-based-design\supervisor-tx\SupervisorFSM_TX.cpp - - - - - mbd::control-outer - - - control_outer.cpp - 8 - ..\src\model-based-design\control-outer\control_outer.cpp - - - - - mbd::control-foc - - - control_foc.cpp - 8 - ..\src\model-based-design\control-foc\control_foc.cpp - - - FOCInnerLoop.cpp - 8 - ..\src\model-based-design\control-foc\FOCInnerLoop.cpp - - - control_foc_data.cpp - 8 - ..\src\model-based-design\control-foc\control_foc_data.cpp - - - - - mdb::estimator - - - estimation_velocity.cpp - 8 - ..\src\model-based-design\estimator\estimation_velocity.cpp - - - - - mbd::filter-current - - - filter_current.cpp - 8 - ..\src\model-based-design\filter-current\filter_current.cpp - - - - - mbd::amc-bldc - - - AMC_BLDC.cpp - 8 - ..\src\model-based-design\amc-bldc\AMC_BLDC.cpp - - - - - ::CMSIS - - - 0 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 0 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - 2 - 2 - 2 - 2 - 2 - 0 - 0 - 2 - 2 - 2 - 2 - 2 - - - - - - - - - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - - - - - - - - - - - - - - amcbldc-app01-osal-stlink - 0x4 - ARM-ADS - 6160000::V6.16::ARMCLANG - 1 - - - STM32G474QETx - STMicroelectronics - Keil.STM32G4xx_DFP.1.4.0 - http://www.keil.com/pack/ - IRAM(0x20000000,0x00020000) IROM(0x08000000,0x00080000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE - - - UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32G4xx_512 -FS08000000 -FL080000 -FP0($$Device:STM32G474QETx$CMSIS\Flash\STM32G4xx_512.FLM)) - 0 - $$Device:STM32G474QETx$Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g4xx.h - - - - - - - - - - $$Device:STM32G474QETx$CMSIS\SVD\STM32G474xx.svd - 0 - 0 - - - - - - - 0 - 0 - 0 - 0 - 1 - - .\obj\ - amcbldc - 1 - 0 - 1 - 1 - 1 - .\lst\ - 1 - 0 - 0 - - 0 - 0 - - - 0 - 0 - 0 - 0 - - - 0 - 0 - - - 0 - 0 - 0 - 0 - - - 1 - 0 - cmd.exe /C copy .\Obj\amcbldc.hex ..\bin\amcbldc.hex - - 0 - 0 - 0 - 0 - - 0 - - - - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 3 - - - 0 - - - SARMCM3.DLL - -REMAP -MPU - DCM.DLL - -pCM4 - SARMCM3.DLL - -MPU - TCM.DLL - -pCM4 - - - - 1 - 0 - 0 - 0 - 16 - - - - - 1 - 0 - 0 - 1 - 1 - 4096 - - 1 - BIN\UL2CM3.DLL - "" () - - - - - 0 - - - - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 1 - 1 - 0 - 1 - 1 - 0 - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - "Cortex-M4" - - 0 - 0 - 0 - 1 - 1 - 0 - 0 - 2 - 0 - 0 - 0 - 0 - 0 - 8 - 0 - 0 - 0 - 0 - 3 - 3 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 1 - 0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x20000000 - 0x20000 - - - 1 - 0x8000000 - 0x80000 - - - 0 - 0x0 - 0x0 - - - 1 - 0x0 - 0x0 - - - 1 - 0x0 - 0x0 - - - 1 - 0x0 - 0x0 - - - 1 - 0x8000000 - 0x80000 - - - 1 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x20000000 - 0x20000 - - - 0 - 0x0 - 0x0 - - - - - - 1 - 2 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 0 - 3 - 0 - 1 - 0 - 0 - 0 - 3 - 8 - 1 - 1 - 0 - 0 - 0 - - -Wno-pragma-pack -Wno-deprecated-register -DEMBOT_USE_rtos_osal - USE_STM32HAL STM32HAL_BOARD_AMCBLDC STM32HAL_DRIVER_V120 - - ..\..\..\..\..\..\eBcode\arch-arm\libs\highlevel\abslayer\osal\api;..\..\..\..\..\..\eBcode\arch-arm\libs\midware\eventviewer\api;..\..\..\..\..\..\eBcode\arch-arm\libs\lowlevel\stm32hal\api;..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core;..\..\..\..\..\..\eBcode\arch-arm\embot\app;..\..\..\..\..\..\eBcode\arch-arm\embot\i2h;..\..\..\..\..\..\eBcode\arch-arm\embot\hw;..\..\..\..\..\..\eBcode\arch-arm\embot\os;..\..\..\..\..\..\eBcode\arch-arm\embot;..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core;..\..\..\..\embot\app\dsp;..\..\..\..\..\..\..\..\icub-firmware-shared\can\canProtocolLib;..\..\..\..\embot\app\skeleton;..\..\..\..\embot\prot\can;..\..\bsp - - - - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 4 - - - - - - - - - 0 - 0 - 0 - 0 - 1 - 0 - 0x08000000 - 0x20000000 - - .\amcbldc-application.sct - - - --diag_suppress=L6329 - - - - - - - - main - - - amcbldc-main.cpp - 8 - ..\src\amcbldc-main.cpp - - - - - stm32hal - - - stm32hal.g4.amcbldc.v120.lib - 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib - - - stm32hal.startup.amcbldc.s - 2 - ..\cfg\stm32hal.startup.amcbldc.s - - - stm32hal.g4.amcbldc.v122.lib - 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib - - - stm32hal.startup.amcbldc.v122.template.s - 2 - ..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s - - - - - rtos - - - osal.cm4.dbg.lib - 4 - ..\..\..\..\..\..\eBcode\arch-arm\libs\highlevel\abslayer\osal\lib\osal.cm4.dbg.lib - - - eventviewer.c - 1 - ..\..\..\..\..\..\eBcode\arch-arm\libs\midware\eventviewer\src\eventviewer.c - - - cmsisos2.lib - 4 - ..\..\..\..\libs\highlevel\abslayer\cmsisos2\lib\cmsisos2.lib - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - - - - - embot::core - - - embot_core.cpp - 8 - ..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core\embot_core.cpp - - - embot_core_binary.cpp - 8 - ..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core\embot_core_binary.cpp - - - - - embot::tools - - - embot_tools.cpp - 8 - ..\..\..\..\..\..\..\..\icub-firmware-shared\embot\tools\embot_tools.cpp - - - - - embot::hw - - - embot_hw.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw.cpp - - - embot_hw_bsp.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_bsp.cpp - - - embot_hw_sys.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_sys.cpp - - - embot_hw_FlashStorage.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_FlashStorage.cpp - - - embot_hw_FlashBurner.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_FlashBurner.cpp - - - embot_hw_can.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_can.cpp - - - embot_hw_flash.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_flash.cpp - - - embot_hw_timer.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_timer.cpp - - - embot_hw_gpio.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_gpio.cpp - - - embot_hw_led.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_led.cpp - - - embot_hw_button.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_button.cpp - - - embot_hw_i2c.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_i2c.cpp - - - embot_hw_tlv493d.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_tlv493d.cpp - - - embot_hw_types.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_types.cpp - - - embot_hw_motor.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_motor.cpp - - - - - embot::hw::lowlevel - - - embot_hw_lowlevel.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_lowlevel.cpp - - - 2 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 1 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - 2 - 2 - 2 - 2 - 2 - 0 - 0 - 2 - 2 - 2 - 2 - 2 - - - - - - - - - - - - - - embot::hw::bsp - - - embot_hw_bsp_amcbldc.cpp - 8 - ..\..\bsp\embot_hw_bsp_amcbldc.cpp - - - - - embot::os - - - embot_os.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os.cpp - - - embot_os_Thread.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_Thread.cpp - - - embot_os_theCallbackManager.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_theCallbackManager.cpp - - - embot_app_theJumper.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_theJumper.cpp - - - embot_os_theScheduler.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_theScheduler.cpp - - - embot_os_theTimerManager.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_theTimerManager.cpp - - - embot_os_Timer.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_Timer.cpp - - - embot_os_Action.cpp - 8 - ..\..\..\..\embot\os\embot_os_Action.cpp - - - embot_os_rtos.cpp - 8 - ..\..\..\..\embot\os\embot_os_rtos.cpp - - - - - embot::prot::can - - - embot_app_application_theCANparserBasic.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_application_theCANparserBasic.cpp - - - embot_prot_can.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can.cpp - - - embot_prot_can_skin_periodic.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_skin_periodic.cpp - - - embot_prot_can_inertial_periodic.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_inertial_periodic.cpp - - - embot_prot_can_motor_polling.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_motor_polling.cpp - - - embot_prot_can_motor_periodic.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_motor_periodic.cpp - - - embot_prot_can_bootloader.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_bootloader.cpp - - - embot_prot_can_analog_polling.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_analog_polling.cpp - - - embot_prot_can_analog_periodic.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_analog_periodic.cpp - - - - - embot::app-required - - - embot_app_skeleton_os_evthreadcan.cpp - 8 - ..\..\..\..\embot\app\skeleton\embot_app_skeleton_os_evthreadcan.cpp - - - embot_app_skeleton_os_basic.cpp - 8 - ..\..\..\..\embot\app\skeleton\embot_app_skeleton_os_basic.cpp - - - embot_app_theApplication.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_theApplication.cpp - - - embot_app_theCANboardInfo.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_theCANboardInfo.cpp - - - embot_app_application_theCANtracer.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_application_theCANtracer.cpp - - - embot_app_theStorage.cpp - 8 - ..\..\..\..\embot\app\embot_app_theStorage.cpp - - - - - embot::app-others - - - embot_app_scope.cpp - 8 - ..\..\..\..\embot\app\embot_app_scope.cpp - - - embot_app_theLEDmanager.cpp - 8 - ..\..\..\..\embot\app\embot_app_theLEDmanager.cpp - - - - - others - - - embot_app_application_theCANparserMBD.cpp - 8 - ..\src\embot_app_application_theCANparserMBD.cpp - - - embot_app_application_theMBDagent.cpp - 8 - ..\src\embot_app_application_theMBDagent.cpp - - - - - others::foc - - - arm_cortexM4lf_math.lib - 4 - ..\..\..\..\libs\lowlevel\cmsis\dsp\v160\Lib\ARM\arm_cortexM4lf_math.lib - - - - - others::motorhal - - - motorhal_config.c - 1 - ..\src\motorhal\motorhal_config.c - - - encoder.c - 8 - ..\src\motorhal\encoder.c - - - pwm.c - 8 - ..\src\motorhal\pwm.c - - - analog.c - 8 - ..\src\motorhal\analog.c - - - - - mbd - - - rt_hypotf_snf.cpp - 8 - ..\src\model-based-design\sharedutils\rt_hypotf_snf.cpp - - - rt_nonfinite.cpp - 8 - ..\src\model-based-design\sharedutils\rt_nonfinite.cpp - - - rtGetInf.cpp - 8 - ..\src\model-based-design\sharedutils\rtGetInf.cpp - - - rtGetNaN.cpp - 8 - ..\src\model-based-design\sharedutils\rtGetNaN.cpp - - - rtw_enable_disable_motors.c - 8 - ..\src\model-based-design\sharedutils\rtw_enable_disable_motors.c - - - const_params.cpp - 8 - ..\src\model-based-design\sharedutils\const_params.cpp - - - uMultiWord2Double.cpp - 8 - ..\src\model-based-design\sharedutils\uMultiWord2Double.cpp - - - uMultiWordShl.cpp - 8 - ..\src\model-based-design\sharedutils\uMultiWordShl.cpp - - - rt_roundd_snf.cpp - 8 - ..\src\model-based-design\sharedutils\rt_roundd_snf.cpp - - - rtw_motor_config.c - 8 - ..\src\model-based-design\sharedutils\rtw_motor_config.c - - - - - mbd::can-encoder - - - can_encoder.cpp - 8 - ..\src\model-based-design\can-encoder\can_encoder.cpp - - - - - mbd::can-decoder - - - can_decoder.cpp - 8 - ..\src\model-based-design\can-decoder\can_decoder.cpp - - - - - mbd::supervisor-rx - - - SupervisorFSM_RX.cpp - 8 - ..\src\model-based-design\supervisor-rx\SupervisorFSM_RX.cpp - - - - - mbd::supervisor-tx - - - SupervisorFSM_TX.cpp - 8 - ..\src\model-based-design\supervisor-tx\SupervisorFSM_TX.cpp - - - - - mbd::control-outer - - - control_outer.cpp - 8 - ..\src\model-based-design\control-outer\control_outer.cpp - - - - - mbd::control-foc - - - control_foc.cpp - 8 - ..\src\model-based-design\control-foc\control_foc.cpp - - - FOCInnerLoop.cpp - 8 - ..\src\model-based-design\control-foc\FOCInnerLoop.cpp - - - control_foc_data.cpp - 8 - ..\src\model-based-design\control-foc\control_foc_data.cpp - - - - - mdb::estimator - - - estimation_velocity.cpp - 8 - ..\src\model-based-design\estimator\estimation_velocity.cpp - - - - - mbd::filter-current - - - filter_current.cpp - 8 - ..\src\model-based-design\filter-current\filter_current.cpp - - - - - mbd::amc-bldc - - - AMC_BLDC.cpp - 8 - ..\src\model-based-design\amc-bldc\AMC_BLDC.cpp - - - - - ::CMSIS - - - 0 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 0 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - 2 - 2 - 2 - 2 - 2 - 0 - 0 - 2 - 2 - 2 - 2 - 2 - - - - - - - - - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - - - - - - - - - - - - - - amcbldc-app01-cmsisos2-ulpro - 0x4 - ARM-ADS - 6160000::V6.16::ARMCLANG - 1 - - - STM32G474QETx - STMicroelectronics - Keil.STM32G4xx_DFP.1.4.0 - http://www.keil.com/pack/ - IRAM(0x20000000,0x00020000) IROM(0x08000000,0x00080000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE - - - UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32G4xx_512 -FS08000000 -FL080000 -FP0($$Device:STM32G474QETx$CMSIS\Flash\STM32G4xx_512.FLM)) - 0 - $$Device:STM32G474QETx$Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g4xx.h - - - - - - - - - - $$Device:STM32G474QETx$CMSIS\SVD\STM32G474xx.svd - 0 - 0 - - - - - - - 0 - 0 - 0 - 0 - 1 - - .\objcmsisos2\ - amcbldc - 1 - 0 - 1 - 1 - 1 - .\lstcmsisos2\ - 1 - 0 - 0 - - 0 - 0 - - - 0 - 0 - 0 - 0 - - - 0 - 0 - - - 0 - 0 - 0 - 0 - - - 1 - 0 - cmd.exe /C copy .\objcmsisos2\pmc.hex ..\bin\pmc.hex - - 0 - 0 - 0 - 0 - - 0 - - - - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 3 - - - 0 - - - SARMCM3.DLL - -REMAP -MPU - DCM.DLL - -pCM4 - SARMCM3.DLL - -MPU - TCM.DLL - -pCM4 - - - - 1 - 0 - 0 - 0 - 16 - - - - - 1 - 0 - 0 - 1 - 1 - 4096 - - 1 - BIN\UL2CM3.DLL - "" () - - - - - 0 - - - - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 1 - 1 - 0 - 1 - 1 - 0 - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - "Cortex-M4" - - 0 - 0 - 0 - 1 - 1 - 0 - 0 - 2 - 0 - 0 - 0 - 0 - 0 - 8 - 0 - 0 - 0 - 0 - 3 - 3 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 1 - 0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x20000000 - 0x20000 - - - 1 - 0x8000000 - 0x80000 - - - 0 - 0x0 - 0x0 - - - 1 - 0x0 - 0x0 - - - 1 - 0x0 - 0x0 - - - 1 - 0x0 - 0x0 - - - 1 - 0x8000000 - 0x80000 - - - 1 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x20000000 - 0x20000 - - - 0 - 0x0 - 0x0 - - - - - - 1 - 1 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 0 - 3 - 0 - 1 - 0 - 0 - 0 - 3 - 8 - 1 - 1 - 1 - 0 - 0 - - -Wno-pragma-pack -Wno-deprecated-register -DEMBOT_USE_rtos_cmsisos2 - USE_STM32HAL STM32HAL_BOARD_AMCBLDC STM32HAL_DRIVER_V120 - - ..\..\..\..\..\..\eBcode\arch-arm\libs\highlevel\abslayer\cmsisos2\api;..\..\..\..\..\..\eBcode\arch-arm\libs\lowlevel\stm32hal\api;..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core;..\..\..\..\..\..\eBcode\arch-arm\embot\app;..\..\..\..\..\..\eBcode\arch-arm\embot\i2h;..\..\..\..\..\..\eBcode\arch-arm\embot\hw;..\..\..\..\..\..\eBcode\arch-arm\embot\os;..\..\..\..\..\..\eBcode\arch-arm\embot;..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core;..\..\..\..\embot\app\dsp;..\..\..\..\..\..\..\..\icub-firmware-shared\can\canProtocolLib;..\..\..\..\embot\app\skeleton;..\..\..\..\embot\prot\can;..\..\bsp;..\..\..\..\libs\midware\eventviewer\api - - - - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 4 - - - - - - - - - 0 - 0 - 0 - 0 - 1 - 0 - 0x08000000 - 0x20000000 - - .\amcbldc-application.sct - - - --diag_suppress=L6329 - - - - - - - - main - - - amcbldc-main.cpp - 8 - ..\src\amcbldc-main.cpp - - - - - stm32hal - - - stm32hal.g4.amcbldc.v120.lib + stm32hal.g4.v122.amcbldc.lib 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v122.amcbldc.lib stm32hal.startup.amcbldc.s 2 ..\cfg\stm32hal.startup.amcbldc.s - - stm32hal.g4.amcbldc.v122.lib - 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib - - - stm32hal.startup.amcbldc.v122.template.s - 2 - ..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s - @@ -3597,6 +1668,16 @@ osal.cm4.dbg.lib 4 ..\..\..\..\..\..\eBcode\arch-arm\libs\highlevel\abslayer\osal\lib\osal.cm4.dbg.lib + + + eventviewer.c + 1 + ..\..\..\..\..\..\eBcode\arch-arm\libs\midware\eventviewer\src\eventviewer.c + + + cmsisos2.lib + 4 + ..\..\..\..\libs\highlevel\abslayer\cmsisos2\lib\cmsisos2.lib 2 @@ -3617,16 +1698,6 @@ - - eventviewer.c - 1 - ..\..\..\..\..\..\eBcode\arch-arm\libs\midware\eventviewer\src\eventviewer.c - - - cmsisos2.lib - 4 - ..\..\..\..\libs\highlevel\abslayer\cmsisos2\lib\cmsisos2.lib - @@ -3735,7 +1806,76 @@ - embot::hw::lowlevel + embot::hw::lowlevel-0optimized + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 1 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + embot_hw_lowlevel.cpp @@ -3967,6 +2107,57 @@ embot_app_application_theMBDagent.cpp 8 ..\src\embot_app_application_theMBDagent.cpp + + + 2 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 1 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + @@ -3982,6 +2173,75 @@ others::motorhal + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + motorhal_config.c @@ -4005,6 +2265,31 @@ + + others::motorhal2 + + + motorhal_config.c + 8 + ..\src\motorhal2\motorhal_config.c + + + encoder.c + 8 + ..\src\motorhal2\encoder.c + + + pwm.c + 8 + ..\src\motorhal2\pwm.c + + + analog.c + 8 + ..\src\motorhal2\analog.c + + + mbd @@ -4242,10 +2527,8 @@ - - - - + + diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/amcbldc-main.cpp b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/amcbldc-main.cpp index 04c9982d3..a3fdbee80 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/amcbldc-main.cpp +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/amcbldc-main.cpp @@ -11,9 +11,16 @@ // -------------------------------------------------------------------------------------------------------------------- // config start +constexpr uint8_t minor = +#if defined(STM32HAL_DRIVER_V120) + 1; +#else + 2; +#endif + constexpr embot::app::theCANboardInfo::applicationInfo applInfo -{ - embot::prot::can::versionOfAPPLICATION {1, 0, 10}, +{ + embot::prot::can::versionOfAPPLICATION {1, minor, 11}, embot::prot::can::versionOfCANPROTOCOL {2, 0} }; diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/analog.c b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/analog.c index c0bdcc350..10b64d6f9 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/analog.c +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/analog.c @@ -29,7 +29,7 @@ #include "pwm.h" -#if !defined(HALCONFIG_DONTUSE_FLASH) +#if !defined(MOTORHALCONFIG_DONTUSE_FLASH) #include "flash.h" #endif @@ -161,12 +161,30 @@ static uint32_t k_vref = 4096 * VREFINT_NOM / mVolt; /* Measured VREF in mV. Equal to VCC */ static uint16_t vref_mV = VREF_NOM / mVolt; +#if defined(MOTORHAL_changes) && defined(MOTORHALCONFIG_DONTUSE_CURR_FILTERING) +//#warning removed filters as each one uses 8+(4*ANALOG_AVG_FILTER_LENGTH) = 520 bytes of RAM (or 4104 if ANALOG_AVG_FILTER_LENGTH = 1024) +#endif /* Average filters for current measurements */ static analogAvgFilterTypeDef cinFilter; static analogAvgFilterTypeDef cph1Filter; static analogAvgFilterTypeDef cph2Filter; static analogAvgFilterTypeDef cph3Filter; + + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new types, variables, static function prototypes required by MOTORHAL +// -------------------------------------------------------------------------------------------------------------------- + +static volatile int32_t s_analog_rawCph1 = 0; +static volatile int32_t s_analog_rawCph2 = 0; +static volatile int32_t s_analog_rawCph3 = 0; +static volatile int32_t s_analog_raw_cinput = 0; + +#endif // #if defined(MOTORHAL_changes) + /* Public variables ***************************************************************************************************/ @@ -185,12 +203,6 @@ static int32_t analogMovingAverage(analogAvgFilterTypeDef *filter, int32_t sampl return filter->avg; } -void analogMovingAverage(int16_t i1, int16_t i2, int16_t i3) -{ - analogMovingAverage(&cph1Filter, i1); - analogMovingAverage(&cph2Filter, i2); - analogMovingAverage(&cph3Filter, i3); -} /* Callback functions *************************************************************************************************/ @@ -201,9 +213,18 @@ void analogMovingAverage(int16_t i1, int16_t i2, int16_t i3) */ static void adc1_TransferComplete_cb(ADC_HandleTypeDef *hadc) { +#if defined(MOTORHAL_changes) if (0 != adc1_Buffer.vref) vref_mV = (k_vref + (adc1_Buffer.vref>>1))/adc1_Buffer.vref; else vref_mV = VREF_NOM / mVolt; + s_analog_raw_cinput = adc1_Buffer.cin; +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) analogMovingAverage(&cinFilter, adc1_Buffer.cin); +#endif +#else + if (0 != adc1_Buffer.vref) vref_mV = (k_vref + (adc1_Buffer.vref>>1))/adc1_Buffer.vref; + else vref_mV = VREF_NOM / mVolt; + analogMovingAverage(&cinFilter, adc1_Buffer.cin); +#endif } /*******************************************************************************************************************//** @@ -213,10 +234,22 @@ static void adc1_TransferComplete_cb(ADC_HandleTypeDef *hadc) */ static void adc2_HalfTransferComplete_cb(ADC_HandleTypeDef *hadc) { +#if defined(MOTORHAL_changes) + s_analog_rawCph1 = adc2_Buffer[0].cph1; + s_analog_rawCph2 = adc2_Buffer[0].cph2; + s_analog_rawCph3 = adc2_Buffer[0].cph3; + pwmSetCurrents_cb(adc2_Buffer[0].cph1, adc2_Buffer[0].cph2, adc2_Buffer[0].cph3); +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + analogMovingAverage(&cph1Filter, s_analog_rawCph1); + analogMovingAverage(&cph2Filter, s_analog_rawCph2); + analogMovingAverage(&cph3Filter, s_analog_rawCph3); +#endif +#else pwmSetCurrents_cb(adc2_Buffer[0].cph1, adc2_Buffer[0].cph2, adc2_Buffer[0].cph3); - //analogMovingAverage(&cph1Filter, adc2_Buffer[0].cph1); - //analogMovingAverage(&cph2Filter, adc2_Buffer[0].cph2); - //analogMovingAverage(&cph3Filter, adc2_Buffer[0].cph3); + analogMovingAverage(&cph1Filter, adc2_Buffer[0].cph1); + analogMovingAverage(&cph2Filter, adc2_Buffer[0].cph2); + analogMovingAverage(&cph3Filter, adc2_Buffer[0].cph3); +#endif } /*******************************************************************************************************************//** @@ -226,10 +259,22 @@ static void adc2_HalfTransferComplete_cb(ADC_HandleTypeDef *hadc) */ static void adc2_TransferComplete_cb(ADC_HandleTypeDef *hadc) { +#if defined(MOTORHAL_changes) + s_analog_rawCph1 = adc2_Buffer[1].cph1; + s_analog_rawCph2 = adc2_Buffer[1].cph2; + s_analog_rawCph3 = adc2_Buffer[1].cph3; + pwmSetCurrents_cb(adc2_Buffer[0].cph1, adc2_Buffer[1].cph2, adc2_Buffer[1].cph3); +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + analogMovingAverage(&cph1Filter, s_analog_rawCph1); + analogMovingAverage(&cph2Filter, s_analog_rawCph2); + analogMovingAverage(&cph3Filter, s_analog_rawCph3); +#endif +#else pwmSetCurrents_cb(adc2_Buffer[1].cph1, adc2_Buffer[1].cph2, adc2_Buffer[1].cph3); - //analogMovingAverage(&cph1Filter, adc2_Buffer[1].cph1); - //analogMovingAverage(&cph2Filter, adc2_Buffer[1].cph2); - //analogMovingAverage(&cph3Filter, adc2_Buffer[1].cph3); + analogMovingAverage(&cph1Filter, adc2_Buffer[1].cph1); + analogMovingAverage(&cph2Filter, adc2_Buffer[1].cph2); + analogMovingAverage(&cph3Filter, adc2_Buffer[1].cph3); +#endif } @@ -305,8 +350,17 @@ uint32_t analogVph3(void) */ int32_t analogCin(void) { +#if defined(MOTORHAL_changes) +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + int32_t raw = cinFilter.avg >> ANALOG_AVG_FILTER_SHIFT; +#else + int32_t raw = s_analog_raw_cinput; +#endif + return CIN_GAIN * vref_mV * raw >> 16u; +#else int32_t raw = cinFilter.avg >> ANALOG_AVG_FILTER_SHIFT; return CIN_GAIN * vref_mV * raw >> 16u; +#endif } /*******************************************************************************************************************//** @@ -316,9 +370,18 @@ int32_t analogCin(void) */ int32_t analogCph1(void) { - //int32_t raw = cph1Filter.avg >> ANALOG_AVG_FILTER_SHIFT; - //return CIN_GAIN * vref_mV * raw >> 16u; - return cph1Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +#if defined(MOTORHAL_changes) +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + int32_t raw = cph1Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +#else + int32_t raw = s_analog_rawCph1; +#endif + return CIN_GAIN * vref_mV * raw >> 16u; + // note that the above is: return analogConvertCurrent(analog_RawCph1()); +#else + int32_t raw = cph1Filter.avg >> ANALOG_AVG_FILTER_SHIFT; + return CIN_GAIN * vref_mV * raw >> 16u; +#endif } /*******************************************************************************************************************//** @@ -328,14 +391,18 @@ int32_t analogCph1(void) */ int32_t analogCph2(void) { - //int32_t raw = cph2Filter.avg >> ANALOG_AVG_FILTER_SHIFT; - //return CIN_GAIN * vref_mV * raw >> 16u; - return cph2Filter.avg >> ANALOG_AVG_FILTER_SHIFT; -} - -int16_t raw2mAmps(int16_t raw) -{ - return CIN_GAIN * vref_mV * raw >> 16u; +#if defined(MOTORHAL_changes) +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + int32_t raw = cph2Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +#else + int32_t raw = s_analog_rawCph2; +#endif + return CIN_GAIN * vref_mV * raw >> 16u; + // note that the above is: return analogConvertCurrent(analog_RawCph2()); +#else + int32_t raw = cph2Filter.avg >> ANALOG_AVG_FILTER_SHIFT; + return CIN_GAIN * vref_mV * raw >> 16u; +#endif } /*******************************************************************************************************************//** @@ -345,11 +412,26 @@ int16_t raw2mAmps(int16_t raw) */ int32_t analogCph3(void) { - //int32_t raw = cph3Filter.avg >> ANALOG_AVG_FILTER_SHIFT; - //return CIN_GAIN * vref_mV * raw >> 16u; - return cph3Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +#if defined(MOTORHAL_changes) +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + int32_t raw = cph3Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +#else + int32_t raw = s_analog_rawCph3; +#endif + return CIN_GAIN * vref_mV * raw >> 16u; + // note that the above is: return analogConvertCurrent(analog_RawCph3()); +#else + int32_t raw = cph3Filter.avg >> ANALOG_AVG_FILTER_SHIFT; + return CIN_GAIN * vref_mV * raw >> 16u; +#endif } +#if defined(MOTORHAL_changes) +#warning BEWARE: read the note +// note: analogGetOffsetIin() etc will very likely treat raw values of current, not mA ... +// because they manage settings proper of the ADC w/out the conversion (CIN_GAIN * vref_mV * raw >> 16u) +#endif + /*******************************************************************************************************************//** * @brief Read the offset value of the Iin sensor * @param void @@ -443,9 +525,6 @@ int32_t analogSetOffsetIph3(int32_t offs) * @param * @return */ - -#undef MainConf - HAL_StatusTypeDef analogInit(void) { HAL_StatusTypeDef result = HAL_ERROR; @@ -493,8 +572,14 @@ HAL_StatusTypeDef analogInit(void) __HAL_DMA_ENABLE_IT(hadc1.DMA_Handle, DMA_IT_TC); __HAL_DMA_ENABLE_IT(hadc2.DMA_Handle, DMA_IT_TC); /* Enable the ADC in DMA mode */ +#if defined(MOTORHAL_changes) + // applied proper cast + () around sizeof() to prevent errors and warnings if ((HAL_OK == HAL_ADC_Start_DMA(&hadc1, (uint32_t *)&adc1_Buffer, sizeof(adc1_Buffer)/(sizeof(uint16_t)))) && (HAL_OK == HAL_ADC_Start_DMA(&hadc2, (uint32_t *)&adc2_Buffer, sizeof(adc2_Buffer)/(sizeof(uint16_t))))) +#else + if ((HAL_OK == HAL_ADC_Start_DMA(&hadc1, (void *)&adc1_Buffer, sizeof(adc1_Buffer)/sizeof(uint16_t))) && + (HAL_OK == HAL_ADC_Start_DMA(&hadc2, (void *)&adc2_Buffer, sizeof(adc2_Buffer)/sizeof(uint16_t)))) +#endif { /* DMA is running now */ result = HAL_OK; @@ -505,19 +590,10 @@ HAL_StatusTypeDef analogInit(void) return result; } -HAL_StatusTypeDef analogDeinit(void) -{ - /* Stop any ADC operation */ - HAL_ADC_Stop_DMA(&hadc1); - HAL_ADC_Stop_DMA(&hadc2); - - /* uncalibrate ADCs */ - MainConf.analog.cinOffs = 0; - - return HAL_OK; -} -#if defined(HALCONFIG_DONTUSE_TESTS) + +#if defined(MOTORHALCONFIG_DONTUSE_TESTS) +void analogTest(void) {} #else /*******************************************************************************************************************//** @@ -685,6 +761,68 @@ void analogTest(void) } } -#endif // HALCONFIG_DONTUSE_TESTS +#endif // MOTORHALCONFIG_DONTUSE_TESTS + + + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new functions required by MOTORHAL +// -------------------------------------------------------------------------------------------------------------------- + + + +HAL_StatusTypeDef analog_Deinit(void) +{ + /* Stop any ADC operation */ + HAL_ADC_Stop_DMA(&hadc1); + HAL_ADC_Stop_DMA(&hadc2); + + /* uncalibrate ADCs */ + MainConf.analog.cinOffs = 0; + + return HAL_OK; +} + + +//void analog_GetRawCurrentPhases(int32_t *pi1, int32_t *pi2, int32_t *pi3) +//{ +// if((NULL != pi1) && (NULL != pi2) && (NULL != pi3)) +// { +// *pi1 = cph1Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +// *pi2 = cph2Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +// *pi3 = cph3Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +// } +//} + +int32_t analog_RawCph1(void) +{ + return cph1Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +} + +int32_t analog_RawCph2(void) +{ + return cph2Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +} + +int32_t analog_RawCph3(void) +{ + return cph3Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +} + +//int32_t analog_raw2mAmps(int32_t raw) +//{ +// return analogConvertCurrent(raw); +//} + +void analog_MovingAverage(int32_t i1, int32_t i2, int32_t i3) +{ + analogMovingAverage(&cph1Filter, i1); + analogMovingAverage(&cph2Filter, i2); + analogMovingAverage(&cph3Filter, i3); +} + +#endif // #if defined(MOTORHAL_changes) /* END OF FILE ********************************************************************************************************/ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/analog.h b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/analog.h index 76e07a4c3..dbf7ad306 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/analog.h +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/analog.h @@ -23,6 +23,7 @@ #if defined(USE_STM32HAL) #include "stm32hal.h" +#define MOTORHAL_changes #else #include #include "stm32g4xx.h" @@ -50,7 +51,6 @@ typedef struct extern int32_t analogConvertCurrent(int32_t raw); extern HAL_StatusTypeDef analogInit(void); -extern HAL_StatusTypeDef analogDeinit(void); extern uint32_t analogVcc(void); extern uint32_t analogVph1(void); extern uint32_t analogVph2(void); @@ -69,11 +69,19 @@ extern int32_t analogSetOffsetIph2(int32_t offs); extern int32_t analogGetOffsetIph3(void); extern int32_t analogSetOffsetIph3(int32_t offs); -extern int16_t raw2mAmps(int16_t raw); -extern void analogMovingAverage(int16_t i1, int16_t i2, int16_t i3); - extern void analogTest(void); + +#if defined(MOTORHAL_changes) + +extern HAL_StatusTypeDef analog_Deinit(void); +extern int32_t analog_RawCph1(void); +extern int32_t analog_RawCph2(void); +extern int32_t analog_RawCph3(void); +extern void analog_MovingAverage(int32_t i1, int32_t i2, int32_t i3); + +#endif // #if defined(MOTORHAL_changes) + #ifdef __cplusplus } /* extern "C" */ #endif /* __cplusplus */ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/encoder.c b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/encoder.c index 536b9aa9e..2f44e2860 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/encoder.c +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/encoder.c @@ -11,7 +11,7 @@ #include "motorhal_config.h" #endif - #include "embot_core.h" +#include "embot_core.h" #if defined(USE_STM32HAL) // API @@ -27,7 +27,7 @@ #if defined(USE_STM32HAL) #include "stm32hal.h" -#if !defined(HALCONFIG_DONTUSE_FLASH) +#if !defined(MOTORHALCONFIG_DONTUSE_FLASH) #include "flash.h" #endif #else @@ -50,11 +50,19 @@ /* Coversion factor from encoder step value to elctrical angle. It is given by: * encoderConvFactor = 65536 * number_of_poles / number_of_encoder_steps */ -static volatile int16_t encoderConvFactor = 0; -static volatile uint16_t electricalOffset = 0; -static volatile bool encoderCalibrated = false; -static volatile uint16_t encoderForcedValue = 0; +static int16_t encoderConvFactor = 112; +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new types, variables, static function prototypes required by MOTORHAL +// -------------------------------------------------------------------------------------------------------------------- + +static volatile uint16_t s_encoder_electricalOffset = 0; +static volatile bool s_encoder_Calibrated = false; +static volatile uint16_t s_encoder_ForcedValue = 0; + +#endif // #if defined(MOTORHAL_changes) /* Callbacks **********************************************************************************************************/ @@ -65,18 +73,26 @@ static volatile uint16_t encoderForcedValue = 0; */ void encoderIndexCallback(TIM_HandleTypeDef *htim) { +#if defined(MOTORHAL_changes) //++encoderIndex; - embot::core::print("Index!!!"); + // embot::core::print("Index!!!"); +#else + /************** + * TO BE DONE * + **************/ +#endif } /* Exported functions *************************************************************************************************/ -/*******************************************************************************************************************//** - * @brief Start TIM2 as 32 bits incremental encoders - * @param void - * @return HAL_StatusTypeDef Operation result - */ +#if defined(MOTORHAL_changes) + +// in here we dont start the timer TIM2 straight away as in gzini implementation +// rather, we just collect some data which never changes. +// we start the timer in function encoder_Config() called when we receive the encoder properties +// the function encoder_Config() uses the remaining of the code of gzini's encoderInit() + HAL_StatusTypeDef encoderInit(void) { /* here settings not managed by yarprobotinterface but still configurable */ @@ -91,7 +107,132 @@ HAL_StatusTypeDef encoderInit(void) return HAL_OK; } -HAL_StatusTypeDef encoderDeinit(void) +#else + +/*******************************************************************************************************************//** + * @brief Start TIM2 as 32 bits incremental encoders + * @param void + * @return HAL_StatusTypeDef Operation result + */ +HAL_StatusTypeDef encoderInit(void) +{ + TIM_Encoder_InitTypeDef sConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIMEx_EncoderIndexConfigTypeDef sEncoderIndexConfig = {0}; + + if (0 == MainConf.encoder.mode) + { + MainConf.encoder.mode = TIM_ENCODERMODE_TI12; + MainConf.encoder.filter = 4; + MainConf.encoder.idxpos = TIM_ENCODERINDEX_POSITION_00; + MainConf.encoder.nsteps = 4096; + } + + /* Forced, for now */ + encoderConvFactor = 112; + + /* Re-configure TIM2 base, IC1 and IC2 */ + htim2.Instance = TIM2; + htim2.Init.Prescaler = 0; + htim2.Init.CounterMode = TIM_COUNTERMODE_UP; + htim2.Init.Period = MainConf.encoder.nsteps - 1; + htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + sConfig.EncoderMode = MainConf.encoder.mode; + sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; + sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; + sConfig.IC1Prescaler = TIM_ICPSC_DIV1; + sConfig.IC1Filter = MainConf.encoder.filter; + sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; + sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; + sConfig.IC2Prescaler = TIM_ICPSC_DIV1; + sConfig.IC2Filter = MainConf.encoder.filter; + if (HAL_OK != HAL_TIM_Encoder_Init(&htim2, &sConfig)) return HAL_ERROR; + + /* Force master mode witout slaves */ + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_OK != HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig)) return HAL_ERROR; + + /* Configure the INDEX mode */ + sEncoderIndexConfig.Polarity = TIM_ENCODERINDEX_POLARITY_NONINVERTED; + sEncoderIndexConfig.Prescaler = TIM_ENCODERINDEX_PRESCALER_DIV1; + sEncoderIndexConfig.Filter = MainConf.encoder.filter; + sEncoderIndexConfig.FirstIndexEnable = DISABLE; + sEncoderIndexConfig.Position = MainConf.encoder.idxpos; + sEncoderIndexConfig.Direction = TIM_ENCODERINDEX_DIRECTION_UP_DOWN; + if (HAL_OK != HAL_TIMEx_ConfigEncoderIndex(&htim2, &sEncoderIndexConfig)) return HAL_ERROR; + + /* Register the callback function used to signal the activation of the Index pulse */ + if (HAL_OK != HAL_TIM_RegisterCallback(&htim2, HAL_TIM_ENCODER_INDEX_CB_ID, encoderIndexCallback)) return HAL_ERROR; + + /* Start timers in encoder mode */ + if (HAL_OK != HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL)) return HAL_ERROR; + __HAL_TIM_SET_COUNTER(&htim2, 0); + return HAL_OK; +} + +#endif // #if defined(MOTORHAL_changes) + +/*******************************************************************************************************************//** + * @brief Read encoder value + * @param void + * @return int32_t Encoder value + */ +uint32_t encoderGetCounter(void) +{ + return (uint32_t)__HAL_TIM_GET_COUNTER(&htim2); +} + +#if defined(MOTORHAL_changes) + +// in here we just add some controls and we call zgini implementation +// by adding an offset to it + +uint16_t encoderGetElectricalAngle(void) +{ + if (MainConf.encoder.resolution == 0) + { + return s_encoder_ForcedValue; + } + + if (MainConf.encoder.has_hall_sens) + { + if (!s_encoder_Calibrated) + { + return s_encoder_ForcedValue; + } + } + + return s_encoder_electricalOffset + (__HAL_TIM_GET_COUNTER(&htim2) * encoderConvFactor) & 0xFFFF; +} + +#else + +/*******************************************************************************************************************//** + * @brief Read encoder value and convert to electrical-angle + * @param void + * @return uint16_t Encoder value + */ +uint16_t encoderGetElectricalAngle(void) +{ + return (__HAL_TIM_GET_COUNTER(&htim2) * encoderConvFactor) & 0xFFFF; +} + + +#endif // #if defined(MOTORHAL_changes) + + + + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new functions required by MOTORHAL, be them extern or static +// -------------------------------------------------------------------------------------------------------------------- + + +HAL_StatusTypeDef encoder_Deinit(void) { HAL_TIM_Encoder_Stop(&htim2, TIM_CHANNEL_ALL); @@ -101,14 +242,14 @@ HAL_StatusTypeDef encoderDeinit(void) /* deinitialize */ encoderConvFactor = 0; - electricalOffset = 0; - encoderCalibrated = false; - encoderForcedValue = 0; + s_encoder_electricalOffset = 0; + s_encoder_Calibrated = false; + s_encoder_ForcedValue = 0; return HAL_OK; } -HAL_StatusTypeDef encoderConfig(uint8_t has_quad_enc, int16_t resolution, uint8_t num_polar_couples, uint8_t has_hall_sens) +HAL_StatusTypeDef encoder_Config(uint8_t has_quad_enc, int16_t resolution, uint8_t num_polar_couples, uint8_t has_hall_sens) { TIM_Encoder_InitTypeDef sConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; @@ -194,74 +335,34 @@ HAL_StatusTypeDef encoderConfig(uint8_t has_quad_enc, int16_t resolution, uint8_ } -/*******************************************************************************************************************//** - * @brief Read encoder value - * @param void - * @return int32_t Encoder value - */ -uint32_t encoderGetCounter(void) -{ - return (uint32_t)__HAL_TIM_GET_COUNTER(&htim2); -} - -/*******************************************************************************************************************//** - * @brief Reset encoder value - */ -void encoderReset() +void encoder_Reset() { __HAL_TIM_SET_COUNTER(&htim2, 0); } -/*******************************************************************************************************************//** - * @brief Read encoder value and convert to electrical-angle - * @param void - * @return uint16_t Encoder value - */ -uint16_t encoderGetElectricalAngle(void) -{ - - if (MainConf.encoder.resolution == 0) - { - return encoderForcedValue; - } - - if (MainConf.encoder.has_hall_sens) - { - if (!encoderCalibrated) - { - return encoderForcedValue; - } - } - - return electricalOffset + (__HAL_TIM_GET_COUNTER(&htim2) * encoderConvFactor) & 0xFFFF; -} - -uint16_t encoderGetUncalibrated(void) +uint16_t encoder_GetUncalibrated(void) { return (__HAL_TIM_GET_COUNTER(&htim2) * encoderConvFactor) & 0xFFFF; } -/*******************************************************************************************************************//** - * @brief Set encoder electrical-angle offset - * @param uint16_t Encoder offset - * @return void - */ - -void encoderForce(uint16_t value) +void encoder_Force(uint16_t value) { - encoderForcedValue = value; + s_encoder_ForcedValue = value; } -void encoderCalibrate(uint16_t offset) +void encoder_Calibrate(uint16_t offset) { - electricalOffset = offset; + s_encoder_electricalOffset = offset; - encoderCalibrated = true; + s_encoder_Calibrated = true; } -uint16_t encoderGetElectricalOffset() +uint16_t encoder_GetElectricalOffset() { - return electricalOffset; + return s_encoder_electricalOffset; } +#endif // #if defined(MOTORHAL_changes) + + /* END OF FILE ********************************************************************************************************/ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/encoder.h b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/encoder.h index c4e81aaf0..d9bc6f91c 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/encoder.h +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/encoder.h @@ -21,7 +21,8 @@ #include #if defined(USE_STM32HAL) -#include "stm32hal.h" +#include "stm32hal.h" +#define MOTORHAL_changes #else #include #include "stm32g4xx.h" @@ -30,6 +31,8 @@ /* Exported typedefs -------------------------------------------------------------------------------------------------*/ +#if defined(MOTORHAL_changes) + typedef struct { uint16_t mode; @@ -37,25 +40,43 @@ typedef struct uint16_t idxpos; int16_t resolution; uint16_t has_hall_sens; +} encoder_ConfTypeDef; + +#else + +typedef struct +{ + uint16_t mode; + uint16_t filter; + uint16_t idxpos; + uint16_t nsteps; } encoderConfTypeDef; +#endif + + + /* Exported macro ----------------------------------------------------------------------------------------------------*/ /* Exported variables ------------------------------------------------------------------------------------------------*/ /* Exported functions prototypes -------------------------------------------------------------------------------------*/ extern HAL_StatusTypeDef encoderInit(void); -extern HAL_StatusTypeDef encoderDeinit(void); -extern HAL_StatusTypeDef encoderConfig(uint8_t has_quad_enc, int16_t resolution, uint8_t num_polar_couples, uint8_t has_hall_sens); - extern uint32_t encoderGetCounter(void); -extern void encoderReset(); - extern uint16_t encoderGetElectricalAngle(void); -extern void encoderForce(uint16_t value); -extern void encoderCalibrate(uint16_t offset); -extern uint16_t encoderGetElectricalOffset(); -extern uint16_t encoderGetUncalibrated(void); + + +#if defined(MOTORHAL_changes) + +extern HAL_StatusTypeDef encoder_Deinit(void); +extern HAL_StatusTypeDef encoder_Config(uint8_t has_quad_enc, int16_t resolution, uint8_t num_polar_couples, uint8_t has_hall_sens); +extern void encoder_Reset(); +extern void encoder_Force(uint16_t value); +extern void encoder_Calibrate(uint16_t offset); +extern uint16_t encoder_GetElectricalOffset(); +extern uint16_t encoder_GetUncalibrated(void); + +#endif #ifdef __cplusplus } /* extern "C" */ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/motorhal_config.c b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/motorhal_config.c index 09930fb5c..5cc8f256b 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/motorhal_config.c +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/motorhal_config.c @@ -18,15 +18,15 @@ #include "motorhal_config.h" #endif -#if defined(HALCONFIG_DONTUSE_FLASH) +#if defined(MOTORHALCONFIG_DONTUSE_FLASH) MainConfTypeDef MainConf = {0}; #else -#endif // HALCONFIG_DONTUSE_FLASH +#endif // MOTORHALCONFIG_DONTUSE_FLASH -#if defined(HALCONFIG_ADD_IRQHANDLERS) +#if defined(MOTORHALCONFIG_ADD_IRQHANDLERS) #include "stm32hal.h" diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/motorhal_config.h b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/motorhal_config.h index 2047eb8ef..2e6840a40 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/motorhal_config.h +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/motorhal_config.h @@ -5,8 +5,8 @@ * email: marco.accame@iit.it */ -#ifndef __HALCONFIG_H -#define __HALCONFIG_H +#ifndef MOTORHAL_CONFIG_H +#define MOTORHAL_CONFIG_H #ifdef __cplusplus extern "C" { @@ -17,22 +17,24 @@ #define USE_STM32HAL #endif -#define HALCONFIG_DONTUSE_CONSOLE -#define HALCONFIG_DONTUSE_FLASH -#define HALCONFIG_DONTUSE_UTILITIES -#define HALCONFIG_DONTUSE_LED -#define HALCONFIG_DONTUSE_TESTS -#define HALCONFIG_ADD_IRQHANDLERS +#define MOTORHALCONFIG_DONTUSE_CONSOLE +#define MOTORHALCONFIG_DONTUSE_FLASH +#define MOTORHALCONFIG_DONTUSE_UTILITIES +#define MOTORHALCONFIG_DONTUSE_LED +#define MOTORHALCONFIG_DONTUSE_TESTS +#define MOTORHALCONFIG_ADD_IRQHANDLERS + +#define MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING -#if defined(HALCONFIG_DONTUSE_FLASH) +#if defined(MOTORHALCONFIG_DONTUSE_FLASH) #include "pwm.h" #include "encoder.h" #include "analog.h" typedef struct { - pwmConfTypeDef pwm; - encoderConfTypeDef encoder; + pwm_ConfTypeDef pwm; + encoder_ConfTypeDef encoder; analogConfTypeDef analog; } MainConfTypeDef; @@ -41,7 +43,7 @@ extern MainConfTypeDef MainConf; #endif -#if defined(HALCONFIG_DONTUSE_UTILITIES) +#if defined(MOTORHALCONFIG_DONTUSE_UTILITIES) // Get the MSB of an integer. The compiler generates an immediate constant value when the argument is a constant // value known at compile time. Use macro msb(x) for not constant values @@ -55,13 +57,13 @@ extern MainConfTypeDef MainConf; #define MSB$4(x) (x&0x000000000000000CLL?(2+MSB$2(x>>2)):MSB$2(x)) #define MSB$2(x) (x&0x0000000000000002LL?1:0) -#endif // HALCONFIG_DONTUSE_UTILITIES +#endif // MOTORHALCONFIG_DONTUSE_UTILITIES #ifdef __cplusplus } /* extern "C" */ #endif /* __cplusplus */ -#endif /* __HALCONFIG_H */ +#endif // MOTORHAL_CONFIG_H // - end-of-file (leave a blank line after)---------------------------------------------------------------------------- diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/pwm.c b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/pwm.c index 62444dbc8..796e45172 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/pwm.c +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/pwm.c @@ -12,7 +12,7 @@ #include "motorhal_config.h" #endif - #include "embot_core.h" +#include "embot_core.h" #if defined(USE_STM32HAL) // API @@ -22,16 +22,16 @@ /* Includes ***********************************************************************************************************/ #if defined(USE_STM32HAL) #include "stm32hal.h" -#if !defined(HALCONFIG_DONTUSE_UTILITIES) +#if !defined(MOTORHALCONFIG_DONTUSE_UTILITIES) #include "utilities.h" #endif -#if !defined(HALCONFIG_DONTUSE_FLASH) +#if !defined(MOTORHALCONFIG_DONTUSE_FLASH) #include "flash.h" #endif -#if !defined(HALCONFIG_DONTUSE_CONSOLE) +#if !defined(MOTORHALCONFIG_DONTUSE_CONSOLE) #include "console.h" #endif -#if !defined(HALCONFIG_DONTUSE_LED) +#if !defined(MOTORHALCONFIG_DONTUSE_LED) #include "led.h" #endif #else @@ -55,6 +55,9 @@ #define USE_HALL_SENSORS 1 //#define USE_ENCODER_SENSORS 1 +#if !defined(USE_ENCODER_SENSORS) +#warning USE_ENCODER_SENSORS is not defined +#endif /* Private macros *****************************************************************************************************/ @@ -70,55 +73,13 @@ /* Current value of the Hall sensors */ static volatile uint8_t hallStatus = 0; -static volatile uint8_t hallStatus_old = 0; +static volatile int16_t pwmStatus = 0; static volatile int32_t hallCounter = 0; static volatile uint16_t hallAngle = 0; -static volatile uint8_t hallOrder[3]; - -static volatile bool calibrating = true; - -//struct adc_callback_set_T -//{ -// void (*callback_fn)(void *owner, int16_t Iuvw[3], void* rtu, void* rty); -// void *owner; -// void* rtu; -// void* rty; -//}; - -//static volatile adc_callback_set_T adc_callback_set = -//{ -// NULL, NULL, NULL, NULL -//}; - -static void s_pwm_dummy_adc_callback(void *owner, const pwmCurrents_t * const currents) {} -static pwmCurrents_t s_pwm_dummy_currents = {0}; - -static volatile pwm_ADC_callback_t s_pwm_ADC_cbk = -{ - .callback = s_pwm_dummy_adc_callback, - .owner = NULL -}; - +static volatile int16_t hallCurrentPhase = 0; +static volatile int16_t hallCurrent = 0; -//void setADC_cb(void (*fn_cb)(void *, int16_t[3], void*, void*), void *owner, void* rtu, void* rty) -//{ -// adc_callback_set.callback_fn = fn_cb; -// adc_callback_set.owner = owner; -// adc_callback_set.rtu = rtu; -// adc_callback_set.rty = rty; -//} - - -extern void set_ADC_callback(pwm_ADC_callback_t *cbk) -{ - if(NULL != cbk) - { - s_pwm_ADC_cbk.callback = (NULL != cbk->callback) ? cbk->callback : s_pwm_dummy_adc_callback; - s_pwm_ADC_cbk.owner = cbk->owner; - } -} - -#if defined(USE_STM32HAL) && defined(__cplusplus) +#if defined(MOTORHAL_changes) && defined(__cplusplus) constexpr int16_t numHallSectors = 6; constexpr float_t iCubDeg = 65536.0; // Range of angular values that can be represented with the encoder @@ -153,6 +114,7 @@ constexpr uint16_t hallAngleTable[] = //}; #else + static const uint16_t hallAngleTable[] = { /* ABC (°) */ @@ -166,23 +128,58 @@ static const uint16_t hallAngleTable[] = /* HHH ERROR */ 0 }; -static const int16_t hallSectorTable[] = +#endif // #if defined(MOTORHAL_changes) && defined(__cplusplus) + + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new types, variables, static function prototypes required by MOTORHAL +// -------------------------------------------------------------------------------------------------------------------- + + +static volatile uint8_t s_pwm_hallStatus_old = 0; +static volatile uint8_t s_pwm_hallOrder[3] = {0, 0, 0}; + +static volatile bool s_pwm_calibrating = true; + +//struct pwm_adc_callback_set_T +//{ +// void (*callback_fn)(void *owner, int16_t Iuvw[3], void* rtu, void* rty); +// void *owner; +// void* rtu; +// void* rty; +//}; + +//static volatile pwm_adc_callback_set_T s_pwm_adc_callback_set = +//{ +// NULL, NULL, NULL, NULL +//}; + +static void s_pwm_dummy_adc_callback(void *owner, const pwm_Currents_t * const currents) {} +static pwm_Currents_t s_pwm_dummy_currents = {0}; + +static volatile pwm_ADC_callback_t s_pwm_ADC_cbk = { - /* ABC (°) */ - /* LLL ERROR */ 0, - /* LLH 240 */ 4, /* 43690 */ - /* LHL 120 */ 2, /* 21845 */ - /* LHH 180 */ 3, /* 32768 */ - /* HLL 0 */ 0, /* 0 */ - /* HLH 300 */ 5, /* 54613 */ - /* HHL 60 */ 1, /* 10922 */ - /* HHH ERROR */ 0 + .callback = s_pwm_dummy_adc_callback, + .owner = NULL }; -#endif + + +static uint8_t s_pwm_updateHallStatus(void); + +#endif // #if defined(MOTORHAL_changes) /* Public variables ***************************************************************************************************/ /* Private functions **************************************************************************************************/ +#if defined(MOTORHAL_changes) + +// we dont need: static void hallSetPWM(int16_t pwm) +// but a s_pwm_updateHallStatus() + +#else + /*******************************************************************************************************************//** * @brief Read the current Hall sensor status and configure signals EN1, EN2, EN3, PHASE1, PHASE2, PHASE3 as for a * CW or CCW torque @@ -210,131 +207,190 @@ static const int16_t hallSectorTable[] = * LOW means that PHASEx is in LOW state (ENx = 1, PWMx = 0) * PWM means that PHASEx is modulated with the pwm value (ENx = 1, PWMx = pwm) */ - -#define DECODE_HALLSTATUS (((HALL1_GPIO_Port->IDR & HALL1_Pin) >> MSB(HALL1_Pin)) << hallOrder[0]) \ - | (((HALL2_GPIO_Port->IDR & HALL2_Pin) >> MSB(HALL2_Pin)) << hallOrder[1]) \ - | (((HALL3_GPIO_Port->IDR & HALL3_Pin) >> MSB(HALL3_Pin)) << hallOrder[2]) - -static uint8_t updateHallStatus(void) +static void hallSetPWM(int16_t pwm) { - hallStatus_old = hallStatus; - static int8_t calibration_step = 0; - - static uint16_t border[6]={0}; - static uint8_t border_flag = 0; +#ifdef USE_HALL_SENSORS + /* Remeber previous value */ + uint8_t hall = hallStatus; +#endif /* Read current value of HALL1, HALL2 and HALL3 signals in bits 2..0 */ - hallStatus = DECODE_HALLSTATUS; - uint16_t angle = MainConf.pwm.hall_offset + hallAngleTable[hallStatus]; - - // Check which sector between [0 ... 5] the rotor is in - int16_t sector = ((minHallAngleDelta + angle) / hallAngleStep) % numHallSectors; - static int16_t sector_old = sector; - - hallAngle = angle; - - if (MainConf.encoder.resolution == 0) // no encoder - { - encoderForce(angle); - } - else + hallStatus = (((HALL1_GPIO_Port->IDR & HALL1_Pin) >> MSB(HALL1_Pin)) << 2) + | (((HALL2_GPIO_Port->IDR & HALL2_Pin) >> MSB(HALL2_Pin)) << 1) + | (((HALL3_GPIO_Port->IDR & HALL3_Pin) >> MSB(HALL3_Pin)) << 0); + +#ifdef USE_HALL_SENSORS + /* Current hall sensors status */ + switch (hallStatus) { - if (!hallStatus_old) - { - hallCounter = 0; - encoderReset(); - encoderForce(angle); - } - else - { - // Check if the motor is rotating forward (counterclockwise) - bool forward = ((sector-sector_old+numHallSectors)%numHallSectors)==1; - - if (forward) // forward + case 0x05: + /* PHASE1=pwm, PHASE2=-pwm, PHASE3=hiz */ + EN1_GPIO_Port->BSRR = EN1_Pin | EN2_Pin | (EN3_Pin<<16) ; + /* CW rotation */ + if (pwm >= 0) { - ++hallCounter; - angle -= minHallAngleDelta; // -30 deg + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + hallCurrentPhase = HALL_CURRENT_PHASE1; } + /* CCW rotation */ else { - --hallCounter; - angle += minHallAngleDelta; // +30 deg + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, -pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + hallCurrentPhase = HALL_CURRENT_PHASE2; } - /* - 0) Use the Hall sensors to rotate until the wrap-around border is reached, - then reset the encoder value - */ - if (calibration_step == 0) + /* Verify previous HALL sensors status */ + if (hall == 0x01) ++hallCounter; + else if (hall == 0x04) --hallCounter; + break; + + case 0x04: + /* PHASE1=pwm, PHASE2=hiz, PHASE3=-pwm */ + EN1_GPIO_Port->BSRR = EN1_Pin | (EN2_Pin<<16) | EN3_Pin ; + /* CW rotation */ + if (pwm >= 0) { - encoderForce(angle); - - if ((sector == 0 && sector_old == 5) || (sector == 5 && sector_old == 0)) - { - encoderReset(); - calibration_step = 1; - } + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + hallCurrentPhase = HALL_CURRENT_PHASE1; } - /* - 1) Use the hall sensors to rotate. While rotating, store the encoder angle - every time a sector border is crossed. When all 6 borders are crossed, - compute the offset to apply to the encoder by least squares fitting. After - the offset is applied set encoderCalibrated to true - */ - else if (calibration_step == 1) + /* CCW rotation */ + else { - encoderForce(angle); - - // use the current sector if forward rotation or previous if reverse - uint8_t sector_index = forward ? sector : (sector+1)%numHallSectors; - - // keep track of the encoder value between sectors - border[sector_index] = encoderGetUncalibrated(); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, -pwm); + hallCurrentPhase = HALL_CURRENT_PHASE3; + } + /* Verify previous HALL sensors status */ + if (hall == 0x05) ++hallCounter; + else if (hall == 0x06) --hallCounter; + break; - // found the s-th border, put a 1 in the mask - border_flag |= 1 << sector_index; - - // If all sectors are found apply least squares fitting by computing average of - // difference between measured values on borders and expected hall angle - if (border_flag == 63) // 111111 - { - calibration_step = 2; - - int32_t offset = int16_t(border[0] - MainConf.pwm.hall_offset + minHallAngleDelta); - offset += int16_t(border[1] - MainConf.pwm.hall_offset + minHallAngleDelta - hallAngleStep); - offset += int16_t(border[2] - MainConf.pwm.hall_offset + minHallAngleDelta - 2 * hallAngleStep); - offset += int16_t(border[3] - MainConf.pwm.hall_offset + minHallAngleDelta - 3 * hallAngleStep); - offset += int16_t(border[4] - MainConf.pwm.hall_offset + minHallAngleDelta - 4 * hallAngleStep); - offset += int16_t(border[5] - MainConf.pwm.hall_offset + minHallAngleDelta - 5 * hallAngleStep); - - offset /= numHallSectors; - - embot::core::print("CALIBRATED\n"); - - encoderCalibrate(int16_t(offset)); - } + case 0x06: + /* PHASE1=hiz, PHASE2=pwm, PHASE3=-pwm */ + EN1_GPIO_Port->BSRR = (EN1_Pin<<16) | EN2_Pin | EN3_Pin; + /* CW rotation */ + if (pwm >= 0) + { + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + hallCurrentPhase = HALL_CURRENT_PHASE2; } - /* - 2) Update the forced value even if it is not used when the encoder is calibrated. - Reset the encoder angle after a full rotation to avoid desynching - */ - else if (calibration_step == 2) + /* CCW rotation */ + else { - encoderForce(angle); - // reset the angle after full rotation - if ((sector == 0 && sector_old == 5) || (sector == 5 && sector_old == 0)) - { - encoderReset(); - } + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, -pwm); + hallCurrentPhase = HALL_CURRENT_PHASE3; } - } + /* Verify previous HALL sensors status */ + if (hall == 0x04) ++hallCounter; + else if (hall == 0x02) --hallCounter; + break; + + case 0x02: + /* PHASE1=-pwm, PHASE2=pwm, PHASE3=hiz */ + EN1_GPIO_Port->BSRR = EN1_Pin | EN2_Pin | (EN3_Pin<<16) ; + /* CW rotation */ + if (pwm >= 0) + { + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + hallCurrentPhase = HALL_CURRENT_PHASE2; + } + /* CCW rotation */ + else + { + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, -pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + hallCurrentPhase = HALL_CURRENT_PHASE1; + } + /* Verify previous HALL sensors status */ + if (hall == 0x06) ++hallCounter; + else if (hall == 0x03) --hallCounter; + break; + + case 0x03: + /* PHASE1=-pwm, PHASE2=hiz, PHASE3=pwm */ + EN1_GPIO_Port->BSRR = EN1_Pin | (EN2_Pin<<16) | EN3_Pin ; + /* CW rotation */ + if (pwm >= 0) + { + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, pwm); + hallCurrentPhase = HALL_CURRENT_PHASE3; + } + /* CCW rotation */ + else + { + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, -pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + hallCurrentPhase = HALL_CURRENT_PHASE1; + } + /* Verify previous HALL sensors status */ + if (hall == 0x02) ++hallCounter; + else if (hall == 0x01) --hallCounter; + break; + + case 0x01: + /* PHASE1=hiz, PHASE2=-pwm, PHASE3=pwm */ + EN1_GPIO_Port->BSRR = (EN1_Pin<<16) | EN2_Pin | EN3_Pin; + /* CW rotation */ + if (pwm >= 0) + { + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, pwm); + hallCurrentPhase = HALL_CURRENT_PHASE3; + } + /* CCW rotation */ + else + { + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, -pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + hallCurrentPhase = HALL_CURRENT_PHASE2; + } + /* Verify previous HALL sensors status */ + if (hall == 0x03) ++hallCounter; + else if (hall == 0x05) --hallCounter; + break; + + default: + /* ERROR: forbitten combination */ + ledSet(LED2, 0); + EN1_GPIO_Port->BSRR = ((EN3_Pin|EN2_Pin|EN1_Pin)<<16); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + pwm = 0; + break; } - // update the old sector and hall status - sector_old = sector; - hallStatus_old = hallStatus; +#endif - return hallStatus; + /* Update pwm status */ + pwmStatus = pwm; + + /* Update angle */ + hallAngle = hallAngleTable[hallStatus]; } + +#endif // #if defined(MOTORHAL_changes) + + + /* Callback functions *************************************************************************************************/ /*******************************************************************************************************************//** @@ -354,12 +410,14 @@ static void pwmMotorFault_cb(TIM_HandleTypeDef *htim) __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); - +#if defined(MOTORHAL_changes) +#else + /* Null output voltage */ + pwmStatus = 0; /* Advertise the fault */ -#if defined(HALCONFIG_DONTUSE_LED) -#else ledSet(LED2, 0); -#endif +#endif + } } @@ -374,55 +432,93 @@ static void hallStatusChange_cb(TIM_HandleTypeDef *htim) /* Check TIM3 already initialized */ if (TIM3 == htim->Instance) { - updateHallStatus(); +#if defined(MOTORHAL_changes) + s_pwm_updateHallStatus(); +#else + /* Generate the correct PWM configuration following the pwmStatus pattern */ + hallSetPWM(pwmStatus); +#endif } } +#if defined(MOTORHAL_changes) -/*******************************************************************************************************************//** - * @brief Called by DMA associated to ADC2 whenever a new set of phase currents is available - * @param i1, i2, i3 Currents measured in PHASE1, PHASE2 and PHASE3 of the motor - * @return void - */ void pwmSetCurrents_cb(int16_t i1, int16_t i2, int16_t i3) { - static pwmCurrents_t currents = {0}; - // as soon as possible: copy the currents - currents.u = raw2mAmps(i1); - currents.v = raw2mAmps(i2); - currents.w = raw2mAmps(i3); + static pwm_Currents_t currents = {0}; + // as soon as possible: copy the currents (must be converted from raw as i1, i2, i3 come from ADC) + currents.u = analogConvertCurrent(i1); + currents.v = analogConvertCurrent(i2); + currents.w = analogConvertCurrent(i3); - if (calibrating) + // so far, calibration is done only at startup of current acquisition and not at runtime + if (s_pwm_calibrating) { - static int16_t counter = 0; - - if (counter < 1000) + // we must call the filtering of {1, i2, i3} at least for ANALOG_AVG_FILTER_LENGTH times. + // because ... we want to load the full filter so that ANALOG_AVG_FILTER_LENGTH values are accumulated + // correctly before we can get the average value with the division. + constexpr uint16_t maxIter {1024}; // {ANALOG_AVG_FILTER_LENGTH + 10}; // was 1000 + static uint16_t counter = 0; + + if (counter < maxIter) { ++counter; - - analogMovingAverage(i1, i2, i3); +#if defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + // give the values to the filters + analog_MovingAverage(i1, i2, i3); +#else + // dont do filtering because it will be done inside adc2_HalfTransferComplete_cb() + // and adc2_TransferComplete_cb() +#endif } else - { - analogSetOffsetIph1(analogCph1() + analogGetOffsetIph1()); - analogSetOffsetIph2(analogCph2() + analogGetOffsetIph2()); - analogSetOffsetIph3(analogCph3() + analogGetOffsetIph3()); - - calibrating = false; + { + // never mind if we have macro MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING defined or not + // now we surely have filtered values of currents, so we can use + // their raw values to impose their offsets + analogSetOffsetIph1(analog_RawCph1() + analogGetOffsetIph1()); + analogSetOffsetIph2(analog_RawCph2() + analogGetOffsetIph2()); + analogSetOffsetIph3(analog_RawCph3() + analogGetOffsetIph3()); + + // and we dont need to calibrate anymore. + s_pwm_calibrating = false; + counter = 0; + //if we set counter = 0 now, we can maybe decide to start / restart a runtime calibration + // by imposing s_pwm_calibrating = true inside some extern function } } s_pwm_ADC_cbk.callback(s_pwm_ADC_cbk.owner, ¤ts); } - -/* Exported functions *************************************************************************************************/ - +#else /*******************************************************************************************************************//** - * @brief Complete the CubeMx TIM1 configuration for the PWM subsystem - * @param void + * @brief Called by DMA associated to ADC2 whenever a new set of phase currents is available + * @param i1, i2, i3 Currents measured in PHASE1, PHASE2 and PHASE3 of the motor * @return void */ +void pwmSetCurrents_cb(int16_t i1, int16_t i2, int16_t i3) +{ + switch (hallCurrentPhase) + { + case HALL_CURRENT_PHASE1: + hallCurrent = i1; + break; + case HALL_CURRENT_PHASE2: + hallCurrent = i2; + break; + case HALL_CURRENT_PHASE3: + hallCurrent = i3; + break; + } +} + +#endif // #if defined(MOTORHAL_changes) + +/* Exported functions *************************************************************************************************/ + +#if defined(MOTORHAL_changes) + HAL_StatusTypeDef pwmInit(void) { /* todo: no HALL sensor motor index startup calibration */ @@ -448,7 +544,7 @@ HAL_StatusTypeDef pwmInit(void) /* Reset the PWM value */ pwmSet(0, 0 ,0); - //updateHallStatus(); + //s_pwm_updateHallStatus(); /* Start TIM1 as 3-phase PWM generator */ if (HAL_OK != HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1) || @@ -467,12 +563,56 @@ HAL_StatusTypeDef pwmInit(void) return HAL_OK; } -//HAL_StatusTypeDef pwmDeinit(void) -//{ -// pwmPhaseDisable(PWM_PHASE_ALL); -// -// return HAL_OK; -//} +#else + +/*******************************************************************************************************************//** + * @brief Complete the CubeMx TIM1 configuration for the PWM subsystem + * @param void + * @return void + */ +HAL_StatusTypeDef pwmInit(void) +{ + /* Clear any preceeding fault condition */ + pwmReset(ENABLE); + pwmSleep(DISABLE); + HAL_Delay(10); + pwmReset(DISABLE); + HAL_Delay(10); + + if (0 == (MainConf.pwm.mode & PWM_CONF_MODE_MASK)) + { + MainConf.pwm.mode = PWM_CONF_MODE_HALL; + MainConf.pwm.poles = 7; + } + + /* Register the required TIM1 callback functions */ + HAL_TIM_RegisterCallback(&htim1, HAL_TIM_BREAK_CB_ID, pwmMotorFault_cb); + __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_BREAK); + + /* Reset the PWM value */ + hallSetPWM(pwmStatus); + + /* Start TIM1 as 3-phase PWM generator */ + if (HAL_OK != HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1) || + HAL_OK != HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2) || + HAL_OK != HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3) || + HAL_OK != HAL_TIM_Base_Start_IT(&htim1)) + { + HAL_TIM_Base_Stop(&htim1); + HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_1); + HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_2); + HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_3); + return HAL_ERROR; + } + + /* All done */ + return HAL_OK; +} + +#endif // #if defined(MOTORHAL_changes) + + + /*******************************************************************************************************************//** * @brief Complete the CubeMx TIM3 configuration for the PWM subsystem @@ -481,6 +621,16 @@ HAL_StatusTypeDef pwmInit(void) */ HAL_StatusTypeDef hallInit(void) { +#if defined(MOTORHAL_changes) +#else + /* Read value of HALL1, HALL2 and HALL3 signals in bits 2..0 */ + hallStatus = (((HALL1_GPIO_Port->IDR & HALL1_Pin) >> MSB(HALL1_Pin)) << 2) + | (((HALL2_GPIO_Port->IDR & HALL2_Pin) >> MSB(HALL2_Pin)) << 1) + | (((HALL3_GPIO_Port->IDR & HALL3_Pin) >> MSB(HALL3_Pin)) << 0); + + /* Init angle */ + hallAngle = hallAngleTable[hallStatus]; +#endif // #if defined(MOTORHAL_changes) /* Start position counter */ hallCounter = 0; @@ -493,27 +643,6 @@ HAL_StatusTypeDef hallInit(void) (HAL_OK == HAL_TIM_Base_Start_IT(&htim3)))? HAL_OK : HAL_ERROR; } -HAL_StatusTypeDef hallDeinit(void) -{ - return HAL_OK; -} - -HAL_StatusTypeDef hallConfig(uint8_t swapBC, uint16_t pwm_hall_offset) -{ - MainConf.pwm.hall_offset = pwm_hall_offset; - MainConf.pwm.swapBC = swapBC; - - hallOrder[0] = 0; - hallOrder[1] = MainConf.pwm.swapBC ? 2 : 1; - hallOrder[2] = MainConf.pwm.swapBC ? 1 : 2; - - updateHallStatus(); - - /* Start position counter */ - hallCounter = 0; - - return HAL_OK; -} /*******************************************************************************************************************//** * @brief Read the position counter driven by the Hall sensors @@ -559,6 +688,17 @@ uint16_t hallGetStatus(void) } +/*******************************************************************************************************************//** + * @brief Read the phase current in hall 6-step mode + * @param void + * @return int16_t Current in mA + */ +int16_t hallGetCurrent(void) +{ + return hallStatus; +} + + /*******************************************************************************************************************//** * @brief Enter or Exit the SLEEP mode of the motor driver * @param enable It can assume one of the following values: @@ -598,18 +738,24 @@ HAL_StatusTypeDef pwmResetFault(void) pwmSleep(DISABLE); if (GPIO_PIN_SET == HAL_GPIO_ReadPin(nMFAULT_GPIO_Port, nMFAULT_Pin)) { +#if defined(MOTORHAL_changes) pwmPhaseEnable(PWM_PHASE_ALL); +#else +#ifdef USE_ENCODER_SENSORS + pwmPhaseEnable(PWM_PHASE_ALL); +#endif +#endif __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_BREAK); __HAL_TIM_CLEAR_IT(&htim1, TIM_IT_BREAK); __HAL_TIM_MOE_ENABLE(&htim1); HAL_Delay(10); __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_BREAK); -#if defined(HALCONFIG_DONTUSE_LED) +#if defined(MOTORHAL_changes) #else ledSet(0, LED2); #endif return HAL_OK; } -#if defined(HALCONFIG_DONTUSE_LED) +#if defined(MOTORHAL_changes) #else ledSet(LED2, 0); #endif @@ -624,8 +770,9 @@ HAL_StatusTypeDef pwmResetFault(void) */ void pwmSet(uint16_t u, uint16_t v, uint16_t w) { - if (calibrating) u = v = w = 0; - +#if defined(MOTORHAL_changes) + if (s_pwm_calibrating) u = v = w = 0; +#endif /* Saturate arguments */ if (u > (uint16_t)MAX_PWM) u = MAX_PWM; if (v > (uint16_t)MAX_PWM) v = MAX_PWM; @@ -671,10 +818,24 @@ void pwmPhaseDisable(uint16_t mask) */ HAL_StatusTypeDef pwmSetValue(int32_t pwm) { +#if defined(MOTORHAL_changes) + return HAL_ERROR; +#else + if ((pwm >= -(int32_t)MAX_PWM) && (pwm <= (int32_t)MAX_PWM)) + { +#ifdef USE_HALL_SENSORS + __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3); + hallSetPWM(pwm); + __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3); +#endif + return HAL_OK; + } return HAL_ERROR; +#endif } -#if defined(HALCONFIG_DONTUSE_TESTS) +#if defined(MOTORHALCONFIG_DONTUSE_TESTS) +void pwmTest(void) {} #else /*******************************************************************************************************************//** @@ -761,6 +922,194 @@ void pwmTest(void) } } -#endif // HALCONFIG_DONTUSE_TESTS +#endif // MOTORHALCONFIG_DONTUSE_TESTS + + + + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new functions required by MOTORHAL +// -------------------------------------------------------------------------------------------------------------------- + + + +extern void pwm_set_ADC_callback(pwm_ADC_callback_t *cbk) +{ + if(NULL != cbk) + { + s_pwm_ADC_cbk.callback = (NULL != cbk->callback) ? cbk->callback : s_pwm_dummy_adc_callback; + s_pwm_ADC_cbk.owner = cbk->owner; + } +} + +//HAL_StatusTypeDef pwm_Deinit(void) +//{ +// pwmPhaseDisable(PWM_PHASE_ALL); +// +// return HAL_OK; +//} + + +HAL_StatusTypeDef pwm_hallDeinit(void) +{ + return HAL_OK; +} + + +#define DECODE_HALLSTATUS (((HALL1_GPIO_Port->IDR & HALL1_Pin) >> MSB(HALL1_Pin)) << s_pwm_hallOrder[0]) \ + | (((HALL2_GPIO_Port->IDR & HALL2_Pin) >> MSB(HALL2_Pin)) << s_pwm_hallOrder[1]) \ + | (((HALL3_GPIO_Port->IDR & HALL3_Pin) >> MSB(HALL3_Pin)) << s_pwm_hallOrder[2]) + +static uint8_t s_pwm_updateHallStatus(void) +{ + s_pwm_hallStatus_old = hallStatus; + static int8_t calibration_step = 0; + + static uint16_t border[6]={0}; + static uint8_t border_flag = 0; + + /* Read current value of HALL1, HALL2 and HALL3 signals in bits 2..0 */ + hallStatus = DECODE_HALLSTATUS; + uint16_t angle = MainConf.pwm.hall_offset + hallAngleTable[hallStatus]; + + // Check which sector between [0 ... 5] the rotor is in + int16_t sector = ((minHallAngleDelta + angle) / hallAngleStep) % numHallSectors; + static int16_t sector_old = sector; + + hallAngle = angle; + + if (MainConf.encoder.resolution == 0) // no encoder + { + encoder_Force(angle); + } + else + { + if (!s_pwm_hallStatus_old) + { + hallCounter = 0; + encoder_Reset(); + encoder_Force(angle); + } + else + { + // Check if the motor is rotating forward (counterclockwise) + bool forward = ((sector-sector_old+numHallSectors)%numHallSectors)==1; + + if (forward) // forward + { + ++hallCounter; + angle -= minHallAngleDelta; // -30 deg + } + else + { + --hallCounter; + angle += minHallAngleDelta; // +30 deg + } + /* + 0) Use the Hall sensors to rotate until the wrap-around border is reached, + then reset the encoder value + */ + if (calibration_step == 0) + { + encoder_Force(angle); + + if ((sector == 0 && sector_old == 5) || (sector == 5 && sector_old == 0)) + { + encoder_Reset(); + calibration_step = 1; + } + } + /* + 1) Use the hall sensors to rotate. While rotating, store the encoder angle + every time a sector border is crossed. When all 6 borders are crossed, + compute the offset to apply to the encoder by least squares fitting. After + the offset is applied set encoderCalibrated to true + */ + else if (calibration_step == 1) + { + encoder_Force(angle); + + // use the current sector if forward rotation or previous if reverse + uint8_t sector_index = forward ? sector : (sector+1)%numHallSectors; + + // keep track of the encoder value between sectors + border[sector_index] = encoder_GetUncalibrated(); + + // found the s-th border, put a 1 in the mask + border_flag |= 1 << sector_index; + + // If all sectors are found apply least squares fitting by computing average of + // difference between measured values on borders and expected hall angle + if (border_flag == 63) // 111111 + { + calibration_step = 2; + + int32_t offset = int16_t(border[0] - MainConf.pwm.hall_offset + minHallAngleDelta); + offset += int16_t(border[1] - MainConf.pwm.hall_offset + minHallAngleDelta - hallAngleStep); + offset += int16_t(border[2] - MainConf.pwm.hall_offset + minHallAngleDelta - 2 * hallAngleStep); + offset += int16_t(border[3] - MainConf.pwm.hall_offset + minHallAngleDelta - 3 * hallAngleStep); + offset += int16_t(border[4] - MainConf.pwm.hall_offset + minHallAngleDelta - 4 * hallAngleStep); + offset += int16_t(border[5] - MainConf.pwm.hall_offset + minHallAngleDelta - 5 * hallAngleStep); + + offset /= numHallSectors; + + embot::core::print("CALIBRATED\n"); + + encoder_Calibrate(int16_t(offset)); + } + } + /* + 2) Update the forced value even if it is not used when the encoder is calibrated. + Reset the encoder angle after a full rotation to avoid desynching + */ + else if (calibration_step == 2) + { + encoder_Force(angle); + // reset the angle after full rotation + if ((sector == 0 && sector_old == 5) || (sector == 5 && sector_old == 0)) + { + encoder_Reset(); + } + } + } + } + // update the old sector and hall status + sector_old = sector; + s_pwm_hallStatus_old = hallStatus; + + return hallStatus; +} + + +HAL_StatusTypeDef pwm_hallConfig(uint8_t swapBC, uint16_t pwm_hall_offset) +{ + MainConf.pwm.hall_offset = pwm_hall_offset; + MainConf.pwm.swapBC = swapBC; + + s_pwm_hallOrder[0] = 0; + s_pwm_hallOrder[1] = MainConf.pwm.swapBC ? 2 : 1; + s_pwm_hallOrder[2] = MainConf.pwm.swapBC ? 1 : 2; + + s_pwm_updateHallStatus(); + + /* Start position counter */ + hallCounter = 0; + + return HAL_OK; +} + +//void pwm_setADC_cb(void (*fn_cb)(void *, int16_t[3], void*, void*), void *owner, void* rtu, void* rty) +//{ +// s_pwm_adc_callback_set.callback_fn = fn_cb; +// s_pwm_adc_callback_set.owner = owner; +// s_pwm_adc_callback_set.rtu = rtu; +// s_pwm_adc_callback_set.rty = rty; +//} + + + +#endif // #if defined(MOTORHAL_changes) /* END OF FILE ********************************************************************************************************/ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/pwm.h b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/pwm.h index e021c5930..1a13c5e5b 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/pwm.h +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal/pwm.h @@ -22,7 +22,8 @@ #include #if defined(USE_STM32HAL) -#include "stm32hal.h" +#include "stm32hal.h" +#define MOTORHAL_changes #else #include #include "analog.h" @@ -46,6 +47,8 @@ /* Exported typedefs -------------------------------------------------------------------------------------------------*/ +#if defined(MOTORHAL_changes) + typedef struct { uint32_t mode; @@ -53,16 +56,29 @@ typedef struct //uint16_t sector_offset; uint8_t num_polar_couples; uint8_t swapBC; +} pwm_ConfTypeDef; + +#else + +typedef struct +{ + uint32_t mode; + uint32_t poles; } pwmConfTypeDef; +#endif + +#if defined(MOTORHAL_changes) + // we keep int32_t even if the adc gets only int16_t values typedef struct { int32_t u; int32_t v; int32_t w; -} pwmCurrents_t; +} pwm_Currents_t; +#endif /* Exported variables ------------------------------------------------------------------------------------------------*/ @@ -71,15 +87,12 @@ typedef struct /* Exported functions prototypes -------------------------------------------------------------------------------------*/ extern HAL_StatusTypeDef hallInit(void); -HAL_StatusTypeDef hallDeinit(void); -HAL_StatusTypeDef hallConfig(uint8_t swapBC, uint16_t pwm_hall_offset); extern int32_t hallGetCounter(void); extern void hallSetCounter(int32_t count); extern uint16_t hallGetAngle(void); extern uint16_t hallGetStatus(void); extern HAL_StatusTypeDef pwmInit(void); -//extern HAL_StatusTypeDef pwmDeinit(void); extern void pwmSleep(FunctionalState enable); extern void pwmReset(FunctionalState enable); extern HAL_StatusTypeDef pwmResetFault(void); @@ -88,10 +101,23 @@ extern void pwmSet(uint16_t u, uint16_t v, uint16_t w); extern void pwmPhaseEnable(uint16_t mask); extern void pwmPhaseDisable(uint16_t mask); -extern HAL_StatusTypeDef pwmSetValue(int32_t pwm); /* DEPRECATED: it returns HAL_ERROR */ +// pwmSetCurrents_cb(): REWRITTEN by iCubTech +extern void pwmSetCurrents_cb(int16_t i1, int16_t i2, int16_t i3); +extern HAL_StatusTypeDef pwmSetValue(int32_t pwm); /* DEPRECATED */ extern void pwmTest(void); -//extern void setADC_cb(void (*fn_cb)(void *, int16_t[3], void*, void*), void *owner, void* rtu, void* rty); + + +#if defined(MOTORHAL_changes) + +HAL_StatusTypeDef pwm_hallDeinit(void); +HAL_StatusTypeDef pwm_hallConfig(uint8_t swapBC, uint16_t pwm_hall_offset); + +//extern HAL_StatusTypeDef pwm_Deinit(void); + + + +//extern void pwm_setADC_cb(void (*fn_cb)(void *, int16_t[3], void*, void*), void *owner, void* rtu, void* rty); // a function of this type is used by the ADC IRQ Handler to report the measured currents to higher levels // we need two param to to the job: @@ -100,7 +126,7 @@ extern void pwmTest(void); // - currents: is a pointer to the three currents. the memory pointed by currents belongs to owner // so that the caller of the callback will just copy the memory of the ADC (typically DMA memory) // straigth away to destination to avoid corruptions. -typedef void (*pwm_fp_adc_callback_t) (void *owner, const pwmCurrents_t * const currents); +typedef void (*pwm_fp_adc_callback_t) (void *owner, const pwm_Currents_t * const currents); typedef struct @@ -115,16 +141,20 @@ typedef struct // and in here is explained the mechanism of the ADC: // the ADC uses DMA to gets its values. the DMA peridically calls function pwmSetCurrents_cb() // at half transfer and at end transfer. this function performs calibration if required, and -// calls a user-defined function which we can set with set_ADC_callback() so that the values +// calls a user-defined function which we can set with pwm_set_ADC_callback() so that the values // of currents can be used by other software modules. -extern void set_ADC_callback(pwm_ADC_callback_t *cbk); +extern void pwm_set_ADC_callback(pwm_ADC_callback_t *cbk); // this function must be used only inside the file analog.c ..... // it is called at the completion of dma transfer (both half and full). then this function may call a user defined -// callback spefified by set_ADC_callback(). +// callback spefified by pwm_set_ADC_callback(). // to do: i may remove it from the public API to avoid confusion -extern void pwmSetCurrents_cb(int16_t i1, int16_t i2, int16_t i3); +// extern void pwmSetCurrents_cb(int16_t i1, int16_t i2, int16_t i3); + +#endif // #if defined(MOTORHAL_changes) + + #ifdef __cplusplus diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/analog.c b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/analog.c new file mode 100644 index 000000000..4721e0afe --- /dev/null +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/analog.c @@ -0,0 +1,805 @@ +/*******************************************************************************************************************//** + * @file analog.c + * @author G.Zini + * @version 1.0 + * @date 2021 January, 20 + * @brief Analog signals management + **********************************************************************************************************************/ + +// CODE SHAPER +#if defined(USE_STM32HAL) +#include "motorhal_config.h" +#endif + +#if defined(USE_STM32HAL) +// API +#include "analog.h" +#endif + +/* Includes ***********************************************************************************************************/ +#include +#include +#include +#include +#include +#include + +#if defined(USE_STM32HAL) +#include "stm32hal.h" + +#include "pwm.h" + +#if !defined(MOTORHALCONFIG_DONTUSE_FLASH) +#include "flash.h" +#endif + +#else +#include "adc.h" +#include "analog.h" +#include "console.h" +#include "flash.h" +#include "led.h" +#include "main.h" +#include "pwm.h" +#include "utilities.h" +#include "FreeRTOS.h" +#include "task.h" + +#endif + +#if (USE_HAL_ADC_REGISTER_CALLBACKS != 1) + #error Flag ADC1 in menu "Project Manager -> Advanced Settings -> Register CallBack" of CubeMx must be ENABLED +#endif + + +/* Private macros *****************************************************************************************************/ + +/* Calibration parameter stored by the manufacturer + * Given: + * VREF Current reference voltage (VREF pin. About 3300 mV) + * VREFINT Current ADC measurement of VREFIN channel (About 1504 raw) + * VREF_CAL Reference voltage during manufacturer calibration (3000 mV) + * VREFINT_CAL ADC measurement of VREFIN channel during manufacturer calibration (about 1655 raw) + * + * The following equation holds: + * VREFINT * VREF = VREFINT_CAL * VREF_CAL + * + * Hence: + * VREF = VREFINT_CAL * VREF_CAL / VREFINT = k_vref / VREFINT; + * + * The product k_vref = VREFINT_CAL * VREF_CAL is costant hence it can be evaluated in advance, during initialization. + * The current VREF voltage can be tracked any time a new VREFINT value is measured + */ +#define VREF_CAL ((double)VREFINT_CAL_VREF) /* 3000 mV */ +#define VREFINT_CAL (*VREFINT_CAL_ADDR) /* about 1655 */ +#define VREF_NOM (3.300 * Volt) +#define VREFINT_NOM (1.212 * Volt) + +/* Scaling factor */ +#define SCALING_FACTOR (65536.0/4096.0) + +/* Hardware component definitions */ +#define kOhm (1000.0) +#define Ohm (1.000) +#define mOhm (0.001) +#define Volt (1.000) +#define mVolt (0.001) +#define uVolt (0.000001) +#define nVolt (0.000000001) +#define Ampere (1.000) +#define mAmpere (0.001) + +/* Hardware related constants */ +#define R37 (560.0 * kOhm) +#define R43 (560.0 * kOhm) +#define R44 (33.0 * kOhm) +#define R47 (33.0 * kOhm) +#define ACS70331_OFFS (1500.0 * mVolt) +#define ACS70331_GAIN (2.5 * Ampere/Volt) +#define CIN_OFFS (4096.0 * ACS70331_OFFS/VREF_NOM +0.5) +#define CIN_GAIN ((int32_t)(SCALING_FACTOR * ACS70331_GAIN + 0.5)) +#define VIN_GAIN ((uint32_t)(SCALING_FACTOR * (R47+R43)/R47 + 0.5)) +#define VPH_GAIN ((uint32_t)(SCALING_FACTOR * (R44+R37)/R44 + 0.5)) + + +/* Private typedefs ***************************************************************************************************/ + +/************************************************************************************************************* + * NOTE: The following data structures comply with the workaround described in section 2.7.7 of the document * + * ES0430, rev 6: STM32G471xx/473xx/474xx/483xx/484xx device errata. * + * The workaround is mandatory for devices with REV_ID <= 0x2001 (package marking Z) * + *************************************************************************************************************/ + +/* Data record of ADC1 */ +typedef struct +{ + uint16_t vref; /* Channel 18: Internal voltage reference */ + uint16_t nul1; + uint16_t vph1; /* Channel_1: Phase 1 voltage */ + uint16_t nul2; + uint16_t vph2; /* Channel_3: Phase 2 voltage */ + uint16_t nul3; + uint16_t vph3; /* Channel_4: Phase 3 voltage */ + uint16_t nul4; + uint16_t vin; /* Channel 12: Input voltage */ + uint16_t nul5; + int16_t cin; /* Channel 14: Input average current */ + int16_t nul6; + uint16_t temp; /* Channel 16: Internal temperature sensor */ + uint16_t nul7; +} ADC1_Record_t; + +//#warning very important: il workaround e'implemenettao dal nul8 + +/* Data record of ADC2 */ +typedef struct +{ + int16_t cph1; /* Channel_3: Phase 1 current */ + int16_t nul8; + int16_t cph2; /* Channel_4: Phase 2 current */ + int16_t nul9; + int16_t cph3; /* Channel_5: Phase 3 current */ + int16_t nul10; +} ADC2_Record_t; + + +/* Private variables **************************************************************************************************/ + +/* DMA Buffer of ADC1 and ADC2 */ +/*static*/ ADC1_Record_t adc1_Buffer; +/*static*/ ADC2_Record_t adc2_Buffer[2]; + +/* VREF constant: VREFINT_CAL * VREFINT_CAL_VREF */ +static uint32_t k_vref = 1655UL * 3000UL; + +/* Measured VREF in mV. Equal to VCC */ +static uint16_t vref_mV = VREF_NOM / mVolt; + +/* Measured raw phase currents */ +static int16_t rawCph1; +static int16_t rawCph2; +static int16_t rawCph3; + +#if defined(MOTORHAL_changes) && defined(MOTORHALCONFIG_DONTUSE_CURR_FILTERING) +//#warning removed filters as each one uses 8+(4*ANALOG_AVG_FILTER_LENGTH) = 520 bytes of RAM (or 4104 if ANALOG_AVG_FILTER_LENGTH = 1024) +#endif +/* Average filters for current measurements */ +static analogAvgFilterTypeDef cinFilter; +static analogAvgFilterTypeDef cph1Filter; +static analogAvgFilterTypeDef cph2Filter; +static analogAvgFilterTypeDef cph3Filter; + + + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new types, variables, static function prototypes required by MOTORHAL +// -------------------------------------------------------------------------------------------------------------------- + +// dont need anymore s_analog_rawCphx because we have rawCphx +//static volatile int32_t s_analog_rawCph1 = 0; +//static volatile int32_t s_analog_rawCph2 = 0; +//static volatile int32_t s_analog_rawCph3 = 0; +static volatile int32_t s_analog_raw_cinput = 0; + +#endif // #if defined(MOTORHAL_changes) + +/* Public variables ***************************************************************************************************/ + + +/* Private functions **************************************************************************************************/ + +/* Callback functions *************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief + * @param + * @return + */ +static void adc1_TransferComplete_cb(ADC_HandleTypeDef *hadc) +{ +#if defined(MOTORHAL_changes) + if (0 != adc1_Buffer.vref) vref_mV = (k_vref + (adc1_Buffer.vref>>1))/adc1_Buffer.vref; + else vref_mV = VREF_NOM / mVolt; + s_analog_raw_cinput = adc1_Buffer.cin; +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + analogMovingAverageFromISR(&cinFilter, adc1_Buffer.cin); +#endif +#else + if (0 != adc1_Buffer.vref) vref_mV = (k_vref + (adc1_Buffer.vref>>1))/adc1_Buffer.vref; + else vref_mV = VREF_NOM / mVolt; + analogMovingAverageFromISR(&cinFilter, adc1_Buffer.cin); +#endif +} + +/*******************************************************************************************************************//** + * @brief + * @param + * @return + */ + +// a che frequenza vengono chiamate? +#if 0 + +pwm -> 97 khz ~. 168 m / 2048 -> 82 khz gli impulsi +ogni tre di questi -> +82 / 3 e' la frequanza di ciascuna adc2_HalfTransferComplete_cb() e adc2_TransferComplete_cb() + +36.6 us = delta. + +h 36.6 f 36.6 h ---- + +quindi: la pwmSetCurrents_cb() viene chiamata ogni 36.6 us + + + +il contatore +#endif +static void adc2_HalfTransferComplete_cb(ADC_HandleTypeDef *hadc) +{ +#if defined(MOTORHAL_changes) + rawCph1 = adc2_Buffer[0].cph1; + rawCph2 = adc2_Buffer[0].cph2; + rawCph3 = adc2_Buffer[0].cph3; + pwmSetCurrents_cb(rawCph1, rawCph2, rawCph3); +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + analogMovingAverageFromISR(&cph1Filter, rawCph1); + analogMovingAverageFromISR(&cph2Filter, rawCph2); + analogMovingAverageFromISR(&cph3Filter, rawCph3); +#endif +#else + rawCph1 = adc2_Buffer[0].cph1; + rawCph2 = adc2_Buffer[0].cph2; + rawCph3 = adc2_Buffer[0].cph3; + pwmSetCurrents_cb(rawCph1, rawCph2, rawCph3); + analogMovingAverageFromISR(&cph1Filter, rawCph1); + analogMovingAverageFromISR(&cph2Filter, rawCph2); + analogMovingAverageFromISR(&cph3Filter, rawCph3); +#endif +} + +/*******************************************************************************************************************//** + * @brief + * @param + * @return + */ +static void adc2_TransferComplete_cb(ADC_HandleTypeDef *hadc) +{ +#if defined(MOTORHAL_changes) + rawCph1 = adc2_Buffer[1].cph1; + rawCph2 = adc2_Buffer[1].cph2; + rawCph3 = adc2_Buffer[1].cph3; + pwmSetCurrents_cb(rawCph1, rawCph2, rawCph3); +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + analogMovingAverage(&cph1Filter, rawCph1); + analogMovingAverage(&cph2Filter, rawCph2); + analogMovingAverage(&cph3Filter, rawCph3); +#endif +#else + rawCph1 = adc2_Buffer[1].cph1; + rawCph2 = adc2_Buffer[1].cph2; + rawCph3 = adc2_Buffer[1].cph3; + pwmSetCurrents_cb(rawCph1, rawCph2, rawCph3); + analogMovingAverageFromISR(&cph1Filter, rawCph1); + analogMovingAverageFromISR(&cph2Filter, rawCph2); + analogMovingAverageFromISR(&cph3Filter, rawCph3); +#endif +} + + +/* Public functions ***************************************************************************************************/ + + +/*******************************************************************************************************************//** + * @brief + * @param + * @return + */ +int32_t analogMovingAverage(analogAvgFilterTypeDef *filter, int32_t sample) +{ + int32_t avg; + taskENTER_CRITICAL(); + avg = analogMovingAverageFromISR(filter, sample); + taskEXIT_CRITICAL(); + return avg; +} + +/*******************************************************************************************************************//** + * @brief Measure IPHASE1 current + * @param void + * @return IPHASE1 current in mA [-2500mA .. 2500mA] + */ +int32_t analogConvertCurrent(int32_t raw) +{ + return CIN_GAIN * vref_mV * raw >> 16u; +} + + +/*******************************************************************************************************************//** + * @brief Measure VCC voltage in mV. Value must be inside the interval 3200 mV to 3400 mV + * @param void + * @return VCC voltage in mV + */ +uint32_t analogVcc(void) +{ + return vref_mV; +} + +/*******************************************************************************************************************//** + * @brief Measure VIN voltage + * @param void + * @return VIN voltage in mV [9500mV .. 57000mV] + */ +uint32_t analogVin(void) +{ + /* Convert value in mV */ + return VIN_GAIN * vref_mV * adc1_Buffer.vin >> 16u; +} + +/*******************************************************************************************************************//** + * @brief Measure VPHASE1 voltage + * @param void + * @return VPHASE1 voltage in mV [0 .. 57000mV] + */ +uint32_t analogVph1(void) +{ + return VPH_GAIN * vref_mV * adc1_Buffer.vph1 >> 16u; +} + +/*******************************************************************************************************************//** + * @brief Measure VPHASE2 voltage + * @param void + * @return VPHASE2 voltage in mV [0 .. 57000mV] + */ +uint32_t analogVph2(void) +{ + return VPH_GAIN * vref_mV * adc1_Buffer.vph2 >> 16u; +} + +/*******************************************************************************************************************//** + * @brief Measure VPHASE3 voltage + * @param void + * @return VPHASE3 voltage in mV [0 .. 57000mV] + */ +uint32_t analogVph3(void) +{ + return VPH_GAIN * vref_mV * adc1_Buffer.vph3 >> 16u; +} + +/*******************************************************************************************************************//** + * @brief Measure IIN current + * @param void + * @return IIN current in mA [-2500mA .. 2500mA] + */ +int32_t analogCin(void) +{ +#if defined(MOTORHAL_changes) +#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + int32_t raw = cinFilter.avg >> ANALOG_AVG_FILTER_SHIFT; +#else + int32_t raw = s_analog_raw_cinput; +#endif + return CIN_GAIN * vref_mV * raw >> 16u; +#else + int32_t raw = cinFilter.avg >> ANALOG_AVG_FILTER_SHIFT; + return CIN_GAIN * vref_mV * raw >> 16u; +#endif +} + +/*******************************************************************************************************************//** + * @brief Measure IPHASE1 current + * @param void + * @return IPHASE1 current in mA [-2500mA .. 2500mA] + */ +int32_t analogCph1(void) +{ +#if defined(MOTORHAL_changes) +// #warning CAVEAT: analogCph1() use unfiltered current +#endif + return CIN_GAIN * vref_mV * rawCph1 >> 16u; +} + +/*******************************************************************************************************************//** + * @brief Measure IPHASE2 current + * @param void + * @return IPHASE2 current in mA [-2500mA .. 2500mA] + */ +int32_t analogCph2(void) +{ +#if defined(MOTORHAL_changes) +// #warning CAVEAT: analogCph2() use unfiltered current +#endif + return CIN_GAIN * vref_mV * rawCph2 >> 16u; +} + +/*******************************************************************************************************************//** + * @brief Measure IPHASE3 current + * @param void + * @return IPHASE3 current in mA [-2500mA .. 2500mA] + */ +int32_t analogCph3(void) +{ +#if defined(MOTORHAL_changes) +// #warning CAVEAT: analogCph3() use unfiltered current +#endif + return CIN_GAIN * vref_mV * rawCph3 >> 16u; +} + +/*******************************************************************************************************************//** + * @brief Read the offset value of the Iin sensor + * @param void + * @return Offset current in mA + */ +int32_t analogGetOffsetIin( void ) +{ + return LL_ADC_GetOffsetLevel(ADC1, LL_ADC_OFFSET_4); +} + +/*******************************************************************************************************************//** + * @brief Write the offset value of the Iin sensor + * @param Offset current in mA + * @return Previous value of Offset current in mA + */ +int32_t analogSetOffsetIin(int32_t offs) +{ + int32_t prev = LL_ADC_GetOffsetLevel(ADC1, LL_ADC_OFFSET_4); + LL_ADC_SetOffset(ADC1, LL_ADC_OFFSET_4, LL_ADC_CHANNEL_14, offs); + return prev; +} + +/*******************************************************************************************************************//** + * @brief Read the offset value of the Phase 1 sensor + * @param void + * @return Offset current in mA + */ +int32_t analogGetOffsetIph1( void ) +{ + return LL_ADC_GetOffsetLevel(ADC2, LL_ADC_OFFSET_1); +} + +/*******************************************************************************************************************//** + * @brief Write the offset value of the Phase 1 sensor + * @param Offset current in mA + * @return Previous value of Offset current in mA + */ +int32_t analogSetOffsetIph1(int32_t offs) +{ + int32_t prev = LL_ADC_GetOffsetLevel(ADC2, LL_ADC_OFFSET_1); + LL_ADC_SetOffset(ADC2, LL_ADC_OFFSET_1, ADC_CHANNEL_3, offs); + return prev; +} + +/*******************************************************************************************************************//** + * @brief Read the offset value of the Phase 2 sensor + * @param void + * @return Offset current in mA + */ +int32_t analogGetOffsetIph2( void ) +{ + return LL_ADC_GetOffsetLevel(ADC2, LL_ADC_OFFSET_2); +} + +/*******************************************************************************************************************//** + * @brief Write the offset value of the Phase 2 sensor + * @param Offset current in mA + * @return Previous value of Offset current in mA + */ +int32_t analogSetOffsetIph2(int32_t offs) +{ + int32_t prev = LL_ADC_GetOffsetLevel(ADC2, LL_ADC_OFFSET_2); + LL_ADC_SetOffset(ADC2, LL_ADC_OFFSET_2, ADC_CHANNEL_4, offs); + return prev; +} + +/*******************************************************************************************************************//** + * @brief Read the offset value of the Phase 3 sensor + * @param void + * @return Offset current in mA + */ +int32_t analogGetOffsetIph3( void ) +{ + return LL_ADC_GetOffsetLevel(ADC2, LL_ADC_OFFSET_3); +} + +/*******************************************************************************************************************//** + * @brief Write the offset value of the Phase 3 sensor + * @param Offset current in mA + * @return Previous value of Offset current in mA + */ +int32_t analogSetOffsetIph3(int32_t offs) +{ + int32_t prev = LL_ADC_GetOffsetLevel(ADC2, LL_ADC_OFFSET_3); + LL_ADC_SetOffset(ADC2, LL_ADC_OFFSET_3, ADC_CHANNEL_5, offs); + return prev; +} + +/*******************************************************************************************************************//** + * @brief + * @param + * @return + */ +HAL_StatusTypeDef analogInit(void) +{ + HAL_StatusTypeDef result = HAL_ERROR; + + /* Check ADC initialization */ + if ((NULL != hadc1.Instance) && (NULL != hadc2.Instance)) + { + /* Stop any ADC operation */ + HAL_ADC_Stop_DMA(&hadc1); + HAL_ADC_Stop_DMA(&hadc2); + + /* Calibrate ADC1 and ADC2 */ + if ((HAL_OK == HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED)) && + (HAL_OK == HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED))) + { + /* Calculate the proportionality constant */ + k_vref = (uint32_t)VREF_CAL * (uint32_t)VREFINT_CAL; + + /* If the board has never been calibrated */ + if (0 == MainConf.analog.cinOffs) + { + /* Configure default values */ + MainConf.analog.cinOffs = CIN_OFFS; + MainConf.analog.cphOffs[0] = CIN_OFFS; + MainConf.analog.cphOffs[1] = CIN_OFFS; + MainConf.analog.cphOffs[2] = CIN_OFFS; + } + + /* Set the calibration parameters */ + analogSetOffsetIin(MainConf.analog.cinOffs); + analogSetOffsetIph1(MainConf.analog.cphOffs[0]); + analogSetOffsetIph2(MainConf.analog.cphOffs[1]); + analogSetOffsetIph3(MainConf.analog.cphOffs[2]); + + /* Clear the input buffers */ + memset((void *)&adc1_Buffer, 0, sizeof(adc1_Buffer)); + memset((void *)&adc2_Buffer, 0, sizeof(adc2_Buffer)); + + /* Register the interrupt callback function for the DMA Transfer Complete interrupt */ + if ((HAL_OK == HAL_ADC_RegisterCallback(&hadc1, HAL_ADC_CONVERSION_COMPLETE_CB_ID, adc1_TransferComplete_cb)) && + (HAL_OK == HAL_ADC_RegisterCallback(&hadc2, HAL_ADC_CONVERSION_HALF_CB_ID, adc2_HalfTransferComplete_cb)) && + (HAL_OK == HAL_ADC_RegisterCallback(&hadc2, HAL_ADC_CONVERSION_COMPLETE_CB_ID, adc2_TransferComplete_cb))) + { + /* Enable the Transfer Complete interrupts of the DMA */ + // forse non serve ... +// __HAL_DMA_ENABLE_IT(hadc1.DMA_Handle, DMA_IT_TC); +// __HAL_DMA_ENABLE_IT(hadc2.DMA_Handle, DMA_IT_TC); + /* Enable the ADC in DMA mode */ +#if defined(MOTORHAL_changes) + // applied proper cast + () around sizeof() to prevent errors and warnings + if ((HAL_OK == HAL_ADC_Start_DMA(&hadc1, (uint32_t *)&adc1_Buffer, sizeof(adc1_Buffer)/(sizeof(uint16_t)))) && + (HAL_OK == HAL_ADC_Start_DMA(&hadc2, (uint32_t *)&adc2_Buffer, sizeof(adc2_Buffer)/(sizeof(uint16_t))))) +#else + if ((HAL_OK == HAL_ADC_Start_DMA(&hadc1, (void *)&adc1_Buffer, sizeof(adc1_Buffer)/sizeof(uint16_t))) && + (HAL_OK == HAL_ADC_Start_DMA(&hadc2, (void *)&adc2_Buffer, sizeof(adc2_Buffer)/sizeof(uint16_t)))) +#endif + { + /* DMA is running now */ + result = HAL_OK; + } + } + } + } + return result; +} + + + +#if defined(MOTORHALCONFIG_DONTUSE_TESTS) +void analogTest(void) {} +#else + +/*******************************************************************************************************************//** + * @brief + * @param + * @return + */ +void analogTest(void) +{ + char ch; + int32_t value; + + coprintf("Analog Test\n"); vTaskDelay(250); + coprintf("Vin = %5u mV, Iin = %+5d mA, Vcc = %5u mV\n", analogVin(), analogCin(), analogVcc()); vTaskDelay(250); + + /* Infinite loop */ + for(;;) + { + coprintf("0 : Set Iin offset\n" + "1 : Set phase 1 offset\n" + "2 : Set phase 2 offset\n" + "3 : Set phase 3 offset\n" + "D : Display currents/voltages\n" + "Z : Autozero phase offsets\n" + "ESC : Exit test\n" + "? "); + ch = coRxChar(); + if (isprint(ch)) + { + coprintf("%c\n", ch); + switch (toupper(ch)) + { + case '0': + while (1) + { + coprintf("\rIin = %+5d mA", analogCin()); vTaskDelay(250); + if (coRxReady()) + { + ch = coRxChar(); + value = analogGetOffsetIin(); + if (ch == '+') --value; + else if (ch == '-') ++value; + else if (ch == '<') value += 10; + else if (ch == '>') value -= 10; + else { coprintf("\n"); break; } + analogSetOffsetIin(value); + MainConf.analog.cinOffs = value; + } + } + break; + + case '1': + while (1) + { + coprintf("\rIph1 = %+5d mA", analogCph1()); vTaskDelay(250); + if (coRxReady()) + { + ch = coRxChar(); + value = analogGetOffsetIph1(); + if (ch == '+') --value; + else if (ch == '-') ++value; + else if (ch == '<') value += 10; + else if (ch == '>') value -= 10; + else { coprintf("\n"); break; } + analogSetOffsetIph1(value); + MainConf.analog.cphOffs[0] = value; + } + } + break; + + case '2': + while (1) + { + coprintf("\rIph2 = %+5d mA", analogCph2()); vTaskDelay(250); + if (coRxReady()) + { + ch = coRxChar(); + value = analogGetOffsetIph2(); + if (ch == '+') --value; + else if (ch == '-') ++value; + else if (ch == '<') value += 10; + else if (ch == '>') value -= 10; + else { coprintf("\n"); break; } + analogSetOffsetIph2(value); + MainConf.analog.cphOffs[1] = value; + } + } + break; + + case '3': + while (1) + { + coprintf("\rIph3 = %+5d mA", analogCph3()); vTaskDelay(250); + if (coRxReady()) + { + ch = coRxChar(); + value = analogGetOffsetIph3(); + if (ch == '+') --value; + else if (ch == '-') ++value; + else if (ch == '<') value += 10; + else if (ch == '>') value -= 10; + else { coprintf("\n"); break; } + analogSetOffsetIph3(value); + MainConf.analog.cphOffs[2] = value; + } + } + break; + + case 'D': + coprintf("Press ESC to stop\n"); vTaskDelay(100); + do + { + coprintf("| Vcc | Vin | Phase #1 | Phase #2 | Phase #3 |\n"); vTaskDelay(100); + coprintf("| mV | mV/mA | mV/mA | mV/mA | mV/mA |\n"); vTaskDelay(100); + do + { + coprintf("\r|%5u |", analogVcc()); + coprintf("%5u/%+-5d|", analogVin(), analogCin()); + coprintf("%5u/%+-5d|", analogVph1(), analogCph1()); + coprintf("%5u/%+-5d|", analogVph2(), analogCph2()); + coprintf("%5u/%+-5d|", analogVph3(), analogCph3()); + vTaskDelay(100); + } while (!coRxReady()); + coPutChar('\n'); + } while ('\x1B' != coGetChar()); + break; + + case 'Z': + coprintf("Sorry: not implemented yet\n", ch); + break; + + default: + coprintf("Unknown command: %c\n", ch); + break; + } + } + else if ('\x1B' == ch) + { + coprintf("\n"); + coprintf("- Iin offset: %+d LSB\n", analogGetOffsetIin()); + coprintf("- Iphase1 offset: %+d LSB\n", analogGetOffsetIph1()); + coprintf("- Iphase2 offset: %+d LSB\n", analogGetOffsetIph2()); + coprintf("- Iphase3 offset: %+d LSB\n", analogGetOffsetIph3()); + coprintf("Exit test\n"); + return ; + } + } +} + +#endif // MOTORHALCONFIG_DONTUSE_TESTS + + + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new functions required by MOTORHAL +// -------------------------------------------------------------------------------------------------------------------- + + + +HAL_StatusTypeDef analog_Deinit(void) +{ + /* Stop any ADC operation */ + HAL_ADC_Stop_DMA(&hadc1); + HAL_ADC_Stop_DMA(&hadc2); + + /* uncalibrate ADCs */ + MainConf.analog.cinOffs = 0; + + return HAL_OK; +} + + +//void analog_GetRawCurrentPhases(int32_t *pi1, int32_t *pi2, int32_t *pi3) +//{ +// if((NULL != pi1) && (NULL != pi2) && (NULL != pi3)) +// { +// *pi1 = cph1Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +// *pi2 = cph2Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +// *pi3 = cph3Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +// } +//} + +int32_t analog_RawCph1(void) +{ + return cph1Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +} + +int32_t analog_RawCph2(void) +{ + return cph2Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +} + +int32_t analog_RawCph3(void) +{ + return cph3Filter.avg >> ANALOG_AVG_FILTER_SHIFT; +} + +//int32_t analog_raw2mAmps(int32_t raw) +//{ +// return analogConvertCurrent(raw); +//} + +void analog_MovingAverage(int32_t i1, int32_t i2, int32_t i3) +{ + analogMovingAverage(&cph1Filter, i1); + analogMovingAverage(&cph2Filter, i2); + analogMovingAverage(&cph3Filter, i3); +} + +#endif // #if defined(MOTORHAL_changes) + +/* END OF FILE ********************************************************************************************************/ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/analog.h b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/analog.h new file mode 100644 index 000000000..7ca829504 --- /dev/null +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/analog.h @@ -0,0 +1,120 @@ +/*******************************************************************************************************************//** + * @file analog.c + * @author G.Zini + * @version 1.0 + * @date 2021 January, 20 + * @brief Analog signals management + **********************************************************************************************************************/ + +/* Define to prevent recursive inclusion */ +#ifndef __ANALOG_H +#define __ANALOG_H + +#ifdef __cplusplus + extern "C" { +#endif + + +/* Includes ----------------------------------------------------------------------------------------------------------*/ +#include +#include +#include +#include + +#if defined(USE_STM32HAL) +#include "stm32hal.h" +#define MOTORHAL_changes +#else +#include +#include "stm32g4xx.h" +#include "adc.h" +#endif + +/* Exported macro ----------------------------------------------------------------------------------------------------*/ +#if defined(MOTORHAL_changes) +#define ANALOG_AVG_FILTER_SHIFT (7) +#define ANALOG_AVG_FILTER_LENGTH (1U<avg -= filter->buf[filter->idx]; + filter->avg += (filter->buf[filter->idx] = sample); + if (++(filter->idx) >= ANALOG_AVG_FILTER_LENGTH) filter->idx = 0; + return filter->avg; +} + +extern int32_t analogMovingAverage(analogAvgFilterTypeDef *filter, int32_t sample); +extern int32_t analogConvertCurrent(int32_t raw); +extern HAL_StatusTypeDef analogInit(void); +extern uint32_t analogVcc(void); +extern uint32_t analogVph1(void); +extern uint32_t analogVph2(void); +extern uint32_t analogVph3(void); +extern uint32_t analogVin(void); +extern int32_t analogCin(void); +extern int32_t analogCph1(void); +extern int32_t analogCph2(void); +extern int32_t analogCph3(void); +extern int32_t analogGetOffsetIin(void); +extern int32_t analogSetOffsetIin(int32_t offs); +extern int32_t analogGetOffsetIph1(void); +extern int32_t analogSetOffsetIph1(int32_t offs); +extern int32_t analogGetOffsetIph2(void); +extern int32_t analogSetOffsetIph2(int32_t offs); +extern int32_t analogGetOffsetIph3(void); +extern int32_t analogSetOffsetIph3(int32_t offs); + +extern void analogTest(void); + + +#if defined(MOTORHAL_changes) + +extern HAL_StatusTypeDef analog_Deinit(void); +extern int32_t analog_RawCph1(void); +extern int32_t analog_RawCph2(void); +extern int32_t analog_RawCph3(void); +extern void analog_MovingAverage(int32_t i1, int32_t i2, int32_t i3); + +#endif // #if defined(MOTORHAL_changes) + +#ifdef __cplusplus + } /* extern "C" */ +#endif /* __cplusplus */ +#endif /* __ANALOG_H */ +/* END OF FILE ********************************************************************************************************/ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/encoder.c b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/encoder.c new file mode 100644 index 000000000..dbbf8c465 --- /dev/null +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/encoder.c @@ -0,0 +1,523 @@ +/*******************************************************************************************************************//** + * @file encoder.c + * @author G.Zini + * @version 1.0 + * @date 2021 March, 9 + * @brief Incremental Encoder management + **********************************************************************************************************************/ + +// CODE SHAPER +#if defined(USE_STM32HAL) +#include "motorhal_config.h" +#endif + +#include "embot_core.h" + +#if defined(USE_STM32HAL) +// API +#include "encoder.h" +#endif + +/* Includes ***********************************************************************************************************/ +#include +#include +#include +#include +#include + +#if defined(USE_STM32HAL) +#include "stm32hal.h" +#if !defined(MOTORHALCONFIG_DONTUSE_FLASH) +#include "flash.h" +#endif +#else + +#include "FreeRTOS.h" +#include "encoder.h" +#include "flash.h" +#include "led.h" +#include "main.h" +#include "utilities.h" +#include "tim.h" +#include "stm32g4xx_hal_tim.h" + +#endif + +#if (USE_HAL_TIM_REGISTER_CALLBACKS != 1) + #error Flag TIM2 in menu "Project Manager -> Advanced Settings -> Register CallBack" of CubeMx must be ENABLED +#endif + +/* Private macros *****************************************************************************************************/ +#if defined(MOTORHAL_changes) +#else +#define ENCODER_AVERAGE_LENGTH (10) +#endif + +/* Private variables **************************************************************************************************/ + +/* Coversion factor from encoder step value to elctrical angle. It is given by: + * encoderConvFactor = 16777216 * number_of_poles / number_of_encoder_steps + */ +static int32_t encoderConvFactor = 29360; /* 29360.128 */ + +/* Encoder averaged speed */ +static volatile int32_t encoderSpeed = 0; + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new types, variables, static function prototypes required by MOTORHAL +// -------------------------------------------------------------------------------------------------------------------- + +static volatile uint16_t s_encoder_electricalOffset = 0; +static volatile bool s_encoder_Calibrated = false; +static volatile uint16_t s_encoder_ForcedValue = 0; + +#endif // #if defined(MOTORHAL_changes) + +/* Callbacks **********************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief + * @param + * @return + */ +void encoderIndexCallback(TIM_HandleTypeDef *htim) +{ +// UNUSED(htim); + /************** + * TO BE DONE * + **************/ +// ledSet(LED1, 0); +// ledSet(0, LED1); +} + + +/*******************************************************************************************************************//** + * @brief + * @param + * @return + */ +void encoderCaptureCallback(TIM_HandleTypeDef *htim) +{ +// UNUSED(htim); + static int32_t last = 0; +#if defined(MOTORHAL_changes) + enum { sizeOfbuffer = 10 }; + static int32_t buffer[sizeOfbuffer] = {0}; +#else + static int32_t buffer[10] = {0}; +#endif + static unsigned index = 0; +// ledSet(LED2, 0); + /* Read the new capture value */ + int32_t count = READ_REG(htim->Instance->CCR4); + /* Calculate the difference from last reading */ + int32_t delta = count - last; last = count; + /* Adjust for over/under flow */ + if (delta >= ENCODER_COUNT_PER_REVOLUTION/2) delta -= ENCODER_COUNT_PER_REVOLUTION; + else if (delta <= -ENCODER_COUNT_PER_REVOLUTION/2) delta += ENCODER_COUNT_PER_REVOLUTION; + /* Update the running average (multiplied by 100) */ + int32_t speed = encoderSpeed - buffer[index]; + encoderSpeed = speed + (buffer[index++] = delta); +#if defined(MOTORHAL_changes) + if (index >= sizeOfbuffer) index = 0; +#else + if (index >= lengthof(buffer)) index = 0; +#endif +// ledSet(0, LED2); +} + + +/* Exported functions *************************************************************************************************/ + +#if defined(MOTORHAL_changes) + +// in here we dont start the timer TIM2 straight away as in gzini implementation +// rather, we just collect some data which never changes. +// we start the timer in function encoder_Config() called when we receive the encoder properties +// the function encoder_Config() uses the remaining of the code of gzini's encoderInit() + +HAL_StatusTypeDef encoderInit(void) +{ + /* here settings not managed by yarprobotinterface but still configurable */ + MainConf.encoder.mode = TIM_ENCODERMODE_TI12; + MainConf.encoder.filter = 4; + MainConf.encoder.idxpos = TIM_ENCODERINDEX_POSITION_00; + + /* default values */ + MainConf.encoder.resolution = 0; + MainConf.encoder.has_hall_sens = 1; + + return HAL_OK; +} + +#else + +/*******************************************************************************************************************//** + * @brief Start TIM2 as 32 bits incremental encoders and TIM15 as periodic counter. + * @param void + * @return HAL_StatusTypeDef Operation result + * + * Start TIM2 as 32 bits incremental encoders in mode x 4 with index input. TIM15 is configured as periodic counter + * with 1.5 ms period. The TRGO output of TIM15 is configured as UPDATE trigger output. The UPDATE is routed to + * the input tim_itr6 of TIM2, and connected to capture/compare register CC4. + * In this way TIM2_CC4 register stores the encoder counter every 1.5 ms. Register value is: + * + * CC4 = Tsample * Nstep * SPEEDrpm / 60 + * + * Given Tsample = 0.0015 s and Nstep = 4000, we get + * + * CC4 = SPEEDrpm/10. + * + * Function encoderCaptureCallback(), called by the CC4 interrupt every 1.5 ms, calculates the sum of 10 consecutive + * speed samples and stores the result in encoderSpeed variables. The value rapresents a lightly filterd measure of + * the motor speed in rpm. + * + * The sample rate must ensure at least 2 samples per encoder rotation. Therefore the maximum encoder speed is: + * + * SPEEDrpm(max) < 30/Tsample + * + * that is 20000 rpm in this implementetion + */ +HAL_StatusTypeDef encoderInit(void) +{ + TIM_Encoder_InitTypeDef sEncConf = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIMEx_EncoderIndexConfigTypeDef sEncoderIndexConfig = {0}; + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + + /* Default configuration */ + if (0 == MainConf.encoder.mode) + { + MainConf.encoder.mode = TIM_ENCODERMODE_TI12; + MainConf.encoder.filter = 4; + MainConf.encoder.idxpos = TIM_ENCODERINDEX_POSITION_00; + MainConf.encoder.nsteps = 4000; + } + + /* Forced, for now */ + // numero che serve pe convertire da tacche ad angolo + encoderConvFactor = 29360; + + /* Re-configure TIM2 base, IC1 and IC2 */ + htim2.Instance = TIM2; + htim2.Init.Prescaler = 0; + htim2.Init.CounterMode = TIM_COUNTERMODE_UP; + htim2.Init.Period = MainConf.encoder.nsteps - 1; + htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + sEncConf.EncoderMode = MainConf.encoder.mode; + sEncConf.IC1Polarity = TIM_ICPOLARITY_RISING; + sEncConf.IC1Selection = TIM_ICSELECTION_DIRECTTI; + sEncConf.IC1Prescaler = TIM_ICPSC_DIV1; + sEncConf.IC1Filter = MainConf.encoder.filter; + sEncConf.IC2Polarity = TIM_ICPOLARITY_RISING; + sEncConf.IC2Selection = TIM_ICSELECTION_DIRECTTI; + sEncConf.IC2Prescaler = TIM_ICPSC_DIV1; + sEncConf.IC2Filter = MainConf.encoder.filter; + if (HAL_OK != HAL_TIM_Encoder_Init(&htim2, &sEncConf)) return HAL_ERROR; + + /* Disable master mode */ + sMasterConfig.MasterOutputTrigger = TIM_TRGO_ENCODER_CLK; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_OK != HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig)) return HAL_ERROR; + + /* Configure the INDEX mode */ + sEncoderIndexConfig.Polarity = TIM_ENCODERINDEX_POLARITY_NONINVERTED; + sEncoderIndexConfig.Prescaler = TIM_ENCODERINDEX_PRESCALER_DIV1; + sEncoderIndexConfig.Filter = MainConf.encoder.filter; + sEncoderIndexConfig.FirstIndexEnable = DISABLE; + sEncoderIndexConfig.Position = MainConf.encoder.idxpos; + sEncoderIndexConfig.Direction = TIM_ENCODERINDEX_DIRECTION_UP_DOWN; + if (HAL_OK != HAL_TIMEx_ConfigEncoderIndex(&htim2, &sEncoderIndexConfig)) return HAL_ERROR; + + htim15.Instance = TIM15; + htim15.Init.Prescaler = 167; + htim15.Init.CounterMode = TIM_COUNTERMODE_UP; + htim15.Init.Period = 1499; /* Forced for now */ + htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim15.Init.RepetitionCounter = 0; + htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim15) != HAL_OK) return HAL_ERROR; + + /* Configure the clock source */ + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim15, &sClockSourceConfig) != HAL_OK) return HAL_ERROR; + + /* Disable master mode */ + sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK) return HAL_ERROR; + + /* Select tim_itr6 = TIM15_TRGO */ + htim2.Instance->SMCR = (htim2.Instance->SMCR & ~TIM_SMCR_TS) + | TIM_SMCR_TS_3|TIM_SMCR_TS_1; + + /* Link CC4 to tim_itr6 */ + htim2.Instance->CCMR2 = TIM_CCMR2_CC4S; + htim2.Instance->CCER |= TIM_CCER_CC4E; + + /* Reset counters */ + __HAL_TIM_SET_COUNTER(&htim2, 0); + __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, 0); + + /* Register the callback function used to signal the activation of the Index pulse */ + if ((HAL_OK != HAL_TIM_RegisterCallback(&htim2, HAL_TIM_ENCODER_INDEX_CB_ID, encoderIndexCallback)) || + (HAL_OK != HAL_TIM_RegisterCallback(&htim2, HAL_TIM_IC_CAPTURE_CB_ID, encoderCaptureCallback))) return HAL_ERROR; + + /* Start base frequency for speed measurements */ + HAL_TIM_Base_Start(&htim15); + + /* Start timers in encoder mode */ + if (HAL_OK != HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL)) return HAL_ERROR; + __HAL_TIM_ENABLE_IT(&htim2, TIM_IT_IDX|TIM_IT_CC4); + return HAL_OK; +} + +#endif // #if defined(MOTORHAL_changes) + + +/*******************************************************************************************************************//** + * @brief Read encoder value + * @param void + * @return int32_t Encoder value + */ +uint32_t encoderGetCounter(void) +{ + return (uint32_t)__HAL_TIM_GET_COUNTER(&htim2); +} + +#if defined(MOTORHAL_changes) + +// in here we just add some controls and we call zgini implementation +// by adding an offset to it + +uint32_t encoderGetElectricalAngle(void) +{ + #warning acemor: attenzione al >> 8 che manca + if (MainConf.encoder.resolution == 0) + { + return s_encoder_ForcedValue; + } + + if (MainConf.encoder.has_hall_sens) + { + if (!s_encoder_Calibrated) + { + return s_encoder_ForcedValue; + } + } + + return s_encoder_electricalOffset + (__HAL_TIM_GET_COUNTER(&htim2) * encoderConvFactor) & 0xFFFF; +} + +#else + +/*******************************************************************************************************************//** + * @brief Read encoder value and convert to electrical-angle + * @param void + * @return uint16_t Encoder value + */ +uint32_t encoderGetElectricalAngle(void) +{ + return ((__HAL_TIM_GET_COUNTER(&htim2) * encoderConvFactor) >> 8) & 0x0000FFFF; +} + +#endif // #if defined(MOTORHAL_changes) + + +/*******************************************************************************************************************//** + * @brief Read encoder value + * @param void + * @return int32_t Encoder value + */ +int32_t encoderGetSpeed(void) +{ + return encoderSpeed; +} + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new functions required by MOTORHAL, be them extern or static +// -------------------------------------------------------------------------------------------------------------------- + + +HAL_StatusTypeDef encoder_Deinit(void) +{ + // marco.accame: no changes in TIM2 across the two versions of gzini's motorhal + HAL_TIM_Encoder_Stop(&htim2, TIM_CHANNEL_ALL); + + /* default values */ + MainConf.encoder.resolution = 0; + MainConf.encoder.has_hall_sens = 1; + + /* deinitialize */ + encoderConvFactor = 0; + s_encoder_electricalOffset = 0; + s_encoder_Calibrated = false; + s_encoder_ForcedValue = 0; + + return HAL_OK; +} + +#define USE_TIM15 +// for speed measurement + +HAL_StatusTypeDef encoder_Config(uint8_t has_quad_enc, int16_t resolution, uint8_t num_polar_couples, uint8_t has_hall_sens) +{ + TIM_Encoder_InitTypeDef sEncConf = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIMEx_EncoderIndexConfigTypeDef sEncoderIndexConfig = {0}; + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + + MainConf.encoder.has_hall_sens = has_hall_sens; + MainConf.pwm.num_polar_couples = num_polar_couples; + + if(!has_quad_enc) + resolution=0; + + MainConf.encoder.resolution = resolution; + + if (resolution == 0) + { + return HAL_OK; + } + + if (resolution < 0) + { + resolution = -resolution; + htim2.Init.CounterMode = TIM_COUNTERMODE_DOWN; + } + else + { + htim2.Init.CounterMode = TIM_COUNTERMODE_UP; + } + + + /* Forced, for now */ + // numero che serve pe convertire da tacche ad angolo + encoderConvFactor = 65536L*num_polar_couples/resolution; + + /* Re-configure TIM2 base, IC1 and IC2 */ + htim2.Instance = TIM2; + htim2.Init.Prescaler = 0; + //htim2.Init.CounterMode = TIM_COUNTERMODE_UP; + htim2.Init.Period = (resolution/num_polar_couples + 0.5) - 1; + htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + sEncConf.EncoderMode = MainConf.encoder.mode; + sEncConf.IC1Polarity = TIM_ICPOLARITY_RISING; + sEncConf.IC1Selection = TIM_ICSELECTION_DIRECTTI; + sEncConf.IC1Prescaler = TIM_ICPSC_DIV1; + sEncConf.IC1Filter = MainConf.encoder.filter; + sEncConf.IC2Polarity = TIM_ICPOLARITY_RISING; + sEncConf.IC2Selection = TIM_ICSELECTION_DIRECTTI; + sEncConf.IC2Prescaler = TIM_ICPSC_DIV1; + sEncConf.IC2Filter = MainConf.encoder.filter; + if (HAL_OK != HAL_TIM_Encoder_Init(&htim2, &sEncConf)) return HAL_ERROR; + + /* Disable master mode */ + sMasterConfig.MasterOutputTrigger = TIM_TRGO_ENCODER_CLK; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_OK != HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig)) return HAL_ERROR; + + if (MainConf.encoder.has_hall_sens) + { + /* no INDEX needed */ + HAL_TIMEx_DisableEncoderIndex(&htim2); + } + else + { + /* Configure the INDEX mode */ + sEncoderIndexConfig.Polarity = TIM_ENCODERINDEX_POLARITY_NONINVERTED; + sEncoderIndexConfig.Prescaler = TIM_ENCODERINDEX_PRESCALER_DIV1; + sEncoderIndexConfig.Filter = MainConf.encoder.filter; + sEncoderIndexConfig.FirstIndexEnable = DISABLE; + sEncoderIndexConfig.Position = MainConf.encoder.idxpos; + sEncoderIndexConfig.Direction = TIM_ENCODERINDEX_DIRECTION_UP_DOWN; + if (HAL_OK != HAL_TIMEx_ConfigEncoderIndex(&htim2, &sEncoderIndexConfig)) return HAL_ERROR; + + +#if defined(USE_TIM15) + htim15.Instance = TIM15; + htim15.Init.Prescaler = 167; + htim15.Init.CounterMode = TIM_COUNTERMODE_UP; + htim15.Init.Period = 1499; /* Forced for now */ + htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim15.Init.RepetitionCounter = 0; + htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim15) != HAL_OK) return HAL_ERROR; + + /* Configure the clock source */ + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim15, &sClockSourceConfig) != HAL_OK) return HAL_ERROR; + + /* Disable master mode */ + sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK) return HAL_ERROR; + + /* Select tim_itr6 = TIM15_TRGO */ + htim2.Instance->SMCR = (htim2.Instance->SMCR & ~TIM_SMCR_TS) + | TIM_SMCR_TS_3|TIM_SMCR_TS_1; + + /* Link CC4 to tim_itr6 */ + htim2.Instance->CCMR2 = TIM_CCMR2_CC4S; + htim2.Instance->CCER |= TIM_CCER_CC4E; +#endif + + /* Reset counters */ + __HAL_TIM_SET_COUNTER(&htim2, 0); + __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, 0); + + /* Register the callback function used to signal the activation of the Index pulse */ + if ((HAL_OK != HAL_TIM_RegisterCallback(&htim2, HAL_TIM_ENCODER_INDEX_CB_ID, encoderIndexCallback)) || + (HAL_OK != HAL_TIM_RegisterCallback(&htim2, HAL_TIM_IC_CAPTURE_CB_ID, encoderCaptureCallback))) return HAL_ERROR; + + /* Start base frequency for speed measurements */ + HAL_TIM_Base_Start(&htim15); + } + + /* Start timers in encoder mode */ + if (HAL_OK != HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL)) return HAL_ERROR; + __HAL_TIM_ENABLE_IT(&htim2, TIM_IT_IDX|TIM_IT_CC4); + + return HAL_OK; +} + + +void encoder_Reset() +{ + __HAL_TIM_SET_COUNTER(&htim2, 0); + __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, 0); +} + +#warning acemor: attenzione al >> 8 che manca +uint16_t encoder_GetUncalibrated(void) +{ + return (__HAL_TIM_GET_COUNTER(&htim2) * encoderConvFactor) & 0xFFFF; +} + +void encoder_Force(uint16_t value) +{ + s_encoder_ForcedValue = value; +} + +void encoder_Calibrate(uint16_t offset) +{ + s_encoder_electricalOffset = offset; + + s_encoder_Calibrated = true; +} + +uint16_t encoder_GetElectricalOffset() +{ + return s_encoder_electricalOffset; +} + +#endif // #if defined(MOTORHAL_changes) + + +/* END OF FILE ********************************************************************************************************/ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/encoder.h b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/encoder.h new file mode 100644 index 000000000..1d349ab77 --- /dev/null +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/encoder.h @@ -0,0 +1,90 @@ +/*******************************************************************************************************************//** + * @file encoder.h + * @author G.Zini + * @version 1.0 + * @date 2021 March, 9 + * @brief Incremental Encoder management + **********************************************************************************************************************/ + +/* Define to prevent recursive inclusion */ +#ifndef __ENCODER_H +#define __ENCODER_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ----------------------------------------------------------------------------------------------------------*/ +#include +#include +#include +#include + +#if defined(USE_STM32HAL) +#include "stm32hal.h" +#define MOTORHAL_changes +#else +#include +#include "stm32g4xx.h" +#include "stm32g4xx_hal_tim.h" +#endif + +/* Exported typedefs -------------------------------------------------------------------------------------------------*/ + +#if defined(MOTORHAL_changes) + +typedef struct +{ + uint16_t mode; + uint16_t filter; + uint16_t idxpos; + int16_t resolution; + uint16_t has_hall_sens; +} encoder_ConfTypeDef; + +#else + +typedef struct +{ + uint16_t mode; + uint16_t filter; + uint16_t idxpos; + uint16_t nsteps; +} encoderConfTypeDef; + +#endif + + + + +/* Exported macro ----------------------------------------------------------------------------------------------------*/ + +/* Number of step per revolution */ +#define ENCODER_COUNT_PER_REVOLUTION (4000) + + +/* Exported variables ------------------------------------------------------------------------------------------------*/ +/* Exported functions prototypes -------------------------------------------------------------------------------------*/ + +extern HAL_StatusTypeDef encoderInit(void); +extern uint32_t encoderGetCounter(void); +extern uint32_t encoderGetElectricalAngle(void); +extern int32_t encoderGetSpeed(void); + +#if defined(MOTORHAL_changes) + +extern HAL_StatusTypeDef encoder_Deinit(void); +extern HAL_StatusTypeDef encoder_Config(uint8_t has_quad_enc, int16_t resolution, uint8_t num_polar_couples, uint8_t has_hall_sens); +extern void encoder_Reset(); +extern void encoder_Force(uint16_t value); +extern void encoder_Calibrate(uint16_t offset); +extern uint16_t encoder_GetElectricalOffset(); +extern uint16_t encoder_GetUncalibrated(void); + +#endif + +#ifdef __cplusplus + } /* extern "C" */ +#endif /* __cplusplus */ +#endif /* __ENCODER_H */ +/* END OF FILE ********************************************************************************************************/ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/motorhal_config.c b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/motorhal_config.c new file mode 100644 index 000000000..96ab9814a --- /dev/null +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/motorhal_config.c @@ -0,0 +1,240 @@ + +/* + * Copyright (C) 2021 iCub Tech - Istituto Italiano di Tecnologia + * Author: Marco Accame + * email: marco.accame@iit.it +*/ + + +#if 0 + The files motorhal_config.[h, c] contain macros and code which cuts aways un-necessary dependencies + for the files provided by Giorgio Zini for the motor control of the amcbldc. These files are: + encoder.[c, h], pwm.[c, h], analog.[c, h]. The dependencies cut away are those which offer + generic services such as logging, leds, flash storage. +#endif + +// CODE SHAPER +#if defined(USE_STM32HAL) +#include "motorhal_config.h" +#endif + +#if defined(MOTORHALCONFIG_DONTUSE_FLASH) + +MainConfTypeDef MainConf = {0}; + +#else +#endif // MOTORHALCONFIG_DONTUSE_FLASH + + +#if defined(MOTORHALCONFIG_REDEFINE_RTOS) + +void taskENTER_CRITICAL(void) {} +void taskEXIT_CRITICAL(void) {} +void vTaskDelay(uint32_t ms) +{ + HAL_Delay(ms); +} + +#endif + +#if defined(MOTORHALCONFIG_DONTUSE_LED) + +void ledSet(uint32_t led, uint32_t v) {} + + +#endif + + +#if defined(MOTORHALCONFIG_ADD_IRQHANDLERS) + +#include "stm32hal.h" + +/** + * @brief This function handles DMA1 channel1 global interrupt. + */ +void DMA1_Channel1_IRQHandler(void) +{ + /* USER CODE BEGIN DMA1_Channel1_IRQn 0 */ + + /* USER CODE END DMA1_Channel1_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_adc1); + /* USER CODE BEGIN DMA1_Channel1_IRQn 1 */ + + /* USER CODE END DMA1_Channel1_IRQn 1 */ +} + +/** + * @brief This function handles DMA1 channel2 global interrupt. + */ +void DMA1_Channel2_IRQHandler(void) +{ + /* USER CODE BEGIN DMA1_Channel2_IRQn 0 */ + + /* USER CODE END DMA1_Channel2_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_adc2); + /* USER CODE BEGIN DMA1_Channel2_IRQn 1 */ + + /* USER CODE END DMA1_Channel2_IRQn 1 */ +} + +/** + * @brief This function handles ADC1 and ADC2 global interrupt. + */ +void ADC1_2_IRQHandler(void) +{ + /* USER CODE BEGIN ADC1_2_IRQn 0 */ + + /* USER CODE END ADC1_2_IRQn 0 */ + HAL_ADC_IRQHandler(&hadc1); + HAL_ADC_IRQHandler(&hadc2); + /* USER CODE BEGIN ADC1_2_IRQn 1 */ + + /* USER CODE END ADC1_2_IRQn 1 */ +} + +///** +// * @brief This function handles USB low priority interrupt remap. +// */ +//void USB_LP_IRQHandler(void) +//{ +// /* USER CODE BEGIN USB_LP_IRQn 0 */ + +// /* USER CODE END USB_LP_IRQn 0 */ +// HAL_PCD_IRQHandler(&hpcd_USB_FS); +// /* USER CODE BEGIN USB_LP_IRQn 1 */ + +// /* USER CODE END USB_LP_IRQn 1 */ +//} + +/** + * @brief This function handles TIM1 break interrupt and TIM15 global interrupt. + */ +void TIM1_BRK_TIM15_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_BRK_TIM15_IRQn 0 */ + + /* USER CODE END TIM1_BRK_TIM15_IRQn 0 */ + HAL_TIM_IRQHandler(&htim1); + /* USER CODE BEGIN TIM1_BRK_TIM15_IRQn 1 */ + + /* USER CODE END TIM1_BRK_TIM15_IRQn 1 */ +} + +/** + * @brief This function handles TIM1 update interrupt and TIM16 global interrupt. + */ +void TIM1_UP_TIM16_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_UP_TIM16_IRQn 0 */ + + /* USER CODE END TIM1_UP_TIM16_IRQn 0 */ + HAL_TIM_IRQHandler(&htim1); + /* USER CODE BEGIN TIM1_UP_TIM16_IRQn 1 */ + + /* USER CODE END TIM1_UP_TIM16_IRQn 1 */ +} + +/** + * @brief This function handles TIM1 trigger and commutation interrupts and TIM17 global interrupt. + */ +void TIM1_TRG_COM_TIM17_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 0 */ + + /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 0 */ + HAL_TIM_IRQHandler(&htim1); + /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 1 */ + + /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 1 */ +} + +/** + * @brief This function handles TIM1 capture compare interrupt. + */ +void TIM1_CC_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_CC_IRQn 0 */ + + /* USER CODE END TIM1_CC_IRQn 0 */ + HAL_TIM_IRQHandler(&htim1); + /* USER CODE BEGIN TIM1_CC_IRQn 1 */ + + /* USER CODE END TIM1_CC_IRQn 1 */ +} + +/** + * @brief This function handles TIM2 global interrupt. + */ +void TIM2_IRQHandler(void) +{ + /* USER CODE BEGIN TIM2_IRQn 0 */ + + /* USER CODE END TIM2_IRQn 0 */ + HAL_TIM_IRQHandler(&htim2); + /* USER CODE BEGIN TIM2_IRQn 1 */ + + /* USER CODE END TIM2_IRQn 1 */ +} + +/** + * @brief This function handles TIM3 global interrupt. + */ +void TIM3_IRQHandler(void) +{ + /* USER CODE BEGIN TIM3_IRQn 0 */ + + /* USER CODE END TIM3_IRQn 0 */ + HAL_TIM_IRQHandler(&htim3); + /* USER CODE BEGIN TIM3_IRQn 1 */ + + /* USER CODE END TIM3_IRQn 1 */ +} + +// marco.accame: removed because managed by the embot::hw::bsp +/** + * @brief This function handles EXTI line[15:10] interrupts. + */ +//void EXTI15_10_IRQHandler(void) +//{ +// /* USER CODE BEGIN EXTI15_10_IRQn 0 */ + +// /* USER CODE END EXTI15_10_IRQn 0 */ +// HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13); +// HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14); +// /* USER CODE BEGIN EXTI15_10_IRQn 1 */ + +// /* USER CODE END EXTI15_10_IRQn 1 */ +//} + +///** +// * @brief This function handles I2C4 event interrupt / I2C4 wake-up interrupt through EXTI line 42. +// */ +//void I2C4_EV_IRQHandler(void) +//{ +// /* USER CODE BEGIN I2C4_EV_IRQn 0 */ + +// /* USER CODE END I2C4_EV_IRQn 0 */ +// HAL_I2C_EV_IRQHandler(&hi2c4); +// /* USER CODE BEGIN I2C4_EV_IRQn 1 */ + +// /* USER CODE END I2C4_EV_IRQn 1 */ +//} + +///** +// * @brief This function handles I2C4 error interrupt. +// */ +//void I2C4_ER_IRQHandler(void) +//{ +// /* USER CODE BEGIN I2C4_ER_IRQn 0 */ + +// /* USER CODE END I2C4_ER_IRQn 0 */ +// HAL_I2C_ER_IRQHandler(&hi2c4); +// /* USER CODE BEGIN I2C4_ER_IRQn 1 */ + +// /* USER CODE END I2C4_ER_IRQn 1 */ +//} + + +#endif + +// - end-of-file (leave a blank line after)---------------------------------------------------------------------------- diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/motorhal_config.h b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/motorhal_config.h new file mode 100644 index 000000000..efbade454 --- /dev/null +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/motorhal_config.h @@ -0,0 +1,86 @@ + +/* + * Copyright (C) 2021 iCub Tech - Istituto Italiano di Tecnologia + * Author: Marco Accame + * email: marco.accame@iit.it +*/ + +#ifndef MOTORHAL_CONFIG_H +#define MOTORHAL_CONFIG_H + +#ifdef __cplusplus + extern "C" { +#endif + + +#if !defined(USE_STM32HAL) +#define USE_STM32HAL +#endif + +#define MOTORHALCONFIG_DONTUSE_CONSOLE +#define MOTORHALCONFIG_DONTUSE_FLASH +#define MOTORHALCONFIG_DONTUSE_UTILITIES +#define MOTORHALCONFIG_DONTUSE_LED +#define MOTORHALCONFIG_DONTUSE_TESTS +#define MOTORHALCONFIG_ADD_IRQHANDLERS +#define MOTORHALCONFIG_REDEFINE_RTOS + +#define MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING + +#if defined(MOTORHALCONFIG_DONTUSE_FLASH) + +#include "pwm.h" +#include "encoder.h" +#include "analog.h" +typedef struct +{ + pwm_ConfTypeDef pwm; + encoder_ConfTypeDef encoder; + analogConfTypeDef analog; +} MainConfTypeDef; + +extern MainConfTypeDef MainConf; + +#endif + + +#if defined(MOTORHALCONFIG_DONTUSE_UTILITIES) + +// Get the MSB of an integer. The compiler generates an immediate constant value when the argument is a constant +// value known at compile time. Use macro msb(x) for not constant values +// @param x Integer constant value +// @return Bit number of the left-most not-zero bit of the argument, or -1 when the argument is 0 +#define MSB(x) ((x)?MSB$64(((uint64_t)(x))):-1) +#define MSB$64(x) (x&0xFFFFFFFF00000000LL?(32+MSB$32(x>>32)):MSB$32(x)) +#define MSB$32(x) (x&0x00000000FFFF0000LL?(16+MSB$16(x>>16)):MSB$16(x)) +#define MSB$16(x) (x&0x000000000000FF00LL?(8+MSB$8(x>>8)):MSB$8(x)) +#define MSB$8(x) (x&0x00000000000000F0LL?(4+MSB$4(x>>4)):MSB$4(x)) +#define MSB$4(x) (x&0x000000000000000CLL?(2+MSB$2(x>>2)):MSB$2(x)) +#define MSB$2(x) (x&0x0000000000000002LL?1:0) + +#endif // MOTORHALCONFIG_DONTUSE_UTILITIES + + +#if defined(MOTORHALCONFIG_REDEFINE_RTOS) + +void taskENTER_CRITICAL(void); +void taskEXIT_CRITICAL(void); +void vTaskDelay(uint32_t ms); + +#endif + +#if defined(MOTORHALCONFIG_DONTUSE_LED) + +enum { LED2 = 0 }; +void ledSet(uint32_t led, uint32_t v); + +#endif + +#ifdef __cplusplus + } /* extern "C" */ +#endif /* __cplusplus */ + +#endif // MOTORHAL_CONFIG_H + +// - end-of-file (leave a blank line after)---------------------------------------------------------------------------- + diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/pwm.c b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/pwm.c new file mode 100644 index 000000000..1e397305f --- /dev/null +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/pwm.c @@ -0,0 +1,1190 @@ +/*******************************************************************************************************************//** + * @file pwm.c + * @author G.Zini + * @version 1.0 + * @date 2021 January, 19 + * @brief PWM signals management + **********************************************************************************************************************/ + + +// CODE SHAPER +#if defined(USE_STM32HAL) +#include "motorhal_config.h" +#endif + +#include "embot_core.h" + +#if defined(USE_STM32HAL) +// API +#include "pwm.h" +#endif + +/* Includes ***********************************************************************************************************/ +#if defined(USE_STM32HAL) +#include "stm32hal.h" +#if !defined(MOTORHALCONFIG_DONTUSE_UTILITIES) +#include "utilities.h" +#endif +#if !defined(MOTORHALCONFIG_DONTUSE_FLASH) +#include "flash.h" +#endif +#if !defined(MOTORHALCONFIG_DONTUSE_CONSOLE) + #include "console.h" +#endif +#if !defined(MOTORHALCONFIG_DONTUSE_LED) +#include "led.h" +#endif +#else +#include "console.h" +#include "cordic.h" +#include "encoder.h" +#include "flash.h" +#include "led.h" +#include "pwm.h" +#include "tim.h" +#include "utilities.h" +#include "FreeRTOS.h" +#include "task.h" +#include "main.h" +#include "stm32g4xx_hal_tim.h" +#endif + +#if (USE_HAL_TIM_REGISTER_CALLBACKS != 1) + #error Flag TIM1 in menu "Project Manager -> Advanced Settings -> Register CallBack" of CubeMx must be ENABLED +#endif + +#define USE_HALL_SENSORS 1 +//#define USE_ENCODER_SENSORS 1 + +#if !defined(USE_ENCODER_SENSORS) +#warning USE_ENCODER_SENSORS is not defined +#endif + +/* Private macros *****************************************************************************************************/ + +#define PWM_ENABLE_MASK (EN1_Pin|EN2_Pin|EN3_Pin) + +/* Current in six-step mode */ +#define HALL_CURRENT_PHASE1 (0) +#define HALL_CURRENT_PHASE2 (1) +#define HALL_CURRENT_PHASE3 (2) + + +/* Private variables **************************************************************************************************/ + +/* Current value of the Hall sensors */ +static volatile uint8_t hallStatus = 0; +static volatile int16_t pwmStatus = 0; +static volatile int32_t hallCounter = 0; +static volatile uint16_t hallAngle = 0; +static volatile int16_t hallCurrent = 0; +#if defined(MOTORHAL_changes) +#warning evalute how to manage hallFilteredCurrent which uses 4104 bytes of RAM +#endif +analogAvgFilterTypeDef hallFilteredCurrent; + + +#if defined(MOTORHAL_changes) && defined(__cplusplus) + +constexpr int16_t numHallSectors = 6; +constexpr float_t iCubDeg = 65536.0; // Range of angular values that can be represented with the encoder +constexpr float_t Deg2iCub = iCubDeg / 360.0; +constexpr int16_t hallAngleStep = 60.0 * Deg2iCub; // 60 degrees scaled by the range of possible values +constexpr int16_t minHallAngleDelta = 30.0 * Deg2iCub; // 30 degrees scaled by the range of possible values + +constexpr uint16_t hallAngleTable[] = +{ + /* ABC (°) */ + /* LLL ERROR */ 0, + /* LLH 240 */ static_cast(240.0 * Deg2iCub), /* 43690 */ + /* LHL 120 */ static_cast(120.0 * Deg2iCub), /* 21845 */ + /* LHH 180 */ static_cast(180.0 * Deg2iCub), /* 32768 */ + /* HLL 0 */ static_cast( 0.0 * Deg2iCub), /* 0 */ + /* HLH 300 */ static_cast(300.0 * Deg2iCub), /* 54613 */ + /* HHL 60 */ static_cast( 60.0 * Deg2iCub), /* 10922 */ + /* HHH ERROR */ static_cast(0) +}; + +//constexpr int16_t hallSectorTable[] = +//{ +// /* ABC (°) */ +// /* LLL ERROR */ static_cast(0), +// /* LLH 240 */ static_cast(4), /* 43690 */ +// /* LHL 120 */ static_cast(2), /* 21845 */ +// /* LHH 180 */ static_cast(3), /* 32768 */ +// /* HLL 0 */ static_cast(0), /* 0 */ +// /* HLH 300 */ static_cast(5), /* 54613 */ +// /* HHL 60 */ static_cast(1), /* 10922 */ +// /* HHH ERROR */ static_cast(0) +//}; + +#else + +static const uint16_t hallAngleTable[] = +{ + /* ABC (°) */ + /* LLL ERROR */ 0, + /* LLH 300 */ 300.0 * 65536.0 / 360.0 + 0.5, /* 54613 */ + /* LHL 180 */ 180.0 * 65536.0 / 360.0 + 0.5, /* 32768 */ + /* LHH 240 */ 240.0 * 65536.0 / 360.0 + 0.5, /* 43690 */ + /* HLL 60 */ 60.0 * 65536.0 / 360.0 + 0.5, /* 10923 */ + /* HLH 0 */ 0.0 * 65536.0 / 360.0 + 0.5, /* 0 */ + /* HHL 120 */ 120.0 * 65536.0 / 360.0 + 0.5, /* 21845 */ + /* HHH ERROR */ 0 +}; + +#endif // #if defined(MOTORHAL_changes) && defined(__cplusplus) + + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new types, variables, static function prototypes required by MOTORHAL +// -------------------------------------------------------------------------------------------------------------------- + + +static volatile uint8_t s_pwm_hallStatus_old = 0; +static volatile uint8_t s_pwm_hallOrder[3] = {0, 0, 0}; + +static volatile bool s_pwm_calibrating = true; + +//struct pwm_adc_callback_set_T +//{ +// void (*callback_fn)(void *owner, int16_t Iuvw[3], void* rtu, void* rty); +// void *owner; +// void* rtu; +// void* rty; +//}; + +//static volatile pwm_adc_callback_set_T s_pwm_adc_callback_set = +//{ +// NULL, NULL, NULL, NULL +//}; + +static void s_pwm_dummy_adc_callback(void *owner, const pwm_Currents_t * const currents) {} +static pwm_Currents_t s_pwm_dummy_currents = {0}; + +static volatile pwm_ADC_callback_t s_pwm_ADC_cbk = +{ + .callback = s_pwm_dummy_adc_callback, + .owner = NULL +}; + + +static uint8_t s_pwm_updateHallStatus(void); + +#endif // #if defined(MOTORHAL_changes) + +/* Public variables ***************************************************************************************************/ +/* Private functions **************************************************************************************************/ + +#if defined(MOTORHAL_changes) + +// we dont need: static void hallSetPWM(int16_t pwm) +// but a s_pwm_updateHallStatus() + +#else + +/*******************************************************************************************************************//** + * @brief Read the current Hall sensor status and configure signals EN1, EN2, EN3, PHASE1, PHASE2, PHASE3 as for a + * CW or CCW torque + * @param pwm Set the new PWM value. A positive value generate a CW torque, whereas a negative value generate a + * CCW torque. Absolute value must be lower than MAX_PWM + * @return void + * + * This function configures the signals as in the following table + * + * | || CW || CCW | + * | HALL1 HALL2 HALL3 || PHASE1 PHASE2 PHASE3 || PHASE1 PHASE2 PHASE3 | + * |-------------------++----------------------++----------------------| + * | 1 0 1 || PWM LOW HIZ || LOW PWM HIZ | + * | 1 0 0 || PWM HIZ LOW || LOW HIZ PWM | + * | 1 1 0 || HIZ PWM LOW || HIZ LOW PWM | + * | 0 1 0 || LOW PWM HIZ || PWM LOW HIZ | + * | 0 1 1 || LOW HIZ PWM || PWM HIZ LOW | + * | 0 0 1 || HIZ LOW PWM || HIZ PWM LOW | + * |-------------------||----------------------||----------------------| + * | 0 0 0 || HIZ HIZ HIZ || HIZ HIZ HIZ | ERROR + * | 1 1 1 || HIZ HIZ HIZ || HIZ HIZ HIZ | ERROR + * + * where: + * HIZ means that PHASEx is in high impedanace state (ENx = 0, PWMx = 0) + * LOW means that PHASEx is in LOW state (ENx = 1, PWMx = 0) + * PWM means that PHASEx is modulated with the pwm value (ENx = 1, PWMx = pwm) + */ +static void hallSetPWM(int16_t pwm) +{ + /* Remeber previous value */ + uint8_t hall = hallStatus; + + /* Read current value of HALL1, HALL2 and HALL3 signals in bits 2..0 */ + hallStatus = (((HALL1_GPIO_Port->IDR & HALL1_Pin) >> MSB(HALL1_Pin)) << 2) + | (((HALL2_GPIO_Port->IDR & HALL2_Pin) >> MSB(HALL2_Pin)) << 1) + | (((HALL3_GPIO_Port->IDR & HALL3_Pin) >> MSB(HALL3_Pin)) << 0); + + /* CW torque */ + if (pwm >= 0) + { + switch(hallStatus) + { + case 0x05: + /* PHASE1=pwm, PHASE2=-pwm, PHASE3=hiz */ + EN1_GPIO_Port->BSRR = EN1_Pin | EN2_Pin | (EN3_Pin<<16) ; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + /* Verify previous HALL sensors status */ + if (hall == 0x01) ++hallCounter; + else if (hall == 0x04) --hallCounter; + break; + + case 0x04: + /* PHASE1=pwm, PHASE2=hiz, PHASE3=-pwm */ + EN1_GPIO_Port->BSRR = EN1_Pin | (EN2_Pin<<16) | EN3_Pin ; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + /* Verify previous HALL sensors status */ + if (hall == 0x05) ++hallCounter; + else if (hall == 0x06) --hallCounter; + break; + + case 0x06: + /* PHASE1=hiz, PHASE2=pwm, PHASE3=-pwm */ + EN1_GPIO_Port->BSRR = (EN1_Pin<<16) | EN2_Pin | EN3_Pin; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + /* Verify previous HALL sensors status */ + if (hall == 0x04) ++hallCounter; + else if (hall == 0x02) --hallCounter; + break; + + case 0x02: + /* PHASE1=-pwm, PHASE2=pwm, PHASE3=hiz */ + EN1_GPIO_Port->BSRR = EN1_Pin | EN2_Pin | (EN3_Pin<<16) ; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + /* Verify previous HALL sensors status */ + if (hall == 0x06) ++hallCounter; + else if (hall == 0x03) --hallCounter; + break; + + case 0x03: + /* PHASE1=-pwm, PHASE2=hiz, PHASE3=pwm */ + EN1_GPIO_Port->BSRR = EN1_Pin | (EN2_Pin<<16) | EN3_Pin ; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, pwm); + /* Verify previous HALL sensors status */ + if (hall == 0x02) ++hallCounter; + else if (hall == 0x01) --hallCounter; + break; + + case 0x01: + /* PHASE1=hiz, PHASE2=-pwm, PHASE3=pwm */ + EN1_GPIO_Port->BSRR = (EN1_Pin<<16) | EN2_Pin | EN3_Pin; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, pwm); + /* Verify previous HALL sensors status */ + if (hall == 0x03) ++hallCounter; + else if (hall == 0x05) --hallCounter; + break; + + default: + /* ERROR: forbitten combination */ + ledSet(LED2, 0); + EN1_GPIO_Port->BSRR = ((EN3_Pin|EN2_Pin|EN1_Pin)<<16); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + pwm = 0; + break; + } + } + /* CCW torque */ + else + { + /* Current hall sensors status */ + switch (hallStatus) + { + case 0x05: + /* PHASE1=pwm, PHASE2=-pwm, PHASE3=hiz */ + EN1_GPIO_Port->BSRR = EN1_Pin | EN2_Pin | (EN3_Pin<<16) ; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, -pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + /* Verify previous HALL sensors status */ + if (hall == 0x01) ++hallCounter; + else if (hall == 0x04) --hallCounter; + break; + + case 0x04: + /* PHASE1=pwm, PHASE2=hiz, PHASE3=-pwm */ + EN1_GPIO_Port->BSRR = EN1_Pin | (EN2_Pin<<16) | EN3_Pin ; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, -pwm); + /* Verify previous HALL sensors status */ + if (hall == 0x05) ++hallCounter; + else if (hall == 0x06) --hallCounter; + break; + + case 0x06: + /* PHASE1=hiz, PHASE2=pwm, PHASE3=-pwm */ + EN1_GPIO_Port->BSRR = (EN1_Pin<<16) | EN2_Pin | EN3_Pin; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, -pwm); + /* Verify previous HALL sensors status */ + if (hall == 0x04) ++hallCounter; + else if (hall == 0x02) --hallCounter; + break; + + case 0x02: + /* PHASE1=-pwm, PHASE2=pwm, PHASE3=hiz */ + EN1_GPIO_Port->BSRR = EN1_Pin | EN2_Pin | (EN3_Pin<<16) ; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, -pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + /* Verify previous HALL sensors status */ + if (hall == 0x06) ++hallCounter; + else if (hall == 0x03) --hallCounter; + break; + + case 0x03: + /* PHASE1=-pwm, PHASE2=hiz, PHASE3=pwm */ + EN1_GPIO_Port->BSRR = EN1_Pin | (EN2_Pin<<16) | EN3_Pin ; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, -pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + /* Verify previous HALL sensors status */ + if (hall == 0x02) ++hallCounter; + else if (hall == 0x01) --hallCounter; + break; + + case 0x01: + /* PHASE1=hiz, PHASE2=-pwm, PHASE3=pwm */ + EN1_GPIO_Port->BSRR = (EN1_Pin<<16) | EN2_Pin | EN3_Pin; + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, -pwm); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + /* Verify previous HALL sensors status */ + if (hall == 0x03) ++hallCounter; + else if (hall == 0x05) --hallCounter; + break; + + default: + /* ERROR: forbitten combination */ + ledSet(LED2, 0); + EN1_GPIO_Port->BSRR = ((EN3_Pin|EN2_Pin|EN1_Pin)<<16); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); + pwm = 0; + break; + } + } + + /* Update pwm status */ + pwmStatus = pwm; + + /* Update angle */ + hallAngle = hallAngleTable[hallStatus]; +} + + +#endif // #if defined(MOTORHAL_changes) + + + +/* Callback functions *************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief Called by TIM1 when signal nMFAULT is activated by the motor driver. + * @param htim Pointer to TIM1 handler + * @return void + */ +static void pwmMotorFault_cb(TIM_HandleTypeDef *htim) +{ + /* Check TIM1 already initialized */ + if (TIM1 == htim->Instance) + { + /* Avoid re-entering in the isr */ + __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_BREAK); + /* Disable the driver */ + EN1_GPIO_Port->BSRR = ((EN3_Pin|EN2_Pin|EN1_Pin)<<16); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0); +#if defined(MOTORHAL_changes) +#else + /* Null output voltage */ + pwmStatus = 0; + /* Advertise the fault */ + ledSet(LED2, 0); +#endif + + } +} + + +/*******************************************************************************************************************//** + * @brief Called by TIM3 whenever it detects an edge over HALL1, HALL2 and HALL3 signals + * @param htim Pointer to TIM3 handler + * @return void + */ +static void hallStatusChange_cb(TIM_HandleTypeDef *htim) +{ + /* Check TIM3 already initialized */ + if (TIM3 == htim->Instance) + { +#if defined(MOTORHAL_changes) + s_pwm_updateHallStatus(); +#else + /* Generate the correct PWM configuration following the pwmStatus pattern */ + hallSetPWM(pwmStatus); +#endif + } +} + +#if defined(MOTORHAL_changes) + +void pwmSetCurrents_cb(int16_t i1, int16_t i2, int16_t i3) +{ + static pwm_Currents_t currents = {0}; + // as soon as possible: copy the currents (must be converted from raw as i1, i2, i3 come from ADC) + currents.u = analogConvertCurrent(i1); + currents.v = analogConvertCurrent(i2); + currents.w = analogConvertCurrent(i3); + + // so far, calibration is done only at startup of current acquisition and not at runtime + if (s_pwm_calibrating) + { + // we must call the filtering of {1, i2, i3} at least for ANALOG_AVG_FILTER_LENGTH times. + // because ... we want to load the full filter so that ANALOG_AVG_FILTER_LENGTH values are accumulated + // correctly before we can get the average value with the division. + constexpr uint16_t maxIter {1024}; // {ANALOG_AVG_FILTER_LENGTH + 10}; // was 1000 + static uint16_t counter = 0; + + if (counter < maxIter) + { + ++counter; +#if defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING) + // give the values to the filters + analog_MovingAverage(i1, i2, i3); +#else + // dont do filtering because it will be done inside adc2_HalfTransferComplete_cb() + // and adc2_TransferComplete_cb() +#endif + } + else + { + // never mind if we have macro MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING defined or not + // now we surely have filtered values of currents, so we can use + // their raw values to impose their offsets + analogSetOffsetIph1(analog_RawCph1() + analogGetOffsetIph1()); + analogSetOffsetIph2(analog_RawCph2() + analogGetOffsetIph2()); + analogSetOffsetIph3(analog_RawCph3() + analogGetOffsetIph3()); + + // and we dont need to calibrate anymore. + s_pwm_calibrating = false; + counter = 0; + //if we set counter = 0 now, we can maybe decide to start / restart a runtime calibration + // by imposing s_pwm_calibrating = true inside some extern function + } + } + + s_pwm_ADC_cbk.callback(s_pwm_ADC_cbk.owner, ¤ts); +} + +#else +/*******************************************************************************************************************//** + * @brief Called by DMA associated to ADC2 whenever a new set of phase currents is available + * @param i1, i2, i3 Currents measured in PHASE1, PHASE2 and PHASE3 of the motor + * @return void + */ +void pwmSetCurrents_cb(int16_t i1, int16_t i2, int16_t i3) +{ + /* CW torque */ + if (pwmStatus >= 0) + { + switch (hallStatus) + { + case 0x05: + /* PHASE1=pwm, PHASE2=low, PHASE3=hiz */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, -analogConvertCurrent(i2+i3)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + case 0x04: + /* PHASE1=pwm, PHASE2=hiz, PHASE3=low */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, -analogConvertCurrent(i2+i3)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + case 0x06: + /* PHASE1=hiz, PHASE2=pwm, PHASE3=low */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, -analogConvertCurrent(i1+i3)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + case 0x02: + /* PHASE1=low, PHASE2=pwm, PHASE3=hiz */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, -analogConvertCurrent(i1+i3)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + case 0x03: + /* PHASE1=low, PHASE2=hiz, PHASE3=pwm */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, -analogConvertCurrent(i1+i2)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + case 0x01: + /* PHASE1=hiz, PHASE2=low, PHASE3=pwm */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, -analogConvertCurrent(i1+i2)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + default: + /* ERROR: forbitten combination */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, 0); + break; + } + } + /* CCW torque */ + else + { + switch (hallStatus) + { + case 0x05: + /* PHASE1=low, PHASE2=-pwm, PHASE3=hiz */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, analogConvertCurrent(i1+i3)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + case 0x04: + /* PHASE1=low, PHASE2=hiz, PHASE3=-pwm */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, analogConvertCurrent(i1+i2)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + case 0x06: + /* PHASE1=hiz, PHASE2=low, PHASE3=-pwm */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, analogConvertCurrent(i1+i2)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + case 0x02: + /* PHASE1=-pwm, PHASE2=low, PHASE3=hiz */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, analogConvertCurrent(i2+i3)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + case 0x03: + /* PHASE1=-pwm, PHASE2=hiz, PHASE3=low */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, analogConvertCurrent(i2+i3)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + case 0x01: + /* PHASE1=hiz, PHASE2=-pwm, PHASE3=low */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, analogConvertCurrent(i1+i3)) >> ANALOG_AVG_FILTER_SHIFT; + break; + + default: + /* ERROR: forbitten combination */ + hallCurrent = analogMovingAverageFromISR(&hallFilteredCurrent, 0); + break; + } + } +} + +#endif // #if defined(MOTORHAL_changes) + +/* Exported functions *************************************************************************************************/ + +#if defined(MOTORHAL_changes) + +HAL_StatusTypeDef pwmInit(void) +{ + /* todo: no HALL sensor motor index startup calibration */ + MainConf.pwm.mode = PWM_CONF_MODE_HALL; + + /* Clear any preceeding fault condition */ + pwmReset(ENABLE); + pwmSleep(DISABLE); + HAL_Delay(10); + pwmReset(DISABLE); + HAL_Delay(10); + +// if (0 == (MainConf.pwm.mode & PWM_CONF_MODE_MASK)) +// { +// MainConf.pwm.mode = PWM_CONF_MODE_HALL; +// MainConf.pwm.num_polar_couples = num_polar_couples; +// } + + /* Register the required TIM1 callback functions */ + HAL_TIM_RegisterCallback(&htim1, HAL_TIM_BREAK_CB_ID, pwmMotorFault_cb); + __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_BREAK); + + /* Reset the PWM value */ + pwmSet(0, 0 ,0); + + //s_pwm_updateHallStatus(); + + /* Start TIM1 as 3-phase PWM generator */ + if (HAL_OK != HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1) || + HAL_OK != HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2) || + HAL_OK != HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3) || + HAL_OK != HAL_TIM_Base_Start_IT(&htim1)) + { + HAL_TIM_Base_Stop(&htim1); + HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_1); + HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_2); + HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_3); + return HAL_ERROR; + } + + /* All done */ + return HAL_OK; +} + +#else + +/*******************************************************************************************************************//** + * @brief Complete the CubeMx TIM1 configuration for the PWM subsystem + * @param void + * @return void + */ +HAL_StatusTypeDef pwmInit(void) +{ + /* Clear any preceeding fault condition */ + pwmReset(ENABLE); + pwmSleep(DISABLE); + vTaskDelay(10); + pwmReset(DISABLE); + vTaskDelay(10); + + if (0 == (MainConf.pwm.mode & PWM_CONF_MODE_MASK)) + { + MainConf.pwm.mode = PWM_CONF_MODE_HALL; + MainConf.pwm.poles = 7; + } + // callback sul fault del motor, non ext fault (slo overcurrent e heat) + /* Register the required TIM1 callback functions */ + HAL_TIM_RegisterCallback(&htim1, HAL_TIM_BREAK_CB_ID, pwmMotorFault_cb); + __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_BREAK); + + /* Reset the PWM value */ + hallSetPWM(pwmStatus); + + /* Start TIM1 as 3-phase PWM generator */ + if (HAL_OK != HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1) || + HAL_OK != HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2) || + HAL_OK != HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3) || + HAL_OK != HAL_TIM_Base_Start_IT(&htim1)) + { + HAL_TIM_Base_Stop(&htim1); + HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_1); + HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_2); + HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_3); + return HAL_ERROR; + } + + /* All done */ + return HAL_OK; +} + +#endif // #if defined(MOTORHAL_changes) + + + + +/*******************************************************************************************************************//** + * @brief Complete the CubeMx TIM3 configuration for the PWM subsystem + * @param void + * @return void + */ +HAL_StatusTypeDef hallInit(void) +{ +#if defined(MOTORHAL_changes) +#else + /* Read value of HALL1, HALL2 and HALL3 signals in bits 2..0 */ + hallStatus = (((HALL1_GPIO_Port->IDR & HALL1_Pin) >> MSB(HALL1_Pin)) << 2) + | (((HALL2_GPIO_Port->IDR & HALL2_Pin) >> MSB(HALL2_Pin)) << 1) + | (((HALL3_GPIO_Port->IDR & HALL3_Pin) >> MSB(HALL3_Pin)) << 0); + + /* Init angle */ + hallAngle = hallAngleTable[hallStatus]; +#endif // #if defined(MOTORHAL_changes) + /* Start position counter */ + hallCounter = 0; + + /* Check TIM3 configuration and start it */ + return ((TIM3 == htim3.Instance) && + (HAL_OK == HAL_TIM_RegisterCallback(&htim3, HAL_TIM_IC_CAPTURE_CB_ID, hallStatusChange_cb)) && + (HAL_OK == HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1)) && + (HAL_OK == HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_2)) && + (HAL_OK == HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_3)) && + (HAL_OK == HAL_TIM_Base_Start_IT(&htim3)))? HAL_OK : HAL_ERROR; +} + + +/*******************************************************************************************************************//** + * @brief Read the position counter driven by the Hall sensors + * @param void + * @return int32_t Current value of the position counter + */ +int32_t hallGetCounter(void) +{ + return hallCounter; +} + + +/*******************************************************************************************************************//** + * @brief Set the position counter driven by the Hall sensors + * @param count New value of the position counter + * @return void + */ +void hallSetCounter(int32_t count) +{ + hallCounter = count; +} + + +/*******************************************************************************************************************//** + * @brief Read the angle measured by the Hall sensors + * @param void + * @return uint16_t Current value of the angle + */ +uint16_t hallGetAngle(void) +{ + return hallAngle; +} + + +/*******************************************************************************************************************//** + * @brief Read the last measured status of the Hall sensors + * @param void + * @return uint16_t bit2 <- HALL_1, bit1 <- HALL_2, bit0 <- HALL_3 + */ +uint16_t hallGetStatus(void) +{ + return hallStatus; +} + + +/*******************************************************************************************************************//** + * @brief Read the phase current in hall 6-step mode + * @param void + * @return int16_t Current in mA + */ +int16_t hallGetCurrent(void) +{ + return hallCurrent; +} + + +/*******************************************************************************************************************//** + * @brief Enter or Exit the SLEEP mode of the motor driver + * @param enable It can assume one of the following values: + * ENABLE Motor driver in SLEEP mode: Power dissipation is limited but PWM is not allowed + * DISABLE Motor driver in active mode: PWM generation is allowed. + * @return void + */ +void pwmSleep(FunctionalState enable) +{ + /* Configure signal nMSLEEP as required */ + HAL_GPIO_WritePin(nMSLEEP_GPIO_Port, nMSLEEP_Pin, (ENABLE==enable)?GPIO_PIN_RESET:GPIO_PIN_SET); +} + + +/*******************************************************************************************************************//** + * @brief Assert or release the nMRESET signal of the driver. It can be used to clear any fault condition + * @param enable It can assume one of the following values: + * ENABLE Assert motor driver RESET + * DISABLE Release motor driver RESET + * @return void + */ +void pwmReset(FunctionalState enable) +{ + HAL_GPIO_WritePin(nMRESET_GPIO_Port, nMRESET_Pin, (ENABLE==enable)?GPIO_PIN_RESET:GPIO_PIN_SET); +} + + +/*******************************************************************************************************************//** + * @brief + * @param + * @return Function result + */ +HAL_StatusTypeDef pwmResetFault(void) +{ + pwmSet(0, 0, 0); + pwmReset(ENABLE); + vTaskDelay(10); + pwmReset(DISABLE); + vTaskDelay(10); + if (GPIO_PIN_SET == HAL_GPIO_ReadPin(nMFAULT_GPIO_Port, nMFAULT_Pin)) + { +#if defined(MOTORHAL_changes) + pwmPhaseEnable(PWM_PHASE_ALL); +#else +#ifdef USE_ENCODER_SENSORS + pwmPhaseEnable(PWM_PHASE_ALL); +#endif +#endif + __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_BREAK); + __HAL_TIM_CLEAR_IT(&htim1, TIM_IT_BREAK); + __HAL_TIM_MOE_ENABLE(&htim1); vTaskDelay(10); + __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_BREAK); + ledSet(0, LED2); + return HAL_OK; + } + ledSet(LED2, 0); + return HAL_ERROR; +} + + +/*******************************************************************************************************************//** + * @brief + * @param + * @return void + */ +void pwmSet(uint16_t u, uint16_t v, uint16_t w) +{ +#if defined(MOTORHAL_changes) + if (s_pwm_calibrating) u = v = w = 0; +#endif + /* Saturate arguments */ + if (u > (uint16_t)MAX_PWM) u = MAX_PWM; + if (v > (uint16_t)MAX_PWM) v = MAX_PWM; + if (w > (uint16_t)MAX_PWM) w = MAX_PWM; + /* Update PWM generators */ + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, u); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, v); + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, w); +} + + +/*******************************************************************************************************************//** + * @brief Enable the PWM driver outputs + * @param mask Any combination of the following values + * PWM_PHASE_U + * PWM_PHASE_V + * PWM_PHASE_W + * @return void + */ +void pwmPhaseEnable(uint16_t mask) +{ + EN1_GPIO_Port->BSRR = ((uint32_t)mask & PWM_PHASE_ALL); +} + + +/*******************************************************************************************************************//** + * @brief Disable the PWM driver outputs + * @param mask Any combination of the following values + * PWM_PHASE_U + * PWM_PHASE_V + * PWM_PHASE_W + * @return void + */ +void pwmPhaseDisable(uint16_t mask) +{ + EN1_GPIO_Port->BSRR = ((uint32_t)mask & PWM_PHASE_ALL) << 16u; +} + +/*******************************************************************************************************************//** + * @brief + * @param + * @return Function result + */ +HAL_StatusTypeDef pwmSetValue(int32_t pwm) +{ +#if defined(MOTORHAL_changes) + return HAL_ERROR; +#else + if ((pwm >= -(int32_t)MAX_PWM) && (pwm <= (int32_t)MAX_PWM)) + { +#ifdef USE_HALL_SENSORS + __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3); + hallSetPWM(pwm); + __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3); +#endif + return HAL_OK; + } + return HAL_ERROR; +#endif +} + +#if defined(MOTORHALCONFIG_DONTUSE_TESTS) +void pwmTest(void) {} +#else + +/*******************************************************************************************************************//** + * @brief + * @param + * @return + */ +void pwmTest(void) +{ + char ch; + char coBuffer[80]; + const char *curs; + int32_t pwm; + + coprintf("Motor Test\n"); + if (GPIO_PIN_RESET == HAL_GPIO_ReadPin(nMFAULT_GPIO_Port, nMFAULT_Pin)) + { + ledSet(LED2, 0); + coprintf("ATTENTION: FAULT indication active\n"); + } + else ledSet(0, LED2); + for (;;) + { + coprintf("D - Display HALL and ENCODER status\n" + "F - Clear motor FAULT indication\n" + "P - Set motor PWM\n" + "R - Reset Hall sensor counter\n" + "ESC : Exit test\n" + "? "); vTaskDelay(250); + if (isgraph(ch = coRxChar())) coPutChar(ch); + coPutChar('\n'); + + switch (toupper(ch)) + { + case 'D': + while (1) + { + coprintf("\rENCODER = %5u, HALL = %+11d, CURRENT=%+5d mA, speed=%+5d rpm ", + encoderGetCounter(), hallGetCounter(), hallGetCurrent(), encoderGetSpeed()); + vTaskDelay(100); + if (coRxReady()) + { + ch = coRxChar(); + if (('r'==ch)||('R'==ch)) hallSetCounter(0); + else if ('\x1B'==ch) break; + } + } + coprintf("\n"); + break; + + case 'F': + if (HAL_OK != pwmResetFault()) + { + coprintf("ERROR: Cannot clear FAULT indication\n"); + } + break; + + case 'P': + coprintf("(%d)? ", pwmStatus); + coEditString(coBuffer, sizeof(coBuffer)); + coprintf("\n"); + curs = &(coBuffer[0]); + if ('\0' != skipblank(&curs)) + { + if (!atosl(&curs, &pwm) || (HAL_OK != pwmSetValue(pwm))) + { + coprintf("ERROR: %s\n", coBuffer); + } + } + break; + + case 'R': + hallSetCounter(0); + break; + + case '\x1B': + coprintf("Exit test\n"); + return; + + default: + coprintf("ERROR: %c\n", ch); + break; + } + } +} + +#endif // MOTORHALCONFIG_DONTUSE_TESTS + + + + +#if defined(MOTORHAL_changes) + +// -------------------------------------------------------------------------------------------------------------------- +// add in here all the new functions required by MOTORHAL +// -------------------------------------------------------------------------------------------------------------------- + + + +extern void pwm_set_ADC_callback(pwm_ADC_callback_t *cbk) +{ + if(NULL != cbk) + { + s_pwm_ADC_cbk.callback = (NULL != cbk->callback) ? cbk->callback : s_pwm_dummy_adc_callback; + s_pwm_ADC_cbk.owner = cbk->owner; + } +} + +//HAL_StatusTypeDef pwm_Deinit(void) +//{ +// pwmPhaseDisable(PWM_PHASE_ALL); +// +// return HAL_OK; +//} + + +HAL_StatusTypeDef pwm_hallDeinit(void) +{ + return HAL_OK; +} + + +#define DECODE_HALLSTATUS (((HALL1_GPIO_Port->IDR & HALL1_Pin) >> MSB(HALL1_Pin)) << s_pwm_hallOrder[0]) \ + | (((HALL2_GPIO_Port->IDR & HALL2_Pin) >> MSB(HALL2_Pin)) << s_pwm_hallOrder[1]) \ + | (((HALL3_GPIO_Port->IDR & HALL3_Pin) >> MSB(HALL3_Pin)) << s_pwm_hallOrder[2]) + +static uint8_t s_pwm_updateHallStatus(void) +{ + s_pwm_hallStatus_old = hallStatus; + static int8_t calibration_step = 0; + + static uint16_t border[6]={0}; + static uint8_t border_flag = 0; + + /* Read current value of HALL1, HALL2 and HALL3 signals in bits 2..0 */ + hallStatus = DECODE_HALLSTATUS; + uint16_t angle = MainConf.pwm.hall_offset + hallAngleTable[hallStatus]; + + // Check which sector between [0 ... 5] the rotor is in + int16_t sector = ((minHallAngleDelta + angle) / hallAngleStep) % numHallSectors; + static int16_t sector_old = sector; + + hallAngle = angle; + + if (MainConf.encoder.resolution == 0) // no encoder + { + encoder_Force(angle); + } + else + { + if (!s_pwm_hallStatus_old) + { + hallCounter = 0; + encoder_Reset(); + encoder_Force(angle); + } + else + { + // Check if the motor is rotating forward (counterclockwise) + bool forward = ((sector-sector_old+numHallSectors)%numHallSectors)==1; + + if (forward) // forward + { + ++hallCounter; + angle -= minHallAngleDelta; // -30 deg + } + else + { + --hallCounter; + angle += minHallAngleDelta; // +30 deg + } + /* + 0) Use the Hall sensors to rotate until the wrap-around border is reached, + then reset the encoder value + */ + if (calibration_step == 0) + { + encoder_Force(angle); + + if ((sector == 0 && sector_old == 5) || (sector == 5 && sector_old == 0)) + { + encoder_Reset(); + calibration_step = 1; + } + } + /* + 1) Use the hall sensors to rotate. While rotating, store the encoder angle + every time a sector border is crossed. When all 6 borders are crossed, + compute the offset to apply to the encoder by least squares fitting. After + the offset is applied set encoderCalibrated to true + */ + else if (calibration_step == 1) + { + encoder_Force(angle); + + // use the current sector if forward rotation or previous if reverse + uint8_t sector_index = forward ? sector : (sector+1)%numHallSectors; + + // keep track of the encoder value between sectors + border[sector_index] = encoder_GetUncalibrated(); + + // found the s-th border, put a 1 in the mask + border_flag |= 1 << sector_index; + + // If all sectors are found apply least squares fitting by computing average of + // difference between measured values on borders and expected hall angle + if (border_flag == 63) // 111111 + { + calibration_step = 2; + + int32_t offset = int16_t(border[0] - MainConf.pwm.hall_offset + minHallAngleDelta); + offset += int16_t(border[1] - MainConf.pwm.hall_offset + minHallAngleDelta - hallAngleStep); + offset += int16_t(border[2] - MainConf.pwm.hall_offset + minHallAngleDelta - 2 * hallAngleStep); + offset += int16_t(border[3] - MainConf.pwm.hall_offset + minHallAngleDelta - 3 * hallAngleStep); + offset += int16_t(border[4] - MainConf.pwm.hall_offset + minHallAngleDelta - 4 * hallAngleStep); + offset += int16_t(border[5] - MainConf.pwm.hall_offset + minHallAngleDelta - 5 * hallAngleStep); + + offset /= numHallSectors; + + embot::core::print("CALIBRATED\n"); + + encoder_Calibrate(int16_t(offset)); + } + } + /* + 2) Update the forced value even if it is not used when the encoder is calibrated. + Reset the encoder angle after a full rotation to avoid desynching + */ + else if (calibration_step == 2) + { + encoder_Force(angle); + // reset the angle after full rotation + if ((sector == 0 && sector_old == 5) || (sector == 5 && sector_old == 0)) + { + encoder_Reset(); + } + } + } + } + // update the old sector and hall status + sector_old = sector; + s_pwm_hallStatus_old = hallStatus; + + return hallStatus; +} + + +HAL_StatusTypeDef pwm_hallConfig(uint8_t swapBC, uint16_t pwm_hall_offset) +{ + MainConf.pwm.hall_offset = pwm_hall_offset; + MainConf.pwm.swapBC = swapBC; + + s_pwm_hallOrder[0] = 0; + s_pwm_hallOrder[1] = MainConf.pwm.swapBC ? 2 : 1; + s_pwm_hallOrder[2] = MainConf.pwm.swapBC ? 1 : 2; + + s_pwm_updateHallStatus(); + + /* Start position counter */ + hallCounter = 0; + + return HAL_OK; +} + +//void pwm_setADC_cb(void (*fn_cb)(void *, int16_t[3], void*, void*), void *owner, void* rtu, void* rty) +//{ +// s_pwm_adc_callback_set.callback_fn = fn_cb; +// s_pwm_adc_callback_set.owner = owner; +// s_pwm_adc_callback_set.rtu = rtu; +// s_pwm_adc_callback_set.rty = rty; +//} + + + +#endif // #if defined(MOTORHAL_changes) + +/* END OF FILE ********************************************************************************************************/ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/pwm.h b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/pwm.h new file mode 100644 index 000000000..5b6357ac8 --- /dev/null +++ b/emBODY/eBcode/arch-arm/board/amcbldc/application/src/motorhal2/pwm.h @@ -0,0 +1,166 @@ +/*******************************************************************************************************************//** + * @file pwm.h + * @author G.Zini + * @version 1.0 + * @date 2021 January, 19 + * @brief PWM signals management + **********************************************************************************************************************/ + +/* Define to prevent recursive inclusion */ +#ifndef __PWM_H +#define __PWM_H + +#ifdef __cplusplus + extern "C" { +#endif + + +/* Includes ----------------------------------------------------------------------------------------------------------*/ +#include +#include +#include +#include + +#if defined(USE_STM32HAL) +#include "stm32hal.h" +#define MOTORHAL_changes +#else +#include +#include "analog.h" +#include "main.h" +#include "stm32g4xx.h" +#endif + +/* Exported macro ----------------------------------------------------------------------------------------------------*/ + +// dithering -> max 2^14, ma un po meno +// se si usasse il modo no-dithering -> 2^10 (4 bit in meno) +#define MAX_PWM (16383U) + +#define PWM_CONF_MODE_HALL (0x0001UL) +#define PWM_CONF_MODE_ENCODER (0x0002UL) +#define PWM_CONF_MODE_MASK (PWM_CONF_MODE_HALL|PWM_CONF_MODE_ENCODER) + +#define PWM_PHASE_U (EN1_Pin) +#define PWM_PHASE_V (EN2_Pin) +#define PWM_PHASE_W (EN3_Pin) +#define PWM_PHASE_ALL (EN1_Pin|EN2_Pin|EN3_Pin) + + +/* Exported typedefs -------------------------------------------------------------------------------------------------*/ + +#if defined(MOTORHAL_changes) + +typedef struct +{ + uint32_t mode; + uint16_t hall_offset; + //uint16_t sector_offset; + uint8_t num_polar_couples; + uint8_t swapBC; +} pwm_ConfTypeDef; + +#else + +typedef struct +{ + uint32_t mode; + uint32_t poles; +} pwmConfTypeDef; + +#endif + +#if defined(MOTORHAL_changes) + +// we keep int32_t even if the adc gets only int16_t values +typedef struct +{ + int32_t u; + int32_t v; + int32_t w; +} pwm_Currents_t; + +#endif + +/* Exported variables ------------------------------------------------------------------------------------------------*/ + + + +/* Exported functions prototypes -------------------------------------------------------------------------------------*/ + +extern HAL_StatusTypeDef hallInit(void); +extern int32_t hallGetCounter(void); +extern void hallSetCounter(int32_t count); +extern uint16_t hallGetAngle(void); +extern uint16_t hallGetStatus(void); + +extern HAL_StatusTypeDef pwmInit(void); +extern void pwmSleep(FunctionalState enable); +extern void pwmReset(FunctionalState enable); +extern HAL_StatusTypeDef pwmResetFault(void); + +extern void pwmSet(uint16_t u, uint16_t v, uint16_t w); +extern void pwmPhaseEnable(uint16_t mask); +extern void pwmPhaseDisable(uint16_t mask); + +// pwmSetCurrents_cb(): REWRITTEN by iCubTech +extern void pwmSetCurrents_cb(int16_t i1, int16_t i2, int16_t i3); +extern HAL_StatusTypeDef pwmSetValue(int32_t pwm); /* DEPRECATED */ + +extern void pwmTest(void); + + +#if defined(MOTORHAL_changes) + +HAL_StatusTypeDef pwm_hallDeinit(void); +HAL_StatusTypeDef pwm_hallConfig(uint8_t swapBC, uint16_t pwm_hall_offset); + +//extern HAL_StatusTypeDef pwm_Deinit(void); + + + +//extern void pwm_setADC_cb(void (*fn_cb)(void *, int16_t[3], void*, void*), void *owner, void* rtu, void* rty); + +// a function of this type is used by the ADC IRQ Handler to report the measured currents to higher levels +// we need two param to to the job: +// - owner: is a pointer to the high level calling module. we need it so that inside the callback +// we just reinterpret_cast<> it to the calling class +// - currents: is a pointer to the three currents. the memory pointed by currents belongs to owner +// so that the caller of the callback will just copy the memory of the ADC (typically DMA memory) +// straigth away to destination to avoid corruptions. +typedef void (*pwm_fp_adc_callback_t) (void *owner, const pwm_Currents_t * const currents); + + +typedef struct +{ + pwm_fp_adc_callback_t callback; + void* owner; +} pwm_ADC_callback_t; + +// this funtion sets the callback of the ADC. we need to specify the callback itself but also +// the owner of the callback (useful if it is a static method of a class) and the destination of +// the currents. +// and in here is explained the mechanism of the ADC: +// the ADC uses DMA to gets its values. the DMA peridically calls function pwmSetCurrents_cb() +// at half transfer and at end transfer. this function performs calibration if required, and +// calls a user-defined function which we can set with pwm_set_ADC_callback() so that the values +// of currents can be used by other software modules. + +extern void pwm_set_ADC_callback(pwm_ADC_callback_t *cbk); + +// this function must be used only inside the file analog.c ..... +// it is called at the completion of dma transfer (both half and full). then this function may call a user defined +// callback spefified by pwm_set_ADC_callback(). +// to do: i may remove it from the public API to avoid confusion +// extern void pwmSetCurrents_cb(int16_t i1, int16_t i2, int16_t i3); + +#endif // #if defined(MOTORHAL_changes) + + + + +#ifdef __cplusplus + } /* extern "C" */ +#endif /* __cplusplus */ +#endif /* __PWM_H */ +/* END OF FILE ********************************************************************************************************/ diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/proj/amcbldc-bootloader.uvoptx b/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/proj/amcbldc-bootloader.uvoptx index 19ff3914a..229cff284 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/proj/amcbldc-bootloader.uvoptx +++ b/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/proj/amcbldc-bootloader.uvoptx @@ -75,7 +75,7 @@ 1 0 - 1 + 0 18 @@ -125,215 +125,7 @@ 0 ULP2CM3 - -UAny -O206 -S13 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65555 -TC160000000 -TT10000000 -TP18 -TDX0 -TDD0 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP9 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32G4xx_256.FLM -FS08000000 -FL040000 -FP0($$Device:STM32G474CCUx$CMSIS\Flash\STM32G4xx_256.FLM) - - - 0 - ARMRTXEVENTFLAGS - -L70 -Z18 -C0 -M0 -T1 - - - 0 - DLGTARM - (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0) - - - 0 - ARMDBGFLAGS - - - - 0 - DLGUARM - - - - - - - 0 - 1 - SystemCoreClock,0x0A - - - - - 1 - 0 - defInfo32 - 0 - - - - - 2 - 0 - 0x08040000 - 0 - - - - 0 - - - 0 - 1 - 1 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - - - - 0 - 0 - 0 - - - - - - - - - - 1 - 0 - 0 - 2 - 33000000 - - - - - - pmc-btl-cmsios2 - 0x4 - ARM-ADS - - 12000000 - - 1 - 1 - 0 - 1 - 0 - - - 1 - 65535 - 0 - 0 - 0 - - - 79 - 66 - 8 - .\lst\ - - - 1 - 1 - 1 - 0 - 1 - 1 - 0 - 1 - 0 - 0 - 0 - 0 - - - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - - - 0 - 0 - 0 - - 18 - - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - 1 - 0 - 0 - 6 - - - - - - - - - - - STLink\ST-LINKIII-KEIL_SWO.dll - - - - 0 - ST-LINKIII-KEIL_SWO - -U003A00163038510234333935 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("") -D00(00000000) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32G4xx_512 -FS08000000 -FL080000 -FP0($$Device:STM32G474VEHx$CMSIS\Flash\STM32G4xx_512.FLM) - - - 0 - UL2CM3 - UL2CM3(-S0 -C0 -P0 ) -FN1 -FC1000 -FD20000000 -FF0STM32G4xx_512 -FL080000 -FS08000000 -FP0($$Device:STM32G474VEHx$CMSIS\Flash\STM32G4xx_512.FLM) - - - 0 - ULP2CM3 - UL2CM3(-S0 -C0 -P0 ) -FN1 -FC1000 -FD20000000 -FF0STM32G4xx_512 -FL080000 -FS08000000 -FP0($$Device:STM32G474VEHx$CMSIS\Flash\STM32G4xx_512.FLM) + -UAny -O206 -S13 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65555 -TC168000000 -TT10000000 -TP18 -TDX0 -TDD0 -TDS8000 -TDT0 -TDC1F -TIE80000001 -TIP9 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32G4xx_256.FLM -FS08000000 -FL040000 -FP0($$Device:STM32G474CCUx$CMSIS\Flash\STM32G4xx_256.FLM) 0 @@ -362,33 +154,23 @@ 0 26 1 -
134249234
+
0
0 0 0 0 0 - 1 + 0 ../src/main-bootloader.cpp - \\strain2_v190_bootloader\../src/main-bootloader.cpp\26 + 0 1 - pp - - - 1 - 1 - info - - - 2 - 1 - type + SystemCoreClock,0x0A @@ -430,7 +212,7 @@ 0 0 0 - 0 + 1 0 0 0 @@ -454,7 +236,7 @@ 0 0 2 - 10000000 + 33000000
@@ -513,7 +295,7 @@ 1 0 - 0 + 1 18 @@ -707,8 +489,8 @@ 0 0 0 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib - stm32hal.g4.amcbldc.v120.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v120.amcbldc.lib + stm32hal.g4.v120.amcbldc.lib 0 0 @@ -719,8 +501,8 @@ 0 0 0 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib - stm32hal.g4.amcbldc.v122.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v122.amcbldc.lib + stm32hal.g4.v122.amcbldc.lib 0 0 @@ -744,29 +526,17 @@ 0 0 - - 3 - 6 - 2 - 0 - 0 - 0 - ..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s - stm32hal.startup.amcbldc.v122.template.s - 0 - 0 - rtos - 0 + 1 0 0 0 4 - 7 + 6 4 0 0 @@ -778,7 +548,7 @@ 4 - 8 + 7 1 0 0 @@ -788,18 +558,6 @@ 0 0 - - 4 - 9 - 4 - 0 - 0 - 0 - ..\..\..\..\libs\highlevel\abslayer\cmsisos2\lib\cmsisos2.lib - cmsisos2.lib - 0 - 0 - @@ -810,7 +568,7 @@ 0 5 - 10 + 8 8 0 0 @@ -822,7 +580,7 @@ 5 - 11 + 9 8 0 0 @@ -834,7 +592,7 @@ 5 - 12 + 10 8 0 0 @@ -846,7 +604,7 @@ 5 - 13 + 11 8 0 0 @@ -858,7 +616,7 @@ 5 - 14 + 12 8 0 0 @@ -870,7 +628,7 @@ 5 - 15 + 13 8 0 0 @@ -882,7 +640,7 @@ 5 - 16 + 14 8 0 0 @@ -894,7 +652,7 @@ 5 - 17 + 15 8 0 0 @@ -906,7 +664,7 @@ 5 - 18 + 16 8 0 0 @@ -918,7 +676,7 @@ 5 - 19 + 17 8 0 0 @@ -930,7 +688,7 @@ 5 - 20 + 18 8 0 0 @@ -942,7 +700,7 @@ 5 - 21 + 19 8 0 0 @@ -954,7 +712,7 @@ 5 - 22 + 20 8 0 0 @@ -966,7 +724,7 @@ 5 - 23 + 21 8 0 0 @@ -978,7 +736,7 @@ 5 - 24 + 22 8 0 0 @@ -990,7 +748,7 @@ 5 - 25 + 23 8 0 0 @@ -1002,7 +760,7 @@ 5 - 26 + 24 8 0 0 @@ -1022,7 +780,7 @@ 0 6 - 27 + 25 8 0 0 @@ -1034,7 +792,7 @@ 6 - 28 + 26 8 0 0 @@ -1046,7 +804,7 @@ 6 - 29 + 27 8 0 0 @@ -1058,7 +816,7 @@ 6 - 30 + 28 8 0 0 @@ -1070,7 +828,7 @@ 6 - 31 + 29 8 0 0 @@ -1082,7 +840,7 @@ 6 - 32 + 30 8 0 0 @@ -1094,7 +852,7 @@ 6 - 33 + 31 8 0 0 @@ -1106,7 +864,7 @@ 6 - 34 + 32 8 0 0 @@ -1118,7 +876,7 @@ 6 - 35 + 33 8 0 0 @@ -1130,7 +888,7 @@ 6 - 36 + 34 8 0 0 @@ -1142,7 +900,7 @@ 6 - 37 + 35 8 0 0 @@ -1154,7 +912,7 @@ 6 - 38 + 36 8 0 0 @@ -1174,7 +932,7 @@ 0 7 - 39 + 37 8 0 0 @@ -1194,7 +952,7 @@ 0 8 - 40 + 38 8 0 0 diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/proj/amcbldc-bootloader.uvprojx b/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/proj/amcbldc-bootloader.uvprojx index 606fb28e6..3b23a94ac 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/proj/amcbldc-bootloader.uvprojx +++ b/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/proj/amcbldc-bootloader.uvprojx @@ -10,7 +10,7 @@ amcbldc-btl 0x4 ARM-ADS - 6180000::V6.18::ARMCLANG + 6190000::V6.19::ARMCLANG 1 @@ -400,14 +400,14 @@ stm32hal - stm32hal.g4.amcbldc.v120.lib + stm32hal.g4.v120.amcbldc.lib 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v120.amcbldc.lib - stm32hal.g4.amcbldc.v122.lib + stm32hal.g4.v122.amcbldc.lib 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v122.amcbldc.lib 2 @@ -438,808 +438,6 @@ 2 ..\cfg\stm32hal.startup.amcbldc.s - - stm32hal.startup.amcbldc.v122.template.s - 2 - ..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - - - - - - - - - - - - - - rtos - - - osal.cm4.dbg.lib - 4 - ..\..\..\..\..\..\eBcode\arch-arm\libs\highlevel\abslayer\osal\lib\osal.cm4.dbg.lib - - - eventviewer.c - 1 - ..\..\..\..\libs\midware\eventviewer\src\eventviewer.c - - - cmsisos2.lib - 4 - ..\..\..\..\libs\highlevel\abslayer\cmsisos2\lib\cmsisos2.lib - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - - - - - embot - - - embot_core.cpp - 8 - ..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core\embot_core.cpp - - - embot_app_theBootloader.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_theBootloader.cpp - - - embot_app_theCANboardInfo.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_theCANboardInfo.cpp - - - embot_os.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os.cpp - - - embot_os_Task.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_Thread.cpp - - - embot_os_theCallbackManager.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_theCallbackManager.cpp - - - embot_app_theJumper.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_theJumper.cpp - - - embot_os_theScheduler.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_theScheduler.cpp - - - embot_os_theTimerManager.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_theTimerManager.cpp - - - embot_os_Timer.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\os\embot_os_Timer.cpp - - - embot_app_bootloader_theCANparser.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\app\embot_app_bootloader_theCANparser.cpp - - - embot_prot_can.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can.cpp - - - embot_prot_can_bootloader.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\prot\can\embot_prot_can_bootloader.cpp - - - embot_core_binary.cpp - 8 - ..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core\embot_core_binary.cpp - - - embot_os_Action.cpp - 8 - ..\..\..\..\embot\os\embot_os_Action.cpp - - - embot_app_theLEDmanager.cpp - 8 - ..\..\..\..\embot\app\embot_app_theLEDmanager.cpp - - - embot_os_rtos.cpp - 8 - ..\..\..\..\embot\os\embot_os_rtos.cpp - - - - - embot::hw - - - embot_hw.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw.cpp - - - embot_hw_bsp.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_bsp.cpp - - - embot_hw_FlashStorage.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_FlashStorage.cpp - - - embot_hw_FlashBurner.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_FlashBurner.cpp - - - embot_hw_can.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_can.cpp - - - embot_hw_sys.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_sys.cpp - - - embot_hw_flash.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_flash.cpp - - - embot_hw_led.cpp - 8 - ..\..\..\..\..\..\eBcode\arch-arm\embot\hw\embot_hw_led.cpp - - - embot_hw_gpio.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_gpio.cpp - - - embot_hw_timer.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_timer.cpp - - - embot_hw_types.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_types.cpp - - - embot_hw_button.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_button.cpp - - - - - embot-hw-lowlevel - - - embot_hw_lowlevel.cpp - 8 - ..\..\..\..\embot\hw\embot_hw_lowlevel.cpp - - - 2 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 1 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - 2 - 2 - 2 - 2 - 2 - 0 - 0 - 2 - 2 - 2 - 2 - 2 - - - - - - - - - - - - - - embot::hw::bsp - - - embot_hw_bsp_amcbldc.cpp - 8 - ..\..\bsp\embot_hw_bsp_amcbldc.cpp - - - - - ::CMSIS - - - 0 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 0 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - 2 - 2 - 2 - 2 - 2 - 0 - 0 - 2 - 2 - 2 - 2 - 2 - - - - - - - - - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - - - - - - - - - - - - - - pmc-btl-cmsios2 - 0x4 - ARM-ADS - 6140000::V6.14::ARMCLANG - 1 - - - STM32G474VEHx - STMicroelectronics - Keil.STM32G4xx_DFP.1.4.0 - http://www.keil.com/pack/ - IRAM(0x20000000,0x00020000) IROM(0x08000000,0x00080000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE - - - UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32G4xx_512 -FS08000000 -FL080000 -FP0($$Device:STM32G474VEHx$CMSIS\Flash\STM32G4xx_512.FLM)) - 0 - $$Device:STM32G474VEHx$Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g4xx.h - - - - - - - - - - $$Device:STM32G474VEHx$CMSIS\SVD\STM32G474xx.svd - 0 - 0 - - - - - - - 0 - 0 - 0 - 0 - 1 - - .\obj\ - strain2_v190_bootloader - 1 - 0 - 1 - 1 - 1 - .\lst\ - 1 - 0 - 0 - - 0 - 0 - - - 0 - 0 - 0 - 0 - - - 0 - 0 - - - 0 - 0 - 0 - 0 - - - 1 - 0 - cmd.exe /C copy .\Obj\strain2_v190_bootloader.hex ..\bin\strain2.v190.bootloader.hex - - 0 - 0 - 0 - 0 - - 0 - - - - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 3 - - - 0 - - - SARMCM3.DLL - -REMAP -MPU - DCM.DLL - -pCM4 - SARMCM3.DLL - -MPU - TCM.DLL - -pCM4 - - - - 1 - 0 - 0 - 0 - 16 - - - - - 1 - 0 - 0 - 1 - 1 - 4096 - - 1 - BIN\UL2CM3.DLL - - - - - - 0 - - - - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 1 - 1 - 0 - 1 - 1 - 0 - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - "Cortex-M4" - - 0 - 0 - 0 - 1 - 1 - 0 - 0 - 2 - 0 - 0 - 0 - 0 - 0 - 8 - 0 - 0 - 0 - 0 - 3 - 3 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 1 - 0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x20000000 - 0x20000 - - - 1 - 0x8000000 - 0x80000 - - - 0 - 0x0 - 0x0 - - - 1 - 0x0 - 0x0 - - - 1 - 0x0 - 0x0 - - - 1 - 0x0 - 0x0 - - - 1 - 0x8000000 - 0x80000 - - - 1 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - - - 0 - 0x20000000 - 0x20000 - - - 0 - 0x0 - 0x0 - - - - - - 1 - 2 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 0 - 3 - 0 - 1 - 0 - 0 - 0 - 3 - 8 - 1 - 1 - 1 - 0 - 0 - - -Wno-pragma-pack -Wno-deprecated-register -DEMBOT_USE_rtos_cmsisos2 - USE_STM32HAL STM32HAL_BOARD_PMC STM32HAL_DRIVER_V120 - - ..\src-plus;..\..\..\..\..\..\eBcode\arch-arm\libs\highlevel\abslayer\cmsisos2\api;..\..\..\..\..\..\eBcode\arch-arm\embobj\core\exec\multitask;..\..\..\..\..\..\..\..\icub-firmware-shared\eth\embobj\core\core;..\..\..\..\..\..\eBcode\arch-arm\libs\lowlevel\stm32hal\api;..\..\..\..\..\..\..\..\icub-firmware-shared\embot\core;..\..\..\..\..\..\eBcode\arch-arm\embot\app;..\..\..\..\..\..\eBcode\arch-arm\embot\i2h;..\..\..\..\..\..\eBcode\arch-arm\embot\hw;..\..\..\..\..\..\eBcode\arch-arm\embot\os;..\..\..\..\..\..\..\..\icub-firmware-shared\can\canProtocolLib;..\..\..\..\embot\app\skeleton;..\..\..\..\embot\prot\can - - - - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 4 - - - - - - - - - 0 - 0 - 0 - 0 - 1 - 0 - 0x08000000 - 0x20000000 - - .\pmc-bootloader.sct - - - --diag_suppress=L6329 - - - - - - - - main - - - main-bootloader.cpp - 8 - ../src/main-bootloader.cpp - - - embot_code_bootloader.cpp - 8 - ..\..\..\..\embot\app\skeleton\embot_app_skeleton_os_bootloader.cpp - - - - - stm32hal - - - stm32hal.g4.amcbldc.v120.lib - 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib - - - stm32hal.g4.amcbldc.v122.lib - 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib - - - - - stm32hal-config - - - stm32hal.startup.amcbldc.s - 2 - ..\cfg\stm32hal.startup.amcbldc.s - - - stm32hal.startup.amcbldc.v122.template.s - 2 - ..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s - @@ -1249,86 +447,11 @@ osal.cm4.dbg.lib 4 ..\..\..\..\..\..\eBcode\arch-arm\libs\highlevel\abslayer\osal\lib\osal.cm4.dbg.lib - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - eventviewer.c 1 ..\..\..\..\libs\midware\eventviewer\src\eventviewer.c - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 0 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - 2 - 2 - 2 - 2 - 2 - 0 - 0 - 2 - 2 - 2 - 2 - 2 - - - - - - - - - - - - cmsisos2.lib - 4 - ..\..\..\..\libs\highlevel\abslayer\cmsisos2\lib\cmsisos2.lib @@ -1636,7 +759,7 @@ amcbldc-btl-v122 0x4 ARM-ADS - 6180000::V6.18::ARMCLANG + 6190000::V6.19::ARMCLANG 1 @@ -2026,9 +1149,9 @@ stm32hal - stm32hal.g4.amcbldc.v120.lib + stm32hal.g4.v120.amcbldc.lib 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v120.amcbldc.lib 2 @@ -2050,9 +1173,9 @@ - stm32hal.g4.amcbldc.v122.lib + stm32hal.g4.v122.amcbldc.lib 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v122.amcbldc.lib @@ -2063,49 +1186,6 @@ stm32hal.startup.amcbldc.s 2 ..\cfg\stm32hal.startup.amcbldc.s - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - - - - - - - - - - - - stm32hal.startup.amcbldc.v122.template.s - 2 - ..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s @@ -2122,30 +1202,6 @@ 1 ..\..\..\..\libs\midware\eventviewer\src\eventviewer.c - - cmsisos2.lib - 4 - ..\..\..\..\libs\highlevel\abslayer\cmsisos2\lib\cmsisos2.lib - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - @@ -2458,7 +1514,6 @@ - diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/src/main-bootloader.cpp b/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/src/main-bootloader.cpp index b93232f7a..2a0eda584 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/src/main-bootloader.cpp +++ b/emBODY/eBcode/arch-arm/board/amcbldc/bootloader/src/main-bootloader.cpp @@ -11,11 +11,18 @@ // -------------------------------------------------------------------------------------------------------------------- // bootloader info +constexpr uint8_t minor = +#if defined(STM32HAL_DRIVER_V120) + 1; +#else + 2; +#endif + constexpr std::uint8_t defADDRESS = 1; constexpr embot::app::theCANboardInfo::bootloaderInfo btlInfo { embot::prot::can::Board::amcbldc, - embot::prot::can::versionOfBOOTLOADER {1, 1}, + embot::prot::can::versionOfBOOTLOADER {1, minor}, defADDRESS, "I am an amcbldc" }; diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/bsp/embot_hw_bsp_amcbldc.cpp b/emBODY/eBcode/arch-arm/board/amcbldc/bsp/embot_hw_bsp_amcbldc.cpp index 657eabb15..5649a419c 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/bsp/embot_hw_bsp_amcbldc.cpp +++ b/emBODY/eBcode/arch-arm/board/amcbldc/bsp/embot_hw_bsp_amcbldc.cpp @@ -733,6 +733,11 @@ namespace embot { namespace hw { namespace motor { MX_CORDIC_Init(); MX_FMAC_Init(); MX_CRC_Init(); +#if defined(STM32HAL_DRIVER_V120) +#else + MX_TIM15_Init(); +#endif + HAL_GPIO_WritePin(VAUXEN_GPIO_Port, VAUXEN_Pin, GPIO_PIN_SET); HAL_Delay(10); @@ -767,16 +772,27 @@ namespace embot { namespace hw { namespace bsp { namespace amcbldc { #include #include +#if 0 +//std::make_tuple(0x00460048, 0x484E500E, 0x20343356) // scheda centrale sul wrist setup (etichettata come scheda numero 2) +//std::make_tuple(0x00470047, 0x484E500E, 0x20343356) // scheda sul wrist setup etichettata come scheda numero 3 +//std::make_tuple(0x00480022, 0x484E500E, 0x20343356) // scheda sul wrist setup etichettata come scheda numero 1 +std::make_tuple(0x00470027, 0x484E500E, 0x20343356 ) // scheda jointlab camozzi + + 0x00470045, 0x484E500E, 0x20343356 labeled as A1. caveat: the fault is broken +#endif - constexpr std::array< std::tuple, 5> theUIDsOfRevA = + constexpr std::array< std::tuple, 7> theUIDsOfRevA = { - std::make_tuple(0x00470045, 0x484E500E, 0x20343356), // 01 - std::make_tuple(0x00460046, 0x484E500E, 0x20343356), // 02 - std::make_tuple(0x00470047, 0x484E500E, 0x20343356), // 05 - std::make_tuple(0x00480022, 0x484E500E, 0x20343356), // wires attached - std::make_tuple(0x00000000, 0x484E500E, 0x20343356) // placeholder for the one used by rocco [value yet to be scanned] + std::make_tuple(0x00470045, 0x484E500E, 0x20343356), // 01 probably broken + std::make_tuple(0x00460046, 0x484E500E, 0x20343356), // 02 probably broken + std::make_tuple(0x00470047, 0x484E500E, 0x20343356), // 03: scheda sul wrist setup etichettata come scheda numero 3 + std::make_tuple(0x00480022, 0x484E500E, 0x20343356), // scheda sul wrist setup etichettata come scheda numero 1 + std::make_tuple(0x00470027, 0x484E500E, 0x20343356), // jointlab camozzi + std::make_tuple(0x00460048, 0x484E500E, 0x20343356), // scheda centrale sul wrist setup (etichettata come scheda numero 2) + std::make_tuple(0x00470045, 0x484E500E, 0x20343356) // labeled as A1 in red ink. caveat: the fault is broken }; - + +#if 0 constexpr std::array< std::tuple, 10> theUIDsOfRevB = { std::make_tuple(0x00400041, 0x4650500F, 0x20313432), // 01 @@ -790,7 +806,7 @@ namespace embot { namespace hw { namespace bsp { namespace amcbldc { std::make_tuple(0x00400032, 0x4650500F, 0x20313432), // 09 std::make_tuple(0x00400043, 0x4650500F, 0x20313432) // 10 }; - +#endif Revision revision() @@ -799,14 +815,14 @@ namespace embot { namespace hw { namespace bsp { namespace amcbldc { if(Revision::none == revision) { - revision = Revision::A; + revision = Revision::B; volatile uint32_t *myuID = ((volatile uint32_t *)(UID_BASE)); auto target = std::make_tuple(myuID[0], myuID[1], myuID[2]); - for(const auto &i : theUIDsOfRevB) + for(const auto &i : theUIDsOfRevA) { if(i == target) { - revision = Revision::B; + revision = Revision::A; } } } @@ -881,7 +897,7 @@ void verify_flash_bank() if(expectedbanks != detectedbanks) { embot::core::print("number of banks is not as expected: detected " + std::to_string(detectedbanks)); - embot::core::print("cannot continue"); + embot::core::print("cannot continue. program Option bytes / User Configuration / DBANK to be 1 or 2 banks"); leds_init_off(); for(;;) diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/examples/basic/proj/amcbldc-basic.uvoptx b/emBODY/eBcode/arch-arm/board/amcbldc/examples/basic/proj/amcbldc-basic.uvoptx index 1cf474613..f834418d9 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/examples/basic/proj/amcbldc-basic.uvoptx +++ b/emBODY/eBcode/arch-arm/board/amcbldc/examples/basic/proj/amcbldc-basic.uvoptx @@ -75,7 +75,7 @@ 1 0 - 1 + 0 18 @@ -314,7 +314,7 @@ 1 0 - 0 + 1 18 @@ -532,8 +532,8 @@ 0 0 0 - ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib - stm32hal.g4.amcbldc.v120.lib + ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v120.amcbldc.lib + stm32hal.g4.v120.amcbldc.lib 0 0 @@ -544,8 +544,8 @@ 0 0 0 - ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib - stm32hal.g4.amcbldc.v122.lib + ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v122.amcbldc.lib + stm32hal.g4.v122.amcbldc.lib 0 0 @@ -569,18 +569,6 @@ 0 0 - - 3 - 5 - 2 - 0 - 0 - 0 - ..\..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s - stm32hal.startup.amcbldc.v122.template.s - 0 - 0 - diff --git a/emBODY/eBcode/arch-arm/board/amcbldc/examples/basic/proj/amcbldc-basic.uvprojx b/emBODY/eBcode/arch-arm/board/amcbldc/examples/basic/proj/amcbldc-basic.uvprojx index 9192f191d..3719cc35a 100644 --- a/emBODY/eBcode/arch-arm/board/amcbldc/examples/basic/proj/amcbldc-basic.uvprojx +++ b/emBODY/eBcode/arch-arm/board/amcbldc/examples/basic/proj/amcbldc-basic.uvprojx @@ -395,14 +395,14 @@ stm32hal - stm32hal.g4.amcbldc.v120.lib + stm32hal.g4.v120.amcbldc.lib 4 - ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib + ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v120.amcbldc.lib - stm32hal.g4.amcbldc.v122.lib + stm32hal.g4.v122.amcbldc.lib 4 - ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib + ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v122.amcbldc.lib 2 @@ -433,49 +433,6 @@ 2 ..\cfg\stm32hal.startup.amcbldc.s - - stm32hal.startup.amcbldc.v122.template.s - 2 - ..\..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - - - - - - - - - - @@ -556,7 +513,7 @@ basic-amcbldc-v122 0x4 ARM-ADS - 6180000::V6.18::ARMCLANG + 6190000::V6.19::ARMCLANG 1 @@ -941,9 +898,9 @@ stm32hal - stm32hal.g4.amcbldc.v120.lib + stm32hal.g4.v120.amcbldc.lib 4 - ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v120.lib + ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v120.amcbldc.lib 2 @@ -965,9 +922,9 @@ - stm32hal.g4.amcbldc.v122.lib + stm32hal.g4.v122.amcbldc.lib 4 - ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.amcbldc.v122.lib + ..\..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.g4.v122.amcbldc.lib @@ -978,49 +935,6 @@ stm32hal.startup.amcbldc.s 2 ..\cfg\stm32hal.startup.amcbldc.s - - - 2 - 0 - 0 - 0 - 0 - 0 - 2 - 2 - 2 - 2 - 11 - - - 1 - - - - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 2 - 0 - - - - - - - - - - - - stm32hal.startup.amcbldc.v122.template.s - 2 - ..\..\..\..\..\libs\lowlevel\stm32hal\startup\stm32hal.startup.amcbldc.v122.template.s diff --git a/emBODY/eBcode/arch-arm/board/strain2/updaterofbootloader/proj/strain2-updaterofbootloader-v6.uvprojx b/emBODY/eBcode/arch-arm/board/strain2/updaterofbootloader/proj/strain2-updaterofbootloader-v6.uvprojx index b467d63f3..1bc8aa97e 100644 --- a/emBODY/eBcode/arch-arm/board/strain2/updaterofbootloader/proj/strain2-updaterofbootloader-v6.uvprojx +++ b/emBODY/eBcode/arch-arm/board/strain2/updaterofbootloader/proj/strain2-updaterofbootloader-v6.uvprojx @@ -1142,11 +1142,6 @@ stm32hal.l4.v1B0.strain2.lib 4 ..\..\..\..\..\..\eBcode\arch-arm\libs\lowlevel\stm32hal\lib\stm32hal.l4.v1B0.strain2.lib - - - stm32hal.l4.v1D3.strain2.lib - 4 - ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.l4.v1D3.strain2.lib 2 @@ -1167,6 +1162,11 @@ + + stm32hal.l4.v1D3.strain2.lib + 4 + ..\..\..\..\libs\lowlevel\stm32hal\lib\stm32hal.l4.v1D3.strain2.lib + diff --git a/emBODY/eBcode/arch-arm/embot/hw/embot_hw_motor.cpp b/emBODY/eBcode/arch-arm/embot/hw/embot_hw_motor.cpp index b5fd23eb9..7c3bbdfb9 100644 --- a/emBODY/eBcode/arch-arm/embot/hw/embot_hw_motor.cpp +++ b/emBODY/eBcode/arch-arm/embot/hw/embot_hw_motor.cpp @@ -149,7 +149,7 @@ namespace embot { namespace hw { namespace motor { uint16_t pwm_hall_offset); Position s_hw_getencoder(MOTOR h); Position s_hw_gethallcounter(MOTOR h); - result_t s_hw_setpwm(MOTOR h, Pwm v); + // result_t s_hw_setpwm(MOTOR h, Pwm v); HallStatus s_hw_gethallstatus(MOTOR h); @@ -332,6 +332,10 @@ namespace embot { namespace hw { namespace motor { result_t setpwm(MOTOR h, Pwm v) { +#if 1 + // deprecated + return resNOK; +#else // if faulted() we are not enabled() ... so we dont need this extra check // if(true == faulted(h)) // { @@ -345,6 +349,7 @@ namespace embot { namespace hw { namespace motor { } return s_hw_setpwm(h, v); +#endif } result_t setpwm(MOTOR h, Pwm u, Pwm v, Pwm w) @@ -402,10 +407,10 @@ namespace embot { namespace hw { namespace motor { result_t s_hw_deinit(MOTOR h) { -// pwmDeinit(); - analogDeinit(); - encoderDeinit(); - hallDeinit(); +// pwm_Deinit(); + analog_Deinit(); + encoder_Deinit(); + pwm_hallDeinit(); return resOK; } @@ -425,8 +430,8 @@ namespace embot { namespace hw { namespace motor { // s_hw_init(h); - if (HAL_OK != encoderConfig(has_quad_enc, enc_resolution, pwm_num_polar_couples, pwm_has_hall_sens)) res = resNOK; - if (HAL_OK != hallConfig(pwm_swapBC, pwm_hall_offset)) res = resNOK; + if (HAL_OK != encoder_Config(has_quad_enc, enc_resolution, pwm_num_polar_couples, pwm_has_hall_sens)) res = resNOK; + if (HAL_OK != pwm_hallConfig(pwm_swapBC, pwm_hall_offset)) res = resNOK; return res; } @@ -447,14 +452,14 @@ namespace embot { namespace hw { namespace motor { } - result_t s_hw_setpwm(MOTOR h, Pwm v) - { - HAL_StatusTypeDef r = HAL_ERROR; -#if defined(EMBOT_AMCBLDC_APP01) || defined(EMBOT_AMCBLDC_APP02) || defined(EMBOT_AMCBLDC_APP03) - r = pwmSetValue(v); -#endif - return (HAL_OK == r) ? resOK : resNOK; - } +// result_t s_hw_setpwm(MOTOR h, Pwm v) +// { +// HAL_StatusTypeDef r = HAL_ERROR; +// +// //r = pwmSetValue(v); + +// return (HAL_OK == r) ? resOK : resNOK; +// } result_t s_hw_setpwmUVW(MOTOR h, Pwm u, Pwm v, Pwm w) { @@ -466,10 +471,10 @@ namespace embot { namespace hw { namespace motor { #if defined(EMBOT_AMCBLDC_APP01) || defined(EMBOT_AMCBLDC_APP02) || defined(EMBOT_AMCBLDC_APP03) #else - static_assert(sizeof(pwmCurrents_t) == sizeof(embot::hw::motor::Currents), "embot::hw::motor::Currents and pwmCurrents_t differs"); - static_assert(sizeof(pwmCurrents_t::u) == sizeof(embot::hw::motor::Currents::u), "embot::hw::motor::Currents and pwmCurrents_t differs"); - static_assert(sizeof(pwmCurrents_t::v) == sizeof(embot::hw::motor::Currents::v), "embot::hw::motor::Currents and pwmCurrents_t differs"); - static_assert(sizeof(pwmCurrents_t::w) == sizeof(embot::hw::motor::Currents::w), "embot::hw::motor::Currents and pwmCurrents_t differs"); + static_assert(sizeof(pwm_Currents_t) == sizeof(embot::hw::motor::Currents), "embot::hw::motor::Currents and pwm_Currents_t differs"); + static_assert(sizeof(pwm_Currents_t::u) == sizeof(embot::hw::motor::Currents::u), "embot::hw::motor::Currents and pwm_Currents_t differs"); + static_assert(sizeof(pwm_Currents_t::v) == sizeof(embot::hw::motor::Currents::v), "embot::hw::motor::Currents and pwm_Currents_t differs"); + static_assert(sizeof(pwm_Currents_t::w) == sizeof(embot::hw::motor::Currents::w), "embot::hw::motor::Currents and pwm_Currents_t differs"); #endif result_t s_hw_setCallbackOnCurrents(MOTOR h, fpOnCurrents callback, void *owner) @@ -486,7 +491,7 @@ namespace embot { namespace hw { namespace motor { pwm_ADC_callback_t cbk {}; cbk.callback = reinterpret_cast(callback); cbk.owner = owner; - set_ADC_callback(&cbk); + pwm_set_ADC_callback(&cbk); return resOK; #endif } diff --git a/emBODY/eBcode/arch-arm/embot/hw/embot_hw_motor.h b/emBODY/eBcode/arch-arm/embot/hw/embot_hw_motor.h index 830900c29..f19471324 100644 --- a/emBODY/eBcode/arch-arm/embot/hw/embot_hw_motor.h +++ b/emBODY/eBcode/arch-arm/embot/hw/embot_hw_motor.h @@ -64,7 +64,7 @@ namespace embot { namespace hw { namespace motor { result_t enable(MOTOR h, bool on); // the pwm can be effectively applied only if(true == enabled(h)), so it also must be: (false == faulted(h)) - result_t setpwm(MOTOR h, Pwm v); + result_t setpwm(MOTOR h, Pwm v); // deprecated result_t setpwm(MOTOR h, Pwm u, Pwm v, Pwm w); // values of encoders and hall sensors can be read if(true == initialised(h)) diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/.mxproject b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/.mxproject index faf87fc56..00e594c5a 100644 --- a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/.mxproject +++ b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/.mxproject @@ -1,9 +1,3 @@ -[PreviousGenFiles] -HeaderPath=..\Inc -HeaderFiles=gpio.h;adc.h;cordic.h;crc.h;dma.h;fdcan.h;fmac.h;i2c.h;rng.h;tim.h;usb.h;stm32g4xx_it.h;stm32g4xx_hal_conf.h;main.h; -SourcePath=..\Src -SourceFiles=gpio.c;adc.c;cordic.c;crc.c;dma.c;fdcan.c;fmac.c;i2c.c;rng.c;tim.c;usb.c;stm32g4xx_it.c;stm32g4xx_hal_msp.c;stm32g4xx_hal_timebase_tim.c;main.c; - [PreviousLibFiles] LibFiles=Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_def.h;Drivers\STM32G4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_bus.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_system.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_utils.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_crs.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ramfunc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dmamux.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_cordic.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_cordic.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_crc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_crc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_crc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_fdcan.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_fmac.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_fmac.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_i2c.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_i2c.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_i2c_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rng.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_rng.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pcd.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pcd_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_usb.h;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cordic.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_crc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_crc_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_fdcan.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_fmac.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_i2c.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_i2c_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rng.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pcd.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pcd_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_usb.c;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_def.h;Drivers\STM32G4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_bus.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_system.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_utils.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_crs.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ramfunc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dmamux.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_cordic.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_cordic.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_crc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_crc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_crc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_fdcan.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_fmac.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_fmac.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_i2c.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_i2c.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_i2c_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rng.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_rng.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pcd.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pcd_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_usb.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g474xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g4xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\system_stm32g4xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\system_stm32g4xx.c;Drivers\CMSIS\Include\cmsis_armcc.h;Drivers\CMSIS\Include\cmsis_armclang.h;Drivers\CMSIS\Include\cmsis_armclang_ltm.h;Drivers\CMSIS\Include\cmsis_compiler.h;Drivers\CMSIS\Include\cmsis_gcc.h;Drivers\CMSIS\Include\cmsis_iccarm.h;Drivers\CMSIS\Include\cmsis_version.h;Drivers\CMSIS\Include\core_armv81mml.h;Drivers\CMSIS\Include\core_armv8mbl.h;Drivers\CMSIS\Include\core_armv8mml.h;Drivers\CMSIS\Include\core_cm0.h;Drivers\CMSIS\Include\core_cm0plus.h;Drivers\CMSIS\Include\core_cm1.h;Drivers\CMSIS\Include\core_cm23.h;Drivers\CMSIS\Include\core_cm3.h;Drivers\CMSIS\Include\core_cm33.h;Drivers\CMSIS\Include\core_cm35p.h;Drivers\CMSIS\Include\core_cm4.h;Drivers\CMSIS\Include\core_cm7.h;Drivers\CMSIS\Include\core_sc000.h;Drivers\CMSIS\Include\core_sc300.h;Drivers\CMSIS\Include\mpu_armv7.h;Drivers\CMSIS\Include\mpu_armv8.h;Drivers\CMSIS\Include\tz_context.h; @@ -12,3 +6,9 @@ SourceFiles=..\Src\main.c;..\Src\gpio.c;..\Src\adc.c;..\Src\cordic.c;..\Src\crc. HeaderPath=..\Drivers\STM32G4xx_HAL_Driver\Inc;..\Drivers\STM32G4xx_HAL_Driver\Inc\Legacy;..\Drivers\CMSIS\Device\ST\STM32G4xx\Include;..\Drivers\CMSIS\Include;..\Inc; CDefines=USE_HAL_DRIVER;STM32G474xx;USE_HAL_DRIVER;USE_HAL_DRIVER; +[PreviousGenFiles] +HeaderPath=..\Inc +HeaderFiles=gpio.h;adc.h;cordic.h;crc.h;dma.h;fdcan.h;fmac.h;i2c.h;rng.h;tim.h;usb.h;stm32g4xx_it.h;stm32g4xx_hal_conf.h;main.h; +SourcePath=..\Src +SourceFiles=gpio.c;adc.c;cordic.c;crc.c;dma.c;fdcan.c;fmac.c;i2c.c;rng.c;tim.c;usb.c;stm32g4xx_it.c;stm32g4xx_hal_msp.c;stm32g4xx_hal_timebase_tim.c;main.c; + diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/AMC_BLDC.ioc b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/AMC_BLDC.ioc index b531d02c6..056b1d215 100644 --- a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/AMC_BLDC.ioc +++ b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/AMC_BLDC.ioc @@ -270,8 +270,8 @@ Mcu.PinsNb=54 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G474CCUx -MxCube.Version=6.7.0 -MxDb.Version=DB.6.0.70 +MxCube.Version=6.8.0 +MxDb.Version=DB.6.0.80 NVIC.ADC1_2_IRQn=true\:5\:0\:true\:false\:true\:true\:true\:true NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.DMA1_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true @@ -564,6 +564,7 @@ ProjectManager.PreviousToolchain= ProjectManager.ProjectBuild=false ProjectManager.ProjectFileName=AMC_BLDC.ioc ProjectManager.ProjectName=AMC_BLDC +ProjectManager.ProjectStructure= ProjectManager.RegisterCallBack=ADC,EXTI,FDCAN,I2C,SPI,TIM ProjectManager.StackSize=0x1000 ProjectManager.TargetToolchain=MDK-ARM V5.27 diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/MDK-ARM/AMC_BLDC.uvoptx b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/MDK-ARM/AMC_BLDC.uvoptx index fb9dde0d7..ebade9cd1 100644 --- a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/MDK-ARM/AMC_BLDC.uvoptx +++ b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/MDK-ARM/AMC_BLDC.uvoptx @@ -1,167 +1,776 @@ - + - 1.0 -
### uVision Project, (C) Keil Software
- - *.c - *.s*; *.src; *.a* - *.obj; *.o - *.lib - *.txt; *.h; *.inc - *.plm - *.cpp - 0 - - - 0 - 0 - - - AMC_BLDC - 0x4 - ARM-ADS - - 16000000 - - 1 - 1 - 0 - 1 - 0 - - - 1 - 65535 - 0 - 0 - 0 - - - 79 - 66 - 8 - - - - 1 - 1 - 1 - 0 - 1 - 1 - 0 - 1 - 0 - 0 - 0 - 0 - - - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - - - 1 - 0 - 1 - - 18 - - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - 1 - 0 - 0 - 6 - - - - - - - - - - - STLink\ST-LINKIII-KEIL_SWO.dll - - - - 0 - ST-LINKIII-KEIL_SWO - -U-O142 -O2254 -S0 -C0 -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32G47x-8x_256.FLM -FS08000000 -FL040000 -FP0($$Device:STM32G474CC$Flash\STM32G47x-8x_256.FLM) - - - 0 - - - - - - 0 - 1 - 1 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - - - - 0 - 0 - 0 - - - - - - - - - - + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + AMC_BLDC + 0x4 + ARM-ADS + + 16000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 18 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 6 + + + + + + + + + + + STLink\ST-LINKIII-KEIL_SWO.dll + + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32G47x-8x_256 -FS08000000 -FL040000 -FP0($$Device:STM32G474CCUx$CMSIS\Flash\STM32G47x-8x_256.FLM)) + + + 0 + ST-LINKIII-KEIL_SWO + -U-O142 -O2254 -S0 -C0 -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32G47x-8x_256.FLM -FS08000000 -FL040000 -FP0($$Device:STM32G474CCUx$CMSIS\Flash\STM32G47x-8x_256.FLM) + + + + + 0 + + + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + 1 + 1 + 0 + 2 + 10000000 + + + + + + Application/MDK-ARM + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + startup_stm32g474xx.s + startup_stm32g474xx.s + 0 + 0 + + + + + Application/User + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ../Src/main.c + main.c + 0 + 0 + + + 2 + 3 + 1 + 0 + 0 + 0 + ../Src/gpio.c + gpio.c + 0 + 0 + + + 2 + 4 + 1 + 0 + 0 + 0 + ../Src/adc.c + adc.c + 0 + 0 + + + 2 + 5 + 1 + 0 + 0 + 0 + ../Src/cordic.c + cordic.c + 0 + 0 + + + 2 + 6 + 1 + 0 + 0 + 0 + ../Src/crc.c + crc.c + 0 + 0 + + + 2 + 7 + 1 + 0 + 0 + 0 + ../Src/dma.c + dma.c + 0 + 0 + + + 2 + 8 + 1 + 0 + 0 + 0 + ../Src/fdcan.c + fdcan.c + 0 + 0 + + + 2 + 9 + 1 + 0 + 0 + 0 + ../Src/fmac.c + fmac.c + 0 + 0 + + + 2 + 10 + 1 + 0 + 0 + 0 + ../Src/i2c.c + i2c.c + 0 + 0 + + + 2 + 11 + 1 + 0 + 0 + 0 + ../Src/rng.c + rng.c + 0 + 0 + + + 2 + 12 + 1 + 0 + 0 + 0 + ../Src/tim.c + tim.c + 0 + 0 + + + 2 + 13 + 1 + 0 + 0 + 0 + ../Src/usb.c + usb.c + 0 + 0 + + + 2 + 14 + 1 + 0 + 0 + 0 + ../Src/stm32g4xx_it.c + stm32g4xx_it.c + 0 + 0 + + + 2 + 15 + 1 + 0 + 0 + 0 + ../Src/stm32g4xx_hal_msp.c + stm32g4xx_hal_msp.c + 0 + 0 + + + 2 + 16 + 1 + 0 + 0 + 0 + ../Src/stm32g4xx_hal_timebase_tim.c + stm32g4xx_hal_timebase_tim.c + 0 + 0 + + + + + Drivers/STM32G4xx_HAL_Driver + 0 + 0 + 0 + 0 + + 3 + 17 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc.c + stm32g4xx_hal_adc.c + 0 + 0 + + + 3 + 18 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc_ex.c + stm32g4xx_hal_adc_ex.c + 0 + 0 + + + 3 + 19 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_adc.c + stm32g4xx_ll_adc.c + 0 + 0 + + + 3 + 20 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal.c + stm32g4xx_hal.c + 0 + 0 + + + 3 + 21 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc.c + stm32g4xx_hal_rcc.c + 0 + 0 + + + 3 + 22 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc_ex.c + stm32g4xx_hal_rcc_ex.c + 0 + 0 + + + 3 + 23 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash.c + stm32g4xx_hal_flash.c + 0 + 0 + + + 3 + 24 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ex.c + stm32g4xx_hal_flash_ex.c + 0 + 0 + + + 3 + 25 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ramfunc.c + stm32g4xx_hal_flash_ramfunc.c + 0 + 0 + + + 3 + 26 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_gpio.c + stm32g4xx_hal_gpio.c + 0 + 0 + + + 3 + 27 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_exti.c + stm32g4xx_hal_exti.c + 0 + 0 + + + 3 + 28 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma.c + stm32g4xx_hal_dma.c + 0 + 0 + + + 3 + 29 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma_ex.c + stm32g4xx_hal_dma_ex.c + 0 + 0 + + + 3 + 30 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr.c + stm32g4xx_hal_pwr.c + 0 + 0 + + + 3 + 31 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr_ex.c + stm32g4xx_hal_pwr_ex.c + 0 + 0 + + + 3 + 32 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_cortex.c + stm32g4xx_hal_cortex.c + 0 + 0 + + + 3 + 33 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_cordic.c + stm32g4xx_hal_cordic.c + 0 + 0 + + + 3 + 34 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_crc.c + stm32g4xx_hal_crc.c + 0 + 0 + + + 3 + 35 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_crc_ex.c + stm32g4xx_hal_crc_ex.c + 0 + 0 + + + 3 + 36 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_fdcan.c + stm32g4xx_hal_fdcan.c + 0 + 0 + + + 3 + 37 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_fmac.c + stm32g4xx_hal_fmac.c + 0 + 0 + + + 3 + 38 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c.c + stm32g4xx_hal_i2c.c + 0 + 0 + + + 3 + 39 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c_ex.c + stm32g4xx_hal_i2c_ex.c + 0 + 0 + + + 3 + 40 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rng.c + stm32g4xx_hal_rng.c + 0 + 0 + + + 3 + 41 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim.c + stm32g4xx_hal_tim.c + 0 + 0 + + + 3 + 42 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim_ex.c + stm32g4xx_hal_tim_ex.c + 0 + 0 + + + 3 + 43 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pcd.c + stm32g4xx_hal_pcd.c + 0 + 0 + + + 3 + 44 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pcd_ex.c + stm32g4xx_hal_pcd_ex.c + 0 + 0 + + + 3 + 45 + 1 + 0 + 0 + 0 + ../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_usb.c + stm32g4xx_ll_usb.c + 0 + 0 + + + + + Drivers/CMSIS + 0 + 0 + 0 + 0 + + 4 + 46 + 1 + 0 + 0 + 0 + ../Src/system_stm32g4xx.c + system_stm32g4xx.c + 0 + 0 + + + + + ::CMSIS + 0 + 0 + 0 + 1 + +
diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/MDK-ARM/AMC_BLDC.uvprojx b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/MDK-ARM/AMC_BLDC.uvprojx index 653a435f9..bf7b2d70a 100644 --- a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/MDK-ARM/AMC_BLDC.uvprojx +++ b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/MDK-ARM/AMC_BLDC.uvprojx @@ -1,39 +1,46 @@ - - + + + 2.1 +
### uVision Project, (C) Keil Software
+ AMC_BLDC 0x4 ARM-ADS + 6190000::V6.19::ARMCLANG + 1 STM32G474CCUx STMicroelectronics + Keil.STM32G4xx_DFP.1.4.0 + http://www.keil.com/pack/ IRAM(0x20000000-0x2001FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4") TZ - - - + + + 0 - - - - - - - - - - - + + + + + + + + + + + $$Device:STM32G474CCUx$CMSIS\SVD\STM32G474xx.svd 0 0 - - - - - + + + + + 0 0 @@ -48,15 +55,15 @@ 1 1 1 - ./AMC_BLDC/ + 1 0 0 0 0 - - + + 0 0 0 @@ -65,8 +72,8 @@ 0 0 - - + + 0 0 0 @@ -75,15 +82,15 @@ 0 0 - - + + 0 0 0 0 1 - + 0 @@ -97,8 +104,8 @@ 0 0 3 - - + + 0 @@ -131,11 +138,11 @@ 1 BIN\UL2V8M.DLL - - - - - + + + + + 0 @@ -168,7 +175,7 @@ 0 0 "Cortex-M4" - + 0 0 0 @@ -178,11 +185,13 @@ 0 2 0 - 1 - 1 + 0 + 0 + 0 + 0 8 0 - 1 + 0 0 0 3 @@ -237,13 +246,13 @@ 0 - - + 0x20000000 + 0x20000 1 - - + 0x8000000 + 0x40000 0 @@ -267,13 +276,13 @@ 1 - - + 0x8000000 + 0x40000 1 - - + 0x0 + 0x0 0 @@ -292,16 +301,16 @@ 0 - - + 0x20000000 + 0x20000 0 - - + 0x0 + 0x0 - + 1 @@ -314,23 +323,23 @@ 0 0 0 - 2 + 3 0 0 1 0 0 - 5 - 3 + 3 + 5 1 1 0 0 0 - + USE_HAL_DRIVER,STM32G474xx - + ../Inc;../Drivers/STM32G4xx_HAL_Driver/Inc;../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32G4xx/Include;../Drivers/CMSIS/Include @@ -344,12 +353,12 @@ 0 0 0 - 0 + 4 - - - - + + + + @@ -359,15 +368,15 @@ 0 1 0 - - - - - - - - - + + + + + + + + + @@ -622,20 +631,24 @@
+ + ::CMSIS +
+ - + - - + + - + - + - + diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/Src/stm32g4xx_hal_timebase_tim.c b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/Src/stm32g4xx_hal_timebase_tim.c index f82981981..a050e4454 100644 --- a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/Src/stm32g4xx_hal_timebase_tim.c +++ b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/cubemx/amcbldc/Src/stm32g4xx_hal_timebase_tim.c @@ -45,7 +45,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) uint32_t uwTimclock = 0; uint32_t uwPrescalerValue = 0; uint32_t pFLatency; - HAL_StatusTypeDef status = HAL_OK; + HAL_StatusTypeDef status; /* Enable TIM7 clock */ __HAL_RCC_TIM7_CLK_ENABLE(); @@ -55,6 +55,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) /* Compute TIM7 clock */ uwTimclock = 2*HAL_RCC_GetPCLK1Freq(); + /* Compute the prescaler value to have TIM7 counter clock equal to 1MHz */ uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); @@ -62,6 +63,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) htim7.Instance = TIM7; /* Initialize TIMx peripheral as follow: + + Period = [(TIM7CLK/1000) - 1]. to have a (1/1000) s time base. + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. + ClockDivision = 0 @@ -94,6 +96,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) } } } + HAL_TIM_RegisterCallback(&htim7, HAL_TIM_PERIOD_ELAPSED_CB_ID, TimeBase_TIM_PeriodElapsedCallback); /* Return function status */ @@ -123,6 +126,7 @@ void HAL_ResumeTick(void) /* Enable TIM7 Update interrupt */ __HAL_TIM_ENABLE_IT(&htim7, TIM_IT_UPDATE); } + /** * @brief Period elapsed callback in non blocking mode * @note This function is called when TIM6 interrupt took place, inside diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.g4.amcbldc.v120.lib b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.g4.amcbldc.v120.lib deleted file mode 100644 index 95933e7a4..000000000 Binary files a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.g4.amcbldc.v120.lib and /dev/null differ diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.g4.amcbldc.v122.lib b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.g4.amcbldc.v122.lib deleted file mode 100644 index 71b8acfb5..000000000 Binary files a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.g4.amcbldc.v122.lib and /dev/null differ diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.g4.v122.amcbldc.lib b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.g4.v122.amcbldc.lib new file mode 100644 index 000000000..7523cd653 Binary files /dev/null and b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.g4.v122.amcbldc.lib differ diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.h7.nucleoh7.v190.lib b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.h7.nucleoh7.v190.lib deleted file mode 100644 index 3ba8c7526..000000000 Binary files a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/lib/stm32hal.h7.nucleoh7.v190.lib and /dev/null differ diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/proj/stm32hal.g4.uvoptx b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/proj/stm32hal.g4.uvoptx index 50b8f93c9..e96534c94 100644 --- a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/proj/stm32hal.g4.uvoptx +++ b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/proj/stm32hal.g4.uvoptx @@ -695,7 +695,7 @@ 1 0 - 1 + 0 18 @@ -850,7 +850,7 @@ 1 0 - 0 + 1 18 @@ -4020,8 +4020,8 @@ 0 0 0 - ..\src\board\amcbldc\v122\src\adc.c - adc.c + ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c + board_amcbldc_v122.c 0 0 @@ -4032,8 +4032,8 @@ 0 0 0 - ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c - board_amcbldc_v122.c + ..\src\board\amcbldc\v122\src\adc.c + adc.c 0 0 diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/proj/stm32hal.g4.uvprojx b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/proj/stm32hal.g4.uvprojx index 6a8d0e755..5e866c15d 100644 --- a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/proj/stm32hal.g4.uvprojx +++ b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/proj/stm32hal.g4.uvprojx @@ -2209,14 +2209,14 @@ - adc.c + board_amcbldc_v122.c 1 - ..\src\board\amcbldc\v122\src\adc.c + ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c - board_amcbldc_v122.c + adc.c 1 - ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c + ..\src\board\amcbldc\v122\src\adc.c cordic.c @@ -5194,14 +5194,14 @@ - adc.c + board_amcbldc_v122.c 1 - ..\src\board\amcbldc\v122\src\adc.c + ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c - board_amcbldc_v122.c + adc.c 1 - ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c + ..\src\board\amcbldc\v122\src\adc.c cordic.c @@ -8179,14 +8179,14 @@ - adc.c + board_amcbldc_v122.c 1 - ..\src\board\amcbldc\v122\src\adc.c + ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c - board_amcbldc_v122.c + adc.c 1 - ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c + ..\src\board\amcbldc\v122\src\adc.c cordic.c @@ -11095,14 +11095,14 @@ - adc.c + board_amcbldc_v122.c 1 - ..\src\board\amcbldc\v122\src\adc.c + ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c - board_amcbldc_v122.c + adc.c 1 - ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c + ..\src\board\amcbldc\v122\src\adc.c cordic.c @@ -11812,7 +11812,7 @@ amcbldc-v120 0x4 ARM-ADS - 6180000::V6.18::ARMCLANG + 6190000::V6.19::ARMCLANG 1 @@ -11884,7 +11884,7 @@ 1 0 - cmd.exe /C copy .\g4-obj\stm32hal_amcbldc_v120.lib ..\lib\stm32hal.g4.amcbldc.v120.lib + cmd.exe /C copy .\g4-obj\stm32hal_amcbldc_v120.lib ..\lib\stm32hal.g4.v120.amcbldc.lib 0 0 @@ -14131,14 +14131,14 @@ - adc.c + board_amcbldc_v122.c 1 - ..\src\board\amcbldc\v122\src\adc.c + ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c - board_amcbldc_v122.c + adc.c 1 - ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c + ..\src\board\amcbldc\v122\src\adc.c cordic.c @@ -14848,7 +14848,7 @@ amcbldc-v122 0x4 ARM-ADS - 6180000::V6.18::ARMCLANG + 6190000::V6.19::ARMCLANG 1 @@ -14891,8 +14891,8 @@ 0 1 0 - 1 - 1 + 0 + 0 .\g4-lst\ 1 0 @@ -14920,7 +14920,7 @@ 1 0 - cmd.exe /C copy .\g4-obj\stm32hal_amcbldc_v122.lib ..\lib\stm32hal.g4.amcbldc.v122.lib + cmd.exe /C copy .\g4-obj\stm32hal_amcbldc_v122.lib ..\lib\stm32hal.g4.v122.amcbldc.lib 0 0 @@ -17236,14 +17236,14 @@ board-amcbldc-v122 - adc.c + board_amcbldc_v122.c 1 - ..\src\board\amcbldc\v122\src\adc.c + ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c - board_amcbldc_v122.c + adc.c 1 - ..\src\board\amcbldc\v122\src\board_amcbldc_v122.c + ..\src\board\amcbldc\v122\src\adc.c cordic.c diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/src/board/amcbldc/v122/src/board_amcbldc_v122.c b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/src/board/amcbldc/v122/src/board_amcbldc_v122.c index 500dec073..797fa9cd1 100644 --- a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/src/board/amcbldc/v122/src/board_amcbldc_v122.c +++ b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/src/board/amcbldc/v122/src/board_amcbldc_v122.c @@ -176,6 +176,12 @@ STM32HAL_BSP_STATIC_SCOPE void SystemClock_Config(void) { Error_Handler(); } + + // marco.accame: cube-mx version 6.8.0 does not generate this. + // maybe because it is redundant as the same code is called inside the i2c.c file + // etc for each clock separately + // i could remove it but i keep it because tests were doen w/ this code +#if 1 /** Initializes the peripherals clocks */ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C4|RCC_PERIPHCLK_USB @@ -190,6 +196,7 @@ STM32HAL_BSP_STATIC_SCOPE void SystemClock_Config(void) { Error_Handler(); } +#endif } diff --git a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/src/board/amcbldc/v122/src/stm32g4xx_hal_timebase_tim.c b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/src/board/amcbldc/v122/src/removed.stm32g4xx_hal_timebase_tim.c similarity index 99% rename from emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/src/board/amcbldc/v122/src/stm32g4xx_hal_timebase_tim.c rename to emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/src/board/amcbldc/v122/src/removed.stm32g4xx_hal_timebase_tim.c index f82981981..a050e4454 100644 --- a/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/src/board/amcbldc/v122/src/stm32g4xx_hal_timebase_tim.c +++ b/emBODY/eBcode/arch-arm/libs/lowlevel/stm32hal/src/board/amcbldc/v122/src/removed.stm32g4xx_hal_timebase_tim.c @@ -45,7 +45,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) uint32_t uwTimclock = 0; uint32_t uwPrescalerValue = 0; uint32_t pFLatency; - HAL_StatusTypeDef status = HAL_OK; + HAL_StatusTypeDef status; /* Enable TIM7 clock */ __HAL_RCC_TIM7_CLK_ENABLE(); @@ -55,6 +55,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) /* Compute TIM7 clock */ uwTimclock = 2*HAL_RCC_GetPCLK1Freq(); + /* Compute the prescaler value to have TIM7 counter clock equal to 1MHz */ uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); @@ -62,6 +63,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) htim7.Instance = TIM7; /* Initialize TIMx peripheral as follow: + + Period = [(TIM7CLK/1000) - 1]. to have a (1/1000) s time base. + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. + ClockDivision = 0 @@ -94,6 +96,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) } } } + HAL_TIM_RegisterCallback(&htim7, HAL_TIM_PERIOD_ELAPSED_CB_ID, TimeBase_TIM_PeriodElapsedCallback); /* Return function status */ @@ -123,6 +126,7 @@ void HAL_ResumeTick(void) /* Enable TIM7 Update interrupt */ __HAL_TIM_ENABLE_IT(&htim7, TIM_IT_UPDATE); } + /** * @brief Period elapsed callback in non blocking mode * @note This function is called when TIM6 interrupt took place, inside