Ignore:
Timestamp:
Apr 2, 2026, 3:56:21 PM (5 weeks ago)
Author:
f.jahn
Message:
  • USB-PD function was implemented;
  • HW parity check on RAM was activated;
  • USB Device CDC mode was activated.
Location:
trunk/fw_g473rct/Core/Src
Files:
2 edited

Legend:

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

    r55 r65  
    5959
    6060  /*Configure GPIO pin Output Level */
    61   HAL_GPIO_WritePin(GPIOB, LED_ERROR_Pin|BUZZER_Pin, GPIO_PIN_RESET);
     61  HAL_GPIO_WritePin(GPIOB, LED_ERROR_Pin|BUZZER_Pin|UCPD1_VBUS_Pin, GPIO_PIN_RESET);
    6262
    6363  /*Configure GPIO pins : AUX_EN_Pin ADC_START_CONV_Pin ADC_RESET_Pin */
     
    7575  HAL_GPIO_Init(LED_FUNCTION_GPIO_Port, &GPIO_InitStruct);
    7676
    77   /*Configure GPIO pins : LED_ERROR_Pin BUZZER_Pin */
    78   GPIO_InitStruct.Pin = LED_ERROR_Pin|BUZZER_Pin;
     77  /*Configure GPIO pins : LED_ERROR_Pin BUZZER_Pin UCPD1_VBUS_Pin */
     78  GPIO_InitStruct.Pin = LED_ERROR_Pin|BUZZER_Pin|UCPD1_VBUS_Pin;
    7979  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    8080  GPIO_InitStruct.Pull = GPIO_NOPULL;
  • trunk/fw_g473rct/Core/Src/main.c

    r55 r65  
    5656#include "self_discharge.h"
    5757#include "ltc_current.h"
     58#include "usbd_cdc_if.h"
    5859
    5960/* USER CODE END Includes */
     
    7172#define MX_IWDG_Init DoNothing
    7273#endif
     74//#define USBPD_DPM_Run DoNothing
    7375
    7476/* USER CODE END PD */
     
    8587uint32_t bootLoaderMark __attribute__((section(".no_init")));
    8688
    87 modbus_t modbusData __attribute__((section(".RAM1")));
    88 
    89 
    90 __IO uint32_t adc1Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1")));
    91 __IO uint32_t adc2Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1")));
    92 __IO uint32_t adc3Data[3] __attribute__((section(".RAM1")));
    93 __IO uint32_t adc4Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1")));
    94 __IO uint32_t adc5Data[4] __attribute__((section(".RAM1")));
     89modbus_t modbusData;
     90
     91
     92__IO uint32_t adc1Data[SAMPLE_ARRAY_SIZE];
     93__IO uint32_t adc2Data[SAMPLE_ARRAY_SIZE];
     94__IO uint32_t adc3Data[3];
     95__IO uint32_t adc4Data[SAMPLE_ARRAY_SIZE];
     96__IO uint32_t adc5Data[4];
    9597int silentmode =0;
    9698static volatile uint32_t newADC124Data = 0;
     
    109111void SaveBackupRegister(void);
    110112void JumpToBootloader(void);
     113void CheckRAMHWParity(void);
    111114void DoNothing(void){};
    112115/* USER CODE END PFP */
     
    125128
    126129  /* USER CODE BEGIN 1 */
     130
     131  CheckRAMHWParity();
    127132
    128133  if (bootLoaderMark == GOTO_SYSTEM_BOOTLOADER_MARK)
     
    223228  //HAL_DMA_Start(hadc2.DMA_Handle,(uint32_t)&hadc2.Instance->DR, (uint32_t)adc2Data,1); //Start ADC slave DMA
    224229  //SET_BIT(hadc1.Instance->CFGR, ADC_CFGR_DMAEN); //Enable DMA transfer for ADC master (ADC12_CCR.MDMA = 0b00 -> MDMA mode disabled)
    225   if (HAL_ADC_Start_DMA(&hadc1,(uint32_t *)adc1Data,SAMPLE_ARRAY_SIZE))  //Start ADC interleaved mode
    226   {
    227      /* Start Error */
    228      Error_Handler();
    229   }
    230  
    231   if (HAL_ADC_Start_DMA(&hadc2,(uint32_t *)adc2Data,SAMPLE_ARRAY_SIZE))  //Start ADC interleaved mode
    232   {
    233      /* Start Error */
    234      Error_Handler();
    235   }
    236 
    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))
    244   {
    245      /* Start Error */
    246      Error_Handler();
    247   }
    248 
    249 
    250   if (HAL_ADC_Start_DMA(&hadc5, (uint32_t *) adc5Data , 4))
    251   {
    252      /* Start Error */
    253      Error_Handler();
    254   }
     230  if (HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc1Data,SAMPLE_ARRAY_SIZE))         Error_Handler();          // Start ADC interleaved mode
     231  if (HAL_ADC_Start_DMA(&hadc2, (uint32_t*)adc2Data,SAMPLE_ARRAY_SIZE))         Error_Handler();          // Start ADC interleaved mode
     232  if (HAL_ADC_Start_DMA(&hadc3, (uint32_t*)adc3Data, 3))                                        Error_Handler();
     233  if (HAL_ADC_Start_DMA(&hadc4, (uint32_t*)adc4Data, SAMPLE_ARRAY_SIZE))        Error_Handler();
     234  if (HAL_ADC_Start_DMA(&hadc5, (uint32_t*)adc5Data, 4))                                        Error_Handler();
    255235
    256236  // ADS1260 Initialierung
     
    300280          newADC124Data = 0;
    301281
    302            
    303          
    304 
    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 
    325 
     282          if (HAL_ADC_Start_DMA(&hadc1,(uint32_t*)adc1Data,SAMPLE_ARRAY_SIZE)) Error_Handler(); //Start ADC interleaved mode
     283          if (HAL_ADC_Start_DMA(&hadc2,(uint32_t*)adc2Data,SAMPLE_ARRAY_SIZE)) Error_Handler(); //Start ADC interleaved mode
    326284        }
    327285
     
    330288          SHUNT_TEMPERATURE_Exec(adc3Data[0]);
    331289          LTC_CURRENT_Exec(adc3Data[1], adc3Data[2]);
    332 
    333         }
    334 
    335 
    336 
    337  
    338        
    339        
    340 
     290        }
    341291
    342292        if (newADC5Data == 1)
     
    348298        }
    349299
    350 
    351300        if (newCurrentValue == 1)
    352301    {
     
    355304
    356305      newCurrentValue = 0;
    357 
    358306    }
    359307
    360        
    361        
     308               
    362309        // Zeitbasis ms Systick;
    363310    newTime = HAL_GetTick();
    364311   
    365         if (newTime != oldTime) {
    366          
     312        if (newTime != oldTime)
     313        {
    367314          oldTime = newTime;
    368315     
     
    406353      }
    407354
    408 
    409355      // Amperestundenzhler
    410356      AH_COUNTER_Exec();
     
    426372
    427373      sys_data.s.values.efficiency = EFFICIENCY_Exec();
     374
     375#ifdef DEBUG
     376          if (sys_data.s.values.onTime % 5U == 0U)
     377          {
     378                  static char* Buf = "Hello everybody!\r\n";
     379                  const unsigned BufLen = strlen(Buf);
     380                  CDC_Transmit_FS((uint8_t*)Buf, BufLen - 1);
     381          }
     382#endif
    428383    }
    429384
     
    610565}
    611566
     567//------------------------------------------------------------------------------
    612568
    613569void SaveBackupRegister(void)
     
    668624 }
    669625
    670 
     626//------------------------------------------------------------------------------
    671627 
    672628/**
     
    756712      printf("Flash  locked\n");
    757713      printf("...Disable lock process finished\n");
    758 
    759 ;
    760714    }
    761715  }
    762716  return true;
    763717}
     718
     719//------------------------------------------------------------------------------
     720
     721void CheckRAMHWParity(void)
     722{
     723        if (FLASH->OPTR & FLASH_OPTR_SRAM_PE)
     724        {       // RAM HW Parity is not activated
     725                if (HAL_OK != HAL_FLASH_Unlock())
     726                {
     727#ifdef DEBUG
     728                        printf("Cannot unlock FLASH!\n");
     729#endif
     730                        return;
     731                }
     732
     733                __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);                                                             // Clear OPTVERR bit set on virgin samples
     734
     735                if (HAL_OK != HAL_FLASH_OB_Unlock())
     736                {
     737#ifdef DEBUG
     738                        printf("Cannot unlock Option Bytes!\n");
     739#endif
     740                        return;
     741                }
     742
     743                // Activating SRAM1(first 32Kb) and CCM SRAM parity check (see RM0440, page 139)
     744                FLASH->OPTR &= ~FLASH_OPTR_SRAM_PE;
     745        while (FLASH->SR & FLASH_SR_BSY) {};
     746        FLASH->CR |= FLASH_CR_OPTSTRT;
     747        while (FLASH->SR & FLASH_SR_BSY) {};
     748        // Updating option bytes by resetting of the device
     749        FLASH->CR |= FLASH_CR_OBL_LAUNCH;
     750                while (1)
     751#ifdef DEBUG
     752                  printf("Option Bytes write ERROR!\n")
     753#endif
     754                ;
     755        }
     756}
     757
     758//------------------------------------------------------------------------------
    764759
    765760bool SetBootFromFlashAndReadOutProtection(void)
     
    769764  HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);
    770765
    771   //Konfiguriere RDP fr Readoutprotection and USER OPTION BYTE FR Boot from Flash
     766  //Set Readout Protection Level 1
    772767  OptionsBytesStruct.OptionType = OPTIONBYTE_USER | OPTIONBYTE_RDP;
    773 
    774   //Set Readout Protection Level 1
    775   OptionsBytesStruct.OptionType = OPTIONBYTE_USER|OPTIONBYTE_RDP;
    776768  OptionsBytesStruct.RDPLevel   = OB_RDP_LEVEL_1;
    777769
     
    780772  OptionsBytesStruct.USERConfig  = OB_USER_nBOOT0 | OB_USER_nSWBOOT0;
    781773
    782   if (HAL_FLASH_Unlock() != HAL_OK)
    783   {
    784     printf("Flash unlock error\n");
    785   }
    786   if (HAL_FLASH_OB_Unlock() != HAL_OK)
    787   {
    788     printf("Flash ob unlock error\n");
    789   }
     774  if (HAL_FLASH_Unlock() != HAL_OK) printf("Flash unlock error\n");
     775  if (HAL_FLASH_OB_Unlock() != HAL_OK) printf("Flash ob unlock error\n");
    790776
    791777  printf("...Flash unlock\n");
     
    804790  return true;
    805791}
     792
     793//------------------------------------------------------------------------------
     794
    806795uint8_t printprotectionstate(void)
    807796{
Note: See TracChangeset for help on using the changeset viewer.