소스 검색

Electrical measurements enabled

Bartosz Jakubski 5 달 전
부모
커밋
6975db02c2
37개의 변경된 파일142777개의 추가작업 그리고 104375개의 파일을 삭제
  1. 1 0
      OZE_Main/Core/Inc/measurements.h
  2. 2 1
      OZE_Main/Core/Inc/serial_protocol.h
  3. 17 12
      OZE_Main/Core/Src/mqtt_client.c
  4. 1 0
      OZE_Main/Core/Src/uart_tasks.c
  5. 71065 71053
      OZE_Main/Debug/OZE_Main.list
  6. 2148 2148
      OZE_Main/Debug/OZE_Main.map
  7. 400 0
      OZE_Sensor/.clang-format
  8. 2 2
      OZE_Sensor/.mxproject
  9. 1 1
      OZE_Sensor/Core/Inc/FreeRTOSConfig.h
  10. 74 0
      OZE_Sensor/Core/Inc/adc_buffers.h
  11. 30 0
      OZE_Sensor/Core/Inc/meas_tasks.h
  12. 3 0
      OZE_Sensor/Core/Inc/measurements.h
  13. 3 1
      OZE_Sensor/Core/Inc/node-red-config.h
  14. 49 0
      OZE_Sensor/Core/Inc/peripherial.h
  15. 2 1
      OZE_Sensor/Core/Inc/serial_protocol.h
  16. 1 1
      OZE_Sensor/Core/Inc/stm32h7xx_hal_conf.h
  17. 4 2
      OZE_Sensor/Core/Inc/stm32h7xx_it.h
  18. 15 0
      OZE_Sensor/Core/Src/adc_buffers.c
  19. 503 21
      OZE_Sensor/Core/Src/main.c
  20. 170 0
      OZE_Sensor/Core/Src/meas_tasks.c
  21. 2 2
      OZE_Sensor/Core/Src/mock_tasks.c
  22. 62 0
      OZE_Sensor/Core/Src/peripherial.c
  23. 324 43
      OZE_Sensor/Core/Src/stm32h7xx_hal_msp.c
  24. 60 30
      OZE_Sensor/Core/Src/stm32h7xx_it.c
  25. 33 14
      OZE_Sensor/Core/Src/uart_tasks.c
  26. 10 1
      OZE_Sensor/Debug/Core/Src/subdir.mk
  27. 8 1
      OZE_Sensor/Debug/Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk
  28. 40812 29447
      OZE_Sensor/Debug/OZE_Sensor.list
  29. 2921 1520
      OZE_Sensor/Debug/OZE_Sensor.map
  30. 5 0
      OZE_Sensor/Debug/objects.list
  31. 2034 0
      OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc.h
  32. 1388 0
      OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc_ex.h
  33. 8412 0
      OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_adc.h
  34. 5213 0
      OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_tim.h
  35. 4056 0
      OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.c
  36. 2659 0
      OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc_ex.c
  37. 287 74
      OZE_Sensor/OZE_Sensor.ioc

+ 1 - 0
OZE_Main/Core/Inc/measurements.h

@@ -8,6 +8,7 @@
 #ifndef INC_MEASUREMENTS_H_
 #define INC_MEASUREMENTS_H_
 
+#define MASTER_BOARD 1
 #define SLAVES_COUNT 4
 #define PHASES_QTY 3
 #define TEMPERATURE_QTY 2

+ 2 - 1
OZE_Main/Core/Inc/serial_protocol.h

@@ -37,12 +37,13 @@ enum _SerialProtocolCommands {
 	spSetmotorXMaxCurrent,
 	spSetmotorYMaxCurrent,
 	spSetDiodeOn,
+	spClearPeakMeasurments,
     spUnknown
 };
 
 typedef enum _SerialProtocolCommands SerialProtocolCommands;
 
-enum _SerialProtocolRespStatus { spInternalError = -3, spCrcFail = -2, spTimeout, spOK };
+enum _SerialProtocolRespStatus { spInternalError = -4, spUnknownCommand = -3, spCrcFail = -2, spTimeout, spOK };
 typedef enum _SerialProtocolRespStatus SerialProtocolRespStatus;
 
 #define GET_SHORT_WORD_FIRST_BYTE(cmd) ((uint8_t)(cmd & 0xFF))

+ 17 - 12
OZE_Main/Core/Src/mqtt_client.c

@@ -24,13 +24,14 @@
 
 #define MQTT_BUFSIZE	1024
 
