#2 FineTuning

開啟中
juraj 請求將 4 次代碼提交從 irep/jd_slaveFIX1 合併至 irep/main
共有 8 個文件被更改,包括 145 次插入75 次删除
  1. 2 4
      .cproject
  2. 6 1
      Core/Inc/main.h
  3. 1 1
      Core/Src/app_imu_dmp.cpp
  4. 120 56
      Core/Src/main.c
  5. 2 3
      Core/Src/stm32l0xx_hal_msp.c
  6. 1 1
      Modules/nbus
  7. 7 3
      baModule-slave Debug.launch
  8. 6 6
      baModule-slave.ioc

+ 2 - 4
.cproject

@@ -21,7 +21,7 @@
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.2016087764" name="CPU" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" useByScannerDiscovery="false" value="0" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.2016087764" name="CPU" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" useByScannerDiscovery="false" value="0" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.423721789" name="Core" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" useByScannerDiscovery="false" value="0" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.423721789" name="Core" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" useByScannerDiscovery="false" value="0" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1415206628" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1415206628" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
-							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.949399491" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32L082KZTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32L0xx/Include | ../Drivers/CMSIS/Include ||  ||  || USE_HAL_DRIVER | STM32L082xx ||  || Drivers | Core/Startup | Core ||  ||  || ${workspace_loc:/${ProjName}/STM32L082KZTX_FLASH.ld} || true || NonSecure ||  || secure_nsclib.o ||  || None ||  ||  || " valueType="string"/>
+							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.949399491" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32L082KZTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32L0xx/Include | ../Drivers/CMSIS/Include ||  ||  || USE_HAL_DRIVER | STM32L082xx ||  || Drivers | Core/Startup | Core ||  ||  || ${workspace_loc:/${ProjName}/STM32L082KZTX_FLASH.ld} || true || NonSecure ||  || secure_nsclib.o ||  || None ||  ||  ||  || ::" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.546024625" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="32" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.546024625" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="32" valueType="string"/>
 							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.922562106" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
 							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.922562106" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
 							<builder buildPath="${workspace_loc:/baModule-slave}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1586147119" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
 							<builder buildPath="${workspace_loc:/baModule-slave}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1586147119" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
@@ -49,7 +49,6 @@
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/dataframe/src}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/dataframe/src}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/one-wire-memory/Inc}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/one-wire-memory/Inc}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/nbus/include}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/nbus/include}&quot;"/>
-									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/icm20948/src}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/DMP-ICM20948/inc}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/DMP-ICM20948/inc}&quot;"/>
 								</option>
 								</option>
 								<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.139895820" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
 								<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.139895820" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
@@ -66,7 +65,6 @@
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/dataframe/src}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/dataframe/src}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/one-wire-memory/Inc}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/one-wire-memory/Inc}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/nbus/include}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/nbus/include}&quot;"/>
-									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/icm20948/src}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/DMP-ICM20948/inc}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Modules/DMP-ICM20948/inc}&quot;"/>
 								</option>
 								</option>
 								<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols.1846472396" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
 								<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols.1846472396" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
@@ -133,7 +131,7 @@
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.562557773" name="CPU" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" useByScannerDiscovery="false" value="0" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.562557773" name="CPU" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" useByScannerDiscovery="false" value="0" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.1525837965" name="Core" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" useByScannerDiscovery="false" value="0" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.1525837965" name="Core" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" useByScannerDiscovery="false" value="0" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1112811640" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1112811640" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
-							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.324250348" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32L082KZTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32L0xx/Include | ../Drivers/CMSIS/Include ||  ||  || USE_HAL_DRIVER | STM32L082xx ||  || Drivers | Core/Startup | Core ||  ||  || ${workspace_loc:/${ProjName}/STM32L082KZTX_FLASH.ld} || true || NonSecure ||  || secure_nsclib.o ||  || None ||  ||  || " valueType="string"/>
+							<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.324250348" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32L082KZTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32L0xx/Include | ../Drivers/CMSIS/Include ||  ||  || USE_HAL_DRIVER | STM32L082xx ||  || Drivers | Core/Startup | Core ||  ||  || ${workspace_loc:/${ProjName}/STM32L082KZTX_FLASH.ld} || true || NonSecure ||  || secure_nsclib.o ||  || None ||  ||  ||  || ::" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.1585210253" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="32" valueType="string"/>
 							<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.1585210253" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="32" valueType="string"/>
 							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.552215938" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
 							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.552215938" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
 							<builder buildPath="${workspace_loc:/baModule-slave}/Release" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1764690039" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
 							<builder buildPath="${workspace_loc:/baModule-slave}/Release" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1764690039" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>

