FDCAN Timings and settings correctly configured
This commit is contained in:
		@ -3,7 +3,7 @@
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#define N_SLAVES 3
 | 
			
		||||
#define N_SLAVES 1
 | 
			
		||||
#define N_CELLS_SERIES 15
 | 
			
		||||
#define N_CELLS_PARALLEL 4
 | 
			
		||||
#define N_TEMP_SENSORS 32
 | 
			
		||||
 | 
			
		||||
@ -107,7 +107,7 @@
 | 
			
		||||
  *        (when HSE is used as system clock source, directly or through the PLL).
 | 
			
		||||
  */
 | 
			
		||||
#if !defined  (HSE_VALUE)
 | 
			
		||||
#define HSE_VALUE    (24000000UL) /*!< Value of the External oscillator in Hz : FPGA case fixed to 60MHZ */
 | 
			
		||||
#define HSE_VALUE    (16000000UL) /*!< Value of the External oscillator in Hz : FPGA case fixed to 60MHZ */
 | 
			
		||||
#endif /* HSE_VALUE */
 | 
			
		||||
 | 
			
		||||
#if !defined  (HSE_STARTUP_TIMEOUT)
 | 
			
		||||
 | 
			
		||||
@ -55,6 +55,7 @@ void SVC_Handler(void);
 | 
			
		||||
void DebugMon_Handler(void);
 | 
			
		||||
void PendSV_Handler(void);
 | 
			
		||||
void SysTick_Handler(void);
 | 
			
		||||
void FDCAN1_IT0_IRQHandler(void);
 | 
			
		||||
/* USER CODE BEGIN EFP */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END EFP */
 | 
			
		||||
 | 
			
		||||
@ -178,14 +178,13 @@ void SystemClock_Config(void)
 | 
			
		||||
  /** Initializes the RCC Oscillators according to the specified parameters
 | 
			
		||||
  * in the RCC_OscInitTypeDef structure.
 | 
			
		||||
  */
 | 
			
		||||
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_CSI|RCC_OSCILLATORTYPE_HSI;
 | 
			
		||||
  RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
 | 
			
		||||
  RCC_OscInitStruct.HSICalibrationValue = 64;
 | 
			
		||||
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_CSI|RCC_OSCILLATORTYPE_HSE;
 | 
			
		||||
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
 | 
			
		||||
  RCC_OscInitStruct.CSIState = RCC_CSI_ON;
 | 
			
		||||
  RCC_OscInitStruct.CSICalibrationValue = 16;
 | 
			
		||||
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 | 
			
		||||
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
 | 
			
		||||
  RCC_OscInitStruct.PLL.PLLM = 4;
 | 
			
		||||
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
 | 
			
		||||
  RCC_OscInitStruct.PLL.PLLM = 1;
 | 
			
		||||
  RCC_OscInitStruct.PLL.PLLN = 8;
 | 
			
		||||
  RCC_OscInitStruct.PLL.PLLP = 2;
 | 
			
		||||
  RCC_OscInitStruct.PLL.PLLQ = 3;
 | 
			
		||||
@ -203,7 +202,7 @@ void SystemClock_Config(void)
 | 
			
		||||
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 | 
			
		||||
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
 | 
			
		||||
                              |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
 | 
			
		||||
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
 | 
			
		||||
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 | 
			
		||||
  RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
 | 
			
		||||
  RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
 | 
			
		||||
  RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
 | 
			
		||||
@ -238,18 +237,18 @@ static void MX_FDCAN1_Init(void)
 | 
			
		||||
  hfdcan1.Init.AutoRetransmission = DISABLE;
 | 
			
		||||
  hfdcan1.Init.TransmitPause = DISABLE;
 | 
			
		||||
  hfdcan1.Init.ProtocolException = DISABLE;
 | 
			
		||||
  hfdcan1.Init.NominalPrescaler = 16;
 | 
			
		||||
  hfdcan1.Init.NominalPrescaler = 2;
 | 
			
		||||
  hfdcan1.Init.NominalSyncJumpWidth = 1;
 | 
			
		||||
  hfdcan1.Init.NominalTimeSeg1 = 2;
 | 
			
		||||
  hfdcan1.Init.NominalTimeSeg2 = 2;
 | 
			
		||||
  hfdcan1.Init.NominalTimeSeg1 = 31;
 | 
			
		||||
  hfdcan1.Init.NominalTimeSeg2 = 8;
 | 
			
		||||
  hfdcan1.Init.DataPrescaler = 1;
 | 
			
		||||
  hfdcan1.Init.DataSyncJumpWidth = 1;
 | 
			
		||||
  hfdcan1.Init.DataTimeSeg1 = 1;
 | 
			
		||||
  hfdcan1.Init.DataTimeSeg2 = 1;
 | 
			
		||||
  hfdcan1.Init.MessageRAMOffset = 0;
 | 
			
		||||
  hfdcan1.Init.StdFiltersNbr = 20;
 | 
			
		||||
  hfdcan1.Init.StdFiltersNbr = 32;
 | 
			
		||||
  hfdcan1.Init.ExtFiltersNbr = 0;
 | 
			
		||||
  hfdcan1.Init.RxFifo0ElmtsNbr = 0;
 | 
			
		||||
  hfdcan1.Init.RxFifo0ElmtsNbr = 16;
 | 
			
		||||
  hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
 | 
			
		||||
  hfdcan1.Init.RxFifo1ElmtsNbr = 0;
 | 
			
		||||
  hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
 | 
			
		||||
