cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to TX on NUCLEO-ST32G491RE FDCAN1

JBend.6
Associate III

I am trying to get CAN working on the STM32G491RE. I happily worked with CAN on STM32F4xxx micros, but the landscape seems to have changed on the STM32G491RE.

The presented code is from a minimal project for the NUCLEO-STM32G491RE board. It is in default configuration, plugged in to my PC. The project was created using STM32CUBEIDE MX and HAL. There is no other hardware than the NUCLEO, PC, Logic Analyser and cables.

The idea is that the program configures FDCAN1 interface and transmits a two-byte payload every second. I have my logic analyser attached to FDCAN1-TX (PA12 or CN10<12> on this NUCLEO) where I expect to see the CAN transmission. I anticipate seeing just three transmissions before the TX buffer is full.

On resetting the NUCLEO I see the TX line dragged low for around 30ms, released and that's it.

I am obviously doing something stupid, but after days of struggling I am now going around in circles.

Info:

Ceramic CLK giving 96 MHz on HCLK

FDCAN1 set to:

  Nominal Prescaler 24

  Nominal Time Seg1 13

  Nominal Time Seg2 2

  Nominal Baud Rate 250000 bit/s

Thank you.

Main Loop

  while (1) {
 
	  /* 1-second blocking delay */
	  HAL_Delay(1000);
 
      /* Set data and transmit */
      TxData[0] = 0x2A;
      TxData[1] = 0xAD;
      HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, TxData);
 
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

FDCAN1 Init (from MX)

static void MX_FDCAN1_Init(void) {
 
  /* USER CODE BEGIN FDCAN1_Init 0 */
 
  /* USER CODE END FDCAN1_Init 0 */
 
  /* USER CODE BEGIN FDCAN1_Init 1 */
 
  /* USER CODE END FDCAN1_Init 1 */
  hfdcan1.Instance = FDCAN1;
  hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
  hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
  hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
  hfdcan1.Init.AutoRetransmission = DISABLE;
  hfdcan1.Init.TransmitPause = DISABLE;
  hfdcan1.Init.ProtocolException = DISABLE;
  hfdcan1.Init.NominalPrescaler = 24;
  hfdcan1.Init.NominalSyncJumpWidth = 1;
  hfdcan1.Init.NominalTimeSeg1 = 13;
  hfdcan1.Init.NominalTimeSeg2 = 2;
  hfdcan1.Init.DataPrescaler = 1;
  hfdcan1.Init.DataSyncJumpWidth = 1;
  hfdcan1.Init.DataTimeSeg1 = 1;
  hfdcan1.Init.DataTimeSeg2 = 1;
  hfdcan1.Init.StdFiltersNbr = 0;
  hfdcan1.Init.ExtFiltersNbr = 0;
  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
  if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN FDCAN1_Init 2 */
 
  /* USER CODE END FDCAN1_Init 2 */
 
}

FDCAN config and start

static void FDCAN_Config(void) {
  FDCAN_FilterTypeDef sFilterConfig;
 
  /* Configure Rx filter */
  sFilterConfig.IdType = FDCAN_STANDARD_ID;
  sFilterConfig.FilterIndex = 0;
  sFilterConfig.FilterType = FDCAN_FILTER_MASK;
  sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
  sFilterConfig.FilterID1 = 0x321;
  sFilterConfig.FilterID2 = 0x7FF;
  if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
  {
    Error_Handler();
  }
 
  /* Configure global filter:
     Filter all remote frames with STD and EXT ID
     Reject non matching frames with STD ID and EXT ID */
  if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
  {
    Error_Handler();
  }
 
  /* Start the FDCAN module */
  if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
  {
    Error_Handler();
  }
 
  if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
  {
    Error_Handler();
  }
 
  /* Prepare Tx Header */
  TxHeader.Identifier = 0x321;
  TxHeader.IdType = FDCAN_STANDARD_ID;
  TxHeader.TxFrameType = FDCAN_DATA_FRAME;
  TxHeader.DataLength = FDCAN_DLC_BYTES_2;
  TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
  TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
  TxHeader.FDFormat = FDCAN_CLASSIC_CAN;
  TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
  TxHeader.MessageMarker = 0;
}

0 REPLIES 0