mirror of https://github.com/rusefi/openblt.git
Refs #591. Improved CAN clock configuration by directly using the APB1 clock frequency.
git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@583 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
parent
d5cbf80a06
commit
330ed30a80
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ/4) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ/4)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ/4) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ/4)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ/4) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ/4)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ/2) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ/2)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ/2) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ/2)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ/2) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ/2)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
@ -335,7 +339,7 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
static void BootComCanInit(void)
|
static void BootComCanInit(void)
|
||||||
{
|
{
|
||||||
unsigned short prescaler;
|
unsigned short prescaler = 0;
|
||||||
unsigned char tseg1 = 0, tseg2 = 0;
|
unsigned char tseg1 = 0, tseg2 = 0;
|
||||||
CAN_FilterTypeDef filterConfig;
|
CAN_FilterTypeDef filterConfig;
|
||||||
unsigned long rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
unsigned long rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
@ -335,7 +339,7 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
static void BootComCanInit(void)
|
static void BootComCanInit(void)
|
||||||
{
|
{
|
||||||
unsigned short prescaler;
|
unsigned short prescaler = 0;
|
||||||
unsigned char tseg1 = 0, tseg2 = 0;
|
unsigned char tseg1 = 0, tseg2 = 0;
|
||||||
CAN_FilterTypeDef filterConfig;
|
CAN_FilterTypeDef filterConfig;
|
||||||
unsigned long rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
unsigned long rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
||||||
|
|
|
@ -303,14 +303,18 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
unsigned char *tseg1, unsigned char *tseg2)
|
unsigned char *tseg1, unsigned char *tseg2)
|
||||||
{
|
{
|
||||||
unsigned char cnt;
|
unsigned char cnt;
|
||||||
|
unsigned long canClockFreqkHz;
|
||||||
|
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = HAL_RCC_GetPCLK1Freq() / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
if ( (*prescaler > 0) && (*prescaler <= 1024) )
|
||||||
|
@ -335,7 +339,7 @@ static unsigned char CanGetSpeedConfig(unsigned short baud, unsigned short *pres
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
static void BootComCanInit(void)
|
static void BootComCanInit(void)
|
||||||
{
|
{
|
||||||
unsigned short prescaler;
|
unsigned short prescaler = 0;
|
||||||
unsigned char tseg1 = 0, tseg2 = 0;
|
unsigned char tseg1 = 0, tseg2 = 0;
|
||||||
CAN_FilterTypeDef filterConfig;
|
CAN_FilterTypeDef filterConfig;
|
||||||
unsigned long rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
unsigned long rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
#include "boot.h" /* bootloader generic header */
|
#include "boot.h" /* bootloader generic header */
|
||||||
#include "stm32f0xx.h" /* STM32 CPU and HAL header */
|
#include "stm32f0xx.h" /* STM32 CPU and HAL header */
|
||||||
|
#include "stm32f0xx_ll_rcc.h" /* STM32 LL RCC header */
|
||||||
|
|
||||||
|
|
||||||
#if (BOOT_COM_CAN_ENABLE > 0)
|
#if (BOOT_COM_CAN_ENABLE > 0)
|
||||||
|
@ -116,14 +117,21 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
|
||||||
blt_int8u *tseg1, blt_int8u *tseg2)
|
blt_int8u *tseg1, blt_int8u *tseg2)
|
||||||
{
|
{
|
||||||
blt_int8u cnt;
|
blt_int8u cnt;
|
||||||
|
blt_int32u canClockFreqkHz;
|
||||||
|
LL_RCC_ClocksTypeDef rccClocks;
|
||||||
|
|
||||||
|
/* read clock frequencies */
|
||||||
|
LL_RCC_GetSystemClocksFreq(&rccClocks);
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = rccClocks.PCLK1_Frequency / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ((*prescaler > 0) && (*prescaler <= 1024))
|
if ((*prescaler > 0) && (*prescaler <= 1024))
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
#include "boot.h" /* bootloader generic header */
|
#include "boot.h" /* bootloader generic header */
|
||||||
#include "stm32f2xx.h" /* STM32 CPU and HAL header */
|
#include "stm32f2xx.h" /* STM32 CPU and HAL header */
|
||||||
|
#include "stm32f2xx_ll_rcc.h" /* STM32 LL RCC header */
|
||||||
|
|
||||||
|
|
||||||
#if (BOOT_COM_CAN_ENABLE > 0)
|
#if (BOOT_COM_CAN_ENABLE > 0)
|
||||||
|
@ -126,14 +127,21 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
|
||||||
blt_int8u *tseg1, blt_int8u *tseg2)
|
blt_int8u *tseg1, blt_int8u *tseg2)
|
||||||
{
|
{
|
||||||
blt_int8u cnt;
|
blt_int8u cnt;
|
||||||
|
blt_int32u canClockFreqkHz;
|
||||||
|
LL_RCC_ClocksTypeDef rccClocks;
|
||||||
|
|
||||||
|
/* read clock frequencies */
|
||||||
|
LL_RCC_GetSystemClocksFreq(&rccClocks);
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = rccClocks.PCLK1_Frequency / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ/4) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ/4)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ((*prescaler > 0) && (*prescaler <= 1024))
|
if ((*prescaler > 0) && (*prescaler <= 1024))
|
||||||
|
@ -158,7 +166,7 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
void CanInit(void)
|
void CanInit(void)
|
||||||
{
|
{
|
||||||
blt_int16u prescaler;
|
blt_int16u prescaler = 0;
|
||||||
blt_int8u tseg1 = 0, tseg2 = 0;
|
blt_int8u tseg1 = 0, tseg2 = 0;
|
||||||
CAN_FilterConfTypeDef filterConfig;
|
CAN_FilterConfTypeDef filterConfig;
|
||||||
blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
#include "boot.h" /* bootloader generic header */
|
#include "boot.h" /* bootloader generic header */
|
||||||
#include "stm32f3xx.h" /* STM32 CPU and HAL header */
|
#include "stm32f3xx.h" /* STM32 CPU and HAL header */
|
||||||
|
#include "stm32f3xx_ll_rcc.h" /* STM32 LL RCC header */
|
||||||
|
|
||||||
|
|
||||||
#if (BOOT_COM_CAN_ENABLE > 0)
|
#if (BOOT_COM_CAN_ENABLE > 0)
|
||||||
|
@ -116,14 +117,21 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
|
||||||
blt_int8u *tseg1, blt_int8u *tseg2)
|
blt_int8u *tseg1, blt_int8u *tseg2)
|
||||||
{
|
{
|
||||||
blt_int8u cnt;
|
blt_int8u cnt;
|
||||||
|
blt_int32u canClockFreqkHz;
|
||||||
|
LL_RCC_ClocksTypeDef rccClocks;
|
||||||
|
|
||||||
|
/* read clock frequencies */
|
||||||
|
LL_RCC_GetSystemClocksFreq(&rccClocks);
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = rccClocks.PCLK1_Frequency / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ/2) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ/2)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ((*prescaler > 0) && (*prescaler <= 1024))
|
if ((*prescaler > 0) && (*prescaler <= 1024))
|
||||||
|
@ -148,7 +156,7 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
void CanInit(void)
|
void CanInit(void)
|
||||||
{
|
{
|
||||||
blt_int16u prescaler;
|
blt_int16u prescaler = 0;
|
||||||
blt_int8u tseg1 = 0, tseg2 = 0;
|
blt_int8u tseg1 = 0, tseg2 = 0;
|
||||||
CAN_FilterConfTypeDef filterConfig;
|
CAN_FilterConfTypeDef filterConfig;
|
||||||
blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
#include "boot.h" /* bootloader generic header */
|
#include "boot.h" /* bootloader generic header */
|
||||||
#include "stm32l4xx.h" /* STM32 CPU and HAL header */
|
#include "stm32l4xx.h" /* STM32 CPU and HAL header */
|
||||||
|
#include "stm32l4xx_ll_rcc.h" /* STM32 LL RCC header */
|
||||||
|
|
||||||
|
|
||||||
#if (BOOT_COM_CAN_ENABLE > 0)
|
#if (BOOT_COM_CAN_ENABLE > 0)
|
||||||
|
@ -110,14 +111,21 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
|
||||||
blt_int8u *tseg1, blt_int8u *tseg2)
|
blt_int8u *tseg1, blt_int8u *tseg2)
|
||||||
{
|
{
|
||||||
blt_int8u cnt;
|
blt_int8u cnt;
|
||||||
|
blt_int32u canClockFreqkHz;
|
||||||
|
LL_RCC_ClocksTypeDef rccClocks;
|
||||||
|
|
||||||
|
/* read clock frequencies */
|
||||||
|
LL_RCC_GetSystemClocksFreq(&rccClocks);
|
||||||
|
/* store CAN peripheral clock speed in kHz */
|
||||||
|
canClockFreqkHz = rccClocks.PCLK1_Frequency / 1000u;
|
||||||
|
|
||||||
/* loop through all possible time quanta configurations to find a match */
|
/* loop through all possible time quanta configurations to find a match */
|
||||||
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
for (cnt=0; cnt < sizeof(canTiming)/sizeof(canTiming[0]); cnt++)
|
||||||
{
|
{
|
||||||
if (((BOOT_CPU_SYSTEM_SPEED_KHZ) % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
if ((canClockFreqkHz % (baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1))) == 0)
|
||||||
{
|
{
|
||||||
/* compute the prescaler that goes with this TQ configuration */
|
/* compute the prescaler that goes with this TQ configuration */
|
||||||
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
*prescaler = canClockFreqkHz/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
|
||||||
|
|
||||||
/* make sure the prescaler is valid */
|
/* make sure the prescaler is valid */
|
||||||
if ((*prescaler > 0) && (*prescaler <= 1024))
|
if ((*prescaler > 0) && (*prescaler <= 1024))
|
||||||
|
@ -142,7 +150,7 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
void CanInit(void)
|
void CanInit(void)
|
||||||
{
|
{
|
||||||
blt_int16u prescaler;
|
blt_int16u prescaler = 0;
|
||||||
blt_int8u tseg1 = 0, tseg2 = 0;
|
blt_int8u tseg1 = 0, tseg2 = 0;
|
||||||
CAN_FilterTypeDef filterConfig;
|
CAN_FilterTypeDef filterConfig;
|
||||||
blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
|
||||||
|
|
Loading…
Reference in New Issue