-char* const subscribeTopicNames[SLAVES_COUNT] = { "Set/1", "Set/2", "Set/3", "Set/4" };
-#define MAX_COMMANDS_IN_MQTT_PAYLOAD 6
-char* const topicCommands[MAX_COMMANDS_IN_MQTT_PAYLOAD] = {"fanSpeed", "motorXon", "motorYon", "diode", "motorXMaxCurrent", "motorYMaxCurrent"};
+char* const subscribeTopicNames[MASTER_BOARD + SLAVES_COUNT] = { "Set/0", "Set/1", "Set/2", "Set/3", "Set/4" };
+#define MAX_COMMANDS_IN_MQTT_PAYLOAD 9
+char* const topicCommands[MAX_COMMANDS_IN_MQTT_PAYLOAD] = {"fanSpeed", "motorXon", "motorYon", "diode", "motorXMaxCurrent", "motorYMaxCurrent", "clearPeakElectricalMeasurements", "mainBoardRelay"};
 
 enum _BoardNoOverTopic
 {
-	board_1 = 1,
+	main_board = 0,
+	board_1,
 	board_2,
 	board_3,
 	board_4,
@@ -203,14 +204,15 @@ void MqttMessageArrived (MessageData* msg) {
 
     for (boardNumber = 0; boardNumber < SLAVES_COUNT; boardNumber++) {
         if (strcmp (topicName, subscribeTopicNames[boardNumber]) == 0) {
-            topicForBoard = (BoardNoOverTopic)(boardNumber + 1);
+            topicForBoard = (BoardNoOverTopic)(boardNumber);
+            break;
         }
     }
 
     cJSON* json             = cJSON_Parse (message->payload);
     const cJSON* objectItem = NULL;
     InterProcessData data   = { 0 };
-    for (int topicCmdNumber = 0; topicCmdNumber < 6; topicCmdNumber++) {
+    for (int topicCmdNumber = 0; topicCmdNumber < MAX_COMMANDS_IN_MQTT_PAYLOAD; topicCmdNumber++) {
         spCommand  = spUnknown;
         objectItem = cJSON_GetObjectItemCaseSensitive (json, topicCommands[topicCmdNumber]);
         if (objectItem != NULL) {
@@ -251,15 +253,21 @@ void MqttMessageArrived (MessageData* msg) {
                 data.values.flaotValues.value[0] = objectItem->valuedouble;
                 data.values.flaotValues.value[1] = 0.0;
                 break;
+            case 6:
+            	data.spCommand = spClearPeakMeasurments;
+            	break;
+            case 7:
+            	break;
             default: break;
             }
 
             switch (topicForBoard) {
+            case main_board:
+            	break;
             case board_1:
-#if 0
+#if 1
                 if (uart1TaskData.sendCmdToSlaveQueue != NULL) {
-                    osMessageQueuePut (
-                    uart1TaskData.sendCmdToSlaveQueue, &data, 0, (TickType_t)100);
+                    osMessageQueuePut (uart1TaskData.sendCmdToSlaveQueue, &data, 0, (TickType_t)100);
                 }
 #else
                 if (uart8TaskData.sendCmdToSlaveQueue != NULL) {
@@ -291,9 +299,6 @@ void MqttMessageArrived (MessageData* msg) {
         }
     }
     cJSON_Delete (json);
-
-    //    printf ("MQTT MSG[%d]:%s\n", (int)message->payloadlen, (char*)message->payload);
-
     printf ("MQTT Topic:%s, MSG[%d]:%s\n", topicName, (int)message->payloadlen, (char*)message->payload);
 }
 

+ 1 - 0
OZE_Main/Core/Src/uart_tasks.c

@@ -379,6 +379,7 @@ void UartTxTask (void* argument) {
             case spSetmotorYMaxCurrent: WriteDataToBuffer (outputDataBuffer, &outputDataBufferPos, &data.values.flaotValues.value[0], sizeof (float)); break;
             case spGetElectricalMeasurments:
             case spGetSensorMeasurments: break;
+            case spClearPeakMeasurments: break;
             default: continue; break;
             }
 

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 71065 - 71053
OZE_Main/Debug/OZE_Main.list


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 2148 - 2148
OZE_Main/Debug/OZE_Main.map


+ 400 - 0
OZE_Sensor/.clang-format

@@ -0,0 +1,400 @@
+# clang-format
+# Made by: Ingmar Delsink
+# idelsink.com
+# See http://clang.llvm.org/docs/ClangFormatStyleOptions.html
+# Tested with: clang-format version 3.7.1
+
+# General
+#########
+
+# The style used for all options not specifically set in the configuration.
+# This option is supported only in the clang-format configuration (both within -style='{...}' and the .clang-format file).
+# Possible values:
+#   LLVM A style complying with the LLVM coding standards
+#   Google A style complying with Google’s C++ style guide
+#   Chromium A style complying with Chromium’s style guide
+#   Mozilla A style complying with Mozilla’s style guide
+#   WebKit A style complying with WebKit’s style guide
+#BasedOnStyle:
+
+# TabWidth (unsigned)
+# The number of columns used for tab stops.
+TabWidth: 4
+
+# IndentWidth (unsigned)
+# The number of columns to use for indentation.
+IndentWidth: 4
+
+# UseTab (UseTabStyle)
+# The way to use tab characters in the resulting file.
+# Possible values:
+#   UT_Never (in configuration: Never) Never use tab.
+#   UT_ForIndentation (in configuration: ForIndentation) Use tabs only for indentation.
+#   UT_Always (in configuration: Always) Use tabs whenever we need to fill whitespace that spans at least from one tab stop to the next one.
+UseTab: Never
+
+# C++
+#####
+
+# Language (LanguageKind)
+# Language, this format style is targeted at.
+# Possible values:
+#   LK_None (in configuration: None) Do not use.
+#   LK_Cpp (in configuration: Cpp) Should be used for C, C++, ObjectiveC, ObjectiveC++.
+#   LK_Java (in configuration: Java) Should be used for Java.
+#   LK_JavaScript (in configuration: JavaScript) Should be used for JavaScript.
+#   LK_Proto (in configuration: Proto) Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).
+#   LK_TableGen (in configuration: TableGen) Should be used for TableGen code.
+Language: Cpp
+
+# Standard (LanguageStandard)
+# Format compatible with this standard, e.g. use A<A<int> > instead of A<A<int>> for LS_Cpp03.
+# Possible values:
+#   LS_Cpp03 (in configuration: Cpp03) Use C++03-compatible syntax.
+#   LS_Cpp11 (in configuration: Cpp11) Use features of C++11 (e.g. A<A<int>> instead of A<A<int> >).
+#   LS_Auto (in configuration: Auto) Automatic detection based on the input.
+Standard: Cpp11
+
+# Pointer and reference alignment style. Possible values: Left, Right, Middle.
+PointerAlignment: Left
+
+# AccessModifierOffset (int)
+# The extra indent or outdent of access modifiers, e.g. public:.
+AccessModifierOffset: 0
+
+# AlignAfterOpenBracket (BracketAlignmentStyle)
+# If true, horizontally aligns arguments after an open bracket.
+# This applies to round brackets (parentheses), angle brackets and square brackets.
+# Possible values:
+#   BAS_Align (in configuration: Align) Align parameters on the open bracket, e.g.:
+#   someLongFunction(argument1,
+#                    argument2);
+#   BAS_DontAlign (in configuration: DontAlign) Don’t align, instead use ContinuationIndentWidth, e.g.:
+#   someLongFunction(argument1,
+#   argument2);
+#   BAS_AlwaysBreak (in configuration: AlwaysBreak) Always break after an open bracket, if the parameters don’t fit on a single line, e.g.:
+#   someLongFunction(
+#       argument1, argument2);
+AlignAfterOpenBracket: false
+
+# AlignConsecutiveAssignments (bool)
+# If true, aligns consecutive assignments.
+# This will align the assignment operators of consecutive lines. This will result in formattings like
+# int aaaa = 12;
+# int b    = 23;
+# int ccc  = 23;
+AlignConsecutiveAssignments: true
+
+# AlignEscapedNewlinesLeft (bool)
+# If true, aligns escaped newlines as far left as possible. Otherwise puts them into the right-most column.
+AlignEscapedNewlinesLeft: true
+
+# AlignOperands (bool)
+# If true, horizontally align operands of binary and ternary expressions.
+# Specifically, this aligns operands of a single expression that needs to be split over multiple lines, e.g.:
+# int aaa = bbbbbbbbbbbbbbb +
+#           ccccccccccccccc;
+AlignOperands: false
+
+# AlignTrailingComments (bool)
+# If true, aligns trailing comments.
+AlignTrailingComments: true
+
+# AllowAllParametersOfDeclarationOnNextLine (bool)
+# Allow putting all parameters of a function declaration onto the next line even if BinPackParameters is false.
+AllowAllParametersOfDeclarationOnNextLine: false
+
+# AllowShortBlocksOnASingleLine (bool)
+# Allows contracting simple braced statements to a single line.
+AllowShortBlocksOnASingleLine: false
+
+# AllowShortCaseLabelsOnASingleLine (bool)
+# If true, short case labels will be contracted to a single line.
+AllowShortCaseLabelsOnASingleLine: true
+
+# AllowShortFunctionsOnASingleLine (ShortFunctionStyle)
+# Dependent on the value, int f() { return 0; } can be put on a single line.
+# Possible values:
+#   SFS_None (in configuration: None) Never merge functions into a single line.
+#   SFS_Empty (in configuration: Empty) Only merge empty functions.
+#   SFS_Inline (in configuration: Inline) Only merge functions defined inside a class. Implies “empty”.
+#   SFS_All (in configuration: All) Merge all functions fitting on a single line.
+AllowShortFunctionsOnASingleLine: false
+
+# AllowShortIfStatementsOnASingleLine (bool)
+# If true, if (a) return; can be put on a single line.
+AllowShortIfStatementsOnASingleLine: false
+
+# AllowShortLoopsOnASingleLine (bool)
+# If true, while (true) continue; can be put on a single line.
+AllowShortLoopsOnASingleLine: false
+
+# AlwaysBreakBeforeMultilineStrings (bool)
+# If true, always break before multiline string literals.
+# This flag is mean to make cases where there are multiple multiline strings in a file look more consistent. Thus, it will only take effect if wrapping the string at that point leads to it being indented ContinuationIndentWidth spaces from the start of the line.
+AlwaysBreakBeforeMultilineStrings: false
+
+# AlwaysBreakTemplateDeclarations (bool)
+# If true, always break after the template<...> of a template declaration.
+AlwaysBreakTemplateDeclarations: false
+
+# BinPackArguments (bool)
+# If false, a function call’s arguments will either be all on the same line or will have one line each.
+#BinPackArguments: false
+
+# BinPackParameters (bool)
+# If false, a function declaration’s or function definition’s parameters will either all be on the same line or will have one line each.
+BinPackParameters: false
+
+# BraceWrapping (BraceWrappingFlags)
+# Control of individual brace wrapping cases.
+# If BreakBeforeBraces is set to BS_Custom, use this to specify how each individual brace case should be handled. Otherwise, this is ignored.
+# Nested configuration flags:
+#   bool AfterClass Wrap class definitions.
+#   bool AfterControlStatement Wrap control statements (if/for/while/switch/..).
+#   bool AfterEnum Wrap enum definitions.
+#   bool AfterFunction Wrap function definitions.
+#   bool AfterNamespace Wrap namespace definitions.
+#   bool AfterObjCDeclaration Wrap ObjC definitions (@autoreleasepool, interfaces, ..).
+#   bool AfterStruct Wrap struct definitions.
+#   bool AfterUnion Wrap union definitions.
+#   bool BeforeCatch Wrap before catch.
+#   bool BeforeElse Wrap before else.
+#   bool IndentBraces Indent the wrapped braces themselves.
+#BraceWrapping:
+
+# BreakAfterJavaFieldAnnotations (bool)
+# Break after each annotation on a field in Java files.
+#BreakAfterJavaFieldAnnotations:
+
+# BreakBeforeBinaryOperators (BinaryOperatorStyle)
+# The way to wrap binary operators.
+# Possible values:
+#   BOS_None (in configuration: None) Break after operators.
+#   BOS_NonAssignment (in configuration: NonAssignment) Break before operators that aren’t assignments.
+#   BOS_All (in configuration: All) Break before operators.
+BreakBeforeBinaryOperators: false
+
+# BreakBeforeBraces (BraceBreakingStyle)
+# The brace breaking style to use.
+# Possible values:
+#   BS_Attach (in configuration: Attach) Always attach braces to surrounding context.
+#   BS_Linux (in configuration: Linux) Like Attach, but break before braces on function, namespace and class definitions.
+#   BS_Mozilla (in configuration: Mozilla) Like Attach, but break before braces on enum, function, and record definitions.
+#   BS_Stroustrup (in configuration: Stroustrup) Like Attach, but break before function definitions, catch, and else.
+#   BS_Allman (in configuration: Allman) Always break before braces.
+#   BS_GNU (in configuration: GNU) Always break before braces and add an extra level of indentation to braces of control statements, not to those of class, function or other definitions.
+#   BS_WebKit (in configuration: WebKit) Like Attach, but break before functions.
+#   BS_Custom (in configuration: Custom) Configure each individual brace in BraceWrapping.
+BreakBeforeBraces: Attach
+
+# BreakBeforeTernaryOperators (bool)
+# If true, ternary operators will be placed after line breaks.
+BreakBeforeTernaryOperators: false
+
+# BreakConstructorInitializersBeforeComma (bool)
+# Always break constructor initializers before commas and align the commas with the colon.
+BreakConstructorInitializersBeforeComma: false
+
+# BreakStringLiterals (bool)
+# Allow breaking string literals when formatting.
+#BreakStringLiterals:
+
+# ColumnLimit (unsigned)
+# The column limit.
+# A column limit of 0 means that there is no column limit. In this case, clang-format will respect the input’s line breaking decisions within statements unless they contradict other rules.
+ColumnLimit: 200
+
+# CommentPragmas (std::string)
+# A regular expression that describes comments with special meaning, which should not be split into lines or otherwise changed.
+CommentPragmas: ''
+
+# ConstructorInitializerAllOnOneLineOrOnePerLine (bool)
+# If the constructor initializers don’t fit on a line, put each initializer on its own line.
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+
+# ConstructorInitializerIndentWidth (unsigned)
+# The number of characters to use for indentation of constructor initializer lists.
+ConstructorInitializerIndentWidth: 0
+
+# ContinuationIndentWidth (unsigned)
+# Indent width for line continuations.
+ContinuationIndentWidth: 0
+
+# Cpp11BracedListStyle (bool)
+# If true, format braced lists as best suited for C++11 braced lists.
+# Important differences: - No spaces inside the braced list. - No line break before the closing brace. - Indentation with the continuation indent, not with the block indent.
+# Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the {} were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.
+Cpp11BracedListStyle: false
+
+# DerivePointerAlignment (bool)
+# If true, analyze the formatted file for the most common alignment of & and \*. PointerAlignment is then used only as fallback.
+DerivePointerBinding: false
+
+# DisableFormat (bool)
+# Disables formatting completely.
+#DisableFormat:
+
+# ExperimentalAutoDetectBinPacking (bool)
+# If true, clang-format detects whether function calls and definitions are formatted with one parameter per line.
+# Each call can be bin-packed, one-per-line or inconclusive. If it is inconclusive, e.g. completely on one line, but a decision needs to be made, clang-format analyzes whether there are other bin-packed cases in the input file and act accordingly.
+# NOTE: This is an experimental flag, that might go away or be renamed. Do not use this in config files, etc. Use at your own risk.
+#ExperimentalAutoDetectBinPacking:
+
+# ForEachMacros (std::vector<std::string>)
+# A vector of macros that should be interpreted as foreach loops instead of as function calls.
+# These are expected to be macros of the form:
+# FOREACH(<variable-declaration>, ...)
+#  <loop-body>
+# In the .clang-format configuration file, this can be configured like:
+# ForEachMacros: ['RANGES_FOR', 'FOREACH']
+# For example: BOOST_FOREACH.
+#ForEachMacros:
+
+# IncludeCategories (std::vector<IncludeCategory>)
+# Regular expressions denoting the different #include categories used for ordering #includes.
+# These regular expressions are matched against the filename of an include (including the <> or “”) in order. The value belonging to the first matching regular expression is assigned and #includes are sorted first according to increasing category number and then alphabetically within each category.
+# If none of the regular expressions match, INT_MAX is assigned as category. The main header for a source file automatically gets category 0. so that it is generally kept at the beginning of the #includes (http://llvm.org/docs/CodingStandards.html#include-style). However, you can also assign negative priorities if you have certain headers that always need to be first.
+# To configure this in the .clang-format file, use:
+# IncludeCategories:
+#   - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+#     Priority:        2
+#   - Regex:           '^(<|"(gtest|isl|json)/)'
+#     Priority:        3
+#   - Regex:           '.\*'
+#     Priority:        1
+#IncludeCategories:
+
+# IndentCaseLabels (bool)
+# Indent case labels one level from the switch statement.
+# When false, use the same indentation level as for the switch statement. Switch statement body is always indented one level more than case labels.
+IndentCaseLabels: false
+
+# IndentFunctionDeclarationAfterType (bool)
+# If true, indent when breaking function declarations which are not also definitions after the type.
+IndentFunctionDeclarationAfterType: false
+
+# IndentWrappedFunctionNames (bool)
+# Indent if a function definition or declaration is wrapped after the type.
+#IndentWrappedFunctionNames:
+
+# KeepEmptyLinesAtTheStartOfBlocks (bool)
+# If true, empty lines at the start of blocks are kept.
+#KeepEmptyLinesAtTheStartOfBlocks:
+
+# MacroBlockBegin (std::string)
+# A regular expression matching macros that start a block.
+#MacroBlockBegin:
+
+# MacroBlockEnd (std::string)
+# A regular expression matching macros that end a block.
+#MacroBlockEnd:
+
+# MaxEmptyLinesToKeep (unsigned)
+# The maximum number of consecutive empty lines to keep.
+MaxEmptyLinesToKeep: 2
+
+# NamespaceIndentation (NamespaceIndentationKind)
+# The indentation used for namespaces.
+# Possible values:
+#   NI_None (in configuration: None) Don’t indent in namespaces.
+#   NI_Inner (in configuration: Inner) Indent only in inner namespaces (nested in other namespaces).
+#   NI_All (in configuration: All) Indent in all namespaces.
+NamespaceIndentation: None
+
+# ObjCBlockIndentWidth (unsigned)
+# The number of characters to use for indentation of ObjC blocks.
+#ObjCBlockIndentWidth:
+
+# ObjCSpaceAfterProperty (bool)
+# Add a space after @property in Objective-C, i.e. use @property (readonly) instead of @property(readonly).
+ObjCSpaceAfterProperty: true
+
+# ObjCSpaceBeforeProtocolList (bool)
+# Add a space in front of an Objective-C protocol list, i.e. use Foo <Protocol> instead of Foo<Protocol>.
+ObjCSpaceBeforeProtocolList: true
+
+# PenaltyBreakBeforeFirstCallParameter (unsigned)
+# The penalty for breaking a function call after call(.
+PenaltyBreakBeforeFirstCallParameter: 100
+
+# PenaltyBreakComment (unsigned)
+# The penalty for each line break introduced inside a comment.
+PenaltyBreakComment: 100
+
+# PenaltyBreakFirstLessLess (unsigned)
+# The penalty for breaking before the first <<.
+PenaltyBreakFirstLessLess: 0
+
+# PenaltyBreakString (unsigned)
+# The penalty for each line break introduced inside a string literal.
+PenaltyBreakString: 100
+
+# PenaltyExcessCharacter (unsigned)
+# The penalty for each character outside of the column limit.
+PenaltyExcessCharacter: 1
+
+# PenaltyReturnTypeOnItsOwnLine (unsigned)
+# Penalty for putting the return type of a function onto its own line.
+PenaltyReturnTypeOnItsOwnLine: 20
+
+# PointerAlignment (PointerAlignmentStyle)
+# Pointer and reference alignment style.
+# Possible values:
+#   PAS_Left (in configuration: Left) Align pointer to the left.
+#   PAS_Right (in configuration: Right) Align pointer to the right.
+#   PAS_Middle (in configuration: Middle) Align pointer in the middle.
+#PointerAlignment:
+
+# ReflowComments (bool)
+# If true, clang-format will attempt to re-flow comments.
+#ReflowComments: true (from v3.9)
+
+# SortIncludes (bool)
+# If true, clang-format will sort #includes.
+#SortIncludes: false (from v3.9)
+
+# SpaceAfterCStyleCast (bool)
+# If true, a space may be inserted after C style casts.
+SpaceAfterCStyleCast: false
+
+# SpaceBeforeAssignmentOperators (bool)
+# If false, spaces will be removed before assignment operators.
+SpaceBeforeAssignmentOperators: true
+
+# SpaceBeforeParens (SpaceBeforeParensOptions)
+# Defines in which cases to put a space before opening parentheses.
+# Possible values:
+#   SBPO_Never (in configuration: Never) Never put a space before opening parentheses.
+#   SBPO_ControlStatements (in configuration: ControlStatements) Put a space before opening parentheses only after control statement keywords (for/if/while...).
+#   SBPO_Always (in configuration: Always) Always put a space before opening parentheses, except when it’s prohibited by the syntax rules (in function-like macro definitions) or when determined by other style rules (after unary operators, opening parentheses, etc.)
+SpaceBeforeParens: Always
+
+# SpaceInEmptyParentheses (bool)
+# If true, spaces may be inserted into ().
+SpaceInEmptyParentheses: false
+
+# SpacesBeforeTrailingComments (unsigned)
+# The number of spaces before trailing line comments (// - comments).
+# This does not affect trailing block comments (/* - comments) as those commonly have different usage patterns and a number of special cases.
+SpacesBeforeTrailingComments: 1
+
+# SpacesInAngles (bool)
+# If true, spaces will be inserted after < and before > in template argument lists.
+SpacesInAngles: false
+
+# SpacesInCStyleCastParentheses (bool)
+# If true, spaces may be inserted into C style casts.
+SpacesInCStyleCastParentheses: false
+
+# SpacesInContainerLiterals (bool)
+# If true, spaces are inserted inside container literals (e.g. ObjC and Javascript array and dict literals).
+SpacesInContainerLiterals: false
+
+# SpacesInParentheses (bool)
+# If true, spaces will be inserted after ( and before ).
+SpacesInParentheses: false
+
+# SpacesInSquareBrackets (bool)
+# If true, spaces will be inserted after [ and before ].
+SpacesInSquareBrackets: false

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 2 - 2
OZE_Sensor/.mxproject


+ 1 - 1
OZE_Sensor/Core/Inc/FreeRTOSConfig.h

@@ -56,7 +56,7 @@
 #define CMSIS_device_header "stm32h7xx.h"
 #endif /* CMSIS_device_header */
 
-#define configENABLE_FPU                         0
+#define configENABLE_FPU                         1
 #define configENABLE_MPU                         0
 
 #define configUSE_PREEMPTION                     1

+ 74 - 0
OZE_Sensor/Core/Inc/adc_buffers.h

@@ -0,0 +1,74 @@
+/*
+ * adc_buffers.h
+ *
+ *  Created on: Sep 5, 2024
+ *      Author: jakubski
+ */
+
+#ifndef INC_ADC_BUFFERS_H_
+#define INC_ADC_BUFFERS_H_
+
+#include "stdint.h"
+#include "stm32h7xx_hal.h"
+
+#define EXT_VREF_mV 3000
+#define U_CHANNEL_CONST 7.59
+#define I_CHANNEL_CONST 7.5758
+#define deltaADC 3.0/65535
+
+enum _ADC1_DataInfo {
+    UL1 = 0,
+    UL2,
+    UL3,
+	IL1Ref,
+	IL2Ref,
+	IL3Ref,
+    ADC1LastData,
+};
+typedef enum _ADC1_DataInfo ADC1_DataInfo;
+
+struct _ADC1_Data {
+    uint16_t adcDataBuffer[ADC1LastData];
+    uint16_t dummy[(__SCB_DCACHE_LINE_SIZE / sizeof (uint16_t)) - ADC1LastData];
+};
+
+enum _ADC2_DataInfo { IL1 = 0, IL2, IL3, ADC2LastData };
+typedef enum _ADC2_DataInfo ADC2_DataInfo;
+
+struct _ADC2_Data {
+    uint16_t adcDataBuffer[ADC2LastData];
+    uint16_t dummy[(__SCB_DCACHE_LINE_SIZE / sizeof (uint16_t)) - ADC2LastData];
+};
+
+enum _ADC3_DataInfo { pvTemp1 = 0, pvTemp2, motorXSense, motorYSense, VrefInt, ADC3LastData };
+typedef enum _ADC3_DataInfo ADC3_DataInfo;
+
+struct _ADC3_Data {
+    uint16_t adcDataBuffer[ADC3LastData];
+    uint16_t dummy[(__SCB_DCACHE_LINE_SIZE / sizeof (uint16_t)) - ADC3LastData];
+};
+
+typedef struct _ADC1_Data ADC1_Data;
+typedef struct _ADC2_Data ADC2_Data;
+typedef struct _ADC3_Data ADC3_Data;
+
+extern ADC1_Data adc1Data;
+extern ADC2_Data adc2Data;
+extern ADC3_Data adc3Data;
+
+#define DEFAULT_U_GAIN 1.0
+#define DEFAULT_U_OFFSET 0.0
+#define DEFAULT_I_GAIN 1.0
+#define DEFAULT_I_OFFSET 0.0
+
+struct _EletricalMeasCorrectionData
+{
+	float gain;
+	float offset;
+};
+typedef struct _EletricalMeasCorrectionData EletricalMeasCorrectionData;
+
+extern EletricalMeasCorrectionData U_MeasCorrectionData[3];
+extern EletricalMeasCorrectionData I_MeasCorrectionData[3];
+
+#endif /* INC_ADC_BUFFERS_H_ */

+ 30 - 0
OZE_Sensor/Core/Inc/meas_tasks.h

@@ -0,0 +1,30 @@
+/*
+ * meas_tasks.h
+ *
+ *  Created on: Sep 5, 2024
+ *      Author: jakubski
+ */
+
+#ifndef INC_MEAS_TASKS_H_
+#define INC_MEAS_TASKS_H_
+
+#include "FreeRTOS.h"
+#include "FreeRTOSConfig.h"
+#include "task.h"
+#include "cmsis_os.h"
+
+#define GAIN_AUTO_CORRECTION
+
+extern osMessageQueueId_t adc1MeasDataQueue;
+extern osMessageQueueId_t adc2MeasDataQueue;
+extern osMessageQueueId_t adc3MeasDataQueue;
+
+extern osMutexId_t resMeasurementsMutex;
+extern osMutexId_t sensorsInfoMutex;
+
+void MeasTasksInit(void);
+void ADC1MeasTask(void *arg);
+void ADC2MeasTask(void *arg);
+void ADC3MeasTask(void *arg);
+
+#endif /* INC_MEAS_TASKS_H_ */

+ 3 - 0
OZE_Sensor/Core/Inc/measurements.h

@@ -39,4 +39,7 @@ struct _SesnorsInfo {
 typedef struct _RESMeasurements RESMeasurements;
 typedef struct _SesnorsInfo SesnorsInfo;
 
+extern RESMeasurements resMeasurements;
+extern SesnorsInfo sensorsInfo;
+
 #endif /* INC_MEASUREMENTS_H_ */

+ 3 - 1
OZE_Sensor/Core/Inc/node-red-config.h

@@ -8,11 +8,13 @@
 #ifndef INC_NODE_RED_CONFIG_H_
 #define INC_NODE_RED_CONFIG_H_
 
+#define PV_BOARD
+
 #define FEATURE_ON 1
 #define FEATURE_OFF 0
 
 #define UART_TASK_LOGS FEATURE_ON
 
-#define USER_MOCKS
+//#define USER_MOCKS
 
 #endif /* INC_NODE_RED_CONFIG_H_ */

+ 49 - 0
OZE_Sensor/Core/Inc/peripherial.h

@@ -0,0 +1,49 @@
+/*
+ * peripherial.h
+ *
+ *  Created on: Sep 10, 2024
+ *      Author: jakubski
+ */
+
+#ifndef INC_PERIPHERIAL_H_
+#define INC_PERIPHERIAL_H_
+
+#include "main.h"
+
+#define DBG_LED1 GPIO_PIN_4
+#define DBG_LED2 GPIO_PIN_5
+#define DBG_LED3 GPIO_PIN_6
+#define DBG_LED4 GPIO_PIN_7
+
+#define CURRENT_SENSOR_L1_GPIO_OFFSET 7
+#define CURRENT_SENSOR_L2_GPIO_OFFSET 9
+#define CURRENT_SENSOR_L3_GPIO_OFFSET 13
+
+#define MCU_CS_PWR_EN GPIO_PIN_15
+
+enum _CurrentSensor
+{
+	CurrentSensorL1,
+	CurrentSensorL2,
+	CurrentSensorL3
+};
+typedef enum _CurrentSensor CurrentSensor;
+
+enum _CurrentSensorGain
+{
+	csGain1,
+	csGain2,
+	csGain3,
+	csGain0
+};
+typedef enum _CurrentSensorGain CurrentSensorGain;
+
+
+void DbgLEDOn(uint8_t ledNumber);
+void DbgLEDOff(uint8_t ledNumber);
+void DbgLEDToggle(uint8_t ledNumber);
+void EnableCurrentSensors(void);
+void DisableCurrentSensors(void);
+void SelectCurrentSensorGain(CurrentSensor sensor, CurrentSensorGain gain);
+
+#endif /* INC_PERIPHERIAL_H_ */

+ 2 - 1
OZE_Sensor/Core/Inc/serial_protocol.h

@@ -37,12 +37,13 @@ enum _SerialProtocolCommands {
 	spSetmotorXMaxCurrent,
 	spSetmotorYMaxCurrent,
 	spSetDiodeOn,
+	spClearPeakMeasurments,
     spUnknown
 };
 
 typedef enum _SerialProtocolCommands SerialProtocolCommands;
 
-enum _SerialProtocolRespStatus { spInternalError = -3, spCrcFail = -2, spTimeout, spOK };
+enum _SerialProtocolRespStatus { spInternalError = -4, spUnknownCommand = -3, spCrcFail = -2, spTimeout, spOK };
 typedef enum _SerialProtocolRespStatus SerialProtocolRespStatus;
 
 #define GET_SHORT_WORD_FIRST_BYTE(cmd) ((uint8_t)(cmd & 0xFF))

+ 1 - 1
OZE_Sensor/Core/Inc/stm32h7xx_hal_conf.h

@@ -34,7 +34,7 @@
   */
 #define HAL_MODULE_ENABLED
 
-  /* #define HAL_ADC_MODULE_ENABLED   */
+  #define HAL_ADC_MODULE_ENABLED
 /* #define HAL_FDCAN_MODULE_ENABLED   */
 /* #define HAL_FMAC_MODULE_ENABLED   */
 /* #define HAL_CEC_MODULE_ENABLED   */

+ 4 - 2
OZE_Sensor/Core/Inc/stm32h7xx_it.h

@@ -53,10 +53,12 @@ void BusFault_Handler(void);
 void UsageFault_Handler(void);
 void DebugMon_Handler(void);
 void RCC_IRQHandler(void);
+void DMA1_Stream0_IRQHandler(void);
+void DMA1_Stream1_IRQHandler(void);
+void DMA1_Stream2_IRQHandler(void);
+void TIM2_IRQHandler(void);
 void USART1_IRQHandler(void);
 void TIM6_DAC_IRQHandler(void);
-void DMA2_Stream6_IRQHandler(void);
-void DMA2_Stream7_IRQHandler(void);
 void UART8_IRQHandler(void);
 /* USER CODE BEGIN EFP */
 

+ 15 - 0
OZE_Sensor/Core/Src/adc_buffers.c

@@ -0,0 +1,15 @@
+/*
+ * adc_buffers.c
+ *
+ *  Created on: Sep 5, 2024
+ *      Author: jakubski
+ */
+
+#include "adc_buffers.h"
+
+ADC1_Data adc1Data __attribute__ ((aligned (32))) = { 0 };
+ADC2_Data adc2Data __attribute__ ((aligned (32))) = { 0 };
+ADC3_Data adc3Data __attribute__ ((aligned (32))) = { 0 };
+
+EletricalMeasCorrectionData U_MeasCorrectionData[3] = { { DEFAULT_U_GAIN, DEFAULT_U_OFFSET }, { DEFAULT_U_GAIN, DEFAULT_U_OFFSET }, { DEFAULT_U_GAIN, DEFAULT_U_OFFSET } };
+EletricalMeasCorrectionData I_MeasCorrectionData[3] = { { DEFAULT_I_GAIN, DEFAULT_I_OFFSET }, { DEFAULT_I_GAIN, DEFAULT_I_OFFSET }, { DEFAULT_I_GAIN, DEFAULT_I_OFFSET } };

+ 503 - 21
OZE_Sensor/Core/Src/main.c

@@ -25,6 +25,9 @@
 #include "uart_tasks.h"
 #include "mock_tasks.h"
 #include "node-red-config.h"
+#include "adc_buffers.h"
+#include "meas_tasks.h"
+#include "peripherial.h"
 /* USER CODE END Includes */
 
 /* Private typedef -----------------------------------------------------------*/
@@ -43,15 +46,21 @@
 /* USER CODE END PM */
 
 /* Private variables ---------------------------------------------------------*/
+ADC_HandleTypeDef hadc1;
+ADC_HandleTypeDef hadc2;
+ADC_HandleTypeDef hadc3;
+DMA_HandleTypeDef hdma_adc1;
+DMA_HandleTypeDef hdma_adc2;
+DMA_HandleTypeDef hdma_adc3;
 
 CRC_HandleTypeDef hcrc;
 
 RNG_HandleTypeDef hrng;
 
+TIM_HandleTypeDef htim2;
+
 UART_HandleTypeDef huart8;
 UART_HandleTypeDef huart1;
-DMA_HandleTypeDef hdma_uart8_rx;
-DMA_HandleTypeDef hdma_uart8_tx;
 
 /* Definitions for defaultTask */
 osThreadId_t defaultTaskHandle;
@@ -62,17 +71,23 @@ const osThreadAttr_t defaultTask_attributes = {
 };
 /* USER CODE BEGIN PV */
 
+
 /* USER CODE END PV */
 
 /* Private function prototypes -----------------------------------------------*/
 void SystemClock_Config(void);
+void PeriphCommonClock_Config(void);
 static void MPU_Config(void);
 static void MX_GPIO_Init(void);
 static void MX_DMA_Init(void);
-static void MX_UART8_Init(void);
-static void MX_CRC_Init(void);
 static void MX_RNG_Init(void);
 static void MX_USART1_UART_Init(void);
+static void MX_ADC1_Init(void);
+static void MX_UART8_Init(void);
+static void MX_CRC_Init(void);
+static void MX_ADC2_Init(void);
+static void MX_ADC3_Init(void);
+static void MX_TIM2_Init(void);
 void StartDefaultTask(void *argument);
 
 /* USER CODE BEGIN PFP */
@@ -118,6 +133,9 @@ int main(void)
   /* Configure the system clock */
   SystemClock_Config();
 
+/* Configure the peripherals common clocks */
+  PeriphCommonClock_Config();
+
   /* USER CODE BEGIN SysInit */
 
   /* USER CODE END SysInit */
@@ -125,10 +143,14 @@ int main(void)
   /* Initialize all configured peripherals */
   MX_GPIO_Init();
   MX_DMA_Init();
-  MX_UART8_Init();
-  MX_CRC_Init();
   MX_RNG_Init();
   MX_USART1_UART_Init();
+  MX_ADC1_Init();
+  MX_UART8_Init();
+  MX_CRC_Init();
+  MX_ADC2_Init();
+  MX_ADC3_Init();
+  MX_TIM2_Init();
   /* USER CODE BEGIN 2 */
 
   /* USER CODE END 2 */
@@ -163,7 +185,7 @@ int main(void)
 #ifdef USER_MOCKS
   MockMeasurmetsTaskInit();
 #else
-
+  MeasTasksInit();
 #endif
   /* USER CODE END RTOS_THREADS */
 
@@ -247,6 +269,325 @@ void SystemClock_Config(void)
 }
 
 /**
+  * @brief Peripherals Common Clock Configuration
+  * @retval None
+  */
+void PeriphCommonClock_Config(void)
+{
+  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
+
+  /** Initializes the peripherals clock
+  */
+  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC;
+  PeriphClkInitStruct.PLL2.PLL2M = 5;
+  PeriphClkInitStruct.PLL2.PLL2N = 52;
+  PeriphClkInitStruct.PLL2.PLL2P = 26;
+  PeriphClkInitStruct.PLL2.PLL2Q = 2;
+  PeriphClkInitStruct.PLL2.PLL2R = 2;
+  PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_2;
+  PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;
+  PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
+  PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
+  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
+  {
+    Error_Handler();
+  }
+}
+
+/**
+  * @brief ADC1 Initialization Function
+  * @param None
+  * @retval None
+  */
+static void MX_ADC1_Init(void)
+{
+
+  /* USER CODE BEGIN ADC1_Init 0 */
+
+  /* USER CODE END ADC1_Init 0 */
+
+  ADC_MultiModeTypeDef multimode = {0};
+  ADC_ChannelConfTypeDef sConfig = {0};
+
+  /* USER CODE BEGIN ADC1_Init 1 */
+
+  /* USER CODE END ADC1_Init 1 */
+
+  /** Common config
+  */
+  hadc1.Instance = ADC1;
+  hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
+  hadc1.Init.Resolution = ADC_RESOLUTION_16B;
+  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
+  hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
+  hadc1.Init.LowPowerAutoWait = DISABLE;
+  hadc1.Init.ContinuousConvMode = ENABLE;
+  hadc1.Init.NbrOfConversion = 6;
+  hadc1.Init.DiscontinuousConvMode = DISABLE;
+  hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T2_TRGO;
+  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
+  hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_ONESHOT;
+  hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
+  hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
+  hadc1.Init.OversamplingMode = DISABLE;
+  if (HAL_ADC_Init(&hadc1) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure the ADC multi-mode
+  */
+  multimode.Mode = ADC_MODE_INDEPENDENT;
+  if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_8;
+  sConfig.Rank = ADC_REGULAR_RANK_1;
+  sConfig.SamplingTime = ADC_SAMPLETIME_387CYCLES_5;
+  sConfig.SingleDiff = ADC_SINGLE_ENDED;
+  sConfig.OffsetNumber = ADC_OFFSET_NONE;
+  sConfig.Offset = 0;
+  sConfig.OffsetSignedSaturation = DISABLE;
+  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_7;
+  sConfig.Rank = ADC_REGULAR_RANK_2;
+  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_9;
+  sConfig.Rank = ADC_REGULAR_RANK_3;
+  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_16;
+  sConfig.Rank = ADC_REGULAR_RANK_4;
+  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_17;
+  sConfig.Rank = ADC_REGULAR_RANK_5;
+  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_14;
+  sConfig.Rank = ADC_REGULAR_RANK_6;
+  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  /* USER CODE BEGIN ADC1_Init 2 */
+  if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED) != HAL_OK)
+  {
+	  Error_Handler();
+  }
+  /* USER CODE END ADC1_Init 2 */
+
+}
+
+/**
+  * @brief ADC2 Initialization Function
+  * @param None
+  * @retval None
+  */
+static void MX_ADC2_Init(void)
+{
+
+  /* USER CODE BEGIN ADC2_Init 0 */
+
+  /* USER CODE END ADC2_Init 0 */
+
+  ADC_ChannelConfTypeDef sConfig = {0};
+
+  /* USER CODE BEGIN ADC2_Init 1 */
+
+  /* USER CODE END ADC2_Init 1 */
+
+  /** Common config
+  */
+  hadc2.Instance = ADC2;
+  hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
+  hadc2.Init.Resolution = ADC_RESOLUTION_16B;
+  hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
+  hadc2.Init.EOCSelection = ADC_EOC_SEQ_CONV;
+  hadc2.Init.LowPowerAutoWait = DISABLE;
+  hadc2.Init.ContinuousConvMode = ENABLE;
+  hadc2.Init.NbrOfConversion = 3;
+  hadc2.Init.DiscontinuousConvMode = DISABLE;
+  hadc2.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T2_TRGO;
+  hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
+  hadc2.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_ONESHOT;
+  hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
+  hadc2.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
+  hadc2.Init.OversamplingMode = DISABLE;
+  if (HAL_ADC_Init(&hadc2) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_3;
+  sConfig.Rank = ADC_REGULAR_RANK_1;
+  sConfig.SamplingTime = ADC_SAMPLETIME_387CYCLES_5;
+  sConfig.SingleDiff = ADC_SINGLE_ENDED;
+  sConfig.OffsetNumber = ADC_OFFSET_NONE;
+  sConfig.Offset = 0;
+  sConfig.OffsetSignedSaturation = DISABLE;
+  if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_4;
+  sConfig.Rank = ADC_REGULAR_RANK_2;
+  if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_5;
+  sConfig.Rank = ADC_REGULAR_RANK_3;
+  if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  /* USER CODE BEGIN ADC2_Init 2 */
+  if (HAL_ADCEx_Calibration_Start(&hadc2, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED) != HAL_OK)
+  {
+	  Error_Handler();
+  }
+  /* USER CODE END ADC2_Init 2 */
+
+}
+
+/**
+  * @brief ADC3 Initialization Function
+  * @param None
+  * @retval None
+  */
+static void MX_ADC3_Init(void)
+{
+
+  /* USER CODE BEGIN ADC3_Init 0 */
+
+  /* USER CODE END ADC3_Init 0 */
+
+  ADC_ChannelConfTypeDef sConfig = {0};
+
+  /* USER CODE BEGIN ADC3_Init 1 */
+
+  /* USER CODE END ADC3_Init 1 */
+
+  /** Common config
+  */
+  hadc3.Instance = ADC3;
+  hadc3.Init.Resolution = ADC_RESOLUTION_16B;
+  hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
+  hadc3.Init.EOCSelection = ADC_EOC_SEQ_CONV;
+  hadc3.Init.LowPowerAutoWait = DISABLE;
+  hadc3.Init.ContinuousConvMode = ENABLE;
+  hadc3.Init.NbrOfConversion = 5;
+  hadc3.Init.DiscontinuousConvMode = DISABLE;
+  hadc3.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T2_TRGO;
+  hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
+  hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_ONESHOT;
+  hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
+  hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
+  hadc3.Init.OversamplingMode = DISABLE;
+  if (HAL_ADC_Init(&hadc3) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_0;
+  sConfig.Rank = ADC_REGULAR_RANK_1;
+  sConfig.SamplingTime = ADC_SAMPLETIME_387CYCLES_5;
+  sConfig.SingleDiff = ADC_SINGLE_ENDED;
+  sConfig.OffsetNumber = ADC_OFFSET_NONE;
+  sConfig.Offset = 0;
+  sConfig.OffsetSignedSaturation = DISABLE;
+  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_1;
+  sConfig.Rank = ADC_REGULAR_RANK_2;
+  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_10;
+  sConfig.Rank = ADC_REGULAR_RANK_3;
+  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_11;
+  sConfig.Rank = ADC_REGULAR_RANK_4;
+  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Configure Regular Channel
+  */
+  sConfig.Channel = ADC_CHANNEL_VREFINT;
+  sConfig.Rank = ADC_REGULAR_RANK_5;
+  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  /* USER CODE BEGIN ADC3_Init 2 */
+  if (HAL_ADCEx_Calibration_Start(&hadc3, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED) != HAL_OK)
+  {
+	  Error_Handler();
+  }
+  /* USER CODE END ADC3_Init 2 */
+
+}
+
+/**
   * @brief CRC Initialization Function
   * @param None
   * @retval None
@@ -307,6 +648,51 @@ static void MX_RNG_Init(void)
 }
 
 /**
+  * @brief TIM2 Initialization Function
+  * @param None
+  * @retval None
+  */
+static void MX_TIM2_Init(void)
+{
+
+  /* USER CODE BEGIN TIM2_Init 0 */
+
+  /* USER CODE END TIM2_Init 0 */
+
+  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
+  TIM_MasterConfigTypeDef sMasterConfig = {0};
+
+  /* USER CODE BEGIN TIM2_Init 1 */
+
+  /* USER CODE END TIM2_Init 1 */
+  htim2.Instance = TIM2;
+  htim2.Init.Prescaler = 0;
+  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
+  htim2.Init.Period = 9999999;
+  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;
+  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
+  if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
+  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
+  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;
+  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  /* USER CODE BEGIN TIM2_Init 2 */
+
+  /* USER CODE END TIM2_Init 2 */
+
+}
+
+/**
   * @brief UART8 Initialization Function
   * @param None
   * @retval None
@@ -410,15 +796,18 @@ static void MX_DMA_Init(void)
 {
 
   /* DMA controller clock enable */
-  __HAL_RCC_DMA2_CLK_ENABLE();
+  __HAL_RCC_DMA1_CLK_ENABLE();
 
   /* DMA interrupt init */
-  /* DMA2_Stream6_IRQn interrupt configuration */
-  HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 5, 0);
-  HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
-  /* DMA2_Stream7_IRQn interrupt configuration */
-  HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 5, 0);
-  HAL_NVIC_EnableIRQ(DMA2_Stream7_IRQn);
+  /* DMA1_Stream0_IRQn interrupt configuration */
+  HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 5, 0);
+  HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
+  /* DMA1_Stream1_IRQn interrupt configuration */
+  HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 5, 0);
+  HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);
+  /* DMA1_Stream2_IRQn interrupt configuration */
+  HAL_NVIC_SetPriority(DMA1_Stream2_IRQn, 5, 0);
+  HAL_NVIC_EnableIRQ(DMA1_Stream2_IRQn);
 
 }
 
