title: PGSERR and PGPERR Bit Clear
body: <p>I have a problem with PGSERR and PGPERR bits being set after reset operation</p>
  <p>I am using stm32f4 board than I am using CANBUS and FW update process.</p>
  <p>When I use serial debug print in MX_CAN1_Init function. I faced with flash erasing error. Then I analyse that error I found PGSERR and PGPERR bits set.</p>
  <p>These bits have to be &quot;0&quot; .</p>
  <p>I wanted to analyze this problem so I did these test in my initlize states:</p>
  <pre><code>    MX_CAN1_Init();
   
   Serialdebugprint(&quot;Read PGAERR FLAG %d\n&quot;,__HAL_FLASH_GET_FLAG((FLASH_FLAG_PGPERR)));
   
   Serialdebugprint(&quot;Read PGSERR FLAG %d\n&quot;,__HAL_FLASH_GET_FLAG((FLASH_FLAG_PGSERR)));
  </code></pre>
  <p>I get this value:</p>
  <pre><code>Read PGAERR FLAG 64
  
  Read PGSERR FLAG 128
  </code></pre>
  <p>I get this value:</p>
  <p>Read PGAERR FLAG 64</p>
  <p>Read PGSERR FLAG 128</p>
  <p>But these flag has to be 0. After the reset.</p>
  <p>If I removed the MX_CAN1_Init these flag equals to &quot;0&quot;.</p>
  <p>When I changed some parameter in the CAN_Init function for example communication speed to 83.3kps to 1Mbs I get this flag as 0 and 128 . By the way when I remove the serialdebug I get the 0 and 128 again.</p>
  <p>If I put the MX_CAN1_Init function after a few function than this flag returns &quot;0&quot; .</p>
  <p>What is the reason?</p>
  <pre><code>    /**
   * @brief CAN1 Init function
   * @retval null
   */
   
  static void MX_CAN1_Init(void)
  {
    CAN_FilterTypeDef  sFilterConfig;
   
    
    hcan1.Instance = CAN1;
    hcan1.Init.Prescaler = 28; //3
    hcan1.Init.Mode = CAN_MODE_NORMAL;
    hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
    hcan1.Init.TimeSeg1 = CAN_BS1_15TQ; //11
    hcan1.Init.TimeSeg2 = CAN_BS2_2TQ; //2
    hcan1.Init.TimeTriggeredMode = DISABLE;
    hcan1.Init.AutoBusOff = ENABLE;
    hcan1.Init.AutoWakeUp = DISABLE;
    hcan1.Init.AutoRetransmission = ENABLE;
    hcan1.Init.ReceiveFifoLocked = DISABLE;
    hcan1.Init.TransmitFifoPriority = DISABLE;
    if (HAL_CAN_Init(&amp;hcan1) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
   
      /*##-2- Configure the CAN Filter ###########################################*/
    sFilterConfig.FilterBank = 0;
    sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
    sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
    sFilterConfig.FilterIdHigh = 0x0000;
    sFilterConfig.FilterIdLow = 0x0000;
    sFilterConfig.FilterMaskIdHigh = 0x0000;
    sFilterConfig.FilterMaskIdLow = 0x0000;
    sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
    sFilterConfig.FilterActivation = ENABLE;
    sFilterConfig.SlaveStartFilterBank = 0;
   
    if (HAL_CAN_ConfigFilter(&amp;hcan1, &amp;sFilterConfig) != HAL_OK)
    {
      /* Filter configuration Error */
          // SerialPrint(&quot;FILTER ERROR !!&quot;);
      Error_Handler();
    }
   
    /*##-3- Start the CAN peripheral ###########################################*/
    if (HAL_CAN_Start(&amp;hcan1) != HAL_OK)
    {
      // SerialPrint(&quot;CAN START ERROR !!&quot;);
      /* Start Error */
      Error_Handler();
    }
   
    /*##-4- Activate CAN RX notification #######################################*/
    if(HAL_CAN_ActivateNotification(&amp;hcan1,CAN_IT_TX_MAILBOX_EMPTY | CAN_IT_RX_FIFO0_MSG_PENDING |CAN_IT_BUSOFF) != HAL_OK)
    {
      Error_Handler();
    }
    Serialdebugprint(&quot;Success CAN Init \n&quot;);
  }
  </code></pre>
  <p>Serialdebugprint function:</p>
  <pre><code>void Serialdebugprint(const char *serial_data, ...)
  {
    char uartbuffer[1024]=&quot;&quot;;
    va_list arg;
    va_start(arg, serial_data);
    uint16_t len = vsnprintf(uartbuffer, 1024, serial_data, arg);
    va_end(arg);
    HAL_UART_Transmit(&amp;huart2, (uint8_t *)uartbuffer, len, 100);
   
  }
   
  </code></pre>
  <p>I think problem start HAL_UART_Transmit(&amp;huart2, (uint8_t *)uartbuffer, len, 100) after this line. What is the reason for ?</p>