+ 6 - 1
Core/Inc/main.h

@@ -37,6 +37,11 @@ extern "C" {
 /* Exported types ------------------------------------------------------------*/
 /* Exported types ------------------------------------------------------------*/
 /* USER CODE BEGIN ET */
 /* USER CODE BEGIN ET */
 
 
+typedef enum {
+    STATE_WAIT_LEN,
+    STATE_PAYLOAD,
+} ProtocolState;
+
 /* USER CODE END ET */
 /* USER CODE END ET */
 
 
 /* Exported constants --------------------------------------------------------*/
 /* Exported constants --------------------------------------------------------*/
@@ -46,7 +51,7 @@ extern "C" {
 
 
 /* Exported macro ------------------------------------------------------------*/
 /* Exported macro ------------------------------------------------------------*/
 /* USER CODE BEGIN EM */
 /* USER CODE BEGIN EM */
-
+#define FIFO_DEPTH 8
 /* USER CODE END EM */
 /* USER CODE END EM */
 
 
 /* Exported functions prototypes ---------------------------------------------*/
 /* Exported functions prototypes ---------------------------------------------*/

+ 1 - 1
Core/Src/app_imu_dmp.cpp

@@ -13,7 +13,7 @@
 DMP_ICM20948 _imuDmpInstance;
 DMP_ICM20948 _imuDmpInstance;
 DMP_ICM20948Settings _imuDmpSettings = {
 DMP_ICM20948Settings _imuDmpSettings = {
   .mode = 1,                            	// 0 = low power mode, 1 = high performance mode
   .mode = 1,                            	// 0 = low power mode, 1 = high performance mode
-  .enable_gyroscope = true,             	// Enables gyroscope output
+  .enable_gyroscope = true,             	// Enables gyroscope output	(true)
   .enable_accelerometer = true,         	// Enables accelerometer output
   .enable_accelerometer = true,         	// Enables accelerometer output
   .enable_magnetometer = false,         	// Enables magnetometer output // Enables quaternion output
   .enable_magnetometer = false,         	// Enables magnetometer output // Enables quaternion output
   .enable_gravity = false,              	// Enables gravity vector output
   .enable_gravity = false,              	// Enables gravity vector output

+ 120 - 56
Core/Src/main.c

@@ -88,12 +88,30 @@ static void MX_USART1_UART_Init(void);
 
 
 /* Private user code ---------------------------------------------------------*/
 /* Private user code ---------------------------------------------------------*/
 /* USER CODE BEGIN 0 */
 /* USER CODE BEGIN 0 */
+
+typedef struct {
+    uint8_t payload[PAYLOAD_SIZE];
+    uint8_t length;
+} rx_packet_t;
+
 #define MAX_SYSTICK  0xFFFFFFFF
 #define MAX_SYSTICK  0xFFFFFFFF
-uint8_t data[BUFF_SIZE];	// tmp read buffer
+
+uint8_t rx_ring_buffer[BUFF_SIZE];
 uint8_t *dataUART;  // pointee for rx_buffer
 uint8_t *dataUART;  // pointee for rx_buffer
-volatile uint8_t dataL;
-volatile uint8_t dataI;
+
+rx_packet_t packet_fifo[FIFO_DEPTH];
+volatile uint8_t fifo_head = 0;  // index pre zápis (z UARTu)
+volatile uint8_t fifo_tail = 0;  // index pre čítanie (do nBus)
+volatile uint8_t fifo_count = 0; // počet nespracovaných paketov vo FIFO
+
+// UART DMA related variables
 volatile uint32_t uart_timeout = MAX_SYSTICK;
 volatile uint32_t uart_timeout = MAX_SYSTICK;
+volatile uint16_t rx_read_pos = 0; // DAM UART CIRCULAR - tail
+volatile uint8_t msg_len = 0;
+volatile uint8_t msg_idx = 0;
+
+ProtocolState state = STATE_WAIT_LEN;
+
 
 
 #if MODULE == MODULE_IMU || MODULE == MODULE_DMP
 #if MODULE == MODULE_IMU || MODULE == MODULE_DMP
 volatile uint8_t icm_data_ready = 0;
 volatile uint8_t icm_data_ready = 0;
@@ -111,13 +129,12 @@ inline void uart_send(uint8_t *data, int n)
 inline void uart_receive(uint8_t *dataNBUS, int n)
 inline void uart_receive(uint8_t *dataNBUS, int n)
 {
 {
 	dataUART = dataNBUS;
 	dataUART = dataNBUS;
-	dataL = 0;
-	dataI = 0;
-	data[0] = 0;
+	rx_ring_buffer[0] = 0;
 	uart_timeout = HAL_GetTick();
 	uart_timeout = HAL_GetTick();
-	HAL_UARTEx_ReceiveToIdle_DMA(&huart1, data, n);
+	HAL_UART_Receive_DMA(&huart1, rx_ring_buffer, n);
 }
 }
 
 
+
 inline void led_on(){
 inline void led_on(){
 	HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
 	HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
 }
 }
@@ -134,71 +151,120 @@ inline void app_delay(uint8_t ms){
 	HAL_Delay(ms);
 	HAL_Delay(ms);
 }
 }
 
 
+static uint8_t Parse_Protocol_Byte(uint8_t b) {
+    uint8_t packet_finished = 0;
+
+    // Timeout reset logic
+    if (state != STATE_WAIT_LEN) {
+        if ((HAL_GetTick() - uart_timeout) > NBUS_UART_FRAME_TIMEOUT){
+            state = STATE_WAIT_LEN;
+            msg_len = 0;
+            msg_idx = 0;
+        }
+    }
+
+    switch (state) {
+        case STATE_WAIT_LEN:
+            // Validácia dĺžky
+            if (b > 3 && b < PAYLOAD_SIZE) {
+                msg_len = b;
+                msg_idx = 0;
+                state = STATE_PAYLOAD;
+                uart_timeout = HAL_GetTick();
+
+            }
+            break;
+
+        case STATE_PAYLOAD:
+            // Zapisujeme do hlavy FIFO namiesto priamo do dataUART
+            packet_fifo[fifo_head].payload[msg_idx++] = b;
+            uart_timeout = HAL_GetTick();
+            //led_toggle();
+            //HAL_GPIO_TogglePin(SPI_SS_GPIO_Port, SPI_SS_Pin);
+            if (msg_idx >= msg_len) { // Koniec paketu
+                packet_fifo[fifo_head].length = msg_len;
+
+
+                // Posunieme hlavu FIFO, ak máme miesto
+                if (fifo_count < FIFO_DEPTH) {
+                    fifo_head = (fifo_head + 1) % FIFO_DEPTH;
+                    fifo_count++;
+                } else {
+                    // FIFO je plné - tu by sa dal riešiť error handling
+                    // (momentálne sa nový paket zahodí, resp. prepíše aktuálny head)
+                }
+
+                state = STATE_WAIT_LEN;
+                packet_finished = 1;
+            }
+            break;
+    }
+    return packet_finished;
+}
+
+static void Process_UART_RingBuffer(void) {
+    uint16_t rx_dma_pos = BUFF_SIZE - __HAL_DMA_GET_COUNTER(huart1.hdmarx);
+
+    // Spracuj všetky dostupné bajty z DMA a nalož pakety do FIFO
+    while (rx_read_pos != rx_dma_pos) {
+        uint8_t byte = rx_ring_buffer[rx_read_pos];
+        rx_read_pos++;
+        if (rx_read_pos >= BUFF_SIZE) {
+            rx_read_pos = 0;
+        }
+
+        // Funkcia už automaticky rieši zápis do FIFO
+        Parse_Protocol_Byte(byte);
+    }
+}
+
+
+uint8_t nbus_fifo_pull(uint8_t *dest_buffer, uint8_t *out_len) {
+
+    if (fifo_count == 0) {
+        return 0; // FIFO je prázdne
+    }
+    // Prekopírujeme dáta a dĺžku
+    *out_len = packet_fifo[fifo_tail].length;
+    memcpy(dest_buffer, packet_fifo[fifo_tail].payload, *out_len);
+
+    // Posunieme tail a znížime počítadlo nespracovaných paketov
+    fifo_tail = (fifo_tail + 1) % FIFO_DEPTH;
+    fifo_count--;
+
+    return 1;
+}
+
 static inline uint8_t loop_callback(nBusStateCallbackType_t state_check) {
 static inline uint8_t loop_callback(nBusStateCallbackType_t state_check) {
-// traba kontrolovat kazdu stav (state_check) zvmlast. Moznost doplnit dalsie kontroly
+// treba kontrolovat kazdy stav (state_check) zvlast. Moznost doplnit dalsie kontroly
 	if (state_check == CallbackType_SENSOR) {
 	if (state_check == CallbackType_SENSOR) {
 #if MODULE == MODULE_IMU || MODULE == MODULE_DMP
 #if MODULE == MODULE_IMU || MODULE == MODULE_DMP
 		if(icm_data_ready == 1){
 		if(icm_data_ready == 1){
 			icm_data_ready = 0;
 			icm_data_ready = 0;
-			return 1;  // interrupt from external sensor: data ready
+			return 1;  // TEMPORARY ALWAYS ENABLE STATE. interrupt from external sensor: data ready
 		}
 		}
 #endif
 #endif
-
-		return 0;
+	return 0;
 	}
 	}
 
 
 	if (state_check == CallbackType_UART) {
 	if (state_check == CallbackType_UART) {
-		// timemout: 1 - 2 ms
-		if(HAL_GetTick() - 1 > uart_timeout) {
-			dataL = 0;
-			dataI = 0;
-			data[0] = 0;
-			uart_timeout = MAX_SYSTICK;
-//			led_off();
-			HAL_UARTEx_ReceiveToIdle_DMA(&huart1, data, BUFF_SIZE);
-			return 1;  // UART receive timeout
-		}
-		return 0;
+		Process_UART_RingBuffer();
 	}
 	}
 
 
 	return 0;
 	return 0;
 }
 }
 
 
 //  Application callbacks
 //  Application callbacks
-void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){
-	HAL_UARTEx_ReceiveToIdle_DMA(huart, data, BUFF_SIZE);
-	uint8_t copy_offset = 0;
-	if (dataL == 0) {
-		uart_timeout = HAL_GetTick();
-		dataL = data[0];
-		dataI = 0;
-		if (Size == 1) {
-			return;
-		}
-
-		Size--;
-		copy_offset = 1;
-	}
-
-	memcpy(&dataUART[dataI], &data[copy_offset], Size);
-
-	dataI += Size;
-	if(dataI >= dataL){
-		nbus_cb_UART_RX(dataI);
-		dataL=0;
-		dataI=0;
-		data[0]=0;
-		uart_timeout = MAX_SYSTICK;
-	}
-}
-
 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart){
 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart){
-	HAL_UARTEx_ReceiveToIdle_DMA(huart, data, BUFF_SIZE);
+	uart_timeout = MAX_SYSTICK;
+	HAL_UART_Receive_DMA(huart, rx_ring_buffer, BUFF_SIZE);
 }
 }
 
 
 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
 #if MODULE == MODULE_IMU || MODULE == MODULE_DMP
 #if MODULE == MODULE_IMU || MODULE == MODULE_DMP