@@ -435,23 +824,86 @@ static void MX_GPIO_Init(void)
 
   /* GPIO Ports Clock Enable */
   __HAL_RCC_GPIOH_CLK_ENABLE();
-  __HAL_RCC_GPIOB_CLK_ENABLE();
+  __HAL_RCC_GPIOC_CLK_ENABLE();
   __HAL_RCC_GPIOA_CLK_ENABLE();
+  __HAL_RCC_GPIOB_CLK_ENABLE();
   __HAL_RCC_GPIOE_CLK_ENABLE();
+  __HAL_RCC_GPIOD_CLK_ENABLE();
+
+  /*Configure GPIO pin Output Level */
+  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
+                          |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
+
+  /*Configure GPIO pin Output Level */
+  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
+
+  /*Configure GPIO pins : PE7 PE8 PE9 PE10
+                           PE13 PE14 PE15 */
+  GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
+                          |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
+
+  /*Configure GPIO pin : PD3 */
+  GPIO_InitStruct.Pin = GPIO_PIN_3;
+  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
+  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
-  /*Configure GPIO pin : PB8 */
-  GPIO_InitStruct.Pin = GPIO_PIN_8;
-  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+  /*Configure GPIO pins : PD4 PD5 PD6 PD7 */
+  GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
-  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
-  GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
-  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
 /* USER CODE BEGIN MX_GPIO_Init_2 */
 /* USER CODE END MX_GPIO_Init_2 */
 }
 
 /* USER CODE BEGIN 4 */
+void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
+{
+	if(hadc->Instance == ADC1)
+	{
+		DbgLEDToggle(DBG_LED4);
+		SCB_InvalidateDCache_by_Addr((uint32_t*)(((uint32_t)adc1Data.adcDataBuffer) & ~(uint32_t)0x1F), __SCB_DCACHE_LINE_SIZE);
+		if(adc1MeasDataQueue != NULL)
+		{
+			osMessageQueuePut(adc1MeasDataQueue, &adc1Data, 0, 0);
+		}
+		if(HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc1Data.adcDataBuffer, ADC1LastData) != HAL_OK)
+		{
+		  Error_Handler();
+		}
+	}
+	if(hadc->Instance == ADC2)
+	{
+		SCB_InvalidateDCache_by_Addr((uint32_t*)(((uint32_t)adc2Data.adcDataBuffer) & ~(uint32_t)0x1F), __SCB_DCACHE_LINE_SIZE);
+		if(adc2MeasDataQueue != NULL)
+		{
+			osMessageQueuePut(adc2MeasDataQueue, &adc2Data, 0, 0);
+		}
+		if(HAL_ADC_Start_DMA(&hadc2, (uint32_t *)adc2Data.adcDataBuffer, ADC2LastData) != HAL_OK)
+		{
+		  Error_Handler();
+		}
+	}
+	if(hadc->Instance == ADC3)
+	{
+		SCB_InvalidateDCache_by_Addr((uint32_t*)(((uint32_t)adc3Data.adcDataBuffer) & ~(uint32_t)0x1F), __SCB_DCACHE_LINE_SIZE);
+		if(adc3MeasDataQueue != NULL)
+		{
+			osMessageQueuePut(adc3MeasDataQueue, &adc3Data, 0, 0);
+		}
+		if(HAL_ADC_Start_DMA(&hadc3, (uint32_t *)adc3Data.adcDataBuffer, ADC3LastData) != HAL_OK)
+		{
+		  Error_Handler();
+		}
+	}
+}
 
 /* USER CODE END 4 */
 
