Changeset 22
- Timestamp:
- Aug 29, 2025, 6:15:42 PM (16 hours ago)
- Location:
- trunk/fw_g473rct
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fw_g473rct/Core/Inc/main.h
r20 r22 70 70 #define ADC2_IN3_UBAT__Pin GPIO_PIN_6 71 71 #define ADC2_IN3_UBAT__GPIO_Port GPIOA 72 #define ADC2_IN4_UBAT__Pin GPIO_PIN_773 #define ADC2_IN4_UBAT__GPIO_Port GPIOA74 72 #define ADC3_IN12_MOSFET_TEMP_Pin GPIO_PIN_0 75 73 #define ADC3_IN12_MOSFET_TEMP_GPIO_Port GPIOB -
trunk/fw_g473rct/Core/Inc/stm32g4xx_it.h
r20 r22 61 61 void DMA1_Channel4_IRQHandler(void); 62 62 void DMA1_Channel5_IRQHandler(void); 63 void DMA1_Channel6_IRQHandler(void); 64 void USART1_IRQHandler(void); 65 void USART2_IRQHandler(void); 63 66 /* USER CODE BEGIN EFP */ 64 67 -
trunk/fw_g473rct/Core/Src/adc.c
r20 r22 59 59 hadc1.Init.GainCompensation = 0; 60 60 hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; 61 hadc1.Init.EOCSelection = ADC_EOC_S EQ_CONV;61 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 62 62 hadc1.Init.LowPowerAutoWait = DISABLE; 63 63 hadc1.Init.ContinuousConvMode = ENABLE; … … 68 68 hadc1.Init.DMAContinuousRequests = ENABLE; 69 69 hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; 70 hadc1.Init.OversamplingMode = DISABLE; 70 hadc1.Init.OversamplingMode = ENABLE; 71 hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256; 72 hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4; 73 hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER; 74 hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE; 71 75 if (HAL_ADC_Init(&hadc1) != HAL_OK) 72 76 { … … 88 92 sConfig.Channel = ADC_CHANNEL_1; 89 93 sConfig.Rank = ADC_REGULAR_RANK_1; 90 sConfig.SamplingTime = ADC_SAMPLETIME_ 2CYCLES_5;94 sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5; 91 95 sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED; 92 96 sConfig.OffsetNumber = ADC_OFFSET_NONE; … … 123 127 hadc2.Init.GainCompensation = 0; 124 128 hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE; 125 hadc2.Init.EOCSelection = ADC_EOC_S EQ_CONV;129 hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 126 130 hadc2.Init.LowPowerAutoWait = DISABLE; 127 131 hadc2.Init.ContinuousConvMode = ENABLE; … … 130 134 hadc2.Init.DMAContinuousRequests = ENABLE; 131 135 hadc2.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; 132 hadc2.Init.OversamplingMode = DISABLE; 136 hadc2.Init.OversamplingMode = ENABLE; 137 hadc2.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256; 138 hadc2.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4; 139 hadc2.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER; 140 hadc2.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE; 133 141 if (HAL_ADC_Init(&hadc2) != HAL_OK) 134 142 { … … 140 148 sConfig.Channel = ADC_CHANNEL_3; 141 149 sConfig.Rank = ADC_REGULAR_RANK_1; 142 sConfig.SamplingTime = ADC_SAMPLETIME_ 2CYCLES_5;143 sConfig.SingleDiff = ADC_ DIFFERENTIAL_ENDED;150 sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5; 151 sConfig.SingleDiff = ADC_SINGLE_ENDED; 144 152 sConfig.OffsetNumber = ADC_OFFSET_NONE; 145 153 sConfig.Offset = 0; … … 396 404 hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; 397 405 hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; 398 hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_ HALFWORD;406 hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; 399 407 hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; 400 408 hdma_adc1.Init.Mode = DMA_CIRCULAR; … … 435 443 /**ADC2 GPIO Configuration 436 444 PA6 ------> ADC2_IN3 437 PA7 ------> ADC2_IN4 438 */ 439 GPIO_InitStruct.Pin = ADC2_IN3_UBAT__Pin|ADC2_IN4_UBAT__Pin; 445 */ 446 GPIO_InitStruct.Pin = ADC2_IN3_UBAT__Pin; 440 447 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; 441 448 GPIO_InitStruct.Pull = GPIO_NOPULL; 442 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct);449 HAL_GPIO_Init(ADC2_IN3_UBAT__GPIO_Port, &GPIO_InitStruct); 443 450 444 451 /* ADC2 DMA Init */ … … 449 456 hdma_adc2.Init.PeriphInc = DMA_PINC_DISABLE; 450 457 hdma_adc2.Init.MemInc = DMA_MINC_ENABLE; 451 hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_ HALFWORD;458 hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; 452 459 hdma_adc2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; 453 460 hdma_adc2.Init.Mode = DMA_CIRCULAR; … … 665 672 /**ADC2 GPIO Configuration 666 673 PA6 ------> ADC2_IN3 667 PA7 ------> ADC2_IN4 668 */ 669 HAL_GPIO_DeInit(GPIOA, ADC2_IN3_UBAT__Pin|ADC2_IN4_UBAT__Pin); 674 */ 675 HAL_GPIO_DeInit(ADC2_IN3_UBAT__GPIO_Port, ADC2_IN3_UBAT__Pin); 670 676 671 677 /* ADC2 DMA DeInit */ -
trunk/fw_g473rct/Core/Src/dma.c
r20 r22 60 60 HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0); 61 61 HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn); 62 /* DMA1_Channel6_IRQn interrupt configuration */ 63 HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0); 64 HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn); 62 65 63 66 } -
trunk/fw_g473rct/Core/Src/stm32g4xx_hal_msp.c
r20 r22 73 73 /* System interrupt init*/ 74 74 75 /** Configure the internal voltage reference buffer high impedance mode 76 */ 77 HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE); 78 79 /** Disable the Internal Voltage Reference buffer 80 */ 81 HAL_SYSCFG_DisableVREFBUF(); 82 75 83 /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral 76 84 */ -
trunk/fw_g473rct/Core/Src/stm32g4xx_it.c
r20 r22 23 23 /* Private includes ----------------------------------------------------------*/ 24 24 /* USER CODE BEGIN Includes */ 25 #include "modbus.h" 25 26 /* USER CODE END Includes */ 26 27 … … 61 62 extern DMA_HandleTypeDef hdma_adc4; 62 63 extern DMA_HandleTypeDef hdma_adc5; 64 extern DMA_HandleTypeDef hdma_usart2_rx; 65 extern UART_HandleTypeDef huart1; 66 extern UART_HandleTypeDef huart2; 63 67 /* USER CODE BEGIN EV */ 64 68 … … 273 277 } 274 278 279 /** 280 * @brief This function handles DMA1 channel6 global interrupt. 281 */ 282 void DMA1_Channel6_IRQHandler(void) 283 { 284 /* USER CODE BEGIN DMA1_Channel6_IRQn 0 */ 285 286 /* USER CODE END DMA1_Channel6_IRQn 0 */ 287 HAL_DMA_IRQHandler(&hdma_usart2_rx); 288 /* USER CODE BEGIN DMA1_Channel6_IRQn 1 */ 289 290 /* USER CODE END DMA1_Channel6_IRQn 1 */ 291 } 292 293 /** 294 * @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25. 295 */ 296 void USART1_IRQHandler(void) 297 { 298 /* USER CODE BEGIN USART1_IRQn 0 */ 299 300 /* USER CODE END USART1_IRQn 0 */ 301 HAL_UART_IRQHandler(&huart1); 302 /* USER CODE BEGIN USART1_IRQn 1 */ 303 304 /* USER CODE END USART1_IRQn 1 */ 305 } 306 307 /** 308 * @brief This function handles USART2 global interrupt / USART2 wake-up interrupt through EXTI line 26. 309 */ 310 void USART2_IRQHandler(void) 311 { 312 /* USER CODE BEGIN USART2_IRQn 0 */ 313 314 /* USER CODE END USART2_IRQn 0 */ 315 HAL_UART_IRQHandler(&huart2); 316 /* USER CODE BEGIN USART2_IRQn 1 */ 317 //MODBUS_UART_IRQHandler(&huart2); 318 /* USER CODE END USART2_IRQn 1 */ 319 } 320 275 321 /* USER CODE BEGIN 1 */ 276 322 -
trunk/fw_g473rct/Core/Src/usart.c
r20 r22 27 27 UART_HandleTypeDef huart1; 28 28 UART_HandleTypeDef huart2; 29 DMA_HandleTypeDef hdma_usart2_rx; 29 30 30 31 /* USART1 init function */ … … 86 87 huart2.Instance = USART2; 87 88 huart2.Init.BaudRate = 115200; 88 huart2.Init.WordLength = UART_WORDLENGTH_ 8B;89 huart2.Init.WordLength = UART_WORDLENGTH_9B; 89 90 huart2.Init.StopBits = UART_STOPBITS_1; 90 huart2.Init.Parity = UART_PARITY_ NONE;91 huart2.Init.Parity = UART_PARITY_EVEN; 91 92 huart2.Init.Mode = UART_MODE_TX_RX; 92 93 huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; … … 94 95 huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 95 96 huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; 96 huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 97 huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT; 98 huart2.AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE; 97 99 if (HAL_UART_Init(&huart2) != HAL_OK) 98 100 { … … 152 154 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 153 155 156 /* USART1 interrupt Init */ 157 HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); 158 HAL_NVIC_EnableIRQ(USART1_IRQn); 154 159 /* USER CODE BEGIN USART1_MspInit 1 */ 155 160 … … 186 191 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 187 192 193 /* USART2 DMA Init */ 194 /* USART2_RX Init */ 195 hdma_usart2_rx.Instance = DMA1_Channel6; 196 hdma_usart2_rx.Init.Request = DMA_REQUEST_USART2_RX; 197 hdma_usart2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; 198 hdma_usart2_rx.Init.PeriphInc = DMA_PINC_DISABLE; 199 hdma_usart2_rx.Init.MemInc = DMA_MINC_ENABLE; 200 hdma_usart2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; 201 hdma_usart2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; 202 hdma_usart2_rx.Init.Mode = DMA_NORMAL; 203 hdma_usart2_rx.Init.Priority = DMA_PRIORITY_LOW; 204 if (HAL_DMA_Init(&hdma_usart2_rx) != HAL_OK) 205 { 206 Error_Handler(); 207 } 208 209 __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart2_rx); 210 211 /* USART2 interrupt Init */ 212 HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); 213 HAL_NVIC_EnableIRQ(USART2_IRQn); 188 214 /* USER CODE BEGIN USART2_MspInit 1 */ 189 215 … … 209 235 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_4|GPIO_PIN_5); 210 236 237 /* USART1 interrupt Deinit */ 238 HAL_NVIC_DisableIRQ(USART1_IRQn); 211 239 /* USER CODE BEGIN USART1_MspDeInit 1 */ 212 240 … … 227 255 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); 228 256 257 /* USART2 DMA DeInit */ 258 HAL_DMA_DeInit(uartHandle->hdmarx); 259 260 /* USART2 interrupt Deinit */ 261 HAL_NVIC_DisableIRQ(USART2_IRQn); 229 262 /* USER CODE BEGIN USART2_MspDeInit 1 */ 230 263 -
trunk/fw_g473rct/SES/inc/battery_voltage.h
r20 r22 20 20 21 21 //--- GLOBALE FUNKTIONS PROTOTYPEN --------------------------------------------- 22 void BATTERY_VOLTAGE_Exec( uint32_t newvalP );22 void BATTERY_VOLTAGE_Exec(int32_t newvalP ); 23 23 24 24 #endif // -
trunk/fw_g473rct/SES/inc/sysdata.h
r20 r22 33 33 //------------------------------------------------------------------------------ 34 34 // This structure must be aligned to 4-byte address 35 typedef struct35 volatile typedef struct 36 36 { 37 37 // Device spezifisch / Einstellungsbereich … … 58 58 uint16_t ibn_year; // 16 Inbetriebnahme Datum: Jahr 59 59 uint16_t user_id; // 17 Freies Feld für eine Kunden ID oder ähnlich 60 uint16_t UNIQUE_NAME(reserved)[8]; // 18-25 RESERVIERT60 uint16_t test[8]; // 18-25 RESERVIERT 61 61 62 62 //--- Konfiguration Schaltausgänge --- … … 175 175 /* 4 of 8 */ uint32_t chargeTotalWh; // 156-157 [mAs] 176 176 /* 6 of 8 */ uint16_t fullCyclesCnt; // 158 177 /* 8 of 8 */ uint16_t UNIQUE_NAME(reserved); // 159177 /* 8 of 8 */ uint16_t volatile UNIQUE_NAME(reserved); // 159 178 178 /* 8 of 8 */ int64_t mAs_AutoMode; // 160-163 179 179 /* 8 of 8 */ int64_t mWs_AutoMode; // 164-167 -
trunk/fw_g473rct/SES/smartPro.emProject
r20 r22 1 1 <!DOCTYPE CrossStudio_Project_File> 2 2 <solution Name="smartPro" target="8" version="2"> 3 <configuration Name="Common" link_merge_sections="No" /> 3 4 <configuration 4 Name="Debug "5 Name="Debug125A_12V" 5 6 c_preprocessor_definitions="DEBUG" 6 7 gcc_debugging_level="Level 3" … … 8 9 gcc_optimization_level="None" /> 9 10 <configuration 10 Name="Release "11 Name="Release125A_12V" 11 12 c_preprocessor_definitions="NDEBUG" 12 13 gcc_debugging_level="Level 2" … … 33 34 c_preprocessor_definitions="__VTOR_CONFIG;ARM_MATH_CM4;STM32G473xx;__STM32G473_SUBFAMILY;__STM32G4XX_FAMILY" 34 35 c_user_include_directories="$(ProjectDir)/../Drivers/STM32G4xx_HAL_Driver/Inc;$(ProjectDir)/../Core/Inc;$(ProjectDir)/../Drivers/CMSIS/Include;$(ProjectDir)/../Drivers/CMSIS/Device/ST/STM32G4xx/Include;$(ProjectDir)/inc" 36 debug_initial_breakpoint_set_option="Never" 35 37 debug_register_definition_file="$(ProjectDir)/STM32G473xx_Registers.xml" 36 38 debug_stack_pointer_start="__stack_end__" … … 45 47 target_load_end_script="Reset();" 46 48 target_reset_script="Reset();" /> 47 <configuration Name="Debug" c_preprocessor_definitions="DEVICETYPE=500" /> 49 <configuration 50 Name="Debug125A_12V" 51 arm_compiler_variant="gcc" 52 c_preprocessor_definitions="DEVICETYPE=125" /> 53 <configuration 54 Name="Release125A_12V" 55 c_preprocessor_definitions="DEVICETYPE=125" /> 48 56 <folder Name="CMSIS Files"> 49 57 <file file_name="STM32G4xx/Device/Include/stm32g4xx.h" /> -
trunk/fw_g473rct/SES/src/battery_voltage.c
r20 r22 21 21 22 22 #define BATTERY_VOLTAGE_VOLTAGE_DIVIDER 6 23 23 #define ADC_RESOLUTION 65536 //65536/2 da im differential mode 24 #define ADC_OFFSET 0 25 #define VREF 3000 24 26 // --- LOKALE TYPE DEFS - bitte hier dokumentieren------------------------------- 25 27 … … 35 37 36 38 37 void BATTERY_VOLTAGE_Exec( uint32_t newvalP )39 void BATTERY_VOLTAGE_Exec(int32_t newvalP ) 38 40 { 39 41 static int measCounter; 40 42 static unsigned long avgsumP = 0; 41 uint32_t avgvalP;43 int32_t avgvalP; 42 44 43 45 if (measCounter < INT32_MAX) measCounter++; … … 53 55 54 56 //Umrechung auf Eingangsspannung am Gerät mit Teiler 55 sys_data.s.values.batteryVoltage = ( avgvalP * (uint64_t)sys_data.s.values.realVdd * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / 65536;57 sys_data.s.values.batteryVoltage = ((avgvalP-2048) * 3000 * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / 2048; 56 58 57 59 … … 75 77 //Berechnung schnellen Wert ohne Glättung: 76 78 //Umrechung auf Eingangsspannung am Gerät mit Teiler 77 sys_data.s.values.fast_voltage = ( newvalP * (uint64_t)sys_data.s.values.realVdd * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / 65536;79 sys_data.s.values.fast_voltage = ((newvalP-ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / ADC_RESOLUTION; 78 80 79 81 -
trunk/fw_g473rct/SES/src/main.c
r20 r22 37 37 #include "modbus.h" 38 38 #include "chip_temperature.h" 39 #include "battery_voltage.h" 40 #include "ads1260.h" 39 41 /* USER CODE END Includes */ 40 42 … … 57 59 58 60 /* USER CODE BEGIN PV */ 59 modbus_t modbusData ;60 #define ADCCONVERTEDVALUES_BUFFER_SIZE 2 61 __IO uint 32_t adc12Data[ADCCONVERTEDVALUES_BUFFER_SIZE] __attribute__((section(".RAM1")));61 modbus_t modbusData __attribute__((section(".RAM1"))); 62 63 __IO uint16_t adc12Data[2] __attribute__((section(".RAM1"))); 62 64 __IO uint32_t adc1Data[1] __attribute__((section(".RAM1"))); 63 65 __IO uint32_t adc2Data[1] __attribute__((section(".RAM1"))); … … 66 68 __IO uint32_t adc5Data[4] __attribute__((section(".RAM1"))); 67 69 int silentmode =0; 70 static volatile uint32_t newADC1Data = 0; 71 static volatile uint32_t newADC2Data = 0; 68 72 /* USER CODE END PV */ 69 73 … … 71 75 void SystemClock_Config(void); 72 76 /* USER CODE BEGIN PFP */ 73 77 bool SetFlashReadProtection(bool state); 78 uint8_t printprotectionstate(void); 79 bool SetBootFromFlashAndReadOutProtection(void); 74 80 /* USER CODE END PFP */ 75 81 … … 88 94 /* USER CODE BEGIN 1 */ 89 95 uint8_t firstStartCatcher; 96 int mode_button_disable_time=0; 90 97 /* USER CODE END 1 */ 91 98 … … 168 175 169 176 //HAL_ADC_Start_DMA(&hadc2, (uint32_t*)adc2Data, 1); 170 if (HAL_ADCEx_MultiModeStart_DMA(&hadc1,(uint32_t *)adc12Data, ADCCONVERTEDVALUES_BUFFER_SIZE)) //Start ADC interleaved mode177 if (HAL_ADCEx_MultiModeStart_DMA(&hadc1,(uint32_t *)adc12Data,1)) //Start ADC interleaved mode 171 178 { 172 179 /* Start Error */ … … 189 196 190 197 /* USER CODE BEGIN 3 */ 198 if (newADC1Data == 1) 199 { 200 BATTERY_VOLTAGE_Exec( adc12Data[1]); 201 } 202 203 204 if(sys_data.s.parameter.command != 0) 205 { 206 if (modbusData.current_query == MB_QUERY_NOTHING) 207 { 208 //printf("CMD = %d\n", sys_data.s.parameter.command); 209 switch (sys_data.s.parameter.command ) 210 { 211 case COMMAND_STORE_CONFIG: EEPROM_storeConfig(&sys_data,0); break; 212 case COMMAND_FULL_RESTORE: EEPROM_fullRestore(&sys_data); break; 213 case COMMAND_FACTORY_RESTORE: EEPROM_factoryRestore(&sys_data, 1); break; 214 case COMMAND_RESTORE_LAST_SAVED_VALUES: EEPROM_readConfig(&sys_data); break; 215 case COMMAND_STORE_WITH_SERIAL_NUMBER: EEPROM_storeConfig(&sys_data,1); break; // Seriennummer schreiben 216 case COMMAND_RESTART: NVIC_SystemReset(); break; 217 case COMMAND_BATTERY_CURRENT_OFFSET_CAL: ADS_1260_BatteryCurrentOffsetCalibrationStart(&sys_data); break; 218 case COMMAND_BATTERY_CURRENT_OFFSET_COMMONMODE_CAL: ADS_1260_BatteryCurrentOffsetCommonModeErrorComepensationStart(&sys_data); break; 219 case COMMAND_BATTERY_CURRENT_OFFSET_TEMP_CAL: ADS_1260_BatteryCurrentOffsetTemperatureErrorComepensationStart(); break; 220 case COMMAND_BATTERY_CURRENT_GAIN_CAL: ADS_1260_BatteryCurrentGainCalibrationStart(&sys_data); break; 221 case COMMAND_BATTERY_CURRENT_GAIN_TEMP_SHUNT_CAL: ADS_1260_BatteryCurrentGainTemperatureCalibrationShuntStart(); break; 222 // case COMMAND_BATTERY_CURRENT_GAIN_TEMP_CHIP_CAL: ADS_1260_BatteryCurrentGainTemperatureCalibrationChipStart(); break; 223 case COMMAND_SET_RDP_LEVEL0: SetFlashReadProtection(false); break; 224 case COMMAND_SET_RDP_LEVEL1: SetFlashReadProtection(true); break; 225 case COMMAND_SET_RDP_LEVEL1_AND_BOOTSEL: SetBootFromFlashAndReadOutProtection(); break; 226 default: printf("UNKNOWN COMMAND\n"); 227 } 228 sys_data.s.parameter.command = 0; 229 } 230 else 231 { 232 //printf("wait with execution till modbus communnikation finished\n"); 233 } 234 } 235 236 if((HAL_GPIO_ReadPin(GPIO_INPUT_BTN_MODE_GPIO_Port, GPIO_INPUT_BTN_MODE_Pin) == GPIO_PIN_RESET) && (mode_button_disable_time == 0)) 237 { 238 HAL_Delay(10); 239 //Taste weiterhin gedrckt? 240 if(HAL_GPIO_ReadPin(GPIO_INPUT_BTN_MODE_GPIO_Port, GPIO_INPUT_BTN_MODE_Pin) == GPIO_PIN_RESET) 241 { 242 //Ja, dann Silent Mode umschalten 243 mode_button_disable_time=500; 244 if (silentmode == 0) 245 { 246 silentmode = 1; 247 HAL_GPIO_WritePin(LED_FUNC_GPIO_Port, LED_FUNC_Pin,GPIO_PIN_SET); 248 } 249 else 250 { 251 silentmode = 0; 252 } 253 } 254 } 255 191 256 // Modbus Kommunikation 192 HAL_Delay(1000); 193 printf("data12d1=%d,data12d2=%d,data5=%d\r\n", adc12Data[0], adc12Data[1], adc5Data[2]);257 258 // printf("data12d1=%d,data12d2=%d,data5=%d\r\n", adc12Data[0], adc12Data[1] , adc5Data[2]); 194 259 if (mbGetFrameComplete(&modbusData) == true) 195 260 { … … 258 323 259 324 /* USER CODE BEGIN 4 */ 260 325 void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) 326 { 327 if (hadc->Instance==ADC1) 328 { 329 newADC1Data=1; 330 } 331 332 if (hadc->Instance==ADC2) 333 { 334 newADC2Data=1; 335 } 336 } 337 338 339 340 /** 341 342 * @brief Set flash read protection. 343 344 * @param [in] state: Flash read protection state, true: enable protection, false: disable protection. 345 346 * @retval true: Successful operation. 347 348 * @retval false: Operation failed. 349 350 */ 351 352 bool SetFlashReadProtection(bool state) 353 { 354 355 FLASH_OBProgramInitTypeDef OptionsBytesStruct = {0}; 356 HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct); 357 358 if(state == true) 359 { 360 printf("Start enable readout protection\n"); 361 if(OptionsBytesStruct.RDPLevel == OB_RDP_LEVEL_0) 362 { 363 OptionsBytesStruct.OptionType = OPTIONBYTE_RDP; 364 OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_1; 365 if (HAL_FLASH_Unlock() != HAL_OK) 366 { 367 printf("Flash unlock error\n"); 368 } 369 if (HAL_FLASH_OB_Unlock() != HAL_OK) 370 { 371 printf("Flash ob unlock error\n"); 372 } 373 374 printf("...Flash unlock\n"); 375 if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK) 376 { 377 printf("...Enable lock error\n"); 378 HAL_FLASH_OB_Lock(); 379 return false; 380 } 381 HAL_FLASH_OB_Lock(); 382 printf("Flash Optionbyte locked\n"); 383 HAL_FLASH_Lock(); 384 printf("Flash locked\n"); 385 printf("...Enable lock process finished\n"); 386 } 387 else 388 { 389 printf("...Flash lock already active\n"); 390 } 391 } 392 else 393 { 394 if(OptionsBytesStruct.RDPLevel == OB_RDP_LEVEL_1) 395 { 396 OptionsBytesStruct.OptionType = OPTIONBYTE_RDP; 397 OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_0; 398 399 if (HAL_FLASH_Unlock() != HAL_OK) 400 { 401 printf("Flash unlock error\n"); 402 return false; 403 } 404 printf("...Flash unlocked\n"); 405 406 if (HAL_FLASH_OB_Unlock() != HAL_OK) 407 { 408 printf("Flash ob unlock error\n"); 409 return false; 410 } 411 printf("...Flash ob unlocked\n"); 412 413 if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK) 414 { 415 HAL_FLASH_OB_Lock(); 416 printf("Flash Optionbyte programm failed\n"); 417 return false; 418 } 419 420 printf("Flash Optionbyte programmed\n"); 421 HAL_FLASH_OB_Lock(); 422 printf("Flash Optionbyte locked\n"); 423 HAL_FLASH_Lock(); 424 printf("Flash locked\n"); 425 printf("...Disable lock process finished\n"); 426 427 ; 428 } 429 } 430 return true; 431 } 432 433 bool SetBootFromFlashAndReadOutProtection(void) 434 { 435 436 FLASH_OBProgramInitTypeDef OptionsBytesStruct = {0}; 437 HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct); 438 439 //Konfiguriere RDP fr Readoutprotection and USER OPTION BYTE FR Boot from Flash 440 OptionsBytesStruct.OptionType = OPTIONBYTE_USER | OPTIONBYTE_RDP; 441 442 //Set Readout Protection Level 1 443 OptionsBytesStruct.OptionType = OPTIONBYTE_USER|OPTIONBYTE_RDP; 444 OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_1; 445 446 //Selecting Boot from Main Flash Memory 447 OptionsBytesStruct.USERType = OB_USER_nBOOT0 | OB_USER_nSWBOOT0 | OB_USER_nBOOT1 ; 448 OptionsBytesStruct.USERConfig = OB_USER_nBOOT0 | OB_USER_nSWBOOT0; 449 450 if (HAL_FLASH_Unlock() != HAL_OK) 451 { 452 printf("Flash unlock error\n"); 453 } 454 if (HAL_FLASH_OB_Unlock() != HAL_OK) 455 { 456 printf("Flash ob unlock error\n"); 457 } 458 459 printf("...Flash unlock\n"); 460 if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK) 461 { 462 printf("...Enable lock error\n"); 463 HAL_FLASH_OB_Lock(); 464 return false; 465 } 466 HAL_FLASH_OB_Lock(); 467 printf("Flash Optionbyte locked\n"); 468 HAL_FLASH_Lock(); 469 printf("Flash locked\n"); 470 printf("...Enable lock process finished\n"); 471 472 return true; 473 } 474 uint8_t printprotectionstate(void) 475 { 476 FLASH_OBProgramInitTypeDef OptionsBytesStruct = {0}; 477 HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct); 478 uint8_t result = 0; 479 480 if(OptionsBytesStruct.RDPLevel == OB_RDP_LEVEL_0) 481 { 482 //OptionsBytesStruct.OptionType = OPTIONBYTE_RDP; 483 //OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_1; 484 printf("PROTECTION: OB_RDP_LEVEL_0\n"); 485 result = 0; 486 } 487 else if(OptionsBytesStruct.RDPLevel == OB_RDP_LEVEL_1) 488 { 489 printf("PROTECTION: OB_RDP_LEVEL_1\n"); 490 result = 1; 491 } 492 else if(OptionsBytesStruct.RDPLevel == OB_RDP_LEVEL_2) 493 { 494 printf("PROTECTION: OB_RDP_LEVEL_2\n"); 495 result = 2; 496 } 497 return result; 498 } 261 499 262 500 /* USER CODE END 4 */ -
trunk/fw_g473rct/SES/src/modbus.c
r20 r22 67 67 #define FAST_BAUDRATE_INTERFRAME_DELAY_us (1750UL) 68 68 // --- Externe Variablen -------------------------------------------- 69 extern modbus_t modbusData;70 extern sys_data_t sys_data;69 extern volatile modbus_t modbusData; 70 extern volatile sys_data_t sys_data; 71 71 72 72 … … 158 158 159 159 // Init aus Cube 160 mb_data->uart->Instance = USART 1;161 mb_data->uart->Init.BaudRate = 19200;160 mb_data->uart->Instance = USART2; 161 mb_data->uart->Init.BaudRate = baudrate; 162 162 mb_data->uart->Init.WordLength = UART_WORDLENGTH_9B; 163 163 mb_data->uart->Init.StopBits = UART_STOPBITS_1; … … 168 168 mb_data->uart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 169 169 mb_data->uart->Init.ClockPrescaler = UART_PRESCALER_DIV1; 170 mb_data->uart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 171 172 // Init nderungen 170 mb_data->uart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT; 171 mb_data->uart->AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE; 172 173 // Init änderungen 173 174 174 175 // Baudrate … … 200 201 } 201 202 // Init 202 if (RS485_ModbusEx_Init(mb_data->uart, UART_DE_POLARITY_HIGH, 0, 0,TIMEOUT_FRAME_COMPLETE*nrOfBitsPerChar) != HAL_OK) 203 { 204 Error_Handler(); 205 } 206 if (HAL_UARTEx_DisableFifoMode(mb_data->uart) != HAL_OK) 207 { 208 Error_Handler(); 209 } 210 211 if(HAL_UART_Receive_IT(mb_data->uart, mb_data->rx_buffer, RXBUFFERSIZE) != HAL_OK) 203 // if (RS485_ModbusEx_Init(mb_data->uart, UART_DE_POLARITY_HIGH, 0, 0,TIMEOUT_FRAME_COMPLETE*nrOfBitsPerChar) != HAL_OK) 204 // { 205 // Error_Handler(); 206 // } 207 // if (HAL_UARTEx_DisableFifoMode(mb_data->uart) != HAL_OK) 208 // { 209 // Error_Handler(); 210 // } 211 uint32_t fixedDelayInBitDurations = (FAST_BAUDRATE_INTERFRAME_DELAY_us * baudrate) / 1000000UL + 1UL; 212 // HAL_UART_EnableReceiverTimeout( usart); 213 // HAL_UART_ReceiverTimeout_Config(usart, fixedDelayInBitDurations); 214 215 if(HAL_UARTEx_ReceiveToIdle_DMA(mb_data->uart, mb_data->rx_buffer, RXBUFFERSIZE) != HAL_OK) 212 216 { 213 217 printf("uart error \n\r"); … … 218 222 } 219 223 220 /* 221 * 222 * @brief End ongoing Rx transfer on UART peripheral (following error detection or Reception completion). 223 * @param huart: UART handle. 224 * @retval None 225 */ 226 void mbUartEndRxTransfer(UART_HandleTypeDef *huart) 227 { 228 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ 229 //CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); 230 //CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); 231 232 /* At end of Rx process, restore huart->RxState to Ready */ 233 huart->RxState = HAL_UART_STATE_READY; 234 } 235 236 void mbUartRx(modbus_t* mb_data) 237 { 238 uint32_t pos; 239 uint8_t data; 240 241 pos = mb_data->rx_head; 242 243 if (pos >= RXBUFFERSIZE) 244 { 245 return; 246 } 247 //data = mb_data->uart->Instance->RDR 248 data = mb_data->uart->Instance->RDR & (uint8_t)0x00FF; //NOTE: mb_data->uart.Instance->DR gendert 249 mb_data->rx_buffer[pos] = data; 250 251 mb_data->rx_head++; 252 253 //mbTimerStart(mb_data); 254 } 255 256 HAL_StatusTypeDef mbUartTx(UART_HandleTypeDef *huart) 257 { 258 uint16_t* tmp; 259 260 if(huart->Init.WordLength == UART_WORDLENGTH_9B) 261 { 262 tmp = (uint16_t*) huart->pTxBuffPtr; 263 huart->Instance->TDR = (uint16_t)(*tmp & (uint16_t)0x01FF); //NOTE: huart->Instance->DR gendert 264 265 if(huart->Init.Parity == UART_PARITY_NONE) 266 { 267 huart->pTxBuffPtr += 2; 268 } 269 else 270 { 271 huart->pTxBuffPtr += 1; 272 } 273 } 274 else 275 { 276 huart->Instance->TDR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0x00FF); //NOTE:huart->Instance->DR gendert 277 } 278 279 if(--huart->TxXferCount == 0) 280 { 281 /* Disable the UART Transmit Complete Interrupt */ 282 __HAL_UART_DISABLE_IT(huart, UART_IT_TXE); 283 284 /* Enable the UART Transmit Complete Interrupt */ 285 __HAL_UART_ENABLE_IT(huart, UART_IT_TC); 286 } 287 return HAL_OK; 288 } 289 290 // huart->State gibt es nicht mehr. Ersetzt durch huart->gState. 291 /** 292 * @brief Wraps up transmission in non blocking mode. 293 * @param huart: pointer to a UART_HandleTypeDef structure that contains 294 * the configuration information for the specified UART module. 295 * @retval HAL status 296 */ 297 static void UART_EndTransmit_IT(UART_HandleTypeDef *huart) 298 { 299 /* Disable the UART Transmit Complete Interrupt */ 300 CLEAR_BIT(huart->Instance->CR1, USART_CR1_TCIE); 301 302 /* Tx process is ended, restore huart->gState to Ready */ 303 huart->gState = HAL_UART_STATE_READY; 304 305 /* Cleat TxISR function pointer */ 306 huart->TxISR = NULL; 307 308 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 309 /*Call registered Tx complete callback*/ 310 huart->TxCpltCallback(huart); 311 #else 312 /*Call legacy weak Tx complete callback*/ 313 HAL_UART_TxCpltCallback(huart); 314 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ 315 } 316 317 318 static HAL_StatusTypeDef RS485_ModbusEx_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime, uint32_t DeassertionTime, uint32_t charReceiveTimeout) 224 225 226 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) 319 227 { 320 uint32_t temp; 321 322 /* Check the UART handle allocation */ 323 if (huart == NULL) 324 { 325 return HAL_ERROR; 326 } 327 /* Check the Driver Enable UART instance */ 328 assert_param(IS_UART_DRIVER_ENABLE_INSTANCE(huart->Instance)); 329 330 /* Check the Driver Enable polarity */ 331 assert_param(IS_UART_DE_POLARITY(Polarity)); 332 333 /* Check the Driver Enable assertion time */ 334 assert_param(IS_UART_ASSERTIONTIME(AssertionTime)); 335 336 /* Check the Driver Enable deassertion time */ 337 assert_param(IS_UART_DEASSERTIONTIME(DeassertionTime)); 338 339 if (huart->gState == HAL_UART_STATE_RESET) 340 { 341 /* Allocate lock resource and initialize it */ 342 huart->Lock = HAL_UNLOCKED; 343 344 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 345 UART_InitCallbacksToDefault(huart); 346 347 if (huart->MspInitCallback == NULL) 348 { 349 huart->MspInitCallback = HAL_UART_MspInit; 350 } 351 352 /* Init the low level hardware */ 353 huart->MspInitCallback(huart); 354 #else 355 /* Init the low level hardware : GPIO, CLOCK, CORTEX */ 356 HAL_UART_MspInit(huart); 357 #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ 358 } 359 360 huart->gState = HAL_UART_STATE_BUSY; 361 362 /* Disable the Peripheral */ 363 __HAL_UART_DISABLE(huart); 364 365 /* Set the UART Communication parameters */ 366 if (UART_SetConfig(huart) == HAL_ERROR) 367 { 368 return HAL_ERROR; 369 } 370 371 if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT) 372 { 373 UART_AdvFeatureConfig(huart); 374 } 375 376 /* Enable the Driver Enable mode by setting the DEM bit in the CR3 register */ 377 //EDIT SMART_SWITCH: HIER wurde ein chip mit autoerkennung implementiert 378 // SET_BIT(huart->Instance->CR3, USART_CR3_DEM); 379 380 /* Set the Driver Enable polarity */ 381 // MODIFY_REG(huart->Instance->CR3, USART_CR3_DEP, Polarity); 382 383 /* Set the Driver Enable assertion and deassertion times */ 384 // temp = (AssertionTime << UART_CR1_DEAT_ADDRESS_LSB_POS); 385 // temp |= (DeassertionTime << UART_CR1_DEDT_ADDRESS_LSB_POS); 386 // MODIFY_REG(huart->Instance->CR1, (USART_CR1_DEDT | USART_CR1_DEAT), temp); 387 388 // EDIT ECS START 389 /*Set receive timeout time*/ 390 SET_BIT(huart->Instance->CR2, USART_CR2_RTOEN); 391 SET_BIT(huart->Instance->CR1, USART_CR1_RTOIE); 392 //MODIFY_REG(huart->Instance->RTOR, USART_RTOR_RTO, charReceiveTimeout); 393 if (huart->Init.BaudRate <= 19200) MODIFY_REG(huart->Instance->RTOR, USART_RTOR_RTO, charReceiveTimeout); 394 else 395 { 396 uint32_t fixedDelayInBitDurations = (FAST_BAUDRATE_INTERFRAME_DELAY_us * huart->Init.BaudRate) / 1000000UL + 1UL; 397 MODIFY_REG(huart->Instance->RTOR, USART_RTOR_RTO, fixedDelayInBitDurations); 398 } 399 // EDIT ECS END 400 401 /* Enable the Peripheral */ 402 __HAL_UART_ENABLE(huart); 403 404 /* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */ 405 return (UART_CheckIdleState(huart)); 406 } 407 408 409 static int test; 410 void MODBUS_UART_IRQHandler(UART_HandleTypeDef *huart) 411 { 412 uint32_t isrflags = READ_REG(huart->Instance->ISR); 413 uint32_t cr1its = READ_REG(huart->Instance->CR1); 414 uint32_t cr2its = READ_REG(huart->Instance->CR2); 415 uint32_t cr3its = READ_REG(huart->Instance->CR3); 416 417 uint32_t errorflags; 418 uint32_t errorcode; 419 420 errorflags = (isrflags & (uint32_t)(USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE)); 421 422 /* If some errors occur */ 423 if ((errorflags != 0U) 424 && ((((cr3its & (USART_CR3_RXFTIE | USART_CR3_EIE)) != 0U) 425 || ((cr1its & (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE)) != 0U)))) 426 { 427 /* UART parity error interrupt occurred -------------------------------------*/ 428 if (((isrflags & USART_ISR_PE) != 0U) && ((cr1its & USART_CR1_PEIE) != 0U)) 429 { 430 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_PEF); 431 432 huart->ErrorCode |= HAL_UART_ERROR_PE; 433 } 434 435 /* UART frame error interrupt occurred --------------------------------------*/ 436 if (((isrflags & USART_ISR_FE) != 0U) && ((cr3its & USART_CR3_EIE) != 0U)) 437 { 438 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_FEF); 439 440 huart->ErrorCode |= HAL_UART_ERROR_FE; 441 } 442 443 /* UART noise error interrupt occurred --------------------------------------*/ 444 if (((isrflags & USART_ISR_NE) != 0U) && ((cr3its & USART_CR3_EIE) != 0U)) 445 { 446 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_NEF); 447 448 huart->ErrorCode |= HAL_UART_ERROR_NE; 449 } 450 451 /* UART Over-Run interrupt occurred -----------------------------------------*/ 452 if (((isrflags & USART_ISR_ORE) != 0U) 453 && (((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U) || 454 ((cr3its & (USART_CR3_RXFTIE | USART_CR3_EIE)) != 0U))) 455 { 456 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF); 457 458 huart->ErrorCode |= HAL_UART_ERROR_ORE; 459 } 460 } /* End if some error occurs */ 461 462 463 /* UART in mode Receiver (receive Timeout occured)--------------------------*/ 464 if (((isrflags & USART_ISR_RTOF) != 0U) 465 && (((cr1its & USART_CR1_RTOIE) != 0U) 466 || ((cr3its & USART_CR2_RTOEN) != 0U))) 467 { 468 __HAL_UART_CLEAR_FLAG(huart, USART_ICR_RTOCF); 469 huart->RxState = HAL_UART_STATE_READY; 470 huart->gState = HAL_UART_STATE_READY; 228 if (huart->ErrorCode == HAL_UART_ERROR_RTO) 229 { 471 230 modbusData.mb_rx_frame_complete = 1; 472 231 modbusData.setRxLed = true; 473 474 } 475 476 /* UART in mode Receiver ---------------------------------------------------*/ 477 if (((isrflags & USART_ISR_RXNE_RXFNE) != 0U) 478 && (((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U) 479 || ((cr3its & USART_CR3_RXFTIE) != 0U))) 480 { 481 if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && (modbusData.rx_head < RXBUFFERSIZE)) //-> empfngt dann ein byte aber das ist nicht wild 482 { 483 modbusData.rx_buffer[modbusData.rx_head] = huart->Instance->RDR; 484 /*DEBUG//printf("xx%d: nr:%d %d\n",test ++,modbusData.rx_head, modbusData.rx_buffer[modbusData.rx_head]);*/ 485 modbusData.rx_head++; 486 modbusData.setRxLed = true; 487 } 488 else 489 { 490 __HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST); 491 } 492 } 493 494 /* UART in mode Transmitter ------------------------------------------------*/ 495 if (((isrflags & USART_ISR_TXE_TXFNF) != 0U) 496 && (((cr1its & USART_CR1_TXEIE_TXFNFIE) != 0U) 497 || ((cr3its & USART_CR3_TXFTIE) != 0U))) 498 { 499 UART_TxISR_8BIT(modbusData.uart); 500 modbusData.setTxLed = true; 501 } 502 503 /* UART in mode Transmitter (transmission end) -----------------------------*/ 504 if (((isrflags & USART_ISR_TC) != 0U) && ((cr1its & USART_CR1_TCIE) != 0U)) 505 { 506 modbusData.current_query = MB_QUERY_NOTHING; 507 UART_EndTransmit_IT(huart); 508 huart->RxState = HAL_UART_STATE_BUSY_RX; 509 // /*Reset TX complete interrupt flag*/ 510 // __HAL_UART_CLEAR_FLAG(huart, USART_ISR_TC); 511 // /* Disable the UART Transmit Complete Interrupt */ 512 // CLEAR_BIT(huart->Instance->CR1, USART_CR1_TCIE); 513 // /*TX complete callback function*/ 514 // HAL_UART_TxCpltCallback(huart); 515 // /* Tx process is ended, restore huart->gState to Ready */ 516 // huart->gState = HAL_UART_STATE_READY; 517 } 518 519 /* Call UART Error Call back function if need be --------------------------*/ 520 if (huart->ErrorCode != HAL_UART_ERROR_NONE) 521 { 522 huart->RxState = HAL_UART_STATE_BUSY_RX; 523 /* UART in mode Receiver ---------------------------------------------------*/ 524 if (((isrflags & USART_ISR_RXNE_RXFNE) != 0U) 525 && (((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U) 526 || ((cr3its & USART_CR3_RXFTIE) != 0U))) 527 { 528 __HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST); 529 huart->ErrorCode = HAL_UART_ERROR_NONE; 530 } 531 else if (((isrflags & USART_ISR_TXE_TXFNF) != 0U) 532 && (((cr1its & USART_CR1_TXEIE_TXFNFIE) != 0U) 533 || ((cr3its & USART_CR3_TXFTIE) != 0U))) 534 { 535 modbusData.current_query = MB_QUERY_NOTHING; 536 UART_EndTransmit_IT(huart); 537 huart->RxState = HAL_UART_STATE_BUSY_RX; 538 modbusData.setTxLed = true; 539 } 540 } 232 modbusData.rx_head= 8; 233 printf("MB RTO Event! \n\r"); 234 } 235 236 if(HAL_UARTEx_ReceiveToIdle_DMA(huart, huart->pRxBuffPtr, RXBUFFERSIZE) != HAL_OK) 237 { 238 printf("uart error \n\r"); 239 // while(1) 240 // { 241 // } 242 } 243 541 244 } 542 245 543 544 545 546 547 548 549 /** 550 * @brief TX interrrupt handler for 7 or 8 bits data word length . 551 * @note Function is called under interruption only, once 552 * interruptions have been enabled by HAL_UART_Transmit_IT(). 553 * @param huart UART handle. 554 * @retval None 555 */ 556 static void UART_TxISR_8BIT(UART_HandleTypeDef *huart) 246 void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) 557 247 { 558 /* Check that a Tx process is ongoing */ 559 if (huart->gState == HAL_UART_STATE_BUSY_TX) 560 { 561 if (huart->TxXferCount == 0U) 562 { 563 /* Disable the UART Transmit Data Register Empty Interrupt */ 564 CLEAR_BIT(huart->Instance->CR1, USART_CR1_TXEIE_TXFNFIE); 565 566 /* Enable the UART Transmit Complete Interrupt */ 567 SET_BIT(huart->Instance->CR1, USART_CR1_TCIE); 568 } 569 else 570 { 571 huart->Instance->TDR = (uint8_t)(*huart->pTxBuffPtr & (uint8_t)0xFF); 572 huart->pTxBuffPtr++; 573 huart->TxXferCount--; 574 } 575 } 576 else 577 { 578 /* Disable the UART Transmit Data Register Empty Interrupt */ 579 CLEAR_BIT(huart->Instance->CR1, USART_CR1_TXEIE_TXFNFIE); 580 581 /* Enable the UART Transmit Complete Interrupt */ 582 SET_BIT(huart->Instance->CR1, USART_CR1_TCIE); 583 } 248 printf("MB rxEvent!RX=%d \n\r",Size); 249 modbusData.setRxLed = true; 250 251 modbusData.mb_rx_frame_complete = 1; 252 modbusData.rx_head= Size +1; 253 254 if(HAL_UARTEx_ReceiveToIdle_DMA(huart, huart->pRxBuffPtr, RXBUFFERSIZE) != HAL_OK) 255 { 256 printf("uart error \n\r"); 257 // while(1) 258 // { 259 // } 260 } 261 262 584 263 } 585 264 … … 595 274 596 275 597 /** 598 * @brief Output Compare callback in non blocking mode 599 * @param htim : TIM OC handle 600 * @retval None 601 */ 602 void mbTimerIsr(modbus_t * mb_data) 603 { 604 /* Capture compare 1 event */ 605 // if(__HAL_TIM_GET_FLAG(mb_data->timer, TIM_FLAG_CC1) != RESET) 606 // { 607 // if(__HAL_TIM_GET_IT_SOURCE(mb_data->timer, TIM_IT_CC1) !=RESET) 608 // { 609 // __HAL_TIM_CLEAR_IT(mb_data->timer, TIM_IT_CC1); 610 // mb_data->timer->Channel = HAL_TIM_ACTIVE_CHANNEL_1; 611 612 mb_data->mb_rx_frame_complete=true; 613 // mb_data->timer->Instance->CNT =0; 614 // HAL_TIM_OC_Stop_IT(mb_data->timer, TIM_CHANNEL_1); 615 // mb_data->timer->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; 616 // 617 // } 618 // } 619 } 276 277 278 279 280 281 282 620 283 621 284 -
trunk/fw_g473rct/SES/src/sysdata.c
r20 r22 49 49 50 50 sys_data.s.values.adc_restarts = 0U; 51 sys_data.s.parameter.test[1] = 1; 52 sys_data.s.parameter.test[2] = 3; 53 sys_data.s.parameter.test[3] = 5; 54 51 55 } -
trunk/fw_g473rct/fw_g473rct.ioc
r20 r22 6 6 ADC1.DMAAccessModeView=ENABLE 7 7 ADC1.DMAContinuousRequests=ENABLE 8 ADC1.EOCSelection=ADC_EOC_S EQ_CONV9 ADC1.IPParameters=Rank-20\#ChannelRegularConversion,master,SingleDiff-20\#ChannelRegularConversion,Channel-20\#ChannelRegularConversion,SamplingTime-20\#ChannelRegularConversion,OffsetNumber-20\#ChannelRegularConversion,NbrOfConversionFlag,Mode,DMAAccessModeView,ContinuousConvMode,OversamplingMode,DMAContinuousRequests,Overrun,ClockPrescaler,EOCSelection, CommonPathInternal8 ADC1.EOCSelection=ADC_EOC_SINGLE_CONV 9 ADC1.IPParameters=Rank-20\#ChannelRegularConversion,master,SingleDiff-20\#ChannelRegularConversion,Channel-20\#ChannelRegularConversion,SamplingTime-20\#ChannelRegularConversion,OffsetNumber-20\#ChannelRegularConversion,NbrOfConversionFlag,Mode,DMAAccessModeView,ContinuousConvMode,OversamplingMode,DMAContinuousRequests,Overrun,ClockPrescaler,EOCSelection,RightBitShift,Ratio,CommonPathInternal 10 10 ADC1.Mode=ADC_DUALMODE_REGSIMULT 11 11 ADC1.NbrOfConversionFlag=1 12 12 ADC1.OffsetNumber-20\#ChannelRegularConversion=ADC_OFFSET_NONE 13 13 ADC1.Overrun=ADC_OVR_DATA_OVERWRITTEN 14 ADC1.OversamplingMode= DISABLE14 ADC1.OversamplingMode=ENABLE 15 15 ADC1.Rank-20\#ChannelRegularConversion=1 16 ADC1.SamplingTime-20\#ChannelRegularConversion=ADC_SAMPLETIME_2CYCLES_5 16 ADC1.Ratio=ADC_OVERSAMPLING_RATIO_256 17 ADC1.RightBitShift=ADC_RIGHTBITSHIFT_4 18 ADC1.SamplingTime-20\#ChannelRegularConversion=ADC_SAMPLETIME_640CYCLES_5 17 19 ADC1.SingleDiff-20\#ChannelRegularConversion=ADC_DIFFERENTIAL_ENDED 18 20 ADC1.master=1 … … 22 24 ADC2.DMAAccessModeView=ENABLE 23 25 ADC2.DMAContinuousRequests=ENABLE 24 ADC2.EOCSelection=ADC_EOC_S EQ_CONV25 ADC2.IPParameters=Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,S ingleDiff-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion,OffsetNumber-4\#ChannelRegularConversion,NbrOfConversionFlag,Mode,DMAAccessModeView,EOCSelection,DMAContinuousRequests,Overrun,ClockPrescaler,CommonPathInternal26 ADC2.EOCSelection=ADC_EOC_SINGLE_CONV 27 ADC2.IPParameters=Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion,OffsetNumber-4\#ChannelRegularConversion,NbrOfConversionFlag,Mode,DMAAccessModeView,EOCSelection,DMAContinuousRequests,Overrun,ClockPrescaler,OversamplingMode,RightBitShift,Ratio,CommonPathInternal 26 28 ADC2.Mode=ADC_DUALMODE_REGSIMULT 27 29 ADC2.NbrOfConversionFlag=1 28 30 ADC2.OffsetNumber-4\#ChannelRegularConversion=ADC_OFFSET_NONE 29 31 ADC2.Overrun=ADC_OVR_DATA_OVERWRITTEN 32 ADC2.OversamplingMode=ENABLE 30 33 ADC2.Rank-4\#ChannelRegularConversion=1 31 ADC2.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLETIME_2CYCLES_5 32 ADC2.SingleDiff-4\#ChannelRegularConversion=ADC_DIFFERENTIAL_ENDED 34 ADC2.Ratio=ADC_OVERSAMPLING_RATIO_256 35 ADC2.RightBitShift=ADC_RIGHTBITSHIFT_4 36 ADC2.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLETIME_640CYCLES_5 33 37 ADC3.Channel-1\#ChannelRegularConversion=ADC_CHANNEL_1 34 38 ADC3.ClockPrescaler=ADC_CLOCK_ASYNC_DIV256 … … 86 90 Dma.ADC1.0.MemInc=DMA_MINC_ENABLE 87 91 Dma.ADC1.0.Mode=DMA_CIRCULAR 88 Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_ HALFWORD92 Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_WORD 89 93 Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE 90 94 Dma.ADC1.0.Polarity=HAL_DMAMUX_REQ_GEN_RISING … … 103 107 Dma.ADC2.1.MemInc=DMA_MINC_ENABLE 104 108 Dma.ADC2.1.Mode=DMA_CIRCULAR 105 Dma.ADC2.1.PeriphDataAlignment=DMA_PDATAALIGN_ HALFWORD109 Dma.ADC2.1.PeriphDataAlignment=DMA_PDATAALIGN_WORD 106 110 Dma.ADC2.1.PeriphInc=DMA_PINC_DISABLE 107 111 Dma.ADC2.1.Polarity=HAL_DMAMUX_REQ_GEN_RISING … … 170 174 Dma.Request3=ADC4 171 175 Dma.Request4=ADC5 172 Dma.RequestsNb=5 176 Dma.Request5=USART2_RX 177 Dma.RequestsNb=6 178 Dma.USART2_RX.5.Direction=DMA_PERIPH_TO_MEMORY 179 Dma.USART2_RX.5.EventEnable=DISABLE 180 Dma.USART2_RX.5.Instance=DMA1_Channel6 181 Dma.USART2_RX.5.MemDataAlignment=DMA_MDATAALIGN_BYTE 182 Dma.USART2_RX.5.MemInc=DMA_MINC_ENABLE 183 Dma.USART2_RX.5.Mode=DMA_NORMAL 184 Dma.USART2_RX.5.PeriphDataAlignment=DMA_PDATAALIGN_BYTE 185 Dma.USART2_RX.5.PeriphInc=DMA_PINC_DISABLE 186 Dma.USART2_RX.5.Polarity=HAL_DMAMUX_REQ_GEN_RISING 187 Dma.USART2_RX.5.Priority=DMA_PRIORITY_LOW 188 Dma.USART2_RX.5.RequestNumber=1 189 Dma.USART2_RX.5.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber 190 Dma.USART2_RX.5.SignalID=NONE 191 Dma.USART2_RX.5.SyncEnable=DISABLE 192 Dma.USART2_RX.5.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT 193 Dma.USART2_RX.5.SyncRequestNumber=1 194 Dma.USART2_RX.5.SyncSignalID=NONE 173 195 FDCAN2.CalculateBaudRateNominal=2083333 174 196 FDCAN2.CalculateTimeBitNominal=480 … … 216 238 Mcu.Pin12=PA5 217 239 Mcu.Pin13=PA6 218 Mcu.Pin14=P A7219 Mcu.Pin15=PC 4220 Mcu.Pin16=P C5221 Mcu.Pin17=PB 0222 Mcu.Pin18=PB1 223 Mcu.Pin19=PB1 0240 Mcu.Pin14=PC4 241 Mcu.Pin15=PC5 242 Mcu.Pin16=PB0 243 Mcu.Pin17=PB1 244 Mcu.Pin18=PB10 245 Mcu.Pin19=PB11 224 246 Mcu.Pin2=PC15-OSC32_OUT 225 Mcu.Pin20=PB1 1226 Mcu.Pin21=PB1 2227 Mcu.Pin22=PB1 3228 Mcu.Pin23=PB1 4229 Mcu.Pin24=P B15230 Mcu.Pin25=PC 6231 Mcu.Pin26=PC 7232 Mcu.Pin27=PC 8233 Mcu.Pin28=P C9234 Mcu.Pin29=PA 8247 Mcu.Pin20=PB12 248 Mcu.Pin21=PB13 249 Mcu.Pin22=PB14 250 Mcu.Pin23=PB15 251 Mcu.Pin24=PC6 252 Mcu.Pin25=PC7 253 Mcu.Pin26=PC8 254 Mcu.Pin27=PC9 255 Mcu.Pin28=PA8 256 Mcu.Pin29=PA9 235 257 Mcu.Pin3=PF0-OSC_IN 236 Mcu.Pin30=PA 9237 Mcu.Pin31=PA1 0238 Mcu.Pin32=PA1 1239 Mcu.Pin33=PA1 2240 Mcu.Pin34=PA1 3241 Mcu.Pin35=PA1 4242 Mcu.Pin36=P A15243 Mcu.Pin37=PC1 0244 Mcu.Pin38=PC1 1245 Mcu.Pin39=P C12258 Mcu.Pin30=PA10 259 Mcu.Pin31=PA11 260 Mcu.Pin32=PA12 261 Mcu.Pin33=PA13 262 Mcu.Pin34=PA14 263 Mcu.Pin35=PA15 264 Mcu.Pin36=PC10 265 Mcu.Pin37=PC11 266 Mcu.Pin38=PC12 267 Mcu.Pin39=PD2 246 268 Mcu.Pin4=PF1-OSC_OUT 247 Mcu.Pin40=P D2248 Mcu.Pin41=PB 3249 Mcu.Pin42=PB 4250 Mcu.Pin43=PB 5251 Mcu.Pin44=PB 6252 Mcu.Pin45=PB 7253 Mcu.Pin46= PB9254 Mcu.Pin47=VP_ADC5_ TempSens_Input255 Mcu.Pin48=VP_ ADC5_Vbat_Input256 Mcu.Pin49=VP_ CRC_VS_CRC269 Mcu.Pin40=PB3 270 Mcu.Pin41=PB4 271 Mcu.Pin42=PB5 272 Mcu.Pin43=PB6 273 Mcu.Pin44=PB7 274 Mcu.Pin45=PB9 275 Mcu.Pin46=VP_ADC5_TempSens_Input 276 Mcu.Pin47=VP_ADC5_Vbat_Input 277 Mcu.Pin48=VP_CRC_VS_CRC 278 Mcu.Pin49=VP_SYS_V_VREFBUF 257 279 Mcu.Pin5=PC0 258 280 Mcu.Pin50=VP_SYS_VS_Systick … … 274 296 NVIC.DMA1_Channel4_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true 275 297 NVIC.DMA1_Channel5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true 298 NVIC.DMA1_Channel6_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true 276 299 NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 277 300 NVIC.ForceEnableDMAVector=true … … 283 306 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 284 307 NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false 308 NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true 309 NVIC.USART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true 285 310 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 286 311 PA0.Locked=true … … 322 347 PA6.GPIOParameters=GPIO_Label 323 348 PA6.GPIO_Label=ADC2_IN3_UBAT+ 324 PA6.Mode=IN3- Differential349 PA6.Mode=IN3-Single-Ended 325 350 PA6.Signal=ADC2_IN3 326 PA7.GPIOParameters=GPIO_Label327 PA7.GPIO_Label=ADC2_IN4_UBAT-328 PA7.Mode=IN3-Differential329 PA7.Signal=ADC2_IN4330 351 PA8.GPIOParameters=GPIO_Label 331 352 PA8.GPIO_Label=LVP_SENSE … … 524 545 USART1.Parity=PARITY_EVEN 525 546 USART1.VirtualMode-Asynchronous=VM_ASYNC 526 USART2.IPParameters=VirtualMode-Asynchronous 547 USART2.BaudRate=115200 548 USART2.IPParameters=VirtualMode-Asynchronous,Parity,BaudRate,SwapParam,WordLength 549 USART2.Parity=PARITY_EVEN 550 USART2.SwapParam=ADVFEATURE_SWAP_ENABLE 527 551 USART2.VirtualMode-Asynchronous=VM_ASYNC 552 USART2.WordLength=WORDLENGTH_9B 528 553 VP_ADC5_TempSens_Input.Mode=IN-TempSens 529 554 VP_ADC5_TempSens_Input.Signal=ADC5_TempSens_Input … … 536 561 VP_SYS_VS_Systick.Mode=SysTick 537 562 VP_SYS_VS_Systick.Signal=SYS_VS_Systick 563 VP_SYS_V_VREFBUF.Mode=ExternalMode 564 VP_SYS_V_VREFBUF.Signal=SYS_V_VREFBUF 538 565 board=custom
Note: See TracChangeset
for help on using the changeset viewer.