cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0B1CBT6 System Bootloader: CANFd. No Response

TSola.1
Associate II

Greetings!

I was trying to make a host device on STM32G0 to access system Bootloader of another STM32G0B1CBT6 to update Firmware over CANFd. Reference was taken from "AN5405"

I configured the host device as mentioned in Application note and tried to the "GET Command" on CAN ID from 0x00 to 0x7ff, but i didn't received any response from system bootloder. Configuration of host is as below:

Clock Frequency: 20Mhz

 hfdcan1.Instance = FDCAN1;

 hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;

 hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_BRS;

 hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;

 hfdcan1.Init.AutoRetransmission = ENABLE;

 hfdcan1.Init.TransmitPause = DISABLE;

 hfdcan1.Init.ProtocolException = DISABLE;

 hfdcan1.Init.NominalPrescaler = 1;

 hfdcan1.Init.NominalSyncJumpWidth = 16;

 hfdcan1.Init.NominalTimeSeg1 = 63;

 hfdcan1.Init.NominalTimeSeg2 = 16;

 hfdcan1.Init.DataPrescaler = 1;

 hfdcan1.Init.DataSyncJumpWidth = 4;

 hfdcan1.Init.DataTimeSeg1 = 15;

 hfdcan1.Init.DataTimeSeg2 = 4;

 hfdcan1.Init.StdFiltersNbr = 1;

 hfdcan1.Init.ExtFiltersNbr = 0;

 hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

 if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)

 {

  Error_Handler();

 }

FilterConfig.IdType = FDCAN_STANDARD_ID;

FilterConfig.FilterIndex = 0;

FilterConfig.FilterType = FDCAN_FILTER_RANGE;

FilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;

FilterConfig.FilterID1 = 0;

FilterConfig.FilterID2 = 0x7ff;

if (HAL_FDCAN_ConfigFilter(&hfdcan1, &FilterConfig) != HAL_OK)

{

CAN_FD_ErrorCode = CAN_FD_ConfigFiltterError;

CAN_FaultStatus = true;

globalErrorStatus = true;

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_FILTER_TO_RXFIFO0, FDCAN_FILTER_TO_RXFIFO0, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)

{

CAN_FD_ErrorCode = CAN_FD_GlobalFillterError;

CAN_FaultStatus = true;

globalErrorStatus = true;

Error_Handler();

}

/* Activate Rx FIFO 0 new message notification */

if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)

{

CAN_FD_ErrorCode = CAN_FD_RxFifoActivationError;

CAN_FaultStatus = true;

globalErrorStatus = true;

Error_Handler();

}

/* Prepare Tx message Header */

txHeader.Identifier = 0x1;

txHeader.IdType = FDCAN_STANDARD_ID;

txHeader.TxFrameType = FDCAN_DATA_FRAME;

txHeader.DataLength = FDCAN_DLC_BYTES_64;

txHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;

txHeader.BitRateSwitch = FDCAN_BRS_ON;

txHeader.FDFormat = FDCAN_FD_CAN;

txHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;

txHeader.MessageMarker = 0;

/* Configure and enable Tx Delay Compensation, required for BRS mode.

TdcOffset default recommended value: DataTimeSeg1 * DataPrescaler

TdcFilter default recommended value: 0 */

if (HAL_FDCAN_ConfigTxDelayCompensation(&hfdcan1, 5, 0) != HAL_OK)

{

CAN_FD_ErrorCode = CAN_FD_ConfigTxDelayError;

CAN_FaultStatus = true;

globalErrorStatus = true;

Error_Handler();

}

if (HAL_FDCAN_EnableTxDelayCompensation(&hfdcan1) != HAL_OK)

{

CAN_FD_ErrorCode = CAN_FD_EnableTxDelayError;

CAN_FaultStatus = true;

globalErrorStatus = true;

Error_Handler();

}

/* Start the FDCAN module */

if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)

{

CAN_FD_ErrorCode = CAN_FD_StartError;

CAN_FaultStatus = true;

globalErrorStatus = true;

Error_Handler();

}

During transmission of CAN packet i used to change Tx Identifier from range of 0x00 to 0x7ff.

Also Data Length was tried both 0 and 1 as mentioned in Application note.

Any help would be appriciated.

Thanks,

Tirthraj Solanki

4 REPLIES 4
MM..1
Chief III

Primary you check if client is in bootloader mode.

Secondary your connection need on client be as AN2606 only pin PD0 PD1

Hi,

Thank you for your response.

So, yes client is in bootloader mode, verified by using UART protocol.

Also pin used for CANFd are PD0 and PD1.

Ok then bootloader maybe detect some other interface or you have mistake , protocol speed 0.5M?

chnny_xia
Associate

1. FDCAN clock error in SystemClock_Cnfig() function in the original project,
You can use the function:

canClockFreqkHz = LL_RCC_GetFDCANClockFreq(LL_RCC_FDCAN_CLKSOURCE) / 1000u;


Get the value of canClockFreqkHz as 30MHz

2. Modify the SystemClock_Cnfig() function to use an external crystal at 8MHz:

void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);

//HSE: 8MHz----Config: SYS CLK:60MHz; FDCAN CLK:20MHz----USB: HSI48[48MHz]

/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV2;
RCC_OscInitStruct.PLL.PLLN = 30;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV6;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}

/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}

3. Modify the OPENBL_SDCAN-INnit() function in the fdcan_interface. c file:

static void OPENBL_FDCAN_Init(void)
{
/* Bit time configuration:
Bit time parameter | Nominal | Data
---------------------------|--------------|----------------
fdcan_ker_ck | 20 MHz | 20 MHz
Time_quantum (tq) | 50 ns | 50 ns
Synchronization_segment | 1 tq | 1 tq
Propagation_segment | 23 tq | 1 tq
Phase_segment_1 | 8 tq | 4 tq
Phase_segment_2 | 8 tq | 4 tq
Synchronization_Jump_width | 8 tq | 4 tq
Bit_length | 40 tq = 2 us | 10 tq = 0.5 us
Bit_rate | 0.5 MBit/s | 2 MBit/s
*/

hfdcan.Instance = FDCANx;
hfdcan.Init.FrameFormat = FDCAN_FRAME_FD_BRS;
hfdcan.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan.Init.AutoRetransmission = ENABLE;
hfdcan.Init.TransmitPause = DISABLE;
hfdcan.Init.ProtocolException = ENABLE;

#if 0 //Error!

hfdcan.Init.NominalPrescaler = 0x1;
hfdcan.Init.NominalSyncJumpWidth = 0x10;
hfdcan.Init.NominalTimeSeg1 = 0x3F;
hfdcan.Init.NominalTimeSeg2 = 0x10;
hfdcan.Init.DataPrescaler = 0x1;
hfdcan.Init.DataSyncJumpWidth = 0x4;
hfdcan.Init.DataTimeSeg1 = 0xF;
hfdcan.Init.DataTimeSeg2 = 0x4;

#else //Correct

hfdcan.Init.NominalPrescaler = 0x01;
hfdcan.Init.NominalSyncJumpWidth = 0x8;
hfdcan.Init.NominalTimeSeg1 = 0x1F;
hfdcan.Init.NominalTimeSeg2 = 0x8;

hfdcan.Init.DataPrescaler = 0x01;
hfdcan.Init.DataSyncJumpWidth = 0x4;
hfdcan.Init.DataTimeSeg1 = 0x05;
hfdcan.Init.DataTimeSeg2 = 0x04;
#endif

hfdcan.Init.StdFiltersNbr = 1;
hfdcan.Init.ExtFiltersNbr = 0;
hfdcan.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

if (HAL_FDCAN_Init(&hfdcan) != HAL_OK)
{
while (1);
}

/* Configure Rx filter */
sFilterConfig.IdType = FDCAN_STANDARD_ID;
sFilterConfig.FilterIndex = 0;
sFilterConfig.FilterType = FDCAN_FILTER_MASK;
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
sFilterConfig.FilterID1 = 0x111;
sFilterConfig.FilterID2 = 0x7FF;
HAL_FDCAN_ConfigFilter(&hfdcan, &sFilterConfig);

/* Prepare Tx Header */
TxHeader.Identifier = 0x111;
TxHeader.IdType = FDCAN_STANDARD_ID;
TxHeader.TxFrameType = FDCAN_DATA_FRAME;
TxHeader.DataLength = FDCAN_DLC_BYTES_64;
TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
TxHeader.BitRateSwitch = FDCAN_BRS_ON;
TxHeader.FDFormat = FDCAN_FD_CAN;
TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
TxHeader.MessageMarker = 0;

/* Start the FDCAN module */
HAL_FDCAN_Start(&hfdcan);
}

4. Set a breakpoint at the detected=1 position in the
OPENBL_SDCAN-ProtocolDetection() function,
and you will get detected=1,
5. Test OK