@@ -465,6 +917,31 @@ static void MX_GPIO_Init(void)
 void StartDefaultTask(void *argument)
 {
   /* USER CODE BEGIN 5 */
+  SelectCurrentSensorGain(CurrentSensorL1, csGain3);
+  SelectCurrentSensorGain(CurrentSensorL2, csGain3);
+  SelectCurrentSensorGain(CurrentSensorL3, csGain3);
+  EnableCurrentSensors();
+  osDelay(pdMS_TO_TICKS(1000));
+  if(HAL_TIM_Base_Start(&htim2) != HAL_OK)
+  {
+	  Error_Handler();
+  }
+//  if(HAL_ADC_Start_IT(&hadc1) != HAL_OK)
+//  {
+//	  Error_Handler();
+//  }
+  if(HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc1Data.adcDataBuffer, ADC1LastData) != HAL_OK)
+  {
+	  Error_Handler();
+  }
+  if(HAL_ADC_Start_DMA(&hadc2, (uint32_t *)adc2Data.adcDataBuffer, ADC2LastData) != HAL_OK)
+  {
+	  Error_Handler();
+  }
+  if(HAL_ADC_Start_DMA(&hadc3, (uint32_t *)adc3Data.adcDataBuffer, ADC3LastData) != HAL_OK)
+  {
+	  Error_Handler();
+  }
   /* Infinite loop */
   for(;;)
   {
@@ -542,6 +1019,11 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
     HAL_IncTick();
   }
   /* USER CODE BEGIN Callback 1 */
+  else if (htim->Instance == TIM2)
+  {
+//	  HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_4);
+//	  HAL_ADC_Start_IT(&hadc1);
+  }
 
   /* USER CODE END Callback 1 */
 }

+ 170 - 0
OZE_Sensor/Core/Src/meas_tasks.c

