Ignore:
Timestamp:
Apr 1, 2026, 9:33:58 AM (5 weeks ago)
Author:
f.jahn
Message:

Fixing Projects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/fw_g473rct/Core/Src/main.c

    r54 r55  
    2222#include "crc.h"
    2323#include "dma.h"
    24 #include "fdcan.h"
    2524#include "i2c.h"
    2625#include "iwdg.h"
    2726#include "rtc.h"
    2827#include "spi.h"
     28#include "tim.h"
     29#include "ucpd.h"
    2930#include "usart.h"
    30 #include "usb.h"
     31#include "usbpd.h"
     32#include "usb_device.h"
    3133#include "gpio.h"
    3234
     
    5355#include "efficiency.h"
    5456#include "self_discharge.h"
     57#include "ltc_current.h"
    5558
    5659/* USER CODE END Includes */
     
    6568
    6669#define MAX_OVERCURRENT_RETRYS  3
     70#ifdef DEBUG
     71#define MX_IWDG_Init DoNothing
     72#endif
    6773
    6874/* USER CODE END PD */
     
    8187modbus_t modbusData __attribute__((section(".RAM1")));
    8288
    83 __IO uint16_t adc12Data[SAMPLE_ARRAY_SIZE][2] __attribute__((section(".RAM1")));
    84 __IO uint32_t adc1Data[1] __attribute__((section(".RAM1")));
    85 __IO uint32_t adc2Data[1] __attribute__((section(".RAM1")));
     89
     90__IO uint32_t adc1Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1")));
     91__IO uint32_t adc2Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1")));
    8692__IO uint32_t adc3Data[3] __attribute__((section(".RAM1")));
    87 __IO uint32_t adc4Data[1] __attribute__((section(".RAM1")));
     93__IO uint32_t adc4Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1")));
    8894__IO uint32_t adc5Data[4] __attribute__((section(".RAM1")));
    8995int silentmode =0;
    90 static volatile uint32_t newADC12Data = 0;
     96static volatile uint32_t newADC124Data = 0;
    9197static volatile uint32_t newADC3Data = 0;
    92 static volatile uint32_t newADC4Data = 0;
    9398static volatile uint32_t newADC5Data = 0;
    9499
     
    104109void SaveBackupRegister(void);
    105110void JumpToBootloader(void);
     111void DoNothing(void){};
    106112/* USER CODE END PFP */
    107113
     
    117123int main(void)
    118124{
     125
    119126  /* USER CODE BEGIN 1 */
    120127
     
    160167  MX_ADC4_Init();
    161168  MX_ADC5_Init();
    162   MX_FDCAN2_Init();
    163   MX_FDCAN3_Init();
    164169  MX_I2C3_Init();
    165170  MX_I2C4_Init();
     
    167172  MX_USART1_UART_Init();
    168173  MX_USART2_UART_Init();
    169   MX_USB_PCD_Init();
    170174  MX_CRC_Init();
    171175  MX_RTC_Init();
    172176  MX_IWDG_Init();
     177  MX_TIM3_Init();
     178  MX_USB_Device_Init();
     179  MX_UCPD1_Init();
    173180  /* USER CODE BEGIN 2 */
    174181  printf("Test debug io\r\n");
     
    178185
    179186  startType_t startType = EEPROM_isFirstStart();
    180  
     187
    181188  switch(startType)
    182189  {
     
    212219  HAL_ADCEx_Calibration_Start(&hadc5, ADC_SINGLE_ENDED);
    213220  HAL_IWDG_Refresh(&hiwdg);
    214 
     221 
    215222  //SET_BIT(hadc2.Instance->CFGR, ADC_CFGR_DMAEN); //Enable DMA transfer for ADC slave (ADC12_CCR.MDMA = 0b00 -> MDMA mode disabled)
    216223  //HAL_DMA_Start(hadc2.DMA_Handle,(uint32_t)&hadc2.Instance->DR, (uint32_t)adc2Data,1); //Start ADC slave DMA
    217224  //SET_BIT(hadc1.Instance->CFGR, ADC_CFGR_DMAEN); //Enable DMA transfer for ADC master (ADC12_CCR.MDMA = 0b00 -> MDMA mode disabled)
    218 
    219     //HAL_ADC_Start_DMA(&hadc2, (uint32_t*)adc2Data, 1);
    220   if (HAL_ADCEx_MultiModeStart_DMA(&hadc1,(uint32_t *)adc12Data,SAMPLE_ARRAY_SIZE))  //Start ADC interleaved mode
     225  if (HAL_ADC_Start_DMA(&hadc1,(uint32_t *)adc1Data,SAMPLE_ARRAY_SIZE))  //Start ADC interleaved mode
    221226  {
    222227     /* Start Error */
    223228     Error_Handler();
    224229  }
    225 
    226   if (HAL_ADC_Start_DMA(&hadc3, (uint32_t *) adc3Data , 3))
     230 
     231  if (HAL_ADC_Start_DMA(&hadc2,(uint32_t *)adc2Data,SAMPLE_ARRAY_SIZE))  //Start ADC interleaved mode
    227232  {
    228233     /* Start Error */
     
    230235  }
    231236
    232   if (HAL_ADC_Start_DMA(&hadc4, (uint32_t *) adc4Data , 1))
     237  if (HAL_ADC_Start_DMA(&hadc3, (uint32_t *) adc3Data , 3))
     238  {
     239     /* Start Error */
     240     Error_Handler();
     241  }
     242
     243  if (HAL_ADC_Start_DMA(&hadc4, (uint32_t *) adc4Data , SAMPLE_ARRAY_SIZE))
    233244  {
    234245     /* Start Error */
     
    265276  /* USER CODE END 2 */
    266277
     278  /* USBPD initialisation ---------------------------------*/
     279  MX_USBPD_Init();
     280
    267281  /* Infinite loop */
    268282  /* USER CODE BEGIN WHILE */
     
    270284  {
    271285    /* USER CODE END WHILE */
     286    USBPD_DPM_Run();
    272287
    273288    /* USER CODE BEGIN 3 */
    274289        HAL_IWDG_Refresh(&hiwdg);
    275         if (newADC12Data == 1)
    276     {
     290        if (newADC124Data == 1)
     291    {
     292          SHUNT_VOLTAGE_Exec( adc4Data[0]);
    277293          //Mit ADC_DIV2,Sample time 12,5Cycklen, ADC Clock 50Mhz, Oversampling 256
    278294          //Tconv = 6400 Takte = 0,128ms Pro Konvertierung. Also für 100 messwerte 12,8mS
    279           BATTERY_VOLTAGE_Exec( adc12Data[SAMPLE_ARRAY_SIZE-1][1]);
    280           FAST_CURRENT_Exec(adc12Data[SAMPLE_ARRAY_SIZE-1][0]);
     295          BATTERY_VOLTAGE_Exec( adc2Data[SAMPLE_ARRAY_SIZE-1]);
     296          FAST_CURRENT_Exec(adc1Data[SAMPLE_ARRAY_SIZE-1]);
    281297          ESR_FAST_Exec();
    282298          sys_data.s.values.batteryPower = ((int64_t) sys_data.s.values.batteryVoltage * (int64_t)sys_data.s.values.batteryCurrent) / 1000LL;
    283299          sys_data.s.values.power_Fast = ((int64_t) sys_data.s.values.batteryVoltage * (int64_t)sys_data.s.values.fast_current) / 1000LL;
    284           newADC12Data = 0;
     300          newADC124Data = 0;
     301
     302           
    285303         
    286304
    287           if (HAL_ADCEx_MultiModeStart_DMA(&hadc1,(uint32_t *)adc12Data,SAMPLE_ARRAY_SIZE))  //Start ADC interleaved mode
    288       {
    289          /* Start Error */
    290          Error_Handler();
    291       }
     305           if (HAL_ADC_Start_DMA(&hadc1,(uint32_t *)adc1Data,SAMPLE_ARRAY_SIZE))  //Start ADC interleaved mode
     306          {
     307                 /* Start Error */
     308                 Error_Handler();
     309          }
     310
     311          if (HAL_ADC_Start_DMA(&hadc2,(uint32_t *)adc2Data,SAMPLE_ARRAY_SIZE))  //Start ADC interleaved mode
     312          {
     313                 /* Start Error */
     314                 Error_Handler();
     315          }
     316
     317                //  if (HAL_ADC_Start_DMA(&hadc4, (uint32_t *) adc4Data , SAMPLE_ARRAY_SIZE))
     318                //  {             
     319        //       /* Start Error */
     320        //       Error_Handler();
     321        //  }
     322
     323         
     324
    292325
    293326        }
     
    296329    {
    297330          SHUNT_TEMPERATURE_Exec(adc3Data[0]);
    298         }
    299 
    300 
    301         if (newADC4Data == 1)
    302     {
    303           SHUNT_VOLTAGE_Exec( adc4Data[0]);
    304         }
     331          LTC_CURRENT_Exec(adc3Data[1], adc3Data[2]);
     332
     333        }
     334
     335
     336
     337 
     338       
     339       
    305340
    306341
     
    317352    {
    318353      ADS1260_ConversionFinished();
    319       sys_data.s.values.esrCalcStatus = ESR_Exec();
     354      //sys_data.s.values.esrCalcStatus = ESR_Exec();
    320355
    321356      newCurrentValue = 0;
     
    343378          printf("SHORT_CIRCUIT_PROTECTION\n");
    344379          sys_data.s.values.lvpState = OUTPUTS_LVP_SHORT_PROTECTION;
    345           HAL_GPIO_WritePin(DISCHARGE_ENABLE_GPIO_Port, DISCHARGE_ENABLE_Pin, OUTPUTS_DISCHARGE_NOT_ALLOWED);
     380          OUTPUTS_OverwriteDischargeCtrl_DischargeDisabled();
    346381
    347382          sys_data.s.values.lvpState = OUTPUTS_OVP_SHORT_PROTECTION;
    348           HAL_GPIO_WritePin(CHARGE_ENABLE_GPIO_Port, CHARGE_ENABLE_Pin, OUTPUTS_CHARGE_NOT_ALLOWED);
     383          OUTPUTS_OverwriteChargeCtrl_ChargeDisabled();
    349384        }
    350385
     
    410445          case COMMAND_BATTERY_CURRENT_OFFSET_CAL:           
    411446                                ADS_1260_BatteryCurrentOffsetCalibrationStart(&sys_data);
    412                                 CurrentOffsetCal(adc12Data[SAMPLE_ARRAY_SIZE - 1][0]); 
     447                                CurrentOffsetCal(adc1Data[SAMPLE_ARRAY_SIZE - 1]); 
    413448                                break;
    414449          case COMMAND_BATTERY_CURRENT_OFFSET_COMMONMODE_CAL: ADS_1260_BatteryCurrentOffsetCommonModeErrorComepensationStart(&sys_data);  break;
     
    416451          case COMMAND_BATTERY_CURRENT_GAIN_CAL:             
    417452                                ADS_1260_BatteryCurrentGainCalibrationStart(&sys_data);
    418                                 CurrentGainCal(adc12Data[SAMPLE_ARRAY_SIZE - 1][0]);     
     453                                CurrentGainCal(adc1Data[SAMPLE_ARRAY_SIZE - 1]);         
    419454                                break;
    420455          case COMMAND_BATTERY_CURRENT_GAIN_TEMP_SHUNT_CAL:   ADS_1260_BatteryCurrentGainTemperatureCalibrationShuntStart();                      break;
     
    499534  * in the RCC_OscInitTypeDef structure.
    500535  */
    501   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_LSI
    502                               |RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
     536  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48
     537                              |RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE
     538                              |RCC_OSCILLATORTYPE_LSE;
    503539  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
    504540  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
     541  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
     542  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
    505543  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
    506544  RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
     
    616654    if (hadc->Instance==ADC1)
    617655        {
    618           newADC12Data=1;
     656          newADC124Data=1;
    619657        }
    620658
     
    622660        {
    623661          newADC3Data=1;
    624         }
    625 
    626 
    627         if (hadc->Instance==ADC4)
    628         {
    629           newADC4Data=1;
    630662        }
    631663
Note: See TracChangeset for help on using the changeset viewer.