Changeset 22


Ignore:
Timestamp:
Aug 29, 2025, 6:15:42 PM (16 hours ago)
Author:
f.jahn
Message:

DMA Rx funktioniert, aber BETA und nur feste Baudrate

Location:
trunk/fw_g473rct
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/fw_g473rct/Core/Inc/main.h

    r20 r22  
    7070#define ADC2_IN3_UBAT__Pin GPIO_PIN_6
    7171#define ADC2_IN3_UBAT__GPIO_Port GPIOA
    72 #define ADC2_IN4_UBAT__Pin GPIO_PIN_7
    73 #define ADC2_IN4_UBAT__GPIO_Port GPIOA
    7472#define ADC3_IN12_MOSFET_TEMP_Pin GPIO_PIN_0
    7573#define ADC3_IN12_MOSFET_TEMP_GPIO_Port GPIOB
  • trunk/fw_g473rct/Core/Inc/stm32g4xx_it.h

    r20 r22  
    6161void DMA1_Channel4_IRQHandler(void);
    6262void DMA1_Channel5_IRQHandler(void);
     63void DMA1_Channel6_IRQHandler(void);
     64void USART1_IRQHandler(void);
     65void USART2_IRQHandler(void);
    6366/* USER CODE BEGIN EFP */
    6467
  • trunk/fw_g473rct/Core/Src/adc.c

    r20 r22  
    5959  hadc1.Init.GainCompensation = 0;
    6060  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
    61   hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
     61  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
    6262  hadc1.Init.LowPowerAutoWait = DISABLE;
    6363  hadc1.Init.ContinuousConvMode = ENABLE;
     
    6868  hadc1.Init.DMAContinuousRequests = ENABLE;
    6969  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;
    7175  if (HAL_ADC_Init(&hadc1) != HAL_OK)
    7276  {
     
    8892  sConfig.Channel = ADC_CHANNEL_1;
    8993  sConfig.Rank = ADC_REGULAR_RANK_1;
    90   sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
     94  sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
    9195  sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED;
    9296  sConfig.OffsetNumber = ADC_OFFSET_NONE;
     
    123127  hadc2.Init.GainCompensation = 0;
    124128  hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
    125   hadc2.Init.EOCSelection = ADC_EOC_SEQ_CONV;
     129  hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
    126130  hadc2.Init.LowPowerAutoWait = DISABLE;
    127131  hadc2.Init.ContinuousConvMode = ENABLE;
     
    130134  hadc2.Init.DMAContinuousRequests = ENABLE;
    131135  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;
    133141  if (HAL_ADC_Init(&hadc2) != HAL_OK)
    134142  {
     
    140148  sConfig.Channel = ADC_CHANNEL_3;
    141149  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;
    144152  sConfig.OffsetNumber = ADC_OFFSET_NONE;
    145153  sConfig.Offset = 0;
     
    396404    hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
    397405    hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
    398     hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
     406    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    399407    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    400408    hdma_adc1.Init.Mode = DMA_CIRCULAR;
     
    435443    /**ADC2 GPIO Configuration
    436444    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;
    440447    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
    441448    GPIO_InitStruct.Pull = GPIO_NOPULL;
    442     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
     449    HAL_GPIO_Init(ADC2_IN3_UBAT__GPIO_Port, &GPIO_InitStruct);
    443450
    444451    /* ADC2 DMA Init */
     
    449456    hdma_adc2.Init.PeriphInc = DMA_PINC_DISABLE;
    450457    hdma_adc2.Init.MemInc = DMA_MINC_ENABLE;
    451     hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
     458    hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    452459    hdma_adc2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    453460    hdma_adc2.Init.Mode = DMA_CIRCULAR;
     
    665672    /**ADC2 GPIO Configuration
    666673    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);
    670676
    671677    /* ADC2 DMA DeInit */
  • trunk/fw_g473rct/Core/Src/dma.c

    r20 r22  
    6060  HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0);
    6161  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);
    6265
    6366}
  • trunk/fw_g473rct/Core/Src/stm32g4xx_hal_msp.c

    r20 r22  
    7373  /* System interrupt init*/
    7474
     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
    7583  /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
    7684  */
  • trunk/fw_g473rct/Core/Src/stm32g4xx_it.c

    r20 r22  
    2323/* Private includes ----------------------------------------------------------*/
    2424/* USER CODE BEGIN Includes */
     25#include "modbus.h"
    2526/* USER CODE END Includes */
    2627
     
    6162extern DMA_HandleTypeDef hdma_adc4;
    6263extern DMA_HandleTypeDef hdma_adc5;
     64extern DMA_HandleTypeDef hdma_usart2_rx;
     65extern UART_HandleTypeDef huart1;
     66extern UART_HandleTypeDef huart2;
    6367/* USER CODE BEGIN EV */
    6468
     
    273277}
    274278
     279/**
     280  * @brief This function handles DMA1 channel6 global interrupt.
     281  */
     282void 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  */
     296void 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  */
     310void 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
    275321/* USER CODE BEGIN 1 */
    276322
  • trunk/fw_g473rct/Core/Src/usart.c

    r20 r22  
    2727UART_HandleTypeDef huart1;
    2828UART_HandleTypeDef huart2;
     29DMA_HandleTypeDef hdma_usart2_rx;
    2930
    3031/* USART1 init function */
     
    8687  huart2.Instance = USART2;
    8788  huart2.Init.BaudRate = 115200;
    88   huart2.Init.WordLength = UART_WORDLENGTH_8B;
     89  huart2.Init.WordLength = UART_WORDLENGTH_9B;
    8990  huart2.Init.StopBits = UART_STOPBITS_1;
    90   huart2.Init.Parity = UART_PARITY_NONE;
     91  huart2.Init.Parity = UART_PARITY_EVEN;
    9192  huart2.Init.Mode = UART_MODE_TX_RX;
    9293  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
     
    9495  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
    9596  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;
    9799  if (HAL_UART_Init(&huart2) != HAL_OK)
    98100  {
     
    152154    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
    153155
     156    /* USART1 interrupt Init */
     157    HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
     158    HAL_NVIC_EnableIRQ(USART1_IRQn);
    154159  /* USER CODE BEGIN USART1_MspInit 1 */
    155160
     
    186191    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
    187192
     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);
    188214  /* USER CODE BEGIN USART2_MspInit 1 */
    189215
     
    209235    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_4|GPIO_PIN_5);
    210236
     237    /* USART1 interrupt Deinit */
     238    HAL_NVIC_DisableIRQ(USART1_IRQn);
    211239  /* USER CODE BEGIN USART1_MspDeInit 1 */
    212240
     
    227255    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
    228256
     257    /* USART2 DMA DeInit */
     258    HAL_DMA_DeInit(uartHandle->hdmarx);
     259
     260    /* USART2 interrupt Deinit */
     261    HAL_NVIC_DisableIRQ(USART2_IRQn);
    229262  /* USER CODE BEGIN USART2_MspDeInit 1 */
    230263
  • trunk/fw_g473rct/SES/inc/battery_voltage.h

    r20 r22  
    2020
    2121//--- GLOBALE FUNKTIONS PROTOTYPEN ---------------------------------------------
    22 void BATTERY_VOLTAGE_Exec(uint32_t newvalP );
     22void BATTERY_VOLTAGE_Exec(int32_t newvalP );
    2323
    2424#endif //
  • trunk/fw_g473rct/SES/inc/sysdata.h

    r20 r22  
    3333//------------------------------------------------------------------------------
    3434// This structure must be aligned to 4-byte address
    35 typedef struct
     35volatile  typedef struct
    3636{
    3737        // Device spezifisch / Einstellungsbereich
     
    5858        uint16_t ibn_year;                                                                                                                      // 16   Inbetriebnahme Datum: Jahr
    5959        uint16_t user_id;                                                                                                                       // 17   Freies Feld für eine Kunden ID oder ähnlich
    60         uint16_t UNIQUE_NAME(reserved)[8];                                                                                      // 18-25        RESERVIERT
     60        uint16_t test[8];                                                                                       // 18-25        RESERVIERT
    6161
    6262        //--- Konfiguration Schaltausgänge ---
     
    175175        /* 4 of 8 */ uint32_t chargeTotalWh;                                                                            // 156-157      [mAs]
    176176        /* 6 of 8 */ uint16_t fullCyclesCnt;                                                                            // 158
    177         /* 8 of 8 */ uint16_t UNIQUE_NAME(reserved);                                                            // 159
     177        /* 8 of 8 */ uint16_t volatile UNIQUE_NAME(reserved);                                                           // 159
    178178        /* 8 of 8 */ int64_t  mAs_AutoMode;                                                                                     // 160-163
    179179        /* 8 of 8 */ int64_t  mWs_AutoMode;                                                                                     // 164-167
  • trunk/fw_g473rct/SES/smartPro.emProject

    r20 r22  
    11<!DOCTYPE CrossStudio_Project_File>
    22<solution Name="smartPro" target="8" version="2">
     3  <configuration Name="Common" link_merge_sections="No" />
    34  <configuration
    4     Name="Debug"
     5    Name="Debug125A_12V"
    56    c_preprocessor_definitions="DEBUG"
    67    gcc_debugging_level="Level 3"
     
    89    gcc_optimization_level="None" />
    910  <configuration
    10     Name="Release"
     11    Name="Release125A_12V"
    1112    c_preprocessor_definitions="NDEBUG"
    1213    gcc_debugging_level="Level 2"
     
    3334      c_preprocessor_definitions="__VTOR_CONFIG;ARM_MATH_CM4;STM32G473xx;__STM32G473_SUBFAMILY;__STM32G4XX_FAMILY"
    3435      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"
    3537      debug_register_definition_file="$(ProjectDir)/STM32G473xx_Registers.xml"
    3638      debug_stack_pointer_start="__stack_end__"
     
    4547      target_load_end_script="Reset();"
    4648      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" />
    4856    <folder Name="CMSIS Files">
    4957      <file file_name="STM32G4xx/Device/Include/stm32g4xx.h" />
  • trunk/fw_g473rct/SES/src/battery_voltage.c

    r20 r22  
    2121
    2222#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
    2426//      --- LOKALE TYPE DEFS - bitte hier dokumentieren-------------------------------
    2527
     
    3537
    3638
    37 void BATTERY_VOLTAGE_Exec(uint32_t newvalP )
     39void BATTERY_VOLTAGE_Exec(int32_t newvalP )
    3840{
    3941  static int measCounter;
    4042  static unsigned long avgsumP = 0;
    41   uint32_t avgvalP;
     43  int32_t avgvalP;
    4244
    4345  if (measCounter < INT32_MAX) measCounter++;
     
    5355
    5456  //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;
    5658
    5759 
     
    7577  //Berechnung schnellen Wert ohne Glättung:
    7678  //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;
    7880
    7981
  • trunk/fw_g473rct/SES/src/main.c

    r20 r22  
    3737#include "modbus.h"
    3838#include "chip_temperature.h"
     39#include "battery_voltage.h"
     40#include "ads1260.h"
    3941/* USER CODE END Includes */
    4042
     
    5759
    5860/* USER CODE BEGIN PV */
    59 modbus_t modbusData;
    60 #define ADCCONVERTEDVALUES_BUFFER_SIZE 2
    61 __IO uint32_t adc12Data[ADCCONVERTEDVALUES_BUFFER_SIZE] __attribute__((section(".RAM1")));
     61modbus_t modbusData __attribute__((section(".RAM1")));
     62
     63__IO uint16_t adc12Data[2] __attribute__((section(".RAM1")));
    6264__IO uint32_t adc1Data[1] __attribute__((section(".RAM1")));
    6365__IO uint32_t adc2Data[1] __attribute__((section(".RAM1")));
     
    6668__IO uint32_t adc5Data[4] __attribute__((section(".RAM1")));
    6769int silentmode =0;
     70static volatile uint32_t newADC1Data = 0;
     71static volatile uint32_t newADC2Data = 0;
    6872/* USER CODE END PV */
    6973
     
    7175void SystemClock_Config(void);
    7276/* USER CODE BEGIN PFP */
    73 
     77bool SetFlashReadProtection(bool state);
     78uint8_t printprotectionstate(void);
     79bool SetBootFromFlashAndReadOutProtection(void);
    7480/* USER CODE END PFP */
    7581
     
    8894  /* USER CODE BEGIN 1 */
    8995    uint8_t firstStartCatcher;
     96        int mode_button_disable_time=0;
    9097  /* USER CODE END 1 */
    9198
     
    168175 
    169176    //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 mode
     177  if (HAL_ADCEx_MultiModeStart_DMA(&hadc1,(uint32_t *)adc12Data,1))  //Start ADC interleaved mode
    171178  {
    172179     /* Start Error */
     
    189196
    190197    /* 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
    191256        // 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]);
    194259    if (mbGetFrameComplete(&modbusData) == true)
    195260    {
     
    258323
    259324/* 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
     352bool 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
     433bool 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}
     474uint8_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}
    261499
    262500/* USER CODE END 4 */
  • trunk/fw_g473rct/SES/src/modbus.c

    r20 r22  
    6767  #define FAST_BAUDRATE_INTERFRAME_DELAY_us   (1750UL)
    6868  // --- 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;
    7171
    7272
     
    158158   
    159159    // Init aus Cube
    160     mb_data->uart->Instance = USART1;
    161     mb_data->uart->Init.BaudRate = 19200;
     160    mb_data->uart->Instance = USART2;
     161    mb_data->uart->Init.BaudRate = baudrate;
    162162    mb_data->uart->Init.WordLength = UART_WORDLENGTH_9B;
    163163    mb_data->uart->Init.StopBits = UART_STOPBITS_1;
     
    168168    mb_data->uart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
    169169    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
    173174
    174175    // Baudrate
     
    200201    }
    201202    // 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)
    212216    {
    213217      printf("uart error \n\r");
     
    218222  }
    219223
    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
     226void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
    319227{
    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  {
    471230    modbusData.mb_rx_frame_complete = 1;
    472231    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 
    541244}
    542245
    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)
     246void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
    557247{
    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
    584263}
    585264
     
    595274
    596275
    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
    620283
    621284
  • trunk/fw_g473rct/SES/src/sysdata.c

    r20 r22  
    4949
    5050        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
    5155}
  • trunk/fw_g473rct/fw_g473rct.ioc

    r20 r22  
    66ADC1.DMAAccessModeView=ENABLE
    77ADC1.DMAContinuousRequests=ENABLE
    8 ADC1.EOCSelection=ADC_EOC_SEQ_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,CommonPathInternal
     8ADC1.EOCSelection=ADC_EOC_SINGLE_CONV
     9ADC1.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
    1010ADC1.Mode=ADC_DUALMODE_REGSIMULT
    1111ADC1.NbrOfConversionFlag=1
    1212ADC1.OffsetNumber-20\#ChannelRegularConversion=ADC_OFFSET_NONE
    1313ADC1.Overrun=ADC_OVR_DATA_OVERWRITTEN
    14 ADC1.OversamplingMode=DISABLE
     14ADC1.OversamplingMode=ENABLE
    1515ADC1.Rank-20\#ChannelRegularConversion=1
    16 ADC1.SamplingTime-20\#ChannelRegularConversion=ADC_SAMPLETIME_2CYCLES_5
     16ADC1.Ratio=ADC_OVERSAMPLING_RATIO_256
     17ADC1.RightBitShift=ADC_RIGHTBITSHIFT_4
     18ADC1.SamplingTime-20\#ChannelRegularConversion=ADC_SAMPLETIME_640CYCLES_5
    1719ADC1.SingleDiff-20\#ChannelRegularConversion=ADC_DIFFERENTIAL_ENDED
    1820ADC1.master=1
     
    2224ADC2.DMAAccessModeView=ENABLE
    2325ADC2.DMAContinuousRequests=ENABLE
    24 ADC2.EOCSelection=ADC_EOC_SEQ_CONV
    25 ADC2.IPParameters=Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,SingleDiff-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion,OffsetNumber-4\#ChannelRegularConversion,NbrOfConversionFlag,Mode,DMAAccessModeView,EOCSelection,DMAContinuousRequests,Overrun,ClockPrescaler,CommonPathInternal
     26ADC2.EOCSelection=ADC_EOC_SINGLE_CONV
     27ADC2.IPParameters=Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion,OffsetNumber-4\#ChannelRegularConversion,NbrOfConversionFlag,Mode,DMAAccessModeView,EOCSelection,DMAContinuousRequests,Overrun,ClockPrescaler,OversamplingMode,RightBitShift,Ratio,CommonPathInternal
    2628ADC2.Mode=ADC_DUALMODE_REGSIMULT
    2729ADC2.NbrOfConversionFlag=1
    2830ADC2.OffsetNumber-4\#ChannelRegularConversion=ADC_OFFSET_NONE
    2931ADC2.Overrun=ADC_OVR_DATA_OVERWRITTEN
     32ADC2.OversamplingMode=ENABLE
    3033ADC2.Rank-4\#ChannelRegularConversion=1
    31 ADC2.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLETIME_2CYCLES_5
    32 ADC2.SingleDiff-4\#ChannelRegularConversion=ADC_DIFFERENTIAL_ENDED
     34ADC2.Ratio=ADC_OVERSAMPLING_RATIO_256
     35ADC2.RightBitShift=ADC_RIGHTBITSHIFT_4
     36ADC2.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLETIME_640CYCLES_5
    3337ADC3.Channel-1\#ChannelRegularConversion=ADC_CHANNEL_1
    3438ADC3.ClockPrescaler=ADC_CLOCK_ASYNC_DIV256
     
    8690Dma.ADC1.0.MemInc=DMA_MINC_ENABLE
    8791Dma.ADC1.0.Mode=DMA_CIRCULAR
    88 Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
     92Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_WORD
    8993Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE
    9094Dma.ADC1.0.Polarity=HAL_DMAMUX_REQ_GEN_RISING
     
    103107Dma.ADC2.1.MemInc=DMA_MINC_ENABLE
    104108Dma.ADC2.1.Mode=DMA_CIRCULAR
    105 Dma.ADC2.1.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
     109Dma.ADC2.1.PeriphDataAlignment=DMA_PDATAALIGN_WORD
    106110Dma.ADC2.1.PeriphInc=DMA_PINC_DISABLE
    107111Dma.ADC2.1.Polarity=HAL_DMAMUX_REQ_GEN_RISING
     
    170174Dma.Request3=ADC4
    171175Dma.Request4=ADC5
    172 Dma.RequestsNb=5
     176Dma.Request5=USART2_RX
     177Dma.RequestsNb=6
     178Dma.USART2_RX.5.Direction=DMA_PERIPH_TO_MEMORY
     179Dma.USART2_RX.5.EventEnable=DISABLE
     180Dma.USART2_RX.5.Instance=DMA1_Channel6
     181Dma.USART2_RX.5.MemDataAlignment=DMA_MDATAALIGN_BYTE
     182Dma.USART2_RX.5.MemInc=DMA_MINC_ENABLE
     183Dma.USART2_RX.5.Mode=DMA_NORMAL
     184Dma.USART2_RX.5.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
     185Dma.USART2_RX.5.PeriphInc=DMA_PINC_DISABLE
     186Dma.USART2_RX.5.Polarity=HAL_DMAMUX_REQ_GEN_RISING
     187Dma.USART2_RX.5.Priority=DMA_PRIORITY_LOW
     188Dma.USART2_RX.5.RequestNumber=1
     189Dma.USART2_RX.5.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber
     190Dma.USART2_RX.5.SignalID=NONE
     191Dma.USART2_RX.5.SyncEnable=DISABLE
     192Dma.USART2_RX.5.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT
     193Dma.USART2_RX.5.SyncRequestNumber=1
     194Dma.USART2_RX.5.SyncSignalID=NONE
    173195FDCAN2.CalculateBaudRateNominal=2083333
    174196FDCAN2.CalculateTimeBitNominal=480
     
    216238Mcu.Pin12=PA5
    217239Mcu.Pin13=PA6
    218 Mcu.Pin14=PA7
    219 Mcu.Pin15=PC4
    220 Mcu.Pin16=PC5
    221 Mcu.Pin17=PB0
    222 Mcu.Pin18=PB1
    223 Mcu.Pin19=PB10
     240Mcu.Pin14=PC4
     241Mcu.Pin15=PC5
     242Mcu.Pin16=PB0
     243Mcu.Pin17=PB1
     244Mcu.Pin18=PB10
     245Mcu.Pin19=PB11
    224246Mcu.Pin2=PC15-OSC32_OUT
    225 Mcu.Pin20=PB11
    226 Mcu.Pin21=PB12
    227 Mcu.Pin22=PB13
    228 Mcu.Pin23=PB14
    229 Mcu.Pin24=PB15
    230 Mcu.Pin25=PC6
    231 Mcu.Pin26=PC7
    232 Mcu.Pin27=PC8
    233 Mcu.Pin28=PC9
    234 Mcu.Pin29=PA8
     247Mcu.Pin20=PB12
     248Mcu.Pin21=PB13
     249Mcu.Pin22=PB14
     250Mcu.Pin23=PB15
     251Mcu.Pin24=PC6
     252Mcu.Pin25=PC7
     253Mcu.Pin26=PC8
     254Mcu.Pin27=PC9
     255Mcu.Pin28=PA8
     256Mcu.Pin29=PA9
    235257Mcu.Pin3=PF0-OSC_IN
    236 Mcu.Pin30=PA9
    237 Mcu.Pin31=PA10
    238 Mcu.Pin32=PA11
    239 Mcu.Pin33=PA12
    240 Mcu.Pin34=PA13
    241 Mcu.Pin35=PA14
    242 Mcu.Pin36=PA15
    243 Mcu.Pin37=PC10
    244 Mcu.Pin38=PC11
    245 Mcu.Pin39=PC12
     258Mcu.Pin30=PA10
     259Mcu.Pin31=PA11
     260Mcu.Pin32=PA12
     261Mcu.Pin33=PA13
     262Mcu.Pin34=PA14
     263Mcu.Pin35=PA15
     264Mcu.Pin36=PC10
     265Mcu.Pin37=PC11
     266Mcu.Pin38=PC12
     267Mcu.Pin39=PD2
    246268Mcu.Pin4=PF1-OSC_OUT
    247 Mcu.Pin40=PD2
    248 Mcu.Pin41=PB3
    249 Mcu.Pin42=PB4
    250 Mcu.Pin43=PB5
    251 Mcu.Pin44=PB6
    252 Mcu.Pin45=PB7
    253 Mcu.Pin46=PB9
    254 Mcu.Pin47=VP_ADC5_TempSens_Input
    255 Mcu.Pin48=VP_ADC5_Vbat_Input
    256 Mcu.Pin49=VP_CRC_VS_CRC
     269Mcu.Pin40=PB3
     270Mcu.Pin41=PB4
     271Mcu.Pin42=PB5
     272Mcu.Pin43=PB6
     273Mcu.Pin44=PB7
     274Mcu.Pin45=PB9
     275Mcu.Pin46=VP_ADC5_TempSens_Input
     276Mcu.Pin47=VP_ADC5_Vbat_Input
     277Mcu.Pin48=VP_CRC_VS_CRC
     278Mcu.Pin49=VP_SYS_V_VREFBUF
    257279Mcu.Pin5=PC0
    258280Mcu.Pin50=VP_SYS_VS_Systick
     
    274296NVIC.DMA1_Channel4_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
    275297NVIC.DMA1_Channel5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
     298NVIC.DMA1_Channel6_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
    276299NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
    277300NVIC.ForceEnableDMAVector=true
     
    283306NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
    284307NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
     308NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
     309NVIC.USART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
    285310NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
    286311PA0.Locked=true
     
    322347PA6.GPIOParameters=GPIO_Label
    323348PA6.GPIO_Label=ADC2_IN3_UBAT+
    324 PA6.Mode=IN3-Differential
     349PA6.Mode=IN3-Single-Ended
    325350PA6.Signal=ADC2_IN3
    326 PA7.GPIOParameters=GPIO_Label
    327 PA7.GPIO_Label=ADC2_IN4_UBAT-
    328 PA7.Mode=IN3-Differential
    329 PA7.Signal=ADC2_IN4
    330351PA8.GPIOParameters=GPIO_Label
    331352PA8.GPIO_Label=LVP_SENSE
     
    524545USART1.Parity=PARITY_EVEN
    525546USART1.VirtualMode-Asynchronous=VM_ASYNC
    526 USART2.IPParameters=VirtualMode-Asynchronous
     547USART2.BaudRate=115200
     548USART2.IPParameters=VirtualMode-Asynchronous,Parity,BaudRate,SwapParam,WordLength
     549USART2.Parity=PARITY_EVEN
     550USART2.SwapParam=ADVFEATURE_SWAP_ENABLE
    527551USART2.VirtualMode-Asynchronous=VM_ASYNC
     552USART2.WordLength=WORDLENGTH_9B
    528553VP_ADC5_TempSens_Input.Mode=IN-TempSens
    529554VP_ADC5_TempSens_Input.Signal=ADC5_TempSens_Input
     
    536561VP_SYS_VS_Systick.Mode=SysTick
    537562VP_SYS_VS_Systick.Signal=SYS_VS_Systick
     563VP_SYS_V_VREFBUF.Mode=ExternalMode
     564VP_SYS_V_VREFBUF.Signal=SYS_V_VREFBUF
    538565board=custom
Note: See TracChangeset for help on using the changeset viewer.