精华内容
下载资源
问答
  • 近日与IOS,Android测试多文件上传时偶遇一个413请求实体过大异常。于是乎就开始解决这个问题.-首先,项目采用的是Spring +Spring MVC+MyBatis为整体开发框架,所以最先想到的就是mvc-servlet.xml中是否做了设置。...

    近日与IOS,Android测试多文件上传时偶遇一个413请求实体过大异常。于是乎就开始解决这个问题.

    - 首先,项目采用的是Spring +Spring MVC+MyBatis为整体开发框架,所以最先想到的就是mvc-servlet.xml中是否做了设置。

    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

    明明已经做了文件上传大小限制。怎么还会报请求实体内容过大呢。百思不得其解。就说前台是不是传的文件太大了。所以将maxUploadSize的值调到了100G,发现还是一样的问题。这就不好玩了。思前想后最后才想起来项目中采用了Nginx做负载均衡服务器,是不是Nginx中做了限制 。就上网去查询资料。

    Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

    其大致意思是说,规定请求头的"Content-Length" 字段可以限制客户端允许请求实体的大小。如果实际请求实体大小超过所配置的值,将会返回 一个413错误给客户端(请求实体太大)。注意,浏览器不能正确的显示这个错误。设置值为0就意味着不检查客户端请求实体大小。

    之后,官网又给出了配置Demo

    Syntax:     client_max_body_size size;

    Default:     client_max_body_size 1m;

    Context:     http, server, location

    配置语法就是client_max_body_size 允许上传文件的大小将其放在 http{}块中。保存之后重启nginx服务器即可解决此问题。

    展开全文
  • 上传文件请求返回413

    2021-09-09 11:24:31
    我这里前端用的是nginx部署,同时加上反向代理配置,将请求转发到后端,测试时发现上传文件有时会报错,返回413。 原因分析 此时查看后台日志,发现根本没有错误提示,说明请求没有进入到后端,那很可能该请求直接...

    我这里前端用的是nginx部署,同时加上反向代理配置,将请求转发到后端,测试时发现上传文件有时会报错,返回413。

    原因分析

    此时查看后台日志,发现根本没有错误提示,说明请求没有进入到后端,那很可能该请求直接被nginx拦截了,想到nginx也有默认上传文件大小到限制,默认是1M,所以我再试了下上传大于1M的文件和小于1M文件的情况,发现果然是1M以上的文件上传才不成功。

    解决方法

    修改相应的配置文件conf,在需要的location模块内增加client_max_body_size属性配置,参考如下:

    location / {
            client_max_body_size    10m; #修改成你需要限制大小
        }
    
    展开全文
  • 413 Request Entuty Too Large 上传文件失败,报上面的错:请求实体太大。 原因:nginx有个参数client_max_body_size在限制请求实体的大小,把它改大点就好了。 {如果配置文件没有这个参数,应该会在系统里有个默认...

    413 Request Entuty Too Large
    原因:上传文件失败,请求实体太大。nginx有个参数client_max_body_size在限制请求实体的大小,把它改大点就可以了
    如果配置文件没有这个参数,应该会在系统里有个默认的值

    1.打开nginx配置文件 nginx.conf, 路径一般是:/etc/nginx/nginx.conf
    2.在http{}段中加入 client_max_body_size 20m。20m为允许上传的最大值,自己可进行修改

    可以选择在http{ }中设置:client_max_body_size 20m;
    也可以选择在server{ }中设置:client_max_body_size 20m;
    还可以选择在location{ }中设置:client_max_body_size 20m;
    三者有区别
    设置到http{}内,控制全局nginx所有请求报文大小
    设置到server{}内,控制该server的所有请求报文大小
    设置到location{}内,控制满足该路由规则的请求报文大小
    

    3.保存后重启nginx

    展开全文
  • 在RT-Thread中给STM32F413添加CAN3 简介 目前最新的RT-Thread v4.0.2并不能直接支持STM32F413的CAN3,从配置项添加的CAN驱动只能够支持CAN1 / CAN2,而F413的CAN3需要我们手动添加。 创建STM32F413工程 首先新建一个...

    在RT-Thread中给STM32F413添加CAN3

    简介

    目前最新的RT-Thread v4.0.2并不能直接支持STM32F413的CAN3,从配置项添加的CAN驱动只能够支持CAN1 / CAN2,而F413的CAN3需要我们手动添加。

    创建STM32F413工程

    首先新建一个工程stm32f413-xxx-xxx
    复制模板代码bsp\stm32\libraries\templates\stm32f4xx,在《bsp\stm32\docs\STM32系列BSP制作教程.md》文件中有介绍
    在bsp\stm32\stm32f413-xxx-xxx\board\Kconfig文件中修改MCU型号,改为:

    config SOC_STM32F413VG
    

    添加CAN3驱动代码

    在bsp\stm32\stm32f413-xxx-xxx\board\Kconfig文件中添加CAN配置项

    menuconfig BSP_USING_CAN
            bool "Enable CAN"
            default y
            select RT_USING_CAN
            if BSP_USING_CAN
                config BSP_USING_CAN1
                    bool "Enable CAN1"
                    default y
                config BSP_USING_CAN2
                    bool "Enable CAN2"
                    default y
                config BSP_USING_CAN3
                    bool "Enable CAN3"
                    default y
            endif
    

    添加文件bsp\stm32\stm32f413-xxx-xxx\board\drv_can.c,含CAN3代码

    /*
     * Copyright (c) 2006-2018, RT-Thread Development Team
     *
     * SPDX-License-Identifier: Apache-2.0
     *
     * Change Logs:
     * Date           Author       Notes
     * 2018-08-05     Xeon Xu      the first version
     * 2019-01-22     YLZ          port from stm324xx-HAL to bsp stm3210x-HAL
     * 2019-02-19     YLZ          add support EXTID RTR Frame. modify send, recv functions.
     *                             fix bug.port to BSP [stm32]
     * 2019-03-27     YLZ          support double can channels, support stm32F4xx (only Legacy mode).
     * 2019-06-17     YLZ          port to new STM32F1xx HAL V1.1.3.
     * 2021-04-19     unit,lhs     support 3 can channels, support stm32F413VGTx
     */
    #include "drv_can.h"
    #ifdef BSP_USING_CAN
    
    #define LOG_TAG    "drv_can"
    #include <drv_log.h>
    
    /* attention !!! baud calculation example: Tclk / ((ss + bs1 + bs2) * brp)  36 / ((1 + 8 + 3) * 3) = 1MHz*/
    #if defined (SOC_SERIES_STM32F1)/* APB1 36MHz(max) */
    static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
    {
        {CAN1MBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ  | CAN_BS2_3TQ | 3)},
        {CAN800kBaud, (CAN_SJW_2TQ | CAN_BS1_5TQ  | CAN_BS2_3TQ | 5)},
        {CAN500kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ  | CAN_BS2_3TQ | 6)},
        {CAN250kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ  | CAN_BS2_3TQ | 12)},
        {CAN125kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ  | CAN_BS2_3TQ | 24)},
        {CAN100kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ  | CAN_BS2_3TQ | 30)},
        {CAN50kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ  | CAN_BS2_3TQ | 60)},
        {CAN20kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ  | CAN_BS2_3TQ | 150)},
        {CAN10kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ  | CAN_BS2_3TQ | 300)}
    };
    #elif defined (SOC_SERIES_STM32F4)/* APB1 45MHz(max) */
    static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
    {
        {CAN1MBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ  | CAN_BS2_5TQ | 3)},
        {CAN800kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ  | CAN_BS2_5TQ | 4)},
        {CAN500kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ  | CAN_BS2_5TQ | 6)},
        {CAN250kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ  | CAN_BS2_5TQ | 12)},
        {CAN125kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ  | CAN_BS2_5TQ | 24)},
        {CAN100kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ  | CAN_BS2_5TQ | 30)},
        {CAN50kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ  | CAN_BS2_5TQ | 60)},
        {CAN20kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ  | CAN_BS2_5TQ | 150)},
        {CAN10kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ  | CAN_BS2_5TQ | 300)}
    };
    #elif defined (SOC_SERIES_STM32F7)/* APB1 54MHz(max) */
    static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
    {
        {CAN1MBaud, (CAN_SJW_2TQ | CAN_BS1_10TQ  | CAN_BS2_7TQ | 3)},
        {CAN800kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ  | CAN_BS2_7TQ | 4)},
        {CAN500kBaud, (CAN_SJW_2TQ | CAN_BS1_10TQ  | CAN_BS2_7TQ | 6)},
        {CAN250kBaud, (CAN_SJW_2TQ | CAN_BS1_10TQ  | CAN_BS2_7TQ | 12)},
        {CAN125kBaud, (CAN_SJW_2TQ | CAN_BS1_10TQ  | CAN_BS2_7TQ | 24)},
        {CAN100kBaud, (CAN_SJW_2TQ | CAN_BS1_10TQ  | CAN_BS2_7TQ | 30)},
        {CAN50kBaud, (CAN_SJW_2TQ | CAN_BS1_10TQ  | CAN_BS2_7TQ | 60)},
        {CAN20kBaud, (CAN_SJW_2TQ | CAN_BS1_10TQ  | CAN_BS2_7TQ | 150)},
        {CAN10kBaud, (CAN_SJW_2TQ | CAN_BS1_10TQ  | CAN_BS2_7TQ | 300)}
    };
    #endif
    
    #ifdef BSP_USING_CAN1
    static struct stm32_can drv_can1 =
    {
        .name = "can1",
        .CanHandle.Instance = CAN1,
    };
    #endif
    
    #ifdef BSP_USING_CAN2
    static struct stm32_can drv_can2 =
    {
        "can2",
        .CanHandle.Instance = CAN2,
    };
    #endif
    
    #ifdef BSP_USING_CAN3
    static struct stm32_can drv_can3 =
    {
        "can3",
        .CanHandle.Instance = CAN3,
    };
    #endif
    
    static rt_uint32_t get_can_baud_index(rt_uint32_t baud)
    {
        rt_uint32_t len, index;
    
        len = sizeof(can_baud_rate_tab) / sizeof(can_baud_rate_tab[0]);
        for (index = 0; index < len; index++)
        {
            if (can_baud_rate_tab[index].baud_rate == baud)
                return index;
        }
    
        return 0; /* default baud is CAN1MBaud */
    }
    
    static rt_err_t _can_config(struct rt_can_device *can, struct can_configure *cfg)
    {
        struct stm32_can *drv_can;
        rt_uint32_t baud_index;
    
        RT_ASSERT(can);
        RT_ASSERT(cfg);
        drv_can = (struct stm32_can *)can->parent.user_data;
        RT_ASSERT(drv_can);
    
        drv_can->CanHandle.Init.TimeTriggeredMode = DISABLE;
        drv_can->CanHandle.Init.AutoBusOff = ENABLE;
        drv_can->CanHandle.Init.AutoWakeUp = DISABLE;
        drv_can->CanHandle.Init.AutoRetransmission = DISABLE;
        drv_can->CanHandle.Init.ReceiveFifoLocked = DISABLE;
        drv_can->CanHandle.Init.TransmitFifoPriority = ENABLE;
    
        switch (cfg->mode)
        {
        case RT_CAN_MODE_NORMAL:
            drv_can->CanHandle.Init.Mode = CAN_MODE_NORMAL;
            break;
        case RT_CAN_MODE_LISEN:
            drv_can->CanHandle.Init.Mode = CAN_MODE_SILENT;
            break;
        case RT_CAN_MODE_LOOPBACK:
            drv_can->CanHandle.Init.Mode = CAN_MODE_LOOPBACK;
            break;
        case RT_CAN_MODE_LOOPBACKANLISEN:
            drv_can->CanHandle.Init.Mode = CAN_MODE_SILENT_LOOPBACK;
            break;
        }
    
        baud_index = get_can_baud_index(cfg->baud_rate);
        drv_can->CanHandle.Init.SyncJumpWidth = BAUD_DATA(SJW, baud_index);
        drv_can->CanHandle.Init.TimeSeg1 = BAUD_DATA(BS1, baud_index);
        drv_can->CanHandle.Init.TimeSeg2 = BAUD_DATA(BS2, baud_index);
        drv_can->CanHandle.Init.Prescaler = BAUD_DATA(RRESCL, baud_index);
        /* init can */
        if (HAL_CAN_Init(&drv_can->CanHandle) != HAL_OK)
        {
            return -RT_ERROR;
        }
    
        /* default filter config */
        HAL_CAN_ConfigFilter(&drv_can->CanHandle, &drv_can->FilterConfig);
        /* can start */
        HAL_CAN_Start(&drv_can->CanHandle);
    
        return RT_EOK;
    }
    
    static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
    {
        rt_uint32_t argval;
        struct stm32_can *drv_can;
        struct rt_can_filter_config *filter_cfg;
    
        RT_ASSERT(can != RT_NULL);
        drv_can = (struct stm32_can *)can->parent.user_data;
        RT_ASSERT(drv_can != RT_NULL);
    
        switch (cmd)
        {
        case RT_DEVICE_CTRL_CLR_INT:
            argval = (rt_uint32_t) arg;
            if (argval == RT_DEVICE_FLAG_INT_RX)
            {
                if (CAN1 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_DisableIRQ(CAN1_RX0_IRQn);
                    HAL_NVIC_DisableIRQ(CAN1_RX1_IRQn);
                }
    #ifdef CAN2
                if (CAN2 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_DisableIRQ(CAN2_RX0_IRQn);
                    HAL_NVIC_DisableIRQ(CAN2_RX1_IRQn);
                }
    #endif
    #ifdef CAN3
                if (CAN3 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_DisableIRQ(CAN3_RX0_IRQn);
                    HAL_NVIC_DisableIRQ(CAN3_RX1_IRQn);
                }
    #endif
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO0_MSG_PENDING);
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO0_FULL);
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO0_OVERRUN);
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO1_MSG_PENDING);
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO1_FULL);
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO1_OVERRUN);
            }
            else if (argval == RT_DEVICE_FLAG_INT_TX)
            {
                if (CAN1 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_DisableIRQ(CAN1_TX_IRQn);
                }
    #ifdef CAN2
                if (CAN2 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_DisableIRQ(CAN2_TX_IRQn);
                }
    #endif
    #ifdef CAN3
                if (CAN3 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_DisableIRQ(CAN3_TX_IRQn);
                }
    #endif
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_TX_MAILBOX_EMPTY);
            }
            else if (argval == RT_DEVICE_CAN_INT_ERR)
            {
                if (CAN1 == drv_can->CanHandle.Instance)
                {
                    NVIC_DisableIRQ(CAN1_SCE_IRQn);
                }
    #ifdef CAN2
                if (CAN2 == drv_can->CanHandle.Instance)
                {
                    NVIC_DisableIRQ(CAN2_SCE_IRQn);
                }
    #endif
    #ifdef CAN3
                if (CAN3 == drv_can->CanHandle.Instance)
                {
                    NVIC_DisableIRQ(CAN3_SCE_IRQn);
                }
    #endif
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_ERROR_WARNING);
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_ERROR_PASSIVE);
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_BUSOFF);
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_LAST_ERROR_CODE);
                __HAL_CAN_DISABLE_IT(&drv_can->CanHandle, CAN_IT_ERROR);
            }
            break;
        case RT_DEVICE_CTRL_SET_INT:
            argval = (rt_uint32_t) arg;
            if (argval == RT_DEVICE_FLAG_INT_RX)
            {
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO0_MSG_PENDING);
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO0_FULL);
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO0_OVERRUN);
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO1_MSG_PENDING);
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO1_FULL);
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_RX_FIFO1_OVERRUN);
    
                if (CAN1 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
                    HAL_NVIC_SetPriority(CAN1_RX1_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN1_RX1_IRQn);
                }
    #ifdef CAN2
                if (CAN2 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_SetPriority(CAN2_RX0_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN2_RX0_IRQn);
                    HAL_NVIC_SetPriority(CAN2_RX1_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN2_RX1_IRQn);
                }
    #endif
    #ifdef CAN3
                if (CAN3 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_SetPriority(CAN3_RX0_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN3_RX0_IRQn);
                    HAL_NVIC_SetPriority(CAN3_RX1_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN3_RX1_IRQn);
                }
    #endif
            }
            else if (argval == RT_DEVICE_FLAG_INT_TX)
            {
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_TX_MAILBOX_EMPTY);
    
                if (CAN1 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_SetPriority(CAN1_TX_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);
                }
    #ifdef CAN2
                if (CAN2 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_SetPriority(CAN2_TX_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN2_TX_IRQn);
                }
    #endif
    #ifdef CAN3
                if (CAN3 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_SetPriority(CAN3_TX_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN3_TX_IRQn);
                }
    #endif
            }
            else if (argval == RT_DEVICE_CAN_INT_ERR)
            {
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_ERROR_WARNING);
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_ERROR_PASSIVE);
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_BUSOFF);
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_LAST_ERROR_CODE);
                __HAL_CAN_ENABLE_IT(&drv_can->CanHandle, CAN_IT_ERROR);
    
                if (CAN1 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_SetPriority(CAN1_SCE_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN1_SCE_IRQn);
                }
    #ifdef CAN2
                if (CAN2 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_SetPriority(CAN2_SCE_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN2_SCE_IRQn);
                }
    #endif
    #ifdef CAN3
                if (CAN3 == drv_can->CanHandle.Instance)
                {
                    HAL_NVIC_SetPriority(CAN3_SCE_IRQn, 1, 0);
                    HAL_NVIC_EnableIRQ(CAN3_SCE_IRQn);
                }
    #endif
            }
            break;
        case RT_CAN_CMD_SET_FILTER:
            if (RT_NULL == arg)
            {
                /* default filter config */
                HAL_CAN_ConfigFilter(&drv_can->CanHandle, &drv_can->FilterConfig);
            }
            else
            {
                filter_cfg = (struct rt_can_filter_config *)arg;
                /* get default filter */
                for (int i = 0; i < filter_cfg->count; i++)
                {
                    drv_can->FilterConfig.FilterBank = filter_cfg->items[i].hdr;
                    drv_can->FilterConfig.FilterIdHigh = (filter_cfg->items[i].id >> 13) & 0xFFFF;
                    drv_can->FilterConfig.FilterIdLow = ((filter_cfg->items[i].id << 3) | 
                                                        (filter_cfg->items[i].ide << 2) | 
                                                        (filter_cfg->items[i].rtr << 1)) & 0xFFFF;
                    drv_can->FilterConfig.FilterMaskIdHigh = (filter_cfg->items[i].mask >> 16) & 0xFFFF;
                    drv_can->FilterConfig.FilterMaskIdLow = filter_cfg->items[i].mask & 0xFFFF;
                    drv_can->FilterConfig.FilterMode = filter_cfg->items[i].mode;
                    /* Filter conf */
                    HAL_CAN_ConfigFilter(&drv_can->CanHandle, &drv_can->FilterConfig);
                }
            }
            break;
        case RT_CAN_CMD_SET_MODE:
            argval = (rt_uint32_t) arg;
            if (argval != RT_CAN_MODE_NORMAL &&
                    argval != RT_CAN_MODE_LISEN &&
                    argval != RT_CAN_MODE_LOOPBACK &&
                    argval != RT_CAN_MODE_LOOPBACKANLISEN)
            {
                return -RT_ERROR;
            }
            if (argval != drv_can->device.config.mode)
            {
                drv_can->device.config.mode = argval;
                return _can_config(&drv_can->device, &drv_can->device.config);
            }
            break;
        case RT_CAN_CMD_SET_BAUD:
            argval = (rt_uint32_t) arg;
            if (argval != CAN1MBaud &&
                    argval != CAN800kBaud &&
                    argval != CAN500kBaud &&
                    argval != CAN250kBaud &&
                    argval != CAN125kBaud &&
                    argval != CAN100kBaud &&
                    argval != CAN50kBaud  &&
                    argval != CAN20kBaud  &&
                    argval != CAN10kBaud)
            {
                return -RT_ERROR;
            }
            if (argval != drv_can->device.config.baud_rate)
            {
                drv_can->device.config.baud_rate = argval;
                return _can_config(&drv_can->device, &drv_can->device.config);
            }
            break;
        case RT_CAN_CMD_SET_PRIV:
            argval = (rt_uint32_t) arg;
            if (argval != RT_CAN_MODE_PRIV &&
                    argval != RT_CAN_MODE_NOPRIV)
            {
                return -RT_ERROR;
            }
            if (argval != drv_can->device.config.privmode)
            {
                drv_can->device.config.privmode = argval;
                return _can_config(&drv_can->device, &drv_can->device.config);
            }
            break;
        case RT_CAN_CMD_GET_STATUS:
        {
            rt_uint32_t errtype;
            errtype = drv_can->CanHandle.Instance->ESR;
            drv_can->device.status.rcverrcnt = errtype >> 24;
            drv_can->device.status.snderrcnt = (errtype >> 16 & 0xFF);
            drv_can->device.status.lasterrtype = errtype & 0x70;
            drv_can->device.status.errcode = errtype & 0x07;
    
            rt_memcpy(arg, &drv_can->device.status, sizeof(drv_can->device.status));
        }
        break;
        }
    
        return RT_EOK;
    }
    
    static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t box_num)
    {
        CAN_HandleTypeDef *hcan;
        hcan = &((struct stm32_can *) can->parent.user_data)->CanHandle;
        struct rt_can_msg *pmsg = (struct rt_can_msg *) buf;
        CAN_TxHeaderTypeDef txheader = {0};
        HAL_CAN_StateTypeDef state = hcan->State;
    
        /* Check the parameters */
        RT_ASSERT(IS_CAN_DLC(pmsg->len));
    
        if ((state == HAL_CAN_STATE_READY) ||
                (state == HAL_CAN_STATE_LISTENING))
        {
            /*check select mailbox  is empty */
            switch (1 << box_num)
            {
            case CAN_TX_MAILBOX0:
                if (HAL_IS_BIT_SET(hcan->Instance->TSR, CAN_TSR_TME0) != SET)
                {
                    /* Change CAN state */
                    hcan->State = HAL_CAN_STATE_ERROR;
                    /* Return function status */
                    return -RT_ERROR;
                }
                break;
            case CAN_TX_MAILBOX1:
                if (HAL_IS_BIT_SET(hcan->Instance->TSR, CAN_TSR_TME1) != SET)
                {
                    /* Change CAN state */
                    hcan->State = HAL_CAN_STATE_ERROR;
                    /* Return function status */
                    return -RT_ERROR;
                }
                break;
            case CAN_TX_MAILBOX2:
                if (HAL_IS_BIT_SET(hcan->Instance->TSR, CAN_TSR_TME2) != SET)
                {
                    /* Change CAN state */
                    hcan->State = HAL_CAN_STATE_ERROR;
                    /* Return function status */
                    return -RT_ERROR;
                }
                break;
            default:
                RT_ASSERT(0);
                break;
            }
    
            if (RT_CAN_STDID == pmsg->ide)
            {
                txheader.IDE = CAN_ID_STD;
                RT_ASSERT(IS_CAN_STDID(pmsg->id));
                txheader.StdId = pmsg->id;
            }
            else
            {
                txheader.IDE = CAN_ID_EXT;
                RT_ASSERT(IS_CAN_EXTID(pmsg->id));
                txheader.ExtId = pmsg->id;
            }
    
            if (RT_CAN_DTR == pmsg->rtr)
            {
                txheader.RTR = CAN_RTR_DATA;
            }
            else
            {
                txheader.RTR = CAN_RTR_REMOTE;
            }
            /* clear TIR */
            hcan->Instance->sTxMailBox[box_num].TIR &= CAN_TI0R_TXRQ;
            /* Set up the Id */
            if (RT_CAN_STDID == pmsg->ide)
            {
                hcan->Instance->sTxMailBox[box_num].TIR |= (txheader.StdId << CAN_TI0R_STID_Pos) | txheader.RTR;
            }
            else
            {
                hcan->Instance->sTxMailBox[box_num].TIR |= (txheader.ExtId << CAN_TI0R_EXID_Pos) | txheader.IDE | txheader.RTR;
            }
            /* Set up the DLC */
            hcan->Instance->sTxMailBox[box_num].TDTR = pmsg->len & 0x0FU;
            /* Set up the data field */
            WRITE_REG(hcan->Instance->sTxMailBox[box_num].TDHR,
                      ((uint32_t)pmsg->data[7] << CAN_TDH0R_DATA7_Pos) |
                      ((uint32_t)pmsg->data[6] << CAN_TDH0R_DATA6_Pos) |
                      ((uint32_t)pmsg->data[5] << CAN_TDH0R_DATA5_Pos) |
                      ((uint32_t)pmsg->data[4] << CAN_TDH0R_DATA4_Pos));
            WRITE_REG(hcan->Instance->sTxMailBox[box_num].TDLR,
                      ((uint32_t)pmsg->data[3] << CAN_TDL0R_DATA3_Pos) |
                      ((uint32_t)pmsg->data[2] << CAN_TDL0R_DATA2_Pos) |
                      ((uint32_t)pmsg->data[1] << CAN_TDL0R_DATA1_Pos) |
                      ((uint32_t)pmsg->data[0] << CAN_TDL0R_DATA0_Pos));
            /* Request transmission */
            SET_BIT(hcan->Instance->sTxMailBox[box_num].TIR, CAN_TI0R_TXRQ);
    
            return RT_EOK;
        }
        else
        {
            /* Update error code */
            hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED;
    
            return -RT_ERROR;
        }
    }
    
    static int _can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t fifo)
    {
        HAL_StatusTypeDef status;
        CAN_HandleTypeDef *hcan;
        struct rt_can_msg *pmsg;
        CAN_RxHeaderTypeDef rxheader = {0};
    
        RT_ASSERT(can);
    
        hcan = &((struct stm32_can *)can->parent.user_data)->CanHandle;
        pmsg = (struct rt_can_msg *) buf;
    
        /* get data */
        status = HAL_CAN_GetRxMessage(hcan, fifo, &rxheader, pmsg->data);
        if (HAL_OK != status)
            return -RT_ERROR;
        /* get id */
        if (CAN_ID_STD == rxheader.IDE)
        {
            pmsg->ide = RT_CAN_STDID;
            pmsg->id = rxheader.StdId;
        }
        else
        {
            pmsg->ide = RT_CAN_EXTID;
            pmsg->id = rxheader.ExtId;
        }
        /* get type */
        if (CAN_RTR_DATA == rxheader.RTR)
        {
            pmsg->rtr = RT_CAN_DTR;
        }
        else
        {
            pmsg->rtr = RT_CAN_RTR;
        }
        /* get len */
        pmsg->len = rxheader.DLC;
        /* get hdr */
        if (hcan->Instance == CAN1)
        {
            pmsg->hdr = (rxheader.FilterMatchIndex + 1) >> 1;
        }
    #ifdef CAN2
        else if (hcan->Instance == CAN2)
        {
           pmsg->hdr = (rxheader.FilterMatchIndex >> 1) + 14;
        }
    #endif
    #ifdef CAN3
        else if (hcan->Instance == CAN3)
        {
            pmsg->hdr = (rxheader.FilterMatchIndex + 1) >> 1;
        }
    #endif
    
        return RT_EOK;
    }
    
    
    static const struct rt_can_ops _can_ops =
    {
        _can_config,
        _can_control,
        _can_sendmsg,
        _can_recvmsg,
    };
    
    static void _can_rx_isr(struct rt_can_device *can, rt_uint32_t fifo)
    {
        CAN_HandleTypeDef *hcan;
        RT_ASSERT(can);
        hcan = &((struct stm32_can *) can->parent.user_data)->CanHandle;
    
        switch (fifo)
        {
        case CAN_RX_FIFO0:
            /* save to user list */
            if (HAL_CAN_GetRxFifoFillLevel(hcan, CAN_RX_FIFO0) && __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_RX_FIFO0_MSG_PENDING))
            {
                rt_hw_can_isr(can, RT_CAN_EVENT_RX_IND | fifo << 8);
            }
            /* Check FULL flag for FIFO0 */
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_FF0) && __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_RX_FIFO0_FULL))
            {
                /* Clear FIFO0 FULL Flag */
                __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FF0);
            }
    
            /* Check Overrun flag for FIFO0 */
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_FOV0) && __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_RX_FIFO0_OVERRUN))
            {
                /* Clear FIFO0 Overrun Flag */
                __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FOV0);
                rt_hw_can_isr(can, RT_CAN_EVENT_RXOF_IND | fifo << 8);
            }
            break;
        case CAN_RX_FIFO1:
            /* save to user list */
            if (HAL_CAN_GetRxFifoFillLevel(hcan, CAN_RX_FIFO1) && __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_RX_FIFO1_MSG_PENDING))
            {
                rt_hw_can_isr(can, RT_CAN_EVENT_RX_IND | fifo << 8);
            }
            /* Check FULL flag for FIFO1 */
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_FF1) && __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_RX_FIFO1_FULL))
            {
                /* Clear FIFO1 FULL Flag */
                __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FF1);
            }
    
            /* Check Overrun flag for FIFO1 */
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_FOV1) && __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_RX_FIFO1_OVERRUN))
            {
                /* Clear FIFO1 Overrun Flag */
                __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FOV1);
                rt_hw_can_isr(can, RT_CAN_EVENT_RXOF_IND | fifo << 8);
            }
            break;
        }
    }
    
    #ifdef BSP_USING_CAN1
    /**
     * @brief This function handles CAN1 TX interrupts. transmit fifo0/1/2 is empty can trigger this interrupt
     */
    void CAN1_TX_IRQHandler(void)
    {
        rt_interrupt_enter();
        CAN_HandleTypeDef *hcan;
        hcan = &drv_can1.CanHandle;
        if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_RQCP0))
        {
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_TXOK0))
            {
                rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_DONE | 0 << 8);
            }
            else
            {
                rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_FAIL | 0 << 8);
            }
            /* Write 0 to Clear transmission status flag RQCPx */
            SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP0);
        }
        else if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_RQCP1))
        {
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_TXOK1))
            {
                rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_DONE | 1 << 8);
            }
            else
            {
                rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_FAIL | 1 << 8);
            }
            /* Write 0 to Clear transmission status flag RQCPx */
            SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP1);
        }
        else if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_RQCP2))
        {
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_TXOK2))
            {
                rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_DONE | 2 << 8);
            }
            else
            {
                rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_FAIL | 2 << 8);
            }
            /* Write 0 to Clear transmission status flag RQCPx */
            SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP2);
        }
        rt_interrupt_leave();
    }
    
    /**
     * @brief This function handles CAN1 RX0 interrupts.
     */
    void CAN1_RX0_IRQHandler(void)
    {
        rt_interrupt_enter();
        _can_rx_isr(&drv_can1.device, CAN_RX_FIFO0);
        rt_interrupt_leave();
    }
    
    /**
     * @brief This function handles CAN1 RX1 interrupts.
     */
    void CAN1_RX1_IRQHandler(void)
    {
        rt_interrupt_enter();
        _can_rx_isr(&drv_can1.device, CAN_RX_FIFO1);
        rt_interrupt_leave();
    }
    
    /**
     * @brief This function handles CAN1 SCE interrupts.
     */
    void CAN1_SCE_IRQHandler(void)
    {
        rt_uint32_t errtype;
        CAN_HandleTypeDef *hcan;
    
        hcan = &drv_can1.CanHandle;
        errtype = hcan->Instance->ESR;
    
        rt_interrupt_enter();
        HAL_CAN_IRQHandler(hcan);
    
        switch ((errtype & 0x70) >> 4)
        {
        case RT_CAN_BUS_BIT_PAD_ERR:
            drv_can1.device.status.bitpaderrcnt++;
            break;
        case RT_CAN_BUS_FORMAT_ERR:
            drv_can1.device.status.formaterrcnt++;
            break;
        case RT_CAN_BUS_ACK_ERR:/* attention !!! test ack err's unit is transmit unit */
            drv_can1.device.status.ackerrcnt++;
            if (!READ_BIT(drv_can1.CanHandle.Instance->TSR, CAN_FLAG_TXOK0))
                rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_FAIL | 0 << 8);
            else if (!READ_BIT(drv_can1.CanHandle.Instance->TSR, CAN_FLAG_TXOK0))
                rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_FAIL | 1 << 8);
            else if (!READ_BIT(drv_can1.CanHandle.Instance->TSR, CAN_FLAG_TXOK0))
                rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_FAIL | 2 << 8);
            break;
        case RT_CAN_BUS_IMPLICIT_BIT_ERR:
        case RT_CAN_BUS_EXPLICIT_BIT_ERR:
            drv_can1.device.status.biterrcnt++;
            break;
        case RT_CAN_BUS_CRC_ERR:
            drv_can1.device.status.crcerrcnt++;
            break;
        }
    
        drv_can1.device.status.lasterrtype = errtype & 0x70;
        drv_can1.device.status.rcverrcnt = errtype >> 24;
        drv_can1.device.status.snderrcnt = (errtype >> 16 & 0xFF);
        drv_can1.device.status.errcode = errtype & 0x07;
        hcan->Instance->MSR |= CAN_MSR_ERRI;
        rt_interrupt_leave();
    }
    #endif /* BSP_USING_CAN1 */
    
    #ifdef BSP_USING_CAN2
    /**
     * @brief This function handles CAN2 TX interrupts.
     */
    void CAN2_TX_IRQHandler(void)
    {
        rt_interrupt_enter();
        CAN_HandleTypeDef *hcan;
        hcan = &drv_can2.CanHandle;
        if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_RQCP0))
        {
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_TXOK0))
            {
                rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_DONE | 0 << 8);
            }
            else
            {
                rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_FAIL | 0 << 8);
            }
            /* Write 0 to Clear transmission status flag RQCPx */
            SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP0);
        }
        else if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_RQCP1))
        {
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_TXOK1))
            {
                rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_DONE | 1 << 8);
            }
            else
            {
                rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_FAIL | 1 << 8);
            }
            /* Write 0 to Clear transmission status flag RQCPx */
            SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP1);
        }
        else if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_RQCP2))
        {
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_TXOK2))
            {
                rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_DONE | 2 << 8);
            }
            else
            {
                rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_FAIL | 2 << 8);
            }
            /* Write 0 to Clear transmission status flag RQCPx */
            SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP2);
        }
        rt_interrupt_leave();
    }
    
    /**
     * @brief This function handles CAN2 RX0 interrupts.
     */
    void CAN2_RX0_IRQHandler(void)
    {
        rt_interrupt_enter();
        _can_rx_isr(&drv_can2.device, CAN_RX_FIFO0);
        rt_interrupt_leave();
    }
    
    /**
     * @brief This function handles CAN2 RX1 interrupts.
     */
    void CAN2_RX1_IRQHandler(void)
    {
        rt_interrupt_enter();
        _can_rx_isr(&drv_can2.device, CAN_RX_FIFO1);
        rt_interrupt_leave();
    }
    
    /**
     * @brief This function handles CAN2 SCE interrupts.
     */
    void CAN2_SCE_IRQHandler(void)
    {
        rt_uint32_t errtype;
        CAN_HandleTypeDef *hcan;
    
        hcan = &drv_can2.CanHandle;
        errtype = hcan->Instance->ESR;
    
        rt_interrupt_enter();
        HAL_CAN_IRQHandler(hcan);
    
        switch ((errtype & 0x70) >> 4)
        {
        case RT_CAN_BUS_BIT_PAD_ERR:
            drv_can2.device.status.bitpaderrcnt++;
            break;
        case RT_CAN_BUS_FORMAT_ERR:
            drv_can2.device.status.formaterrcnt++;
            break;
        case RT_CAN_BUS_ACK_ERR:
            drv_can2.device.status.ackerrcnt++;
            if (!READ_BIT(drv_can1.CanHandle.Instance->TSR, CAN_FLAG_TXOK0))
                rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_FAIL | 0 << 8);
            else if (!READ_BIT(drv_can2.CanHandle.Instance->TSR, CAN_FLAG_TXOK0))
                rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_FAIL | 1 << 8);
            else if (!READ_BIT(drv_can2.CanHandle.Instance->TSR, CAN_FLAG_TXOK0))
                rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_FAIL | 2 << 8);
            break;
        case RT_CAN_BUS_IMPLICIT_BIT_ERR:
        case RT_CAN_BUS_EXPLICIT_BIT_ERR:
            drv_can2.device.status.biterrcnt++;
            break;
        case RT_CAN_BUS_CRC_ERR:
            drv_can2.device.status.crcerrcnt++;
            break;
        }
    
        drv_can2.device.status.lasterrtype = errtype & 0x70;
        drv_can2.device.status.rcverrcnt = errtype >> 24;
        drv_can2.device.status.snderrcnt = (errtype >> 16 & 0xFF);
        drv_can2.device.status.errcode = errtype & 0x07;
        hcan->Instance->MSR |= CAN_MSR_ERRI;
        rt_interrupt_leave();
    }
    #endif /* BSP_USING_CAN2 */
    
    #ifdef BSP_USING_CAN3
    /**
     * @brief This function handles CAN3 TX interrupts. transmit fifo0/1/2 is empty can trigger this interrupt
     */
    void CAN3_TX_IRQHandler(void)
    {
        rt_interrupt_enter();
        CAN_HandleTypeDef *hcan;
        hcan = &drv_can3.CanHandle;
        if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_RQCP0))
        {
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_TXOK0))
            {
                rt_hw_can_isr(&drv_can3.device, RT_CAN_EVENT_TX_DONE | 0 << 8);
            }
            else
            {
                rt_hw_can_isr(&drv_can3.device, RT_CAN_EVENT_TX_FAIL | 0 << 8);
            }
            /* Write 0 to Clear transmission status flag RQCPx */
            SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP0);
        }
        else if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_RQCP1))
        {
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_TXOK1))
            {
                rt_hw_can_isr(&drv_can3.device, RT_CAN_EVENT_TX_DONE | 1 << 8);
            }
            else
            {
                rt_hw_can_isr(&drv_can3.device, RT_CAN_EVENT_TX_FAIL | 1 << 8);
            }
            /* Write 0 to Clear transmission status flag RQCPx */
            SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP1);
        }
        else if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_RQCP2))
        {
            if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_TXOK2))
            {
                rt_hw_can_isr(&drv_can3.device, RT_CAN_EVENT_TX_DONE | 2 << 8);
            }
            else
            {
                rt_hw_can_isr(&drv_can3.device, RT_CAN_EVENT_TX_FAIL | 2 << 8);
            }
            /* Write 0 to Clear transmission status flag RQCPx */
            SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP2);
        }
        rt_interrupt_leave();
    }
    
    /**
     * @brief This function handles CAN3 RX0 interrupts.
     */
    void CAN3_RX0_IRQHandler(void)
    {
        rt_interrupt_enter();
        _can_rx_isr(&drv_can3.device, CAN_RX_FIFO0);
        rt_interrupt_leave();
    }
    
    /**
     * @brief This function handles CAN3 RX1 interrupts.
     */
    void CAN3_RX1_IRQHandler(void)
    {
        rt_interrupt_enter();
        _can_rx_isr(&drv_can3.device, CAN_RX_FIFO1);
        rt_interrupt_leave();
    }
    
    /**
     * @brief This function handles CAN3 SCE interrupts.
     */
    void CAN3_SCE_IRQHandler(void)
    {
        rt_uint32_t errtype;
        CAN_HandleTypeDef *hcan;
    
        hcan = &drv_can3.CanHandle;
        errtype = hcan->Instance->ESR;
    
        rt_interrupt_enter();
        HAL_CAN_IRQHandler(hcan);
    
        switch ((errtype & 0x70) >> 4)
        {
        case RT_CAN_BUS_BIT_PAD_ERR:
            drv_can3.device.status.bitpaderrcnt++;
            break;
        case RT_CAN_BUS_FORMAT_ERR:
            drv_can3.device.status.formaterrcnt++;
            break;
        case RT_CAN_BUS_ACK_ERR:/* attention !!! test ack err's unit is transmit unit */
            drv_can3.device.status.ackerrcnt++;
            if (!READ_BIT(drv_can3.CanHandle.Instance->TSR, CAN_FLAG_TXOK0))
                rt_hw_can_isr(&drv_can3.device, RT_CAN_EVENT_TX_FAIL | 0 << 8);
            else if (!READ_BIT(drv_can3.CanHandle.Instance->TSR, CAN_FLAG_TXOK0))
                rt_hw_can_isr(&drv_can3.device, RT_CAN_EVENT_TX_FAIL | 1 << 8);
            else if (!READ_BIT(drv_can3.CanHandle.Instance->TSR, CAN_FLAG_TXOK0))
                rt_hw_can_isr(&drv_can3.device, RT_CAN_EVENT_TX_FAIL | 2 << 8);
            break;
        case RT_CAN_BUS_IMPLICIT_BIT_ERR:
        case RT_CAN_BUS_EXPLICIT_BIT_ERR:
            drv_can3.device.status.biterrcnt++;
            break;
        case RT_CAN_BUS_CRC_ERR:
            drv_can3.device.status.crcerrcnt++;
            break;
        }
    
        drv_can3.device.status.lasterrtype = errtype & 0x70;
        drv_can3.device.status.rcverrcnt = errtype >> 24;
        drv_can3.device.status.snderrcnt = (errtype >> 16 & 0xFF);
        drv_can3.device.status.errcode = errtype & 0x07;
        hcan->Instance->MSR |= CAN_MSR_ERRI;
        rt_interrupt_leave();
    }
    #endif /* BSP_USING_CAN3 */
    
    /**
     * @brief  Error CAN callback.
     * @param  hcan pointer to a CAN_HandleTypeDef structure that contains
     *         the configuration information for the specified CAN.
     * @retval None
     */
    void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan)
    {
        __HAL_CAN_ENABLE_IT(hcan, CAN_IT_ERROR_WARNING |
                            CAN_IT_ERROR_PASSIVE |
                            CAN_IT_BUSOFF |
                            CAN_IT_LAST_ERROR_CODE |
                            CAN_IT_ERROR |
                            CAN_IT_RX_FIFO0_MSG_PENDING |
                            CAN_IT_RX_FIFO0_OVERRUN |
                            CAN_IT_RX_FIFO0_FULL |
                            CAN_IT_RX_FIFO1_MSG_PENDING |
                            CAN_IT_RX_FIFO1_OVERRUN |
                            CAN_IT_RX_FIFO1_FULL |
                            CAN_IT_TX_MAILBOX_EMPTY);
    }
    
    int rt_hw_can_init(void)
    {
        struct can_configure config = CANDEFAULTCONFIG;
        config.privmode = RT_CAN_MODE_NOPRIV;
        config.ticks = 50;
    #ifdef RT_CAN_USING_HDR
        config.maxhdr = 14;
    #ifdef CAN2
        config.maxhdr = 28;
    #endif
    #endif
        /* config default filter */
        CAN_FilterTypeDef filterConf = {0};
        filterConf.FilterIdHigh = 0x0000;
        filterConf.FilterIdLow = 0x0000;
        filterConf.FilterMaskIdHigh = 0x0000;
        filterConf.FilterMaskIdLow = 0x0000;
        filterConf.FilterFIFOAssignment = CAN_FILTER_FIFO0;
        filterConf.FilterBank = 0;
        filterConf.FilterMode = CAN_FILTERMODE_IDMASK;
        filterConf.FilterScale = CAN_FILTERSCALE_32BIT;
        filterConf.FilterActivation = ENABLE;
        filterConf.SlaveStartFilterBank = 14;
    
    #ifdef BSP_USING_CAN1
        filterConf.FilterBank = 0;
    
        drv_can1.FilterConfig = filterConf;
        drv_can1.device.config = config;
        /* register CAN1 device */
        rt_hw_can_register(&drv_can1.device,
                           drv_can1.name,
                           &_can_ops,
                           &drv_can1);
    #endif /* BSP_USING_CAN1 */
    
    #ifdef BSP_USING_CAN2
        filterConf.FilterBank = filterConf.SlaveStartFilterBank;
    
        drv_can2.FilterConfig = filterConf;
        drv_can2.device.config = config;
        /* register CAN2 device */
        rt_hw_can_register(&drv_can2.device,
                           drv_can2.name,
                           &_can_ops,
                           &drv_can2);
    #endif /* BSP_USING_CAN2 */
    
    #ifdef BSP_USING_CAN3
        filterConf.FilterBank = 0;
    
        drv_can3.FilterConfig = filterConf;
        drv_can3.device.config = config;
        /* register CAN3 device */
        rt_hw_can_register(&drv_can3.device,
                           drv_can3.name,
                           &_can_ops,
                           &drv_can3);
    #endif /* BSP_USING_CAN3 */
    
        return 0;
    }
    
    INIT_BOARD_EXPORT(rt_hw_can_init);
    
    #endif /* BSP_USING_CAN */
    
    /************************** end of file ******************/
    
    

    生成keil5工程以及配置参数

    scons --target=mdk5
    

    去掉默认链接的F4xx库文件,因为默认F4xx库文件不支持F413系列

    bsp\stm32\libraries\STM32F4xx_HAL\*
    

    重新添加相关源文件

    bsp\stm32\stm32f413-xxx-xxx\board\drv_can.c
    bsp\stm32\stm32f413-xxx-xxx\board\CubeMX_Config\Drivers\STM32F4xx_HAL_Driver\Src\*
    bsp\stm32\stm32f413-xxx-xxx\board\CubeMX_Config\MDK-ARM\startup_stm32f413xx.s
    bsp\stm32\stm32f413-xxx-xxx\board\CubeMX_Config\Src\system_stm32f4xx.c
    

    在这里插入图片描述
    在这里插入图片描述
    修改包含F413的路径
    在这里插入图片描述

    board\CubeMX_Config\Drivers\CMSIS\Device\ST\STM32F4xx\Include
    board\CubeMX_Config\Drivers\CMSIS\Include
    board\CubeMX_Config\Drivers\STM32F4xx_HAL_Driver\Inc
    board\CubeMX_Config\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy
    

    运行代码

    编译并下载运行,此时驱动已经添加到设备列表

     \ | /
    - RT -     Thread Operating System
     / | \     4.0.2 build Apr 19 2021
     2006 - 2019 Copyright by rt-thread team
    msh />list_d
    list_device
    msh />list_device
    device           type         ref count
    -------- -------------------- ----------
    can3     CAN Device           0       
    can2     CAN Device           0       
    can1     CAN Device           0       
    uart8    Character Device     0       
    uart7    Character Device     0       
    uart6    Character Device     0       
    uart3    Character Device     2       
    uart2    Character Device     0       
    uart1    Character Device     0       
    pin      Miscellaneous Device 0       
    msh />
    

    注:驱动是否正常未经过验证!!!

    参考资料

    [1] https://blog.csdn.net/tcjy1000/article/details/110904956

    展开全文
  • Git提交push报错:HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large解决方案(超详细步骤) 文章目录Git提交push报错:HTTP 413 curl 22 The requested URL returned error: 413 ...
  • nginx-413错误

    2021-11-11 13:13:24
    限制请求体的大小,若超过所设定的大小,返回413错误。 client_header_timeout 读取请求头的超时时间,若超过所设定的大小,返回408错误。 client_body_timeout 读取请求实体的超时时间,若超过所设定的大小,...
  • 查了一下,报413错误,表示http请求实体太大。此错误通常出现在使用http请求进行文件上传的时候,因为上传文件容易出现大文件,比如超过5m的。但是今天导致这个问题的是因为前端post请求发送的json对象太“大”了,...
  • PHPCMS上传错误413

    2021-04-16 01:39:56
    PHPCMS上传错误413?PHPCMS上传错误413,其原因Nginx默认限制最大上传文件就是1M,所以上传文件超过1M就会报413错误,解决方法:找到“nginx.conf”配置下的“client_max_body_size”,更改为10M即可。Apache服务器...
  • 对于需要上传附件或者POST传输很大报文的时候,肯有可能会出现 Nginx 413 Request Entity Too Large 错误。这是因为 nginx 默认对请求 body 的大小限制为 1m(同样像相关 timeout 也都有默认限制)。 如果你遇到了这...
  • 上传文件出现问题 413 Request Entity Too Large,如下图所示 Nginx默认的request body为1M,所以需要配置一下: 如这里配置的上传最大文件限制为 100M 然后重新加载nigix配置文件 [root@service-1 sbin]# ./...
  • vue发送请求报错413

    2021-08-06 11:29:50
    项目场景: ## vue发送post请求报错413 问题描述: 附上图片: 原因分析: post请求体太大。有可能是封装请求不对 解决方案: 1.查看封装该接口的方法,
  • 问题原因出现了413错误,413错误是因为用户请求body的数据大于设置的值。用户请求的body的值可用Content-Length看到可以看到请求的body大小大于6M,通过查看Nginx官网可知默认request body为1M,而设置request body...
  • 发布到私服一个jar包 80kb的可以上传这个war包 大概8M多 上传不过去[INFO] DeviceManager ...................................... SUCCESS [ 1.518 s][INFO] webAction .................... SUCCESS [ 2.413 s][IN...
  • 问题描述:今天接到公司测试反馈,在测试文件上传功能时提示: HTTP:413 Request Entity Too Large. 问题产生原因:为解决前后端分离带来的跨越问题,我们采用nginx 解决跨越问题,但是nginx 针对文件上传是有大小限制...
  • 在上传文件时,如下提示:HTTP 错误 413.1 - Request Entity Too Large未显示页面,因为请求实体过大。最可能的原因:Web 服务器拒绝为请求提供服务,因为该请求实体过大。Web 服务器无法为请求提供服务,因为它正...
  • HTTP/1.1 413 Request Entity Too Large413 Request Entity Too Large413 Request Entity Too Largenginx/1.10.3at org.elasticsearch.client.RestClient$1.completed(RestClient.java:354)at org.elasticsearch.cli...
  • HTTP Status_Code 413

    2021-03-24 13:18:52
    HTTP Status_Code 413 Request Entity Too Large 产生这种原因是因为服务器限制了上传大小 修改nginx.conf的值就可以解决了 client_max_body_size 20M; 可以选择在http{ }中设置:client_max_body_size 20m; 也可以...
  • 具体步骤: 在apache环境中上传较大软件的时候,有时候会出现413错误,出现这个错误的原因,是因为apache的配置不当造成的,找到apache的配置文件目录也就是conf目录,和这个目录平行的一个目录叫conf.d打开这个...
  • “常见的413”错误--在nginx的nginx.conf配置文件http部分增加下面配置client_max_body_size 1m(此处大小设置你想限制上传的文件大小,默认是1M,1.11版本及其以前版本多半是这个数值,不排除后期版本会不会修改...
  • 今天使用测试接口的时候,报了一个413错误 chunk-libs.0d7f7ccf.js:11 Uncaught (in promise) Error: Request failed with status code 413 at e.exports (chunk-libs.0d7f7ccf.js:11) 经查,413的错误码是表示:...
  • mvn 构建 上传到私服 报错413 Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project wshoto-scrm-backend-bootstrap: Failed to deploy artifacts: Could...
  • 1. 详细报错信息 ... 报错信息: ... HTTP 413 curl 22 The requested URL returned error: 413 fatal: the remote end hung up unexpectedly fatal: the remote end hung up unexpectedly Everything up-to-
  • 413 Request Entity Too Large

    2021-10-13 18:42:43
    限制请求体的大小,若超过所设定的大小,返回413错误。 client_header_timeout 读取请求头的超时时间,若超过所设定的大小,返回408错误。 client_body_timeout 读取请求实体的超时时间,若超过所设定的大小,返回...
  • 我是用Nginx服务器发布的系统 原因是请求实体太长了,其实就是文件太大了。 处理方法修改nginx.conf的配置就可以解决了。 将 client_max_body_size的值变大就可以了,加到nginx.conf文件的server配置中
  • 前端有一个上传文件的功能,一直好好的,突然nginx报错413 方案 413问题是指上传文件大小限制问题 默认nginx的限制大小为:1M 当超过默认大小的时候就会报413的错误 我们可以评估我们nginx上传文件的峰值,例如:10M...
  • 远程服务器返回了意外响应: (413) Request Entity Too Large。 出现这个报错的原因是请求的实体太大了。 解决方案: 客户端:App.config在bindings下面加多一个binding: <binding closeTimeout="00:10:00" ...
  • 文件名称 版本号 ...Status Code: 413 Request Entity Too Large 代码 疑似产生的原因 限制 弯路、坑 分析 解决方案 放松限制:client_max_body_size 1024m; 领悟 关于 若交流技术,请联系qq...
  • 因项目国产化需要,使用国产化MCU(雅特力)ATF32F413CBT6替代STM32F103C8T6。该项目使用8M外部晶振作为系统时钟来源,经PLL锁相环倍频至72M作为系统时钟,在使用过程中发现,系统时钟设置失败,默认使用内部8M频率...
  • HTTP 413 curl 22 The requested URL returned error: 413 #解决方案 从上面的报错信息中可以看到,git提交的代码大小为433422517 bytes,约为400M;从而怀疑提交的文件过大导致的。 1、首先修改Git全局配置 git ...
  • 场景: 上传大文件遇413错误 > 这边是nginx做的转发,nginx 默认的接受参数大小是 1M,但是我们上传文件大小是已经大于1M,故抛出413的错误代码 解决方案 找到nginx.conf的对应上传文件配置项 client_...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 73,682
精华内容 29,472
关键字:

413

友情链接: Retina-VesselNet-master.zip