STM32疑难杂症

2024-01-08 20:39:38

1.keil的奇怪问题

创建的数组分配内存到0x10000000地址的时候,数据总是莫名其妙的出现问题,取消勾选就正常了
stm32f407内部有一个CCM内存,这部分内存只能由内核控制,任何外设都不能够进行访问。这样问题就来了,如果使用keil5进行编程时勾选了这个选项(下图),则编译的时候会随机将数据放到CCM中。而Lwip通讯靠的是以太网的专用DMA,如果在编译的时候,lwip的描述符被分配到CCM中,那就会导致ping不同的现象。
在这里插入图片描述

2.STM32的CAN ID滤波器的设置

列表模式和掩码模式的两个设置,以及多滤波器的设置方法

static void CanBSP_STM32_Can1_CfgFilter()   
{
  CAN_FilterTypeDef  sFilterConfig;
	CAN_FilterTypeDef  sFilterConfig1;
	
  sFilterConfig.FilterBank = 0;                       //过滤器0

  sFilterConfig.FilterMode =  CAN_FILTERMODE_IDLIST;  //设为列表模式    
  sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT;    
		
  sFilterConfig.FilterIdHigh = ((uint32_t)0x181)<<5;   //基本ID放入到STID中  
  sFilterConfig.FilterIdLow  = ((uint32_t)0x182) <<5;    
		
  sFilterConfig.FilterMaskIdHigh =((uint32_t)0x183)<<5;
  sFilterConfig.FilterMaskIdLow  =((uint32_t)0x184)<<5; 

  //接收到的报文放入到FIFO0中 
  sFilterConfig.FilterFIFOAssignment = CAN1FIFO;   
 
  sFilterConfig.FilterActivation = ENABLE;  	//激活过滤器
	
	sFilterConfig1 = sFilterConfig;
	
	sFilterConfig1.FilterBank = 1;
  sFilterConfig1.FilterIdHigh = ((uint32_t)0x185)<<5;   //基本ID放入到STID中  
  sFilterConfig1.FilterIdLow  = ((uint32_t)0x186) <<5;    
		
  sFilterConfig1.FilterMaskIdHigh =((uint32_t)0x187)<<5;
  sFilterConfig1.FilterMaskIdLow  =((uint32_t)0x188)<<5; 	
 
  if (HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig) != HAL_OK)
  {
    /* Filter configuration Error */
    Error_Handler();
  }
  if (HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig1) != HAL_OK)
  {
    /* Filter configuration Error */
    Error_Handler();
  }

  /* Start the CAN peripheral */
  if (HAL_CAN_Start(&hcan1) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }

  /* Activate CAN RX notification */
  if (HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
  {
    /* Notification Error ??€??ˉ???èμ·??-??μ?…?è???¤±è′¥*/
    Error_Handler();
  }
}

static void CanBSP_STM32_Can2_CfgFilter()   
{
   CAN_FilterTypeDef  sFilterConfig;
   CAN_FilterTypeDef  sFilterConfig1;
	
	 sFilterConfig.FilterBank = 14;

   sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;    /* 工作在标识符屏蔽位模式 */
   sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;   /* 过滤器位宽为单个32位。*/
	
	 sFilterConfig.FilterIdHigh = (((uint32_t)0x600<<21)&0xFFFF0000) >> 16;  
   sFilterConfig.FilterIdLow = (((uint32_t)0x600 << 21)|CAN_ID_STD|CAN_RTR_DATA)&0XFFFF;
   sFilterConfig.FilterMaskIdHigh = (((uint32_t)0x600<<21)&0xFFFF0000) >> 16;
   sFilterConfig.FilterMaskIdLow = 0x0000;

   sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;  /* 过滤器被关联到FIFO 1 */
 
   sFilterConfig.FilterActivation = ENABLE;  	/* 使能过滤器 */ 
	
	 sFilterConfig1 = sFilterConfig;
	 
	 sFilterConfig1.FilterBank = 15;
	
	 sFilterConfig1.FilterIdHigh = (((uint32_t)0x500<<21)&0xFFFF0000) >> 16;  
   sFilterConfig1.FilterIdLow = (((uint32_t)0x500 << 21)|CAN_ID_STD|CAN_RTR_DATA)&0XFFFF;
   sFilterConfig1.FilterMaskIdHigh = (((uint32_t)0x500<<21)&0xFFFF0000) >> 16;
   sFilterConfig1.FilterMaskIdLow = 0x0000;
 
  if (HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig) != HAL_OK)
  {
    /* Filter configuration Error */
    Error_Handler();
  }
  if (HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig1) != HAL_OK)
  {
    /* Filter configuration Error */
    Error_Handler();
  }

  /* Start the CAN peripheral */
  if (HAL_CAN_Start(&hcan2) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }

  /* Activate CAN RX notification */
  if (HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING) != HAL_OK)
  {
    /* Notification Error ??€??ˉ???èμ·??-??μ?…?è???¤±è′¥*/
    Error_Handler();
  }

 }

文章来源:https://blog.csdn.net/weixin_43996145/article/details/135287193
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。