@ -257,7 +256,7 @@ static void MX_FDCAN1_Init(void)
 | 
			
		||||
  hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
 | 
			
		||||
  hfdcan1.Init.TxEventsNbr = 0;
 | 
			
		||||
  hfdcan1.Init.TxBuffersNbr = 0;
 | 
			
		||||
  hfdcan1.Init.TxFifoQueueElmtsNbr = 0;
 | 
			
		||||
  hfdcan1.Init.TxFifoQueueElmtsNbr = 1;
 | 
			
		||||
  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
 | 
			
		||||
  hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
 | 
			
		||||
  if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
 | 
			
		||||
 | 
			
		||||
@ -95,7 +95,15 @@ void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* hfdcan)
 | 
			
		||||
  /** Initializes the peripherals clock
 | 
			
		||||
  */
 | 
			
		||||
    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_FDCAN;
 | 
			
		||||
    PeriphClkInitStruct.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL;
 | 
			
		||||
    PeriphClkInitStruct.PLL2.PLL2M = 16;
 | 
			
		||||
    PeriphClkInitStruct.PLL2.PLL2N = 160;
 | 
			
		||||
    PeriphClkInitStruct.PLL2.PLL2P = 2;
 | 
			
		||||
    PeriphClkInitStruct.PLL2.PLL2Q = 4;
 | 
			
		||||
    PeriphClkInitStruct.PLL2.PLL2R = 2;
 | 
			
		||||
    PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_0;
 | 
			
		||||
    PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;
 | 
			
		||||
    PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
 | 
			
		||||
    PeriphClkInitStruct.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL2;
 | 
			
		||||
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
      Error_Handler();
 | 
			
		||||
@ -116,6 +124,9 @@ void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* hfdcan)
 | 
			
		||||
    GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1;
 | 
			
		||||
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 | 
			
		||||
 | 
			
		||||
    /* FDCAN1 interrupt Init */
 | 
			
		||||
    HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0);
 | 
			
		||||
    HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn);
 | 
			
		||||
  /* USER CODE BEGIN FDCAN1_MspInit 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END FDCAN1_MspInit 1 */
 | 
			
		||||
@ -145,6 +156,8 @@ void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* hfdcan)
 | 
			
		||||
    */
 | 
			
		||||
    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
 | 
			
		||||
 | 
			
		||||
    /* FDCAN1 interrupt DeInit */
 | 
			
		||||
    HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn);
 | 
			
		||||
  /* USER CODE BEGIN FDCAN1_MspDeInit 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END FDCAN1_MspDeInit 1 */
 | 
			
		||||
 | 
			
		||||
@ -55,7 +55,7 @@
 | 
			
		||||
/* USER CODE END 0 */
 | 
			
		||||
 | 
			
		||||
/* External variables --------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
extern FDCAN_HandleTypeDef hfdcan1;
 | 
			
		||||
/* USER CODE BEGIN EV */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END EV */
 | 
			
		||||
@ -198,6 +198,20 @@ void SysTick_Handler(void)
 | 
			
		||||
/* please refer to the startup file (startup_stm32h7xx.s).                    */
 | 
			
		||||
/******************************************************************************/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function handles FDCAN1 interrupt 0.
 | 
			
		||||
  */
 | 
			
		||||
void FDCAN1_IT0_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END FDCAN1_IT0_IRQn 0 */
 | 
			
		||||
  HAL_FDCAN_IRQHandler(&hfdcan1);
 | 
			
		||||
  /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END FDCAN1_IT0_IRQn 1 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN 1 */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END 1 */
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user