Changeset 23


Ignore:
Timestamp:
Aug 29, 2025, 7:18:36 PM (10 hours ago)
Author:
f.jahn
Message:

modbus via DMA still BETA, aber bautratenumschaltung implementiert

Location:
trunk/fw_g473rct
Files:
9 edited

Legend:

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

    r22 r23  
    6262void DMA1_Channel5_IRQHandler(void);
    6363void DMA1_Channel6_IRQHandler(void);
     64void DMA1_Channel7_IRQHandler(void);
    6465void USART1_IRQHandler(void);
    6566void USART2_IRQHandler(void);
  • trunk/fw_g473rct/Core/Src/dma.c

    r22 r23  
    6363  HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0);
    6464  HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
     65  /* DMA1_Channel7_IRQn interrupt configuration */
     66  HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 0, 0);
     67  HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);
    6568
    6669}
  • trunk/fw_g473rct/Core/Src/stm32g4xx_it.c

    r22 r23  
    6363extern DMA_HandleTypeDef hdma_adc5;
    6464extern DMA_HandleTypeDef hdma_usart2_rx;
     65extern DMA_HandleTypeDef hdma_usart2_tx;
    6566extern UART_HandleTypeDef huart1;
    6667extern UART_HandleTypeDef huart2;
     
    292293
    293294/**
     295  * @brief This function handles DMA1 channel7 global interrupt.
     296  */
     297void DMA1_Channel7_IRQHandler(void)
     298{
     299  /* USER CODE BEGIN DMA1_Channel7_IRQn 0 */
     300
     301  /* USER CODE END DMA1_Channel7_IRQn 0 */
     302  HAL_DMA_IRQHandler(&hdma_usart2_tx);
     303  /* USER CODE BEGIN DMA1_Channel7_IRQn 1 */
     304
     305  /* USER CODE END DMA1_Channel7_IRQn 1 */
     306}
     307
     308/**
    294309  * @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25.
    295310  */
  • trunk/fw_g473rct/Core/Src/usart.c

    r22 r23  
    2828UART_HandleTypeDef huart2;
    2929DMA_HandleTypeDef hdma_usart2_rx;
     30DMA_HandleTypeDef hdma_usart2_tx;
    3031
    3132/* USART1 init function */
     
    8687  /* USER CODE END USART2_Init 1 */
    8788  huart2.Instance = USART2;
    88   huart2.Init.BaudRate = 115200;
     89  huart2.Init.BaudRate = 19200;
    8990  huart2.Init.WordLength = UART_WORDLENGTH_9B;
    9091  huart2.Init.StopBits = UART_STOPBITS_1;
     
    209210    __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart2_rx);
    210211
     212    /* USART2_TX Init */
     213    hdma_usart2_tx.Instance = DMA1_Channel7;
     214    hdma_usart2_tx.Init.Request = DMA_REQUEST_USART2_TX;
     215    hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
     216    hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE;
     217    hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE;
     218    hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
     219    hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
     220    hdma_usart2_tx.Init.Mode = DMA_NORMAL;
     221    hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW;
     222    if (HAL_DMA_Init(&hdma_usart2_tx) != HAL_OK)
     223    {
     224      Error_Handler();
     225    }
     226
     227    __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx);
     228
    211229    /* USART2 interrupt Init */
    212230    HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
     
    257275    /* USART2 DMA DeInit */
    258276    HAL_DMA_DeInit(uartHandle->hdmarx);
     277    HAL_DMA_DeInit(uartHandle->hdmatx);
    259278
    260279    /* USART2 interrupt Deinit */
  • trunk/fw_g473rct/SES/inc/sysdata.h

    r22 r23  
    3333//------------------------------------------------------------------------------
    3434// This structure must be aligned to 4-byte address
    35 volatile  typedef struct
     35typedef struct
    3636{
    3737        // Device spezifisch / Einstellungsbereich
  • trunk/fw_g473rct/SES/src/main.c

    r22 r23  
    202202
    203203
    204             if(sys_data.s.parameter.command != 0)
     204        if(sys_data.s.parameter.command != 0)
    205205    {
    206206      if  (modbusData.current_query ==  MB_QUERY_NOTHING)
  • trunk/fw_g473rct/SES/src/modbus.c

    r22 r23  
    6767  #define FAST_BAUDRATE_INTERFRAME_DELAY_us   (1750UL)
    6868  // --- Externe Variablen --------------------------------------------
    69   extern volatile modbus_t modbusData;
    70   extern volatile sys_data_t sys_data;
     69  extern modbus_t modbusData;
     70  extern sys_data_t sys_data;
    7171
    7272
     
    109109    if (stopBits < 1U || stopBits > 2U) stopBits = 1U;
    110110
    111     // Berechne Stop Bits
    112     /*if ((parityMode== MODBUS_UART_PARITY_EVEN) || (parityMode == MODBUS_UART_PARITY_ODD))
    113     {
    114       stopBits = 1;
    115     }
    116     else
    117     {
    118       stopBits = 2;
    119     }*/
    120  
     111
    121112    // Berechne Anzahl der Bits per Char
    122113    numberOfBitsPerChar = NUMBER_OF_STARTBITS + NUMBER_OF_DATABITS + stopBits;
     
    157148    mb_data->uart      = usart;
    158149   
    159     // Init aus Cube
    160     mb_data->uart->Instance = USART2;
    161     mb_data->uart->Init.BaudRate = baudrate;
    162     mb_data->uart->Init.WordLength = UART_WORDLENGTH_9B;
    163     mb_data->uart->Init.StopBits = UART_STOPBITS_1;
    164     mb_data->uart->Init.Parity = UART_PARITY_EVEN;
    165     mb_data->uart->Init.Mode = UART_MODE_TX_RX;
    166     mb_data->uart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
    167     mb_data->uart->Init.OverSampling = UART_OVERSAMPLING_16;
    168     mb_data->uart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
    169     mb_data->uart->Init.ClockPrescaler = UART_PRESCALER_DIV1;
    170     mb_data->uart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT;
    171         mb_data->uart->AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE;
    172    
    173     // Init änderungen
    174 
    175150    // Baudrate
    176151    mb_data->uart->Init.BaudRate   = baudrate;
     152
    177153    // Parity Mode // Word length
    178154    if(parityMode == MODBUS_UART_PARITY_EVEN)
     
    191167       mb_data->uart->Init.WordLength = UART_WORDLENGTH_8B;
    192168    }
     169
    193170    // Stopbits
    194171    if (stopBits == 1)
     
    200177      mb_data->uart->Init.StopBits = UART_STOPBITS_2;
    201178    }
    202     // Init
    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    // }
     179
     180        if (HAL_UART_Init(mb_data->uart) != HAL_OK)
     181        {
     182          Error_Handler();
     183        }
     184       
    211185        uint32_t fixedDelayInBitDurations = (FAST_BAUDRATE_INTERFRAME_DELAY_us * baudrate) / 1000000UL + 1UL;
    212186//      HAL_UART_EnableReceiverTimeout( usart);
     
    226200void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
    227201{
     202    modbusData.mb_rx_frame_complete = 1;
     203    modbusData.setRxLed = false;
     204        modbusData.rx_head= 0;
     205
     206
    228207  if (huart->ErrorCode == HAL_UART_ERROR_RTO)
    229208  {
    230     modbusData.mb_rx_frame_complete = 1;
    231     modbusData.setRxLed = true;
    232         modbusData.rx_head= 8;
    233209        printf("MB RTO Event! \n\r");
    234210  }
     211  if (huart->ErrorCode == HAL_UART_ERROR_FE)
     212  {
     213        printf("MB FE Error! \n\r");
     214  }
     215 
     216  if (huart->ErrorCode == HAL_UART_ERROR_PE)
     217  {
     218        printf("MB PE Error! \n\r");
     219  }
     220
     221  if (huart->ErrorCode == HAL_UART_ERROR_NE)
     222  {
     223        printf("MB NE Error! \n\r");
     224  }
     225
     226  if (huart->ErrorCode == HAL_UART_ERROR_DMA)
     227  {
     228        printf("MB DMA Error! \n\r");
     229  }
     230
     231  if (huart->ErrorCode == HAL_UART_ERROR_DMA)
     232  {
     233        printf("MB DMA Error! \n\r");
     234  }
     235
     236  if (huart->ErrorCode == HAL_UART_ERROR_ORE)
     237  {
     238        printf("MB ORE Error! \n\r");
     239  }
     240
     241
     242  if(HAL_UARTEx_ReceiveToIdle_DMA(huart, huart->pRxBuffPtr, RXBUFFERSIZE) != HAL_OK)
     243   {
     244     printf("Uart Error bei neustart nach Fehler \n\r");
     245  //   while(1)
     246  //   {
     247  //   }     
     248   }   
     249 
     250}
     251
     252void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
     253{
     254  //printf("MB rxEvent!RX=%d \n\r",Size);
     255  modbusData.setRxLed = true;
     256
     257  modbusData.mb_rx_frame_complete = 1;
     258  modbusData.rx_head= Size +1;
    235259
    236260  if(HAL_UARTEx_ReceiveToIdle_DMA(huart, huart->pRxBuffPtr, RXBUFFERSIZE) != HAL_OK)
     
    242266   }   
    243267 
     268
    244269}
    245270
    246 void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
     271void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
    247272{
    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  
     273  //printf("uart complete \n\r");
     274  modbusData.current_query = MB_QUERY_NOTHING;
    262275
    263276}
     
    286299  {   
    287300    mb_data->current_query = MB_QUERY_SEND_DATA;
    288     HAL_UART_Transmit_IT(mb_data->uart, mb_data->tx_buffer, mb_data->tx_head);
     301    HAL_UART_Transmit_DMA(mb_data->uart, mb_data->tx_buffer, mb_data->tx_head);
    289302  }
    290303
  • trunk/fw_g473rct/SES/src/sysdata.c

    r22 r23  
    77#include "sysdata.h"
    88
    9 volatile sys_data_t sys_data;
     9sys_data_t sys_data;
    1010
    1111void SYS_DATA_Init(void)
  • trunk/fw_g473rct/fw_g473rct.ioc

    r22 r23  
    175175Dma.Request4=ADC5
    176176Dma.Request5=USART2_RX
    177 Dma.RequestsNb=6
     177Dma.Request6=USART2_TX
     178Dma.RequestsNb=7
    178179Dma.USART2_RX.5.Direction=DMA_PERIPH_TO_MEMORY
    179180Dma.USART2_RX.5.EventEnable=DISABLE
     
    193194Dma.USART2_RX.5.SyncRequestNumber=1
    194195Dma.USART2_RX.5.SyncSignalID=NONE
     196Dma.USART2_TX.6.Direction=DMA_MEMORY_TO_PERIPH
     197Dma.USART2_TX.6.EventEnable=DISABLE
     198Dma.USART2_TX.6.Instance=DMA1_Channel7
     199Dma.USART2_TX.6.MemDataAlignment=DMA_MDATAALIGN_BYTE
     200Dma.USART2_TX.6.MemInc=DMA_MINC_ENABLE
     201Dma.USART2_TX.6.Mode=DMA_NORMAL
     202Dma.USART2_TX.6.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
     203Dma.USART2_TX.6.PeriphInc=DMA_PINC_DISABLE
     204Dma.USART2_TX.6.Polarity=HAL_DMAMUX_REQ_GEN_RISING
     205Dma.USART2_TX.6.Priority=DMA_PRIORITY_LOW
     206Dma.USART2_TX.6.RequestNumber=1
     207Dma.USART2_TX.6.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber
     208Dma.USART2_TX.6.SignalID=NONE
     209Dma.USART2_TX.6.SyncEnable=DISABLE
     210Dma.USART2_TX.6.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT
     211Dma.USART2_TX.6.SyncRequestNumber=1
     212Dma.USART2_TX.6.SyncSignalID=NONE
    195213FDCAN2.CalculateBaudRateNominal=2083333
    196214FDCAN2.CalculateTimeBitNominal=480
     
    297315NVIC.DMA1_Channel5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
    298316NVIC.DMA1_Channel6_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
     317NVIC.DMA1_Channel7_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
    299318NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
    300319NVIC.ForceEnableDMAVector=true
     
    545564USART1.Parity=PARITY_EVEN
    546565USART1.VirtualMode-Asynchronous=VM_ASYNC
    547 USART2.BaudRate=115200
     566USART2.BaudRate=19200
    548567USART2.IPParameters=VirtualMode-Asynchronous,Parity,BaudRate,SwapParam,WordLength
    549568USART2.Parity=PARITY_EVEN
Note: See TracChangeset for help on using the changeset viewer.