-	icm_data_ready = 1;
+	if (GPIO_Pin == SPI_INT_Pin) {
+		icm_data_ready = 1;
+	}
 #endif
 #endif
 }
 }
 
 
@@ -239,8 +305,6 @@ int main(void)
   MX_SPI1_Init();
   MX_SPI1_Init();
   MX_USART1_UART_Init();
   MX_USART1_UART_Init();
   /* USER CODE BEGIN 2 */
   /* USER CODE BEGIN 2 */
-  dataI=0;
-  dataL=0;
 
 
 #ifdef MODULE_INIT_IP_ADC
 #ifdef MODULE_INIT_IP_ADC
   MX_ADC_Init();
   MX_ADC_Init();
@@ -263,6 +327,7 @@ int main(void)
 		  led_toggle,
 		  led_toggle,
 		  app_delay,
 		  app_delay,
 		  loop_callback,
 		  loop_callback,
+		  nbus_fifo_pull,
   };
   };
 
 
 #if MODULE_MASTER == 1
 #if MODULE_MASTER == 1
@@ -275,7 +340,6 @@ int main(void)
 #endif
 #endif
 
 
 #if MODULE == MODULE_DMP
 #if MODULE == MODULE_DMP
-
   nbus_init(getImuDriver(), &hw_platform);
   nbus_init(getImuDriver(), &hw_platform);
   nbus_init_app(NULL, NULL);
   nbus_init_app(NULL, NULL);
 #endif
 #endif
@@ -300,9 +364,10 @@ int main(void)
 	 config.mag.mode = mag_mode_power_down;
 	 config.mag.mode = mag_mode_power_down;
 
 
 	 nbus_init(getImuDriver(), &hw_platform);
 	 nbus_init(getImuDriver(), &hw_platform);
-	 nbus_init_app(&hspi1, &config);
+	 nbus_init_app(NULL, NULL);
 #endif
 #endif
 
 
+
   nBus_MemoryDriver memory_ec20 = {
   nBus_MemoryDriver memory_ec20 = {
   		DS28EC20_init,
   		DS28EC20_init,
   		DS28EC20_readData4B,
   		DS28EC20_readData4B,
@@ -315,7 +380,6 @@ int main(void)
 
 
   memory_ec20.init(ONE_WIRE_GPIO_Port, ONE_WIRE_Pin);
   memory_ec20.init(ONE_WIRE_GPIO_Port, ONE_WIRE_Pin);
   nbus_init_memory_driver(&memory_ec20);
   nbus_init_memory_driver(&memory_ec20);
-
   nbus_stack();
   nbus_stack();
 
 
   /* USER CODE END 2 */
   /* USER CODE END 2 */

+ 2 - 3
Core/Src/stm32l0xx_hal_msp.c

@@ -17,7 +17,6 @@
   ******************************************************************************
   ******************************************************************************
   */
   */
 /* USER CODE END Header */
 /* USER CODE END Header */
-
 /* Includes ------------------------------------------------------------------*/
 /* Includes ------------------------------------------------------------------*/
 #include "main.h"
 #include "main.h"
 /* USER CODE BEGIN Includes */
 /* USER CODE BEGIN Includes */
@@ -361,8 +360,8 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
     hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
     hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
     hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
     hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
     hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
     hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
-    hdma_usart1_rx.Init.Mode = DMA_NORMAL;
-    hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
+    hdma_usart1_rx.Init.Mode = DMA_CIRCULAR;
+    hdma_usart1_rx.Init.Priority = DMA_PRIORITY_MEDIUM;
     if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK)
     if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK)
     {
     {
       Error_Handler();
       Error_Handler();

+ 1 - 1
Modules/nbus

@@ -1 +1 @@
-Subproject commit 219ca744699b12ed7f4a9d51ec05092fe0a433e4
+Subproject commit 1b21f45e6e6c5c1cbb101c4a0ff405600f451ad5

+ 7 - 3
baModule-slave Debug.launch

@@ -11,12 +11,16 @@
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_live_expr" value="true"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_live_expr" value="true"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_swv" value="false"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_swv" value="false"/>
     <intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.formatVersion" value="2"/>
     <intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.formatVersion" value="2"/>
+    <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.incremental_flashing" value="false"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.ip_address_local" value="localhost"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.ip_address_local" value="localhost"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.enabled" value="false"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.enabled" value="false"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.value" value=""/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.value" value=""/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.loadList" value="{&quot;fItems&quot;:[{&quot;fIsFromMainTab&quot;:true,&quot;fPath&quot;:&quot;Debug/baModule-slave.elf&quot;,&quot;fProjectName&quot;:&quot;baModule-slave&quot;,&quot;fPerformBuild&quot;:true,&quot;fDownload&quot;:true,&quot;fLoadSymbols&quot;:true}]}"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.loadList" value="{&quot;fItems&quot;:[{&quot;fIsFromMainTab&quot;:true,&quot;fPath&quot;:&quot;Debug/baModule-slave.elf&quot;,&quot;fProjectName&quot;:&quot;baModule-slave&quot;,&quot;fPerformBuild&quot;:true,&quot;fDownload&quot;:true,&quot;fLoadSymbols&quot;:true}]}"/>
+    <intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.mode" value="0"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.override_start_address_mode" value="default"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.override_start_address_mode" value="default"/>
+    <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.port" value=""/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.remoteCommand" value="target remote"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.remoteCommand" value="target remote"/>
+    <stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.semihosting" value="Disabled"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startServer" value="true"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startServer" value="true"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.divby0" value="true"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.divby0" value="true"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.unaligned" value="false"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.unaligned" value="false"/>
@@ -38,11 +42,11 @@
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.low_power_debug" value="enable"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.low_power_debug" value="enable"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.max_halt_delay" value="2"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.max_halt_delay" value="2"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.reset_strategy" value="connect_under_reset"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.reset_strategy" value="connect_under_reset"/>
-    <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_check_serial_number" value="false"/>
-    <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value=""/>
+    <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_check_serial_number" value="true"/>
+    <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value="53FF6D065066505128261087"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="none"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="none"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkenable_rtos" value="false"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkenable_rtos" value="false"/>
-    <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{&quot;fVersion&quot;:1,&quot;fItems&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fIsSuppressible&quot;:false,&quot;fResetAttribute&quot;:&quot;Software system reset&quot;,&quot;fResetStrategies&quot;:[{&quot;fDisplayName&quot;:&quot;Software system reset&quot;,&quot;fLaunchAttribute&quot;:&quot;system_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Hardware reset&quot;,&quot;fLaunchAttribute&quot;:&quot;hardware_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset hardware\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Core reset&quot;,&quot;fLaunchAttribute&quot;:&quot;core_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset core\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;None&quot;,&quot;fLaunchAttribute&quot;:&quot;no_reset&quot;,&quot;fGdbCommands&quot;:[],&quot;fCmdOptions&quot;:[&quot;-g&quot;]}],&quot;fGdbCommandGroup&quot;:{&quot;name&quot;:&quot;Additional commands&quot;,&quot;commands&quot;:[]},&quot;fStartApplication&quot;:true}]}"/>
+    <stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{&quot;fVersion&quot;:1,&quot;fItems&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fIsSuppressible&quot;:false,&quot;fResetAttribute&quot;:&quot;Software system reset&quot;,&quot;fResetStrategies&quot;:[{&quot;fDisplayName&quot;:&quot;Software system reset&quot;,&quot;fLaunchAttribute&quot;:&quot;system_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Hardware reset&quot;,&quot;fLaunchAttribute&quot;:&quot;hardware_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset hardware\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Core reset&quot;,&quot;fLaunchAttribute&quot;:&quot;core_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset core\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;None&quot;,&quot;fLaunchAttribute&quot;:&quot;no_reset&quot;,&quot;fGdbCommands&quot;:[],&quot;fCmdOptions&quot;:[&quot;-g&quot;]}],&quot;fGdbCommandGroup&quot;:{&quot;name&quot;:&quot;Additional commands&quot;,&quot;commands&quot;:[]},&quot;fStartApplication&quot;:true}]}"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.enableRtosProxy" value="false"/>
     <booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.enableRtosProxy" value="false"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyCustomProperties" value=""/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyCustomProperties" value=""/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriver" value="threadx"/>
     <stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriver" value="threadx"/>

+ 6 - 6
baModule-slave.ioc

@@ -37,10 +37,10 @@ Dma.USART1_RX.1.Direction=DMA_PERIPH_TO_MEMORY
 Dma.USART1_RX.1.Instance=DMA1_Channel3
 Dma.USART1_RX.1.Instance=DMA1_Channel3
 Dma.USART1_RX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE
 Dma.USART1_RX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE
 Dma.USART1_RX.1.MemInc=DMA_MINC_ENABLE
 Dma.USART1_RX.1.MemInc=DMA_MINC_ENABLE
-Dma.USART1_RX.1.Mode=DMA_NORMAL
+Dma.USART1_RX.1.Mode=DMA_CIRCULAR
 Dma.USART1_RX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
 Dma.USART1_RX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
 Dma.USART1_RX.1.PeriphInc=DMA_PINC_DISABLE
 Dma.USART1_RX.1.PeriphInc=DMA_PINC_DISABLE
-Dma.USART1_RX.1.Priority=DMA_PRIORITY_LOW
+Dma.USART1_RX.1.Priority=DMA_PRIORITY_MEDIUM
 Dma.USART1_RX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
 Dma.USART1_RX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
 Dma.USART1_TX.2.Direction=DMA_MEMORY_TO_PERIPH
 Dma.USART1_TX.2.Direction=DMA_MEMORY_TO_PERIPH
 Dma.USART1_TX.2.Instance=DMA1_Channel2
 Dma.USART1_TX.2.Instance=DMA1_Channel2
@@ -97,8 +97,8 @@ Mcu.PinsNb=26
 Mcu.ThirdPartyNb=0
 Mcu.ThirdPartyNb=0
 Mcu.UserConstants=
 Mcu.UserConstants=
 Mcu.UserName=STM32L082KZTx
 Mcu.UserName=STM32L082KZTx
-MxCube.Version=6.15.0
-MxDb.Version=DB.6.0.150
+MxCube.Version=6.17.0
+MxDb.Version=DB.6.0.170
 NVIC.ADC1_COMP_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
 NVIC.ADC1_COMP_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
 NVIC.DMA1_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
 NVIC.DMA1_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
 NVIC.DMA1_Channel2_3_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
 NVIC.DMA1_Channel2_3_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
@@ -198,8 +198,9 @@ ProjectManager.CustomerFirmwarePackage=
 ProjectManager.DefaultFWLocation=true
 ProjectManager.DefaultFWLocation=true
 ProjectManager.DeletePrevious=true
 ProjectManager.DeletePrevious=true
 ProjectManager.DeviceId=STM32L082KZTx
 ProjectManager.DeviceId=STM32L082KZTx
-ProjectManager.FirmwarePackage=STM32Cube FW_L0 V1.12.3
+ProjectManager.FirmwarePackage=STM32Cube FW_L0 V1.12.4
 ProjectManager.FreePins=false
 ProjectManager.FreePins=false
+ProjectManager.FreePinsContext=
 ProjectManager.HalAssertFull=false
 ProjectManager.HalAssertFull=false
 ProjectManager.HeapSize=0x200
 ProjectManager.HeapSize=0x200
 ProjectManager.KeepUserCode=true
 ProjectManager.KeepUserCode=true
@@ -280,4 +281,3 @@ VP_SYS_VS_Systick.Signal=SYS_VS_Systick
 VP_TIM21_VS_ClockSourceINT.Mode=Internal
 VP_TIM21_VS_ClockSourceINT.Mode=Internal
 VP_TIM21_VS_ClockSourceINT.Signal=TIM21_VS_ClockSourceINT
 VP_TIM21_VS_ClockSourceINT.Signal=TIM21_VS_ClockSourceINT
 board=custom
 board=custom
-isbadioc=false