@@ -0,0 +1,170 @@
+/*
+ * meas_tasks.c
+ *
+ *  Created on: Sep 5, 2024
+ *      Author: jakubski
+ */
+
+#include "meas_tasks.h"
+#include "adc_buffers.h"
+#include "measurements.h"
+#include "node-red-config.h"
+
+#include "cmsis_os.h"
+#include "main.h"
+
+#ifdef PV_BOARD
+#define VOLTAGES_COUNT 1
+#define CURRENTS_COUNT 1
+#else
+#define VOLTAGES_COUNT 3
+#define CURRENTS_COUNT 3
+#endif
+
+#define CIRC_BUFF_LEN 10
+
+osThreadId_t adc1MeasTaskHandle = NULL;
+osThreadId_t adc2MeasTaskHandle = NULL;
+osThreadId_t adc3MeasTaskHandle = NULL;
+
+osMessageQueueId_t adc1MeasDataQueue = NULL;
+osMessageQueueId_t adc2MeasDataQueue = NULL;
+osMessageQueueId_t adc3MeasDataQueue = NULL;
+
+osMutexId_t vRefmVMutex;
+osMutexId_t resMeasurementsMutex;
+osMutexId_t sensorsInfoMutex;
+osMutexId_t ILxRefMutex;
+
+volatile uint32_t vRefmV = 3000;
+
+RESMeasurements resMeasurements = { 0 };
+SesnorsInfo sensorsInfo         = { 0 };
+
+uint16_t ILxRef[CURRENTS_COUNT] = { 0 };
+
+void MeasTasksInit (void) {
+    vRefmVMutex          = osMutexNew (NULL);
+    resMeasurementsMutex = osMutexNew (NULL);
+    sensorsInfoMutex     = osMutexNew (NULL);
+    ILxRefMutex			 = osMutexNew (NULL);
+    adc1MeasDataQueue    = osMessageQueueNew (8, sizeof (ADC1_Data), NULL);
+    adc2MeasDataQueue    = osMessageQueueNew (8, sizeof (ADC2_Data), NULL);
+    adc3MeasDataQueue    = osMessageQueueNew (8, sizeof (ADC3_Data), NULL);
+
+    osThreadAttr_t osThreadAttradc1MeasTask = { 0 };
+    osThreadAttr_t osThreadAttradc2MeasTask = { 0 };
+    osThreadAttr_t osThreadAttradc3MeasTask = { 0 };
+
+    osThreadAttradc1MeasTask.stack_size = configMINIMAL_STACK_SIZE * 2;
+    osThreadAttradc1MeasTask.priority   = (osPriority_t)osPriorityRealtime;
+
+    osThreadAttradc2MeasTask.stack_size = configMINIMAL_STACK_SIZE * 2;
+    osThreadAttradc2MeasTask.priority   = (osPriority_t)osPriorityRealtime;
+
+    osThreadAttradc3MeasTask.stack_size = configMINIMAL_STACK_SIZE * 2;
+    osThreadAttradc3MeasTask.priority   = (osPriority_t)osPriorityNormal;
+
+    adc1MeasTaskHandle = osThreadNew (ADC1MeasTask, NULL, &osThreadAttradc1MeasTask);
+    adc2MeasTaskHandle = osThreadNew (ADC2MeasTask, NULL, &osThreadAttradc2MeasTask);
+    adc3MeasTaskHandle = osThreadNew (ADC3MeasTask, NULL, &osThreadAttradc3MeasTask);
+}
+
+void ADC1MeasTask (void* arg) {
+    float circBuffer[VOLTAGES_COUNT][CIRC_BUFF_LEN];
+    float rms[VOLTAGES_COUNT];
+    ADC1_Data adcData    = { 0 };
+    uint32_t circBuffPos = 0;
+    float gainCorrection = 1.0;
+    while (pdTRUE) {
+        osMessageQueueGet (adc1MeasDataQueue, &adcData, 0, osWaitForever);
+#ifdef GAIN_AUTO_CORRECTION
+        if (osMutexAcquire (vRefmVMutex, osWaitForever) == osOK) {
+            gainCorrection = (float)vRefmV;
+            osMutexRelease (vRefmVMutex);
+        }
+        gainCorrection = gainCorrection / EXT_VREF_mV;
+#endif
+        for (uint8_t i = 0; i < VOLTAGES_COUNT; i++) {
+            float val                  = adcData.adcDataBuffer[i] * deltaADC * U_CHANNEL_CONST * gainCorrection * U_MeasCorrectionData[i].gain + U_MeasCorrectionData[i].offset;
+            circBuffer[i][circBuffPos] = val;
+            rms[i]                     = 0.0;
+            for (uint8_t c = 0; c < CIRC_BUFF_LEN; c++) {
+                rms[i] += circBuffer[i][c];
+            }
+            rms[i] = rms[i] / CIRC_BUFF_LEN;
+            if (osMutexAcquire (resMeasurementsMutex, osWaitForever) == osOK) {
+                if (fabs(resMeasurements.voltagePeak[i]) < fabs(val)) {
+                    resMeasurements.voltagePeak[i] = val;
+                }
+                resMeasurements.voltageRMS[i] = rms[i];
+                resMeasurements.power[i]      = resMeasurements.voltageRMS[i] * resMeasurements.currentRMS[i];
+                osMutexRelease (resMeasurementsMutex);
+            }
+        }
+        ++circBuffPos;
+        circBuffPos = circBuffPos % CIRC_BUFF_LEN;
+
+        if (osMutexAcquire (ILxRefMutex, osWaitForever) == osOK) {
+            uint8_t refIdx = 0;
+            for (uint8_t i = (uint8_t)IL1Ref; i <= (uint8_t)IL3Ref; i++) {
+                ILxRef[refIdx++] = adcData.adcDataBuffer[i];
+            }
+            osMutexRelease (ILxRefMutex);
+        }
+    }
+}
+
+void ADC2MeasTask (void* arg) {
+    float circBuffer[CURRENTS_COUNT][CIRC_BUFF_LEN];
+    float rms[CURRENTS_COUNT];
+    ADC2_Data adcData    = { 0 };
+    uint32_t circBuffPos = 0;
+    float gainCorrection = 1.0;
+    while (pdTRUE) {
+        osMessageQueueGet (adc2MeasDataQueue, &adcData, 0, osWaitForever);
+        if (osMutexAcquire (vRefmVMutex, osWaitForever) == osOK) {
+            gainCorrection = (float)vRefmV;
+            osMutexRelease (vRefmVMutex);
+        }
+        gainCorrection            = gainCorrection / EXT_VREF_mV;
+        float ref[CURRENTS_COUNT] = { 0 };
+        if (osMutexAcquire (ILxRefMutex, osWaitForever) == osOK) {
+            for (uint8_t i = 0; i < CURRENTS_COUNT; i++) {
+                ref[i] = (float)ILxRef[i];
+            }
+            osMutexRelease (ILxRefMutex);
+        }
+        for (uint8_t i = 0; i < CURRENTS_COUNT; i++) {
+            float adcVal               = (float)adcData.adcDataBuffer[i];
+            float val                  = (adcVal - ref[i]) * deltaADC * I_CHANNEL_CONST * gainCorrection * I_MeasCorrectionData[i].gain + I_MeasCorrectionData[i].offset;
+            circBuffer[i][circBuffPos] = val;
+            rms[i]                     = 0.0;
+            for (uint8_t c = 0; c < CIRC_BUFF_LEN; c++) {
+                rms[i] += circBuffer[i][c];
+            }
+            rms[i] = rms[i] / CIRC_BUFF_LEN;
+            if (osMutexAcquire (resMeasurementsMutex, osWaitForever) == osOK) {
+                if (resMeasurements.currentPeak[i] < val) {
+                    resMeasurements.currentPeak[i] = val;
+                }
+                resMeasurements.currentRMS[i] = rms[i];
+                osMutexRelease (resMeasurementsMutex);
+            }
+        }
+        ++circBuffPos;
+        circBuffPos = circBuffPos % CIRC_BUFF_LEN;
+    }
+}
+
+void ADC3MeasTask (void* arg) {
+    ADC3_Data adcData = { 0 };
+    while (pdTRUE) {
+        osMessageQueueGet (adc3MeasDataQueue, &adcData, 0, osWaitForever);
+        uint32_t vRef = __LL_ADC_CALC_VREFANALOG_VOLTAGE (adcData.adcDataBuffer[VrefInt], LL_ADC_RESOLUTION_16B);
+        if (osMutexAcquire (vRefmVMutex, osWaitForever) == osOK) {
+            vRefmV = vRef;
+            osMutexRelease (vRefmVMutex);
+        }
+    }
+}

+ 2 - 2
OZE_Sensor/Core/Src/mock_tasks.c

@@ -16,8 +16,8 @@
 #include "node-red-config.h"
 #include "stdlib.h"
 
-extern RESMeasurements resMeasurements;
-extern SesnorsInfo sensorsInfo;
+//extern RESMeasurements resMeasurements;
+//extern SesnorsInfo sensorsInfo;
 extern osMutexId_t resMeasurementsMutex;
 extern osMutexId_t sensorsInfoMutex;
 

+ 62 - 0
OZE_Sensor/Core/Src/peripherial.c

@@ -0,0 +1,62 @@
+/*
+ * peripherial.c
+ *
+ *  Created on: Sep 10, 2024
+ *      Author: jakubski
+ */
+
+
+#include "peripherial.h"
+
+void DbgLEDOn(uint8_t ledNumber)
+{
+	HAL_GPIO_WritePin(GPIOD, ledNumber, GPIO_PIN_SET);
+}
+
+void DbgLEDOff(uint8_t ledNumber)
+{
+	HAL_GPIO_WritePin(GPIOD, ledNumber, GPIO_PIN_RESET);
+}
+
+void DbgLEDToggle(uint8_t ledNumber)
+{
+	HAL_GPIO_TogglePin(GPIOD, ledNumber);
+}
+
+void EnableCurrentSensors(void)
+{
+	HAL_GPIO_WritePin(GPIOE, MCU_CS_PWR_EN, GPIO_PIN_SET);
+}
+
+void DisableCurrentSensors(void)
+{
+	HAL_GPIO_WritePin(GPIOE, MCU_CS_PWR_EN, GPIO_PIN_RESET);
+}
+
+void SelectCurrentSensorGain(CurrentSensor sensor, CurrentSensorGain gain)
+{
+	uint8_t gpioOffset = 0;
+	switch(sensor)
+	{
+	case CurrentSensorL1:
+		gpioOffset = CURRENT_SENSOR_L1_GPIO_OFFSET;
+		break;
+	case CurrentSensorL2:
+		gpioOffset = CURRENT_SENSOR_L2_GPIO_OFFSET;
+		break;
+	case CurrentSensorL3:
+		gpioOffset = CURRENT_SENSOR_L3_GPIO_OFFSET;
+		break;
+	default:
+		break;
+	}
+	if(gpioOffset > 0)
+	{
+		uint16_t gain0Gpio = 1 << gpioOffset;
+		uint16_t gain1Gpio = 1 << (gpioOffset + 1);
+		uint16_t gpioState = ((uint16_t)gain) & 0x0001;
+		HAL_GPIO_WritePin(GPIOE, gain0Gpio, gpioState);
+		gpioState = (((uint16_t)gain) >> 1) & 0x0001;
+		HAL_GPIO_WritePin(GPIOE, gain1Gpio, gpioState);
+	}
+}

+ 324 - 43
OZE_Sensor/Core/Src/stm32h7xx_hal_msp.c

@@ -23,9 +23,11 @@
 /* USER CODE BEGIN Includes */
 
 /* USER CODE END Includes */
-extern DMA_HandleTypeDef hdma_uart8_rx;
+extern DMA_HandleTypeDef hdma_adc1;
 
-extern DMA_HandleTypeDef hdma_uart8_tx;
+extern DMA_HandleTypeDef hdma_adc2;
+
+extern DMA_HandleTypeDef hdma_adc3;
 
 /* Private typedef -----------------------------------------------------------*/
 /* USER CODE BEGIN TD */
@@ -86,6 +88,276 @@ void HAL_MspInit(void)
   /* USER CODE END MspInit 1 */
 }
 
+static uint32_t HAL_RCC_ADC12_CLK_ENABLED=0;
+
+/**
+* @brief ADC MSP Initialization
+* This function configures the hardware resources used in this example
+* @param hadc: ADC handle pointer
+* @retval None
+*/
+void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
+{
+  GPIO_InitTypeDef GPIO_InitStruct = {0};
+  if(hadc->Instance==ADC1)
+  {
+  /* USER CODE BEGIN ADC1_MspInit 0 */
+
+  /* USER CODE END ADC1_MspInit 0 */
+    /* Peripheral clock enable */
+    HAL_RCC_ADC12_CLK_ENABLED++;
+    if(HAL_RCC_ADC12_CLK_ENABLED==1){
+      __HAL_RCC_ADC12_CLK_ENABLE();
+    }
+
+    __HAL_RCC_GPIOA_CLK_ENABLE();
+    __HAL_RCC_GPIOC_CLK_ENABLE();
+    __HAL_RCC_GPIOB_CLK_ENABLE();
+    /**ADC1 GPIO Configuration
+    PA0     ------> ADC1_INP16
+    PA1     ------> ADC1_INP17
+    PA2     ------> ADC1_INP14
+    PA7     ------> ADC1_INP7
+    PC5     ------> ADC1_INP8
+    PB0     ------> ADC1_INP9
+    */
+    GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7;
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+    GPIO_InitStruct.Pin = GPIO_PIN_5;
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+    GPIO_InitStruct.Pin = GPIO_PIN_0;
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+    /* ADC1 DMA Init */
+    /* ADC1 Init */
+    hdma_adc1.Instance = DMA1_Stream0;
+    hdma_adc1.Init.Request = DMA_REQUEST_ADC1;
+    hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
+    hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
+    hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
+    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
+    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
+    hdma_adc1.Init.Mode = DMA_NORMAL;
+    hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
+    hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
+    if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
+    {
+      Error_Handler();
+    }
+
+    __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
+
+  /* USER CODE BEGIN ADC1_MspInit 1 */
+
+  /* USER CODE END ADC1_MspInit 1 */
+  }
+  else if(hadc->Instance==ADC2)
+  {
+  /* USER CODE BEGIN ADC2_MspInit 0 */
+
+  /* USER CODE END ADC2_MspInit 0 */
+    /* Peripheral clock enable */
+    HAL_RCC_ADC12_CLK_ENABLED++;
+    if(HAL_RCC_ADC12_CLK_ENABLED==1){
+      __HAL_RCC_ADC12_CLK_ENABLE();
+    }
+
+    __HAL_RCC_GPIOA_CLK_ENABLE();
+    __HAL_RCC_GPIOC_CLK_ENABLE();
+    __HAL_RCC_GPIOB_CLK_ENABLE();
+    /**ADC2 GPIO Configuration
+    PA6     ------> ADC2_INP3
+    PC4     ------> ADC2_INP4
+    PB1     ------> ADC2_INP5
+    */
+    GPIO_InitStruct.Pin = GPIO_PIN_6;
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+    GPIO_InitStruct.Pin = GPIO_PIN_4;
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+    GPIO_InitStruct.Pin = GPIO_PIN_1;
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+    /* ADC2 DMA Init */
+    /* ADC2 Init */
+    hdma_adc2.Instance = DMA1_Stream1;
+    hdma_adc2.Init.Request = DMA_REQUEST_ADC2;
+    hdma_adc2.Init.Direction = DMA_PERIPH_TO_MEMORY;
+    hdma_adc2.Init.PeriphInc = DMA_PINC_DISABLE;
+    hdma_adc2.Init.MemInc = DMA_MINC_ENABLE;
+    hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
+    hdma_adc2.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
+    hdma_adc2.Init.Mode = DMA_NORMAL;
+    hdma_adc2.Init.Priority = DMA_PRIORITY_LOW;
+    hdma_adc2.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
+    if (HAL_DMA_Init(&hdma_adc2) != HAL_OK)
+    {
+      Error_Handler();
+    }
+
+    __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc2);
+
+  /* USER CODE BEGIN ADC2_MspInit 1 */
+
+  /* USER CODE END ADC2_MspInit 1 */
+  }
+  else if(hadc->Instance==ADC3)
+  {
+  /* USER CODE BEGIN ADC3_MspInit 0 */
+
+  /* USER CODE END ADC3_MspInit 0 */
+    /* Peripheral clock enable */
+    __HAL_RCC_ADC3_CLK_ENABLE();
+
+    __HAL_RCC_GPIOC_CLK_ENABLE();
+    /**ADC3 GPIO Configuration
+    PC0     ------> ADC3_INP10
+    PC1     ------> ADC3_INP11
+    PC2_C     ------> ADC3_INP0
+    PC3_C     ------> ADC3_INP1
+    */
+    GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+    HAL_SYSCFG_AnalogSwitchConfig(SYSCFG_SWITCH_PC2, SYSCFG_SWITCH_PC2_OPEN);
+
+    HAL_SYSCFG_AnalogSwitchConfig(SYSCFG_SWITCH_PC3, SYSCFG_SWITCH_PC3_OPEN);
+
+    /* ADC3 DMA Init */
+    /* ADC3 Init */
+    hdma_adc3.Instance = DMA1_Stream2;
+    hdma_adc3.Init.Request = DMA_REQUEST_ADC3;
+    hdma_adc3.Init.Direction = DMA_PERIPH_TO_MEMORY;
+    hdma_adc3.Init.PeriphInc = DMA_PINC_DISABLE;
+    hdma_adc3.Init.MemInc = DMA_MINC_ENABLE;
+    hdma_adc3.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
+    hdma_adc3.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
+    hdma_adc3.Init.Mode = DMA_NORMAL;
+    hdma_adc3.Init.Priority = DMA_PRIORITY_LOW;
+    hdma_adc3.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
+    if (HAL_DMA_Init(&hdma_adc3) != HAL_OK)
+    {
+      Error_Handler();
+    }
+
+    __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc3);
+
+  /* USER CODE BEGIN ADC3_MspInit 1 */
+
+  /* USER CODE END ADC3_MspInit 1 */
+  }
+
+}
+
+/**
+* @brief ADC MSP De-Initialization
+* This function freeze the hardware resources used in this example
+* @param hadc: ADC handle pointer
+* @retval None
+*/
+void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
+{
+  if(hadc->Instance==ADC1)
+  {
+  /* USER CODE BEGIN ADC1_MspDeInit 0 */
+
+  /* USER CODE END ADC1_MspDeInit 0 */
+    /* Peripheral clock disable */
+    HAL_RCC_ADC12_CLK_ENABLED--;
+    if(HAL_RCC_ADC12_CLK_ENABLED==0){
+      __HAL_RCC_ADC12_CLK_DISABLE();
+    }
+
+    /**ADC1 GPIO Configuration
+    PA0     ------> ADC1_INP16
+    PA1     ------> ADC1_INP17
+    PA2     ------> ADC1_INP14
+    PA7     ------> ADC1_INP7
+    PC5     ------> ADC1_INP8
+    PB0     ------> ADC1_INP9
+    */
+    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7);
+
+    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_5);
+
+    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0);
+
+    /* ADC1 DMA DeInit */
+    HAL_DMA_DeInit(hadc->DMA_Handle);
+  /* USER CODE BEGIN ADC1_MspDeInit 1 */
+
+  /* USER CODE END ADC1_MspDeInit 1 */
+  }
+  else if(hadc->Instance==ADC2)
+  {
+  /* USER CODE BEGIN ADC2_MspDeInit 0 */
+
+  /* USER CODE END ADC2_MspDeInit 0 */
+    /* Peripheral clock disable */
+    HAL_RCC_ADC12_CLK_ENABLED--;
+    if(HAL_RCC_ADC12_CLK_ENABLED==0){
+      __HAL_RCC_ADC12_CLK_DISABLE();
+    }
+
+    /**ADC2 GPIO Configuration
+    PA6     ------> ADC2_INP3
+    PC4     ------> ADC2_INP4
+    PB1     ------> ADC2_INP5
+    */
+    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6);
+
+    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_4);
+
+    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_1);
+
+    /* ADC2 DMA DeInit */
+    HAL_DMA_DeInit(hadc->DMA_Handle);
+  /* USER CODE BEGIN ADC2_MspDeInit 1 */
+
+  /* USER CODE END ADC2_MspDeInit 1 */
+  }
+  else if(hadc->Instance==ADC3)
+  {
+  /* USER CODE BEGIN ADC3_MspDeInit 0 */
+
+  /* USER CODE END ADC3_MspDeInit 0 */
+    /* Peripheral clock disable */
+    __HAL_RCC_ADC3_CLK_DISABLE();
+
+    /**ADC3 GPIO Configuration
+    PC0     ------> ADC3_INP10
+    PC1     ------> ADC3_INP11
+    PC2_C     ------> ADC3_INP0
+    PC3_C     ------> ADC3_INP1
+    */
+    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1);
+
+    /* ADC3 DMA DeInit */
+    HAL_DMA_DeInit(hadc->DMA_Handle);
+  /* USER CODE BEGIN ADC3_MspDeInit 1 */
+
+  /* USER CODE END ADC3_MspDeInit 1 */
+  }
+
+}
+
 /**
 * @brief CRC MSP Initialization
 * This function configures the hardware resources used in this example
@@ -186,6 +458,56 @@ void HAL_RNG_MspDeInit(RNG_HandleTypeDef* hrng)
 }
 
 /**
+* @brief TIM_Base MSP Initialization
+* This function configures the hardware resources used in this example
+* @param htim_base: TIM_Base handle pointer
+* @retval None
+*/
+void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
+{
+  if(htim_base->Instance==TIM2)
+  {
+  /* USER CODE BEGIN TIM2_MspInit 0 */
+
+  /* USER CODE END TIM2_MspInit 0 */
+    /* Peripheral clock enable */
+    __HAL_RCC_TIM2_CLK_ENABLE();
+    /* TIM2 interrupt Init */
+    HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0);
+    HAL_NVIC_EnableIRQ(TIM2_IRQn);
+  /* USER CODE BEGIN TIM2_MspInit 1 */
+
+  /* USER CODE END TIM2_MspInit 1 */
+  }
+
+}
+
+/**
+* @brief TIM_Base MSP De-Initialization
+* This function freeze the hardware resources used in this example
+* @param htim_base: TIM_Base handle pointer
+* @retval None
+*/
+void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
+{
+  if(htim_base->Instance==TIM2)
+  {
+  /* USER CODE BEGIN TIM2_MspDeInit 0 */
+
+  /* USER CODE END TIM2_MspDeInit 0 */
+    /* Peripheral clock disable */
+    __HAL_RCC_TIM2_CLK_DISABLE();
+
+    /* TIM2 interrupt DeInit */
+    HAL_NVIC_DisableIRQ(TIM2_IRQn);
+  /* USER CODE BEGIN TIM2_MspDeInit 1 */
+
+  /* USER CODE END TIM2_MspDeInit 1 */
+  }
+
+}
+
+/**
 * @brief UART MSP Initialization
 * This function configures the hardware resources used in this example
 * @param huart: UART handle pointer
@@ -225,43 +547,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
     GPIO_InitStruct.Alternate = GPIO_AF8_UART8;
     HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
 
-    /* UART8 DMA Init */
-    /* UART8_RX Init */
-    hdma_uart8_rx.Instance = DMA2_Stream7;
-    hdma_uart8_rx.Init.Request = DMA_REQUEST_UART8_RX;
-    hdma_uart8_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
-    hdma_uart8_rx.Init.PeriphInc = DMA_PINC_DISABLE;
-    hdma_uart8_rx.Init.MemInc = DMA_MINC_ENABLE;
-    hdma_uart8_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
-    hdma_uart8_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
-    hdma_uart8_rx.Init.Mode = DMA_NORMAL;
-    hdma_uart8_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
-    hdma_uart8_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
-    if (HAL_DMA_Init(&hdma_uart8_rx) != HAL_OK)
-    {
-      Error_Handler();
-    }
-
-    __HAL_LINKDMA(huart,hdmarx,hdma_uart8_rx);
-
-    /* UART8_TX Init */
-    hdma_uart8_tx.Instance = DMA2_Stream6;
-    hdma_uart8_tx.Init.Request = DMA_REQUEST_UART8_TX;
-    hdma_uart8_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
-    hdma_uart8_tx.Init.PeriphInc = DMA_PINC_DISABLE;
-    hdma_uart8_tx.Init.MemInc = DMA_MINC_ENABLE;
-    hdma_uart8_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
-    hdma_uart8_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
-    hdma_uart8_tx.Init.Mode = DMA_NORMAL;
-    hdma_uart8_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
-    hdma_uart8_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
-    if (HAL_DMA_Init(&hdma_uart8_tx) != HAL_OK)
-    {
-      Error_Handler();
-    }
-
-    __HAL_LINKDMA(huart,hdmatx,hdma_uart8_tx);
-
     /* UART8 interrupt Init */
     HAL_NVIC_SetPriority(UART8_IRQn, 5, 0);
     HAL_NVIC_EnableIRQ(UART8_IRQn);
@@ -331,10 +616,6 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
     */
     HAL_GPIO_DeInit(GPIOE, GPIO_PIN_0|GPIO_PIN_1);
 
-    /* UART8 DMA DeInit */
-    HAL_DMA_DeInit(huart->hdmarx);
-    HAL_DMA_DeInit(huart->hdmatx);
-
     /* UART8 interrupt DeInit */
     HAL_NVIC_DisableIRQ(UART8_IRQn);
   /* USER CODE BEGIN UART8_MspDeInit 1 */

+ 60 - 30
OZE_Sensor/Core/Src/stm32h7xx_it.c

@@ -55,8 +55,10 @@
 /* USER CODE END 0 */
 
 /* External variables --------------------------------------------------------*/
-extern DMA_HandleTypeDef hdma_uart8_rx;
-extern DMA_HandleTypeDef hdma_uart8_tx;
+extern DMA_HandleTypeDef hdma_adc1;
+extern DMA_HandleTypeDef hdma_adc2;
+extern DMA_HandleTypeDef hdma_adc3;
+extern TIM_HandleTypeDef htim2;
 extern UART_HandleTypeDef huart8;
 extern UART_HandleTypeDef huart1;
 extern TIM_HandleTypeDef htim6;
@@ -177,59 +179,87 @@ void RCC_IRQHandler(void)
 }
 
 /**
-  * @brief This function handles USART1 global interrupt.
+  * @brief This function handles DMA1 stream0 global interrupt.
   */
-void USART1_IRQHandler(void)
+void DMA1_Stream0_IRQHandler(void)
 {
-  /* USER CODE BEGIN USART1_IRQn 0 */
+  /* USER CODE BEGIN DMA1_Stream0_IRQn 0 */
 
-  /* USER CODE END USART1_IRQn 0 */
-  HAL_UART_IRQHandler(&huart1);
-  /* USER CODE BEGIN USART1_IRQn 1 */
+  /* USER CODE END DMA1_Stream0_IRQn 0 */
+  HAL_DMA_IRQHandler(&hdma_adc1);
+  /* USER CODE BEGIN DMA1_Stream0_IRQn 1 */
 
-  /* USER CODE END USART1_IRQn 1 */
+  /* USER CODE END DMA1_Stream0_IRQn 1 */
 }
 
 /**
-  * @brief This function handles TIM6 global interrupt, DAC1_CH1 and DAC1_CH2 underrun error interrupts.
+  * @brief This function handles DMA1 stream1 global interrupt.
   */
-void TIM6_DAC_IRQHandler(void)
+void DMA1_Stream1_IRQHandler(void)
 {
-  /* USER CODE BEGIN TIM6_DAC_IRQn 0 */
+  /* USER CODE BEGIN DMA1_Stream1_IRQn 0 */
 
-  /* USER CODE END TIM6_DAC_IRQn 0 */
-  HAL_TIM_IRQHandler(&htim6);
-  /* USER CODE BEGIN TIM6_DAC_IRQn 1 */
+  /* USER CODE END DMA1_Stream1_IRQn 0 */
+  HAL_DMA_IRQHandler(&hdma_adc2);
+  /* USER CODE BEGIN DMA1_Stream1_IRQn 1 */
 
-  /* USER CODE END TIM6_DAC_IRQn 1 */
+  /* USER CODE END DMA1_Stream1_IRQn 1 */
+}
+
+/**
+  * @brief This function handles DMA1 stream2 global interrupt.
+  */
+void DMA1_Stream2_IRQHandler(void)
+{
+  /* USER CODE BEGIN DMA1_Stream2_IRQn 0 */
+
+  /* USER CODE END DMA1_Stream2_IRQn 0 */
+  HAL_DMA_IRQHandler(&hdma_adc3);
+  /* USER CODE BEGIN DMA1_Stream2_IRQn 1 */
+
+  /* USER CODE END DMA1_Stream2_IRQn 1 */
 }
 
 /**
-  * @brief This function handles DMA2 stream6 global interrupt.
+  * @brief This function handles TIM2 global interrupt.
   */
-void DMA2_Stream6_IRQHandler(void)
+void TIM2_IRQHandler(void)
 {
-  /* USER CODE BEGIN DMA2_Stream6_IRQn 0 */
+  /* USER CODE BEGIN TIM2_IRQn 0 */
 
-  /* USER CODE END DMA2_Stream6_IRQn 0 */
-  HAL_DMA_IRQHandler(&hdma_uart8_tx);
-  /* USER CODE BEGIN DMA2_Stream6_IRQn 1 */
+  /* USER CODE END TIM2_IRQn 0 */
+  HAL_TIM_IRQHandler(&htim2);
+  /* USER CODE BEGIN TIM2_IRQn 1 */
 
-  /* USER CODE END DMA2_Stream6_IRQn 1 */
+  /* USER CODE END TIM2_IRQn 1 */
 }
 
 /**
-  * @brief This function handles DMA2 stream7 global interrupt.
+  * @brief This function handles USART1 global interrupt.
   */
-void DMA2_Stream7_IRQHandler(void)
+void USART1_IRQHandler(void)
 {
-  /* USER CODE BEGIN DMA2_Stream7_IRQn 0 */
+  /* USER CODE BEGIN USART1_IRQn 0 */
 
-  /* USER CODE END DMA2_Stream7_IRQn 0 */
-  HAL_DMA_IRQHandler(&hdma_uart8_rx);
-  /* USER CODE BEGIN DMA2_Stream7_IRQn 1 */
+  /* USER CODE END USART1_IRQn 0 */
+  HAL_UART_IRQHandler(&huart1);
+  /* USER CODE BEGIN USART1_IRQn 1 */
 
-  /* USER CODE END DMA2_Stream7_IRQn 1 */
+  /* USER CODE END USART1_IRQn 1 */
+}
+
+/**
+  * @brief This function handles TIM6 global interrupt, DAC1_CH1 and DAC1_CH2 underrun error interrupts.
+  */
+void TIM6_DAC_IRQHandler(void)
+{
+  /* USER CODE BEGIN TIM6_DAC_IRQn 0 */
+
+  /* USER CODE END TIM6_DAC_IRQn 0 */
+  HAL_TIM_IRQHandler(&htim6);
+  /* USER CODE BEGIN TIM6_DAC_IRQn 1 */
+
+  /* USER CODE END TIM6_DAC_IRQn 1 */
 }
 
 /**

+ 33 - 14
OZE_Sensor/Core/Src/uart_tasks.c

@@ -15,6 +15,7 @@
 #include "measurements.h"
 #include "mock_tasks.h"
 #include "uart_tasks.h"
+#include "meas_tasks.h"
 
 enum SerialReceiverStates { srWaitForHeader, srCheckCrc, srRecieveData, srExecuteCmd, srFail, srFinish, srLast };
 
@@ -58,11 +59,11 @@ uint16_t outputDataBufferPos = 0;
 //extern SesnorsInfo sensorsInfo[SLAVES_COUNT];
 //extern osMutexId_t resMeasurementsMutex;
 //extern osMutexId_t sensorsInfoMutex;
-RESMeasurements resMeasurements = { 0 };
-SesnorsInfo sensorsInfo         = { 0 };
+//RESMeasurements resMeasurements = { 0 };
+//SesnorsInfo sensorsInfo         = { 0 };
 uint32_t slaveLastSeen[SLAVES_COUNT] = { 0 };
-osMutexId_t resMeasurementsMutex;
-osMutexId_t sensorsInfoMutex;
+//osMutexId_t resMeasurementsMutex;
+//osMutexId_t sensorsInfoMutex;
 
 extern RNG_HandleTypeDef hrng;
 
@@ -125,8 +126,8 @@ void Uart8TasksInit (void) {
 //    uart8TaskData.processDataCb = NULL;
     uart8TaskData.processDataCb = Uart8ReceivedDataProcessCallback;
 
-    resMeasurementsMutex = osMutexNew (NULL);
-    sensorsInfoMutex     = osMutexNew (NULL);
+//    resMeasurementsMutex = osMutexNew (NULL);
+//    sensorsInfoMutex     = osMutexNew (NULL);
 
     osThreadAttrRxUart.name       = "os_thread_uart8_rx";
     osThreadAttrRxUart.stack_size = configMINIMAL_STACK_SIZE * 2;
@@ -350,6 +351,7 @@ void Uart1ReceivedDataProcessCallback (void* arg, SerialProtocolFrameData* spFra
     UartTaskData* uartTaskData = (UartTaskData*)arg;
     uint16_t dataToSend        = 0;
     outputDataBufferPos = 0;
+    SerialProtocolRespStatus respStatus = spUnknownCommand;
     switch (spFrameData->frameHeader.frameCommand) {
     case spGetElectricalMeasurments:
     	osMutexAcquire (resMeasurementsMutex, osWaitForever);
@@ -374,9 +376,10 @@ void Uart1ReceivedDataProcessCallback (void* arg, SerialProtocolFrameData* spFra
 			WriteDataToBuffer(outputDataBuffer, &outputDataBufferPos, &resMeasurements.power[i], sizeof(float));
 		}
         osMutexRelease(resMeasurementsMutex);
+        respStatus = spOK;
         break;
     case spGetSensorMeasurments:
-    	osMutexAcquire (resMeasurementsMutex, osWaitForever);
+    	osMutexAcquire (sensorsInfoMutex, osWaitForever);
     	WriteDataToBuffer(outputDataBuffer, &outputDataBufferPos, &sensorsInfo.pvTemperature[0], sizeof(float));
 		WriteDataToBuffer(outputDataBuffer, &outputDataBufferPos, &sensorsInfo.pvTemperature[1], sizeof(float));
 		WriteDataToBuffer(outputDataBuffer, &outputDataBufferPos, &sensorsInfo.fanVoltage, sizeof(float));
@@ -391,20 +394,36 @@ void Uart1ReceivedDataProcessCallback (void* arg, SerialProtocolFrameData* spFra
 		WriteDataToBuffer(outputDataBuffer, &outputDataBufferPos, &sensorsInfo.limitSwitchDown, sizeof(uint8_t));
 		WriteDataToBuffer(outputDataBuffer, &outputDataBufferPos, &sensorsInfo.limitSwitchCenter, sizeof(uint8_t));
 		WriteDataToBuffer(outputDataBuffer, &outputDataBufferPos, &sensorsInfo.powerSupplyFailMask, sizeof(uint8_t));
-    	osMutexRelease(resMeasurementsMutex);
+    	osMutexRelease(sensorsInfoMutex);
+    	respStatus = spOK;
     	break;
     case spSetFanSpeed:
     case spSetMotorXOn:
     case spSetMotorYOn:
+    	respStatus = spOK;
         break;
-    case spSetDiodeOn:  break;
+    case spSetDiodeOn:
+    	respStatus = spOK;
+    	break;
     case spSetmotorXMaxCurrent:
-    case spSetmotorYMaxCurrent:  break;
-    default: break;
-    }
-    if (outputDataBufferPos > 0) {
-        dataToSend = PrepareRespFrame (uartTaskData->uartTxBuffer, spFrameData->frameHeader.frameId, spFrameData->frameHeader.frameCommand, spOK, outputDataBuffer, outputDataBufferPos);
+    case spSetmotorYMaxCurrent:
+    	respStatus = spOK;
+    	break;
+    case spClearPeakMeasurments:
+    	osMutexAcquire (resMeasurementsMutex, osWaitForever);
+		for(int i = 0; i < 3; i++)
+		{
+			resMeasurements.voltagePeak[i] = resMeasurements.voltageRMS[i];
+			resMeasurements.currentPeak[i] = resMeasurements.currentRMS[i];
+		}
+    	osMutexRelease(resMeasurementsMutex);
+    	respStatus = spOK;
+    	break;
+    default:
+    	respStatus = spUnknownCommand;
+    	break;
     }
+    dataToSend = PrepareRespFrame (uartTaskData->uartTxBuffer, spFrameData->frameHeader.frameId, spFrameData->frameHeader.frameCommand, respStatus, outputDataBuffer, outputDataBufferPos);
     if (dataToSend > 0) {
         HAL_UART_Transmit_IT (uartTaskData->huart, uartTaskData->uartTxBuffer, dataToSend);
     }

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 10 - 1
OZE_Sensor/Debug/Core/Src/subdir.mk


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 8 - 1
OZE_Sensor/Debug/Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 40812 - 29447
OZE_Sensor/Debug/OZE_Sensor.list


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 2921 - 1520
OZE_Sensor/Debug/OZE_Sensor.map


+ 5 - 0
OZE_Sensor/Debug/objects.list

@@ -1,6 +1,9 @@
+"./Core/Src/adc_buffers.o"
 "./Core/Src/freertos.o"
 "./Core/Src/main.o"
+"./Core/Src/meas_tasks.o"
 "./Core/Src/mock_tasks.o"
+"./Core/Src/peripherial.o"
 "./Core/Src/serial_protocol.o"
 "./Core/Src/stm32h7xx_hal_msp.o"
 "./Core/Src/stm32h7xx_hal_timebase_tim.o"
@@ -11,6 +14,8 @@
 "./Core/Src/uart_tasks.o"
 "./Core/Startup/startup_stm32h742vitx.o"
 "./Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.o"
+"./Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.o"
+"./Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc_ex.o"
 "./Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.o"
 "./Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.o"
 "./Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.o"

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 2034 - 0
OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc.h


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1388 - 0
OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc_ex.h


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 8412 - 0
OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_adc.h


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 5213 - 0
OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_tim.h


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 4056 - 0
OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.c


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 2659 - 0
OZE_Sensor/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc_ex.c


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 287 - 74
OZE_Sensor/OZE_Sensor.ioc