mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Merge pull request #4329 from adustm/can_sync_error
Fix for #3863: STM Check can sync errorpull/4216/head
						commit
						45b4d41bbd
					
				| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
#define MBED_CAN_DEVICE_H
 | 
			
		||||
 | 
			
		||||
#include "cmsis.h"
 | 
			
		||||
#include "stm32f0xx_hal.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
#define MBED_CAN_DEVICE_H
 | 
			
		||||
 | 
			
		||||
#include "cmsis.h"
 | 
			
		||||
#include "stm32f1xx_hal.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
#define MBED_CAN_DEVICE_H
 | 
			
		||||
 | 
			
		||||
#include "cmsis.h"
 | 
			
		||||
#include "stm32f2xx_hal.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
#define MBED_CAN_DEVICE_H
 | 
			
		||||
 | 
			
		||||
#include "cmsis.h"
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
#define MBED_CAN_DEVICE_H
 | 
			
		||||
 | 
			
		||||
#include "cmsis.h"
 | 
			
		||||
#include "stm32f4xx_hal.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
#define MBED_CAN_DEVICE_H
 | 
			
		||||
 | 
			
		||||
#include "cmsis.h"
 | 
			
		||||
#include "stm32f7xx_hal.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
#define MBED_CAN_DEVICE_H
 | 
			
		||||
 | 
			
		||||
#include "cmsis.h"
 | 
			
		||||
#include "stm32l4xx_hal.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -85,8 +85,10 @@ void can_init_freq (can_t *obj, PinName rd, PinName td, int hz)
 | 
			
		|||
        error("Cannot initialize CAN");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Set initial CAN frequency to requested kb/s
 | 
			
		||||
    can_frequency(obj, hz);
 | 
			
		||||
    // Set initial CAN frequency to 100 kb/s
 | 
			
		||||
    if (can_frequency(obj, 100000) != 1) {
 | 
			
		||||
        error("Can frequency could not be set\n");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    uint32_t filter_number = (obj->can == CAN_1) ? 0 : 14;
 | 
			
		||||
    can_filter(obj, 0, 0, CANStandard, filter_number);
 | 
			
		||||
| 
						 | 
				
			
			@ -195,19 +197,40 @@ int can_frequency(can_t *obj, int f)
 | 
			
		|||
    int pclk = HAL_RCC_GetPCLK1Freq();
 | 
			
		||||
    int btr = can_speed(pclk, (unsigned int)f, 1);
 | 
			
		||||
    CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
 | 
			
		||||
    uint32_t tickstart = 0;
 | 
			
		||||
    int status = 1;
 | 
			
		||||
 | 
			
		||||
    if (btr > 0) {
 | 
			
		||||
        can->MCR |= CAN_MCR_INRQ ;
 | 
			
		||||
        /* Get tick */
 | 
			
		||||
        tickstart = HAL_GetTick();
 | 
			
		||||
        while ((can->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) {
 | 
			
		||||
            if ((HAL_GetTick() - tickstart) > 2) {
 | 
			
		||||
                status = 0;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (status != 0) {
 | 
			
		||||
            can->BTR = btr;
 | 
			
		||||
            can->MCR &= ~(uint32_t)CAN_MCR_INRQ;
 | 
			
		||||
            /* Get tick */
 | 
			
		||||
            tickstart = HAL_GetTick();
 | 
			
		||||
            while ((can->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) {
 | 
			
		||||
                if ((HAL_GetTick() - tickstart) > 2) {
 | 
			
		||||
                    status = 0;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (status == 0) {
 | 
			
		||||
                error("can ESR  0x%04x.%04x + timeout status %d", (can->ESR & 0xFFFF0000) >> 16, (can->ESR & 0xFFFF), status);
 | 
			
		||||
            }
 | 
			
		||||
        return 1;
 | 
			
		||||
        } else {
 | 
			
		||||
        return 0;
 | 
			
		||||
            error("can init request timeout\n");
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        status = 0;
 | 
			
		||||
    }
 | 
			
		||||
    return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int can_write(can_t *obj, CAN_Message msg, int cc)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue