你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【STM32L562E-DK 测评】开发板功能检测——BSP 工程测试

[复制链接]
无垠的广袤 发布时间:2025-3-9 12:58

【STM32L562E-DK 测评】开发板功能检测——BSP 工程测试

本文介绍了通过官方 Demo 完成开发板功能测试的流程。

工程介绍

打开 ST 官网提供的例程 STM32Cube_FW_L5_V1.5.0\Projects\STM32L562E-DK\Examples\BSP (Board Support Package,BSP),测试内容包括(详见 Doc/readme.txt

Keil_expand.jpg

main 函数

代码

int main(void)
{
  HAL_Init();
  SystemClock_Config();

  HAL_ICACHE_ConfigAssociativityMode(ICACHE_1WAY);
  if (HAL_ICACHE_Enable() != HAL_OK)
  {
    Error_Handler();
  }

  SystemHardwareInit();

  Display_DemoDescription();

  while (1)
  {
    if(UserButtonPressed == SET)
    {
      /* Add delay to avoid rebound and reset it status */
      HAL_Delay(500);
      UserButtonPressed = RESET;

      BSP_examples[DemoIndex++].DemoFunc();

      if(DemoIndex >= COUNT_OF_EXAMPLE(BSP_examples))
      {
        DemoIndex = 0;
      }

      Display_DemoDescription();
    }
  }
}

通过 ****USER 按钮** 切换测试,实现不同组件的功能检测。**

若检测到错误,红色 LED 每 500 毫秒闪烁一次。

LED

该项目展示了如何打开、关闭和切换所有LED。

void Led_demo(void)
{
  uint32_t index = 0;
  
  Led_SetHint();
  
  /* Init and turn on LED 1 to 4  */
  UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
  UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_BLUE);
  UTIL_LCD_DisplayStringAt(0, 120, (uint8_t *)"Initialize then turn on", CENTER_MODE);
  UTIL_LCD_DisplayStringAt(0, 135, (uint8_t *)"each led after 500 ms", CENTER_MODE);

  HAL_Delay(500);
  if (BSP_LED_On(LED9) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  HAL_Delay(500);
  if (BSP_LED_On(LED10) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  /* Keep the LEDs on for two seconds */
  HAL_Delay(2000);
  
  /* Turn off the LEDs */ 
  UTIL_LCD_DisplayStringAt(0, 120, (uint8_t *)"        Turn off        ", CENTER_MODE);
  UTIL_LCD_DisplayStringAt(0, 135, (uint8_t *)"each led after 500 ms", CENTER_MODE);
  HAL_Delay(500);
  if (BSP_LED_Off(LED9) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  HAL_Delay(500);
  if (BSP_LED_Off(LED10) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  HAL_Delay(2000);
  
  /* After two seconds, turn on LED10 and LED9 */
  UTIL_LCD_DisplayStringAt(0, 120, (uint8_t *)"      Turn on led 10      ", CENTER_MODE);
  UTIL_LCD_DisplayStringAt(0, 135, (uint8_t *)"                      ", CENTER_MODE);
  if (BSP_LED_On(LED10) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  HAL_Delay(500);
  
  UTIL_LCD_DisplayStringAt(0, 120, (uint8_t *)"      Turn on led 9      ", CENTER_MODE);
  if (BSP_LED_On(LED9) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  HAL_Delay(500);
  
  /* For about five seconds, toggle all the LEDs */
  UTIL_LCD_DisplayStringAt(0, 120, (uint8_t *)"     Toggle all leds     ", CENTER_MODE);
  while (index < 25)
  {
    HAL_Delay(200);
    index++;
    if (BSP_LED_Toggle(LED9) != BSP_ERROR_NONE)
    {
      Error_Handler();
    }
    if (BSP_LED_Toggle(LED10) != BSP_ERROR_NONE)
    {
      Error_Handler();
    }
  }
}

LCD

该项目展示了如何使用LCD的不同功能来显示不同字体的字符串、显示不同形状以及绘制位图。

void LCD_demo(void)
{
  LCD_SetHint();
  LCD_Feature = 0;
  LCD_Show_Feature (LCD_Feature);

  while (1)
  {
    if (UserButtonPressed == SET)
    {
      /* Add delay to avoid rebound and reset it status */
      HAL_Delay(500);
      UserButtonPressed = RESET;

      if (++LCD_Feature < LCD_FEATURES_NUM)
      {
        LCD_Show_Feature(LCD_Feature);
      }
      else
      {
        return;
      }
    }
  }
}

触摸屏

该项目展示了如何使用触摸屏的不同功能。

void Touchscreen_demo(void)
{
  uint16_t   x, y;
  uint8_t    state = 0;
  uint8_t    text[30];
  uint8_t    radius;
  uint8_t    radius_previous = 0;
  TS_MultiTouch_State_t TsMultipleState = {0};

  Touchscreen_SetHint();

  Touchscreen_DrawBackground(state);
  
  while (1)
  {
    /* Check in interrupt in touch screen the touch status and coordinates    */
      /* if touch occurred                                                      */
    if (TouchDetected == SET)
    {
      TouchDetected = RESET;
      
      if (BSP_TS_Get_MultiTouchState(0, &TsMultipleState) != BSP_ERROR_NONE)
      {
        Error_Handler();
      }
      if(TsMultipleState.TouchDetected >= 1)
      {
        /* Get X and Y position of the touch post calibrated */
        x = TsMultipleState.TouchX[0];
        y = TsMultipleState.TouchY[0];

        UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
        UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_BLACK);
        sprintf((char*)text, "Nb touch detected = %lu", (unsigned long)TsMultipleState.TouchDetected);
        UTIL_LCD_DisplayStringAt(15, 185, (uint8_t *)&text, LEFT_MODE);

        /* Display 1st touch detected coordinates */
        sprintf((char*)text, "1[%lu,%lu]    ", (unsigned long)x, (unsigned long)y);
        UTIL_LCD_DisplayStringAt(15, 200, (uint8_t *)&text, LEFT_MODE);
        
        if (TsMultipleState.TouchDetected >= 2)  /* Display 2nd touch detected coordinates if applicable */
        {
          sprintf((char*)text, "2[%lu,%lu]    ", (unsigned long)TsMultipleState.TouchX[1], (unsigned long)TsMultipleState.TouchY[1]);
          UTIL_LCD_DisplayStringAt(15, 215, (uint8_t *)&text, LEFT_MODE);
        }
        else
        {
          sprintf((char*)text, "              ");
          UTIL_LCD_DisplayStringAt(15, 215, (uint8_t *)&text, LEFT_MODE);
        }
        
        /* Weight not supported so radius maximum */
        radius = CIRCLE_RADIUS;

        if ((y > (CIRCLE_YPOS(1) - CIRCLE_RADIUS)) &&
            (y < (CIRCLE_YPOS(1) + CIRCLE_RADIUS)))
        {

          if ((x > (CIRCLE_XPOS(1) - CIRCLE_RADIUS)) &&
              (x < (CIRCLE_XPOS(1) + CIRCLE_RADIUS)))
          {
            if ((radius != radius_previous) || (state != 1))
            {
              if (state != 1) /* Erase previous filled circle */
              {
                Touchscreen_DrawBackground(state);
              }
              UTIL_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), radius, UTIL_LCD_COLOR_BLUE);
              radius_previous = radius;
              state = 1;
            }
          }
          if ((x > (CIRCLE_XPOS(2) - CIRCLE_RADIUS)) &&
              (x < (CIRCLE_XPOS(2) + CIRCLE_RADIUS)))
          {
            if ((radius != radius_previous) || (state != 2))
            {
              if (state != 2) /* Erase previous filled circle */
              {
                Touchscreen_DrawBackground(state);
              }
              UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), radius, UTIL_LCD_COLOR_RED);
              radius_previous = radius;
              state = 2;
            }
          }

          if ((x > (CIRCLE_XPOS(3) - CIRCLE_RADIUS)) &&
              (x < (CIRCLE_XPOS(3) + CIRCLE_RADIUS)))
          {
            if ((radius != radius_previous) || (state != 4))
            {
              if (state != 4) /* Erase previous filled circle */
              {
                Touchscreen_DrawBackground(state);
              }
              UTIL_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), radius, UTIL_LCD_COLOR_YELLOW);
              radius_previous = radius;
              state = 4;
            }
          }

          if ((x > (CIRCLE_XPOS(4) - CIRCLE_RADIUS)) &&
              (x < (CIRCLE_XPOS(4) + CIRCLE_RADIUS)))
          {
            if ((radius != radius_previous) || (state != 8))
            {
              if (state != 8) /* Erase previous filled circle */
              {
                Touchscreen_DrawBackground(state);
              }
              UTIL_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), radius, UTIL_LCD_COLOR_GREEN);
              radius_previous = radius;
              state = 8;
            }
          }
        }
      } /* of if(TS_State.touchDetected) */
    }

    if (UserButtonPressed == SET)
    {
      /* Add delay to avoid rebound and reset it status */
      HAL_Delay(500);
      UserButtonPressed = RESET;
      
      return;
    }
  }
}

音频播放

该项目展示了如何播放音频文件。

将耳机插入 CN13 连接器以听到声音,默认音量为80%,注意保护耳朵。

void AudioPlay_demo(void)
{  
  WAVE_FormatTypeDef *waveformat =  NULL;
  uint8_t Volume_string[20] = {0};
  BSP_AUDIO_Init_t AudioInit;
  uint8_t status = 0;

  PlaybackPosition   = (2*PLAY_BUFF_SIZE) + PLAY_HEADER;
  
  AudioPlay_SetHint();

  AudioPlayTest = 1;
  
  /* Check if the audio buffer has been loaded in flash */
  if (*((uint64_t *)AUDIO_FILE_ADDRESS) != 0x017EFE2446464952 )
  {
    UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);    
    UTIL_LCD_DisplayStringAt(0, 130, (uint8_t*)"Initialization problem", CENTER_MODE); 
    UTIL_LCD_DisplayStringAt(0, 145, (uint8_t*)"No Audio data in Flash", CENTER_MODE); 
    status = 1;
  }
  else
  {
    /* Retrieve Wave Sample rate*/
    waveformat = (WAVE_FormatTypeDef*) AUDIO_FILE_ADDRESS;
    AudioPlay_DisplayInfos(waveformat);

    /* Initialize Audio Device */
    AudioInit.Device        = AUDIO_OUT_HEADPHONE;
    AudioInit.SampleRate    = waveformat->SampleRate;
    AudioInit.BitsPerSample = waveformat->BitPerSample;
    AudioInit.ChannelsNbr   = waveformat->NbrChannels;
    AudioInit.Volume        = 80;
    if (BSP_AUDIO_OUT_Init(0, &AudioInit) != BSP_ERROR_NONE)
    {
      UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);    
      UTIL_LCD_DisplayStringAt(0, 130, (uint8_t*)"Initialization problem", CENTER_MODE); 
      UTIL_LCD_DisplayStringAt(0, 145, (uint8_t*)"Audio Codec not detected", CENTER_MODE);
      status = 1;
    }
    else
    {
      /* Initialize the data buffer */
      for(int i=0; i < PLAY_BUFF_SIZE; i++)
      {
        PlayBuff[i]=*((__IO uint16_t *)(AUDIO_FILE_ADDRESS + PLAY_HEADER + (2*i)));
      }
      
      /* Start the audio player */
      if (BSP_AUDIO_OUT_Play(0, (uint8_t *) PlayBuff, 2*PLAY_BUFF_SIZE) == BSP_ERROR_NONE)
      {
        /* Turn ON LED green: start of Audio file play */
        BSP_LED_On(LED_GREEN);
        
        UTIL_LCD_DisplayStringAt(20, 195, (uint8_t *)"Playback on-going", LEFT_MODE);
        sprintf((char *) Volume_string, "Volume : %lu%% ", (unsigned long)AudioInit.Volume);
        UTIL_LCD_DisplayStringAt(20, 210, Volume_string, LEFT_MODE);
      }
      else
      {
        Error_Handler();
      }
    }
  }
  
  /* Infinite loop */
  while (UserButtonPressed != SET)
  { 
  }

  /* Add delay to avoid rebound and reset it status */
  HAL_Delay(500);
  UserButtonPressed = RESET;
  
  /* Stop Player before close Test */
  if(status == 0)
  {
    if (BSP_AUDIO_OUT_Stop(0) != BSP_ERROR_NONE)
    {
      /* Audio Stop error */
      Error_Handler();
    }

    /* De-initialize playback */
    if(BSP_AUDIO_OUT_DeInit(0) != BSP_ERROR_NONE)
    {
      Error_Handler();
    }
  }

  AudioPlayTest = 0;

  /* Turn OFF LED green: stop of Audio file play */
  BSP_LED_Off(LED_GREEN);
}

音频录制

该项目使用板上麦克风,声音将自动录制并通过 CN13 连接器播放。

录制期间绿色 LED 闪烁。

void AudioRecord_demo(void)
{
  uint32_t i;
  
  /* Display test information */
  AudioRecord_SetHint();
  
  /* Initialize record */
  Record_Init();
  
  /* Initialize playback */
  Playback_Init();
  
  /* Start record */
  if (BSP_AUDIO_IN_Record(1, (uint8_t*) RecordBuff, 8192) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  /* Start loopback */
  while(UserButtonPressed != SET)
  {
    if(RecHalfBuffCplt == 1)
    {
      /* Store values on Play buff */
      for(i = 0; i < 2048; i++)
      {
        PlaybackBuff[i] = RecordBuff[i];
      }
      if (PlaybackStarted == 0)
      {
        /* Insert a little delay before starting playback to be sure that data are available for playback */
        /* Without this delay, potential noise when optimization high is selected for compiler */
        HAL_Delay(10);
        /* Start the playback */
        if (BSP_AUDIO_OUT_Play(0, (uint8_t *) PlaybackBuff, 8192) != BSP_ERROR_NONE)
        {
          Error_Handler();
        }
        PlaybackStarted = 1;
      }      
      RecHalfBuffCplt = 0;
    }
    if(RecBuffCplt == 1)
    {
      /* Store values on Play buff */
      for(i = 2048; i < 4096; i++)
      {
        PlaybackBuff[i] = RecordBuff[i];
      }
      RecBuffCplt  = 0;
    }
  }
  /* Add delay to avoid rebound and reset it status */
  HAL_Delay(500);
  UserButtonPressed = RESET;
  
  /* Stop playback */
  if (BSP_AUDIO_OUT_Stop(0) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  /* Stop record */
  if(BSP_AUDIO_IN_Stop(1) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  /* De-initialize playback */
  if(BSP_AUDIO_OUT_DeInit(0) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  /* De-initialize record */
  if(BSP_AUDIO_IN_DeInit(1) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  /* Switch off LEDs */
  BSP_LED_Off(LED_GREEN);
  
  /* Reset global variables */
  RecHalfBuffCplt  = 0;
  RecBuffCplt      = 0;
  PlaybackStarted  = 0;
}

SD 卡

该项目展示了如何擦除、写入和读取SD卡,以及如何检测 SD 卡的存在。

void SD_demo(void)
{
  int32_t SD_state = BSP_ERROR_NONE;
  static uint8_t prev_status = 2;  /* Undefined state */

  SD_SetHint();

  SD_state = BSP_SD_Init(0);

#if (SD_CARD_PRESENCE_VALIDATION_MODE == SD_CARD_PRESENCE_INTERRUPT_MODE)
  if (SD_state == BSP_ERROR_NONE)
  {
    SD_state = BSP_SD_DetectITConfig(0);
  }
#endif
  
  if (SD_state != BSP_ERROR_NONE)
  {
    if (SD_state == BSP_ERROR_UNKNOWN_COMPONENT)
    {
      UTIL_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD shall be inserted before", LEFT_MODE);
      UTIL_LCD_DisplayStringAt(20, 115, (uint8_t *)"running test.", LEFT_MODE);
      UTIL_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
    }
    else
    {
      UTIL_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD Initialization : FAIL.", LEFT_MODE);
      UTIL_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
    }
  }
  else
  {
    UTIL_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD Initialization : OK.", LEFT_MODE);

    UTIL_LCD_DisplayStringAt(20, 210, (uint8_t *)"SD Connected    ", LEFT_MODE);
    prev_status = SD_PRESENT;

    SD_state = BSP_SD_Erase(0, BLOCK_START_ADDR, (BLOCKSIZE * NUM_OF_BLOCKS));
  
    /* Wait until SD card is ready to use for new operation */
    while (BSP_SD_GetCardState(0) != SD_TRANSFER_OK)
    {
    }

    if (SD_state != BSP_ERROR_NONE)
    {
      UTIL_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD ERASE : FAILED.", LEFT_MODE);
      UTIL_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
    }
    else
    {
      UTIL_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD ERASE : OK.", LEFT_MODE);

      /* Fill the buffer to write */
      Fill_Buffer(aTxBuffer, BUFFER_WORDS_SIZE, 0x22FF);
      SD_state = BSP_SD_WriteBlocks_DMA(0, aTxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS);

      /* Wait for the write process is completed */
      while((SDWriteStatus == 0))
      {
      }
      SDWriteStatus = 0;

      /* Wait until SD cards are ready to use for new operation */
      while((BSP_SD_GetCardState(0) != SD_TRANSFER_OK))
      {
      } 

      if (SD_state != BSP_ERROR_NONE)
      {
        UTIL_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD WRITE : FAILED.", LEFT_MODE);
        UTIL_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
      }
      else
      {
        UTIL_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD WRITE : OK.", LEFT_MODE);
        SD_state = BSP_SD_ReadBlocks_DMA(0, aRxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS);

        /* Wait for the read process is completed */
        while(SDReadStatus == 0)
        {
        }
        SDReadStatus = 0;

        /* Wait until SD card is ready to use for new operation */
        while(BSP_SD_GetCardState(0) != SD_TRANSFER_OK)
        {
        }

        if (SD_state != BSP_ERROR_NONE)
        {
          UTIL_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD READ : FAILED.", LEFT_MODE);
          UTIL_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
        }
        else
        {
          UTIL_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD READ : OK.", LEFT_MODE);
          if (Buffercmp(aTxBuffer, aRxBuffer, BUFFER_WORDS_SIZE) > 0)
          {
            UTIL_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD COMPARE : FAILED.", LEFT_MODE);
            UTIL_LCD_DisplayStringAt(20, 175, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
          }
          else
          {
            UTIL_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD Test : OK.", LEFT_MODE);
            UTIL_LCD_DisplayStringAt(20, 175, (uint8_t *)"SD can be removed.", LEFT_MODE);
          }
        }
      }
    }
  }

  while (1)
  {
#if (SD_CARD_PRESENCE_VALIDATION_MODE == SD_CARD_PRESENCE_INTERRUPT_MODE)
    if(SDDetectIT != 0)
    {
#endif
      /* Check if the SD card is plugged in the slot */
      if (SDDetectStatus != SD_PRESENT)
      {
        if (prev_status != SD_NOT_PRESENT)
        {
          prev_status = SD_NOT_PRESENT;
          UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);
          UTIL_LCD_DisplayStringAt(20, 210, (uint8_t *)"SD Not Connected", LEFT_MODE);
        }
      }
      else if (prev_status != SD_PRESENT)
      {
        UTIL_LCD_DisplayStringAt(20, 210,   (uint8_t *)"SD Connected    ", LEFT_MODE);
        prev_status = SD_PRESENT;
      }
#if (SD_CARD_PRESENCE_VALIDATION_MODE == SD_CARD_PRESENCE_INTERRUPT_MODE)
      SDDetectIT = 0;
    }
#endif

    if (UserButtonPressed == SET)
    {
      /* Add delay to avoid rebound and reset it status */
      HAL_Delay(500);
      UserButtonPressed = RESET;
      
      return;
    }
  }
}

OSPI NOR

该项目展示了如何擦除、写入和读取板上 Octal Flash 存储器中的数据。

void OSPI_NOR_demo(void)
{ 
  BSP_OSPI_NOR_Init_t sOSPI_NOR_Init;
  BSP_OSPI_NOR_Info_t sOSPI_NOR_Info;
  int32_t status;
  __IO uint8_t *data_ptr;
  uint32_t index;
  Led_TypeDef led = LED_RED;
  uint16_t lcd_text_ypos = LCD_TEXT_YPOS_START;
  
/************ Part 1 ~ 4 *************/
}
Part 1
  /********************************** PART 1 **********************************/
  led = LED_RED;
  lcd_text_ypos = LCD_TEXT_YPOS_START;
  OSPI_NOR_SetHint();
  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Part I : Write & Read,", LEFT_MODE);
  lcd_text_ypos+=LCD_TEXT_YPOS_INC;
  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"         Data Integrity,", LEFT_MODE);
  lcd_text_ypos+=LCD_TEXT_YPOS_INC;
  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"         Memory mapped", LEFT_MODE);
  lcd_text_ypos+=(LCD_TEXT_YPOS_INC * 2);
  
  /*##-1- Configure the OSPI NOR device ######################################*/
  /* OSPI NOR device configuration */ 
  sOSPI_NOR_Init.InterfaceMode = BSP_OSPI_NOR_SPI_MODE;
  sOSPI_NOR_Init.TransferRate  = BSP_OSPI_NOR_STR_TRANSFER;
  status = BSP_OSPI_NOR_Init(0, &sOSPI_NOR_Init);
  
  if (status != BSP_ERROR_NONE)
  {
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Initialization : Failed", LEFT_MODE);
    lcd_text_ypos+=LCD_TEXT_YPOS_INC;
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
  }
  else
  {
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Initialization : OK", LEFT_MODE);
    lcd_text_ypos+=LCD_TEXT_YPOS_INC;

    /*##-2- Read & check the OSPI NOR info ###################################*/
    /* Initialize the structure */
    sOSPI_NOR_Info.FlashSize             = (uint32_t)0x00;
    sOSPI_NOR_Info.EraseSectorSize       = (uint32_t)0x00;
    sOSPI_NOR_Info.EraseSectorsNumber    = (uint32_t)0x00;
    sOSPI_NOR_Info.EraseSubSectorSize    = (uint32_t)0x00;
    sOSPI_NOR_Info.EraseSubSectorNumber  = (uint32_t)0x00;
    sOSPI_NOR_Info.EraseSubSector1Size   = (uint32_t)0x00;
    sOSPI_NOR_Info.EraseSubSector1Number = (uint32_t)0x00;
    sOSPI_NOR_Info.ProgPageSize          = (uint32_t)0x00;
    sOSPI_NOR_Info.ProgPagesNumber       = (uint32_t)0x00;
    
    /* Read the OSPI NOR memory info */
    if (BSP_OSPI_NOR_GetInfo(0, &sOSPI_NOR_Info) != BSP_ERROR_NONE)
    {
      Error_Handler();
    }
    
    /* Test the correctness */
    if((sOSPI_NOR_Info.FlashSize             != MX25LM51245G_FLASH_SIZE)   ||
       (sOSPI_NOR_Info.EraseSectorSize       != MX25LM51245G_SECTOR_64K)   ||
       (sOSPI_NOR_Info.EraseSubSectorSize    != MX25LM51245G_SUBSECTOR_4K) ||
       (sOSPI_NOR_Info.EraseSubSector1Size   != MX25LM51245G_SUBSECTOR_4K) ||
       (sOSPI_NOR_Info.ProgPageSize          != MX25LM51245G_PAGE_SIZE)    ||
       (sOSPI_NOR_Info.EraseSectorsNumber    != (MX25LM51245G_FLASH_SIZE/MX25LM51245G_SECTOR_64K))   ||
       (sOSPI_NOR_Info.EraseSubSectorNumber  != (MX25LM51245G_FLASH_SIZE/MX25LM51245G_SUBSECTOR_4K)) ||
       (sOSPI_NOR_Info.EraseSubSector1Number != (MX25LM51245G_FLASH_SIZE/MX25LM51245G_SUBSECTOR_4K)) ||
       (sOSPI_NOR_Info.ProgPagesNumber       != (MX25LM51245G_FLASH_SIZE/MX25LM51245G_PAGE_SIZE)))
    {
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Get Info : Failed", LEFT_MODE);
      lcd_text_ypos+=LCD_TEXT_YPOS_INC;
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
    }
    else
    {
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Get Info : OK", LEFT_MODE);
      lcd_text_ypos+=LCD_TEXT_YPOS_INC;
      
      /* Caution: Despite instruction cache is enabled, no need for cache invalidation here since no previous */
      /*          fetch (read/execute) instructions were executed from OSPI_NOR_WRITE_READ_ADDR               */

      /*##-3- Erase OSPI NOR memory ##########################################*/ 
      if (BSP_OSPI_NOR_Erase_Block(0, OSPI_NOR_WRITE_READ_ADDR, MX25LM51245G_ERASE_64K) != BSP_ERROR_NONE)
      {
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase : Failed", LEFT_MODE);
        lcd_text_ypos+=LCD_TEXT_YPOS_INC;
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
      }
      else
      {
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase : OK", LEFT_MODE);
        lcd_text_ypos+=LCD_TEXT_YPOS_INC;

        /*##-4- OSPI NOR memory read/write access  ###########################*/   
        /* Fill the buffer to write */
        Fill_Buffer(ospi_nor_aTxBuffer, OSPI_NOR_BUFFER_SIZE, 0xD20F);   
        
        /* Write data to the OSPI NOR memory */
        if (BSP_OSPI_NOR_Write(0, ospi_nor_aTxBuffer, OSPI_NOR_WRITE_READ_ADDR, OSPI_NOR_BUFFER_SIZE) != BSP_ERROR_NONE)
        {
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Write : Failed", LEFT_MODE);
          lcd_text_ypos+=LCD_TEXT_YPOS_INC;
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
        }
        else
        {
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Write : OK", LEFT_MODE);
          lcd_text_ypos+=LCD_TEXT_YPOS_INC;

          /* Read back data from the OSPI NOR memory */
          if (BSP_OSPI_NOR_Read(0, ospi_nor_aRxBuffer, OSPI_NOR_WRITE_READ_ADDR, OSPI_NOR_BUFFER_SIZE) != BSP_ERROR_NONE)
          {
            UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Read : Failed", LEFT_MODE);
            lcd_text_ypos+=LCD_TEXT_YPOS_INC;
            UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
          }
          else
          {
            UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Read : OK", LEFT_MODE);
            lcd_text_ypos+=LCD_TEXT_YPOS_INC;

            /*##-5- Checking data integrity ##################################*/  
            if(Buffercmp(ospi_nor_aRxBuffer, ospi_nor_aTxBuffer, OSPI_NOR_BUFFER_SIZE) > 0)
            {
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Compare : Failed", LEFT_MODE);
              lcd_text_ypos+=LCD_TEXT_YPOS_INC;
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
            }
            else
            {    
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Compare : OK", LEFT_MODE);
              lcd_text_ypos+=LCD_TEXT_YPOS_INC;

              /*##-6- OSPI NOR memory in memory-mapped mode###################*/
              if (BSP_OSPI_NOR_EnableMemoryMappedMode(0) != BSP_ERROR_NONE)
              {
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Mem-Mapped Cfg : Failed", LEFT_MODE);
                lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
              }
              else
              {
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Mem-Mapped Cfg : OK", LEFT_MODE);
                lcd_text_ypos+=LCD_TEXT_YPOS_INC;

                for(index = 0, data_ptr = (__IO uint8_t *)(OSPI_NOR_BASE_ADDR + OSPI_NOR_WRITE_READ_ADDR); 
                    index < OSPI_NOR_BUFFER_SIZE; index++, data_ptr++)
                {
                  if(*data_ptr != ospi_nor_aTxBuffer[index])
                  {
                    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Mem-Mapped Access : Failed", LEFT_MODE);
                    lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
                    break;
                  }
                }
                
                if(index == OSPI_NOR_BUFFER_SIZE)
                {
                  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Mem-Mapped Access : OK", LEFT_MODE);
                  lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test : OK", LEFT_MODE);
                  led = LED_GREEN;
                }
              }
            }  
          }
        }
      }
    }
  }
  
  while (1)
  {    
    if(UserButtonPressed == SET)
    {
      /* Add delay to avoid rebound and reset it status */
      HAL_Delay(500);
      UserButtonPressed = RESET;

      break;
    }
    BSP_LED_Toggle(led);
    HAL_Delay(100);
  }
  BSP_LED_Off(led);
Part 2
  /********************************** PART 2 **********************************/
  /* Suspend/Resume during erase operation */
  led = LED_RED;
  lcd_text_ypos = LCD_TEXT_YPOS_START;
  OSPI_NOR_SetHint();
  
  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Part II : Erase Suspend and", LEFT_MODE);
  lcd_text_ypos+=LCD_TEXT_YPOS_INC;
  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"          Resume", LEFT_MODE);
  lcd_text_ypos+=(LCD_TEXT_YPOS_INC * 2);

  /*##-1- Deconfigure the OSPI NOR device ####################################*/
  status = BSP_OSPI_NOR_DeInit(0);
  
  if (status != BSP_ERROR_NONE)
  {
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"De-Initialization : Failed", LEFT_MODE);
    lcd_text_ypos+=LCD_TEXT_YPOS_INC;
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
  }
  else
  {
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"De-Initialization : OK", LEFT_MODE);
    lcd_text_ypos+=LCD_TEXT_YPOS_INC;

    /*##-2- Reconfigure the OSPI NOR device ##################################*/
    /* QSPI device configuration */ 
    status = BSP_OSPI_NOR_Init(0, &sOSPI_NOR_Init);
    
    if (status != BSP_ERROR_NONE)
    {
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Initialization : Failed", LEFT_MODE);
      lcd_text_ypos+=LCD_TEXT_YPOS_INC;
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
    }
    else
    {
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Initialization : OK", LEFT_MODE);
      lcd_text_ypos+=LCD_TEXT_YPOS_INC;
      
      /*##-3- Erase OSPI NOR memory ##########################################*/ 
      if (BSP_OSPI_NOR_Erase_Block(0, 0, MX25LM51245G_ERASE_4K) != BSP_ERROR_NONE)
      {
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase : Failed", LEFT_MODE);
        lcd_text_ypos+=LCD_TEXT_YPOS_INC;
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
      }
      else
      {

        /*##-4- Suspend erase OSPI NOR memory ################################*/
        if (BSP_OSPI_NOR_SuspendErase(0) != BSP_ERROR_NONE)
        {
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase : OK", LEFT_MODE);
          lcd_text_ypos+=LCD_TEXT_YPOS_INC;
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase Suspend : Failed", LEFT_MODE);
          lcd_text_ypos+=LCD_TEXT_YPOS_INC;
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
        }
        else
        {
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase : OK", LEFT_MODE);
          lcd_text_ypos+=LCD_TEXT_YPOS_INC;
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase Suspend : OK", LEFT_MODE);
          lcd_text_ypos+=LCD_TEXT_YPOS_INC;
          
          /*##-6- Resume erase OSPI NOR memory ###############################*/ 
          if (BSP_OSPI_NOR_ResumeErase(0) != BSP_ERROR_NONE)
          {
            UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase Resume : Failed", LEFT_MODE);
            lcd_text_ypos+=LCD_TEXT_YPOS_INC;
            UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
          }
          else
          {
            UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase Resume : OK", LEFT_MODE);
            lcd_text_ypos+=LCD_TEXT_YPOS_INC;
            
            /*##-7- Check OSPI NOR memory status  ############################*/   
            /* Wait the end of the current operation on memory side */
            do
            {
              status = BSP_OSPI_NOR_GetStatus(0);
            } while((status != BSP_ERROR_NONE) && (status != BSP_ERROR_COMPONENT_FAILURE));
            
            if(status != BSP_ERROR_NONE)
            {
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Memory Status : Failed", LEFT_MODE);
              lcd_text_ypos+=LCD_TEXT_YPOS_INC;
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
            }
            else
            {
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Memory Status : OK", LEFT_MODE);
              lcd_text_ypos+=LCD_TEXT_YPOS_INC;
              
              /*##-8- OSPI NOR memory read access  ###########################*/   
              /* Read back data from the OSPI NOR memory */
              if (BSP_OSPI_NOR_Read(0, ospi_nor_aRxBuffer, 0, MX25LM51245G_SUBSECTOR_4K) != BSP_ERROR_NONE)
              {
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Read : Failed", LEFT_MODE);
                lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
              }
              else
              {
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Read : OK", LEFT_MODE);
                lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                
                /*##-9- Checking data integrity ##############################*/  
                if (DataCmp(ospi_nor_aRxBuffer, 0xFF, MX25LM51245G_SUBSECTOR_4K) > 0)
                {
                  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Compare : Failed", LEFT_MODE);
                  lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
                }
                else
                {    
                  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Compare : OK", LEFT_MODE);
                  lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test : OK", LEFT_MODE);
                  led = LED_GREEN;
                }
              }
            }
          }  
        }
      }
    }
  }

  while (1)
  {    
    if(UserButtonPressed == SET)
    {
      /* Add delay to avoid rebound and reset it status */
      HAL_Delay(500);
      UserButtonPressed = RESET;

      break;
    }
    BSP_LED_Toggle(led);
    HAL_Delay(100);
  }
  BSP_LED_Off(led);
Part 3
  /********************************** PART 3 **********************************/
  led = LED_RED;
  lcd_text_ypos = LCD_TEXT_YPOS_START;
  OSPI_NOR_SetHint();
  
  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Part III : Enter & Leave", LEFT_MODE);
  lcd_text_ypos+=LCD_TEXT_YPOS_INC;
  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"           Flash Power Down", LEFT_MODE);
  lcd_text_ypos+=LCD_TEXT_YPOS_INC;
  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"           mode", LEFT_MODE);
  lcd_text_ypos+=(LCD_TEXT_YPOS_INC * 2);

  /*##-1- Deconfigure the OSPI NOR device ####################################*/
  status = BSP_OSPI_NOR_DeInit(0);
  
  if (status != BSP_ERROR_NONE)
  {
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"De-Initialization : Failed", LEFT_MODE);
    lcd_text_ypos+=LCD_TEXT_YPOS_INC;
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
  }
  else
  {
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"De-Initialization : OK", LEFT_MODE);
    lcd_text_ypos+=LCD_TEXT_YPOS_INC;

    /*##-2- Reconfigure the OSPI NOR device ##################################*/
    /* OSPI NOR device configuration */ 
    status = BSP_OSPI_NOR_Init(0, &sOSPI_NOR_Init);
    
    if (status != BSP_ERROR_NONE)
    {
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Initialization : Failed", LEFT_MODE);
      lcd_text_ypos+=LCD_TEXT_YPOS_INC;
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
    }
    else
    {
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Initialization : OK", LEFT_MODE);
      lcd_text_ypos+=LCD_TEXT_YPOS_INC;
      
      /*##-3- Erase OSPI NOR memory ##########################################*/ 
      if (BSP_OSPI_NOR_Erase_Block(0, OSPI_NOR_WRITE_READ_ADDR, MX25LM51245G_ERASE_4K) != BSP_ERROR_NONE)
      {
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase : Failed", LEFT_MODE);
        lcd_text_ypos+=LCD_TEXT_YPOS_INC;
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
      }
      else
      {
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Erase : OK", LEFT_MODE);
        lcd_text_ypos+=LCD_TEXT_YPOS_INC;

        /*##-4- OSPI NOR memory write access #################################*/
        /* Fill the buffer to write */
        Fill_Buffer(ospi_nor_aTxBuffer, OSPI_NOR_BUFFER_SIZE, 0xD20F);   
        
        /* Write data to the OSPI NOR memory */
        if (BSP_OSPI_NOR_Write(0, ospi_nor_aTxBuffer, OSPI_NOR_WRITE_READ_ADDR, OSPI_NOR_BUFFER_SIZE) != BSP_ERROR_NONE)
        {
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Write : Failed", LEFT_MODE);
          lcd_text_ypos+=LCD_TEXT_YPOS_INC;
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
        }
        else
        {
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Write : OK", LEFT_MODE);
          lcd_text_ypos+=LCD_TEXT_YPOS_INC;

          /*##-5- Enter OSPI NOR memory in deep power down ###################*/ 
          if (BSP_OSPI_NOR_EnterDeepPowerDown(0) != BSP_ERROR_NONE)
          {
            UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Enter Deep PwrDn : Failed", LEFT_MODE);
            lcd_text_ypos+=LCD_TEXT_YPOS_INC;
            UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
          }
          else
          {
            /* !!! Warning : This is only a test of the API. To check if the memory is really in deep power down, 
                   need to use Idd to check the consumption !!! */
            UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Enter Deep PwrDn : OK", LEFT_MODE);
            lcd_text_ypos+=LCD_TEXT_YPOS_INC;
            
            /*##-6- Leave OSPI NOR memory from deep power down ###############*/ 
            HAL_Delay(100);
            if (BSP_OSPI_NOR_LeaveDeepPowerDown(0) != BSP_ERROR_NONE)
            {
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Leave Deep PwrDn : Failed", LEFT_MODE);
              lcd_text_ypos+=LCD_TEXT_YPOS_INC;
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
            }
            else
            {
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Leave Deep PwrDn : OK", LEFT_MODE);
              lcd_text_ypos+=LCD_TEXT_YPOS_INC;
              
              /*##-7- OSPI NOR memory in memory-mapped mode#######################*/
              if (BSP_OSPI_NOR_EnableMemoryMappedMode(0) != BSP_ERROR_NONE)
              {
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Mem-Mapped Cfg : Failed", LEFT_MODE);
                lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
              }
              else
              {
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Mem-Mapped Cfg : OK", LEFT_MODE);
                lcd_text_ypos+=LCD_TEXT_YPOS_INC;

                for(index = 0, data_ptr = (__IO uint8_t *)(OSPI_NOR_BASE_ADDR + OSPI_NOR_WRITE_READ_ADDR); 
                    index < OSPI_NOR_BUFFER_SIZE; index++, data_ptr++)
                {
                  if(*data_ptr != ospi_nor_aTxBuffer[index])
                  {
                    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Mem-Mapped Access : Failed", LEFT_MODE);
                    lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
                    break;
                  }
                }
                
                if(index == OSPI_NOR_BUFFER_SIZE)
                {
                  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Mem-Mapped Access : OK", LEFT_MODE);
                  lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test : OK", LEFT_MODE);
                  led = LED_GREEN;
                }
              }
            }
          }  
        }
      }
    }
  }

  while (1)
  {    
    if(UserButtonPressed == SET)
    {
      /* Add delay to avoid rebound and reset it status */
      HAL_Delay(500);
      UserButtonPressed = RESET;

      break;
    }
    BSP_LED_Toggle(led);
    HAL_Delay(100);
  }
  BSP_LED_Off(led);
Part 4
  /********************************** PART 4 **********************************/
  /* Erase NOR  (up to 300s) */
  led = LED_RED;
  lcd_text_ypos = LCD_TEXT_YPOS_START;
  OSPI_NOR_SetHint();
  
  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Part IV : Erase ...", LEFT_MODE);
  lcd_text_ypos+=LCD_TEXT_YPOS_INC;
  UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"          wait up to 300s", LEFT_MODE);
  lcd_text_ypos+=(LCD_TEXT_YPOS_INC * 2);

  /*##-1- Deconfigure the OSPI NOR device ####################################*/
  status = BSP_OSPI_NOR_DeInit(0);
  
  if (status != BSP_ERROR_NONE)
  {
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"De-Initialization : Failed", LEFT_MODE);
    lcd_text_ypos+=LCD_TEXT_YPOS_INC;
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
  }
  else
  {
    UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"De-Initialization : OK", LEFT_MODE);
    lcd_text_ypos+=LCD_TEXT_YPOS_INC;

    /*##-2- Reconfigure the OSPI NOR device ##################################*/
    /* OSPI NOR device configuration */ 
    status = BSP_OSPI_NOR_Init(0, &sOSPI_NOR_Init);
    
    if (status != BSP_ERROR_NONE)
    {
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Initialization : Failed", LEFT_MODE);
      lcd_text_ypos+=LCD_TEXT_YPOS_INC;
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
    }
    else
    {
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Initialization : OK", LEFT_MODE);
      lcd_text_ypos+=LCD_TEXT_YPOS_INC;
      
      /*##-3- Erase OSPI NOR memory ##########################################*/ 
      UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Chip Erasing...", LEFT_MODE);

      if (BSP_OSPI_NOR_Erase_Chip(0) != BSP_ERROR_NONE)
      {
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Chip Erase : Failed", LEFT_MODE);
        lcd_text_ypos+=LCD_TEXT_YPOS_INC;
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
      }
      else
      {
        UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Chip Erase : OK", LEFT_MODE);
        lcd_text_ypos+=LCD_TEXT_YPOS_INC;

        /* Wait the end of the current operation on memory side */
        do
        {
          status = BSP_OSPI_NOR_GetStatus(0);
        } while((status != BSP_ERROR_NONE) && (status != BSP_ERROR_COMPONENT_FAILURE));
            
        if(status != BSP_ERROR_NONE)
        {
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Memory Status : Failed", LEFT_MODE);
          lcd_text_ypos+=LCD_TEXT_YPOS_INC;
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
        }
        else
        {
          UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Memory Status : OK", LEFT_MODE);
          lcd_text_ypos+=LCD_TEXT_YPOS_INC;

          for (index = 0; index < (MX25LM51245G_FLASH_SIZE / MX25LM51245G_SUBSECTOR_4K); index++)
          {
            /*##-4- OSPI NOR memory read access  ###############################*/
            /* Read back data from the OSPI NOR memory */
            if (BSP_OSPI_NOR_Read(0, ospi_nor_aRxBuffer, (index * MX25LM51245G_SUBSECTOR_4K), MX25LM51245G_SUBSECTOR_4K) != BSP_ERROR_NONE)
            {
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Read : Failed", LEFT_MODE);
              lcd_text_ypos+=LCD_TEXT_YPOS_INC;
              UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
              break;
            }
            else
            {
              /*##-5- Checking data integrity ################################*/  
              if(DataCmp(ospi_nor_aRxBuffer, 0xFF, MX25LM51245G_SUBSECTOR_4K) > 0)
              {
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Compare : Failed", LEFT_MODE);
                lcd_text_ypos+=LCD_TEXT_YPOS_INC;
                UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test Aborted", LEFT_MODE);
                break;
              }
            }
          }

          if (index == (MX25LM51245G_FLASH_SIZE / MX25LM51245G_SUBSECTOR_4K))
          {
            UTIL_LCD_DisplayStringAt(LCD_TEXT_XPOS, lcd_text_ypos, (uint8_t*)"Test : OK", LEFT_MODE);
            led = LED_GREEN;
          }
        }
      }
    }
  }

  /* De-initialization in order to have correct configuration memory on next try */
  BSP_OSPI_NOR_DeInit(0);

  while (1)
  {    
    if(UserButtonPressed == SET)
    {
      /* Add delay to avoid rebound and reset it status */
      BSP_LED_Off(led);
      HAL_Delay(500);
      UserButtonPressed = RESET;

      return;
    }
    BSP_LED_Toggle(led);
    HAL_Delay(100);
  }
}

运动传感器

该项目展示了如何使用板上的运动传感器(加速度计和陀螺仪功能)。

void MotionSensor_demo(void)
{
  BSP_MOTION_SENSOR_Axes_t         axes;
  BSP_MOTION_SENSOR_AxesRaw_t      axesRaw;
  uint8_t string[50] = {0};

  MotionSensor_SetHint();

  /*************************/
  /* Test of Accelerometer */
  /*************************/

  /* Initialize function */
  if (BSP_MOTION_SENSOR_Init(0, MOTION_ACCELERO) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }

  /* Enable function */
  if (BSP_MOTION_SENSOR_Enable(0, MOTION_ACCELERO) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  /* GetAxes function */
  UTIL_LCD_DisplayStringAt(20, 100, (uint8_t*) "Accelerometer axes", LEFT_MODE);
  while (UserButtonPressed == RESET)
  {
    if (BSP_MOTION_SENSOR_GetAxes(0, MOTION_ACCELERO, &axes) != BSP_ERROR_NONE)
    {
      Error_Handler();
    }
    if (BSP_MOTION_SENSOR_GetAxesRaw(0, MOTION_ACCELERO, &axesRaw) != BSP_ERROR_NONE)
    {
      Error_Handler();
    }
    sprintf((char*)string, "X = %ld      ", (signed long)axes.x);
    UTIL_LCD_DisplayStringAt(20, 115, string, LEFT_MODE);
    sprintf((char*)string, "Y = %ld      ", (signed long)axes.y);
    UTIL_LCD_DisplayStringAt(20, 130, string, LEFT_MODE);
    sprintf((char*)string, "Z = %ld      ", (signed long)axes.z);
    UTIL_LCD_DisplayStringAt(20, 145, string, LEFT_MODE);
    sprintf((char*)string, "Xraw = %d      ", axesRaw.x);
    UTIL_LCD_DisplayStringAt(20, 160, string, LEFT_MODE);
    sprintf((char*)string, "Yraw = %d      ", axesRaw.y);
    UTIL_LCD_DisplayStringAt(20, 175, string, LEFT_MODE);
    sprintf((char*)string, "Zraw = %d      ", axesRaw.z);
    UTIL_LCD_DisplayStringAt(20, 190, string, LEFT_MODE);
    HAL_Delay(500);
  }
  HAL_Delay(1000);
  UserButtonPressed = RESET;

  /* Disable function */
  if (BSP_MOTION_SENSOR_Disable(0, MOTION_ACCELERO) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }

  /* De-initialize function */
  if (BSP_MOTION_SENSOR_DeInit(0) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }

  /*********************/
  /* Test of Gyroscope */
  /*********************/

  MotionSensor_SetHint();

  /* Initialize function */
  if (BSP_MOTION_SENSOR_Init(0, MOTION_GYRO) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }

  /* Enable function */
  if (BSP_MOTION_SENSOR_Enable(0, MOTION_GYRO) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  /* GetAxes function */
  UTIL_LCD_DisplayStringAt(20, 100, (uint8_t*) "Gyroscope axes", LEFT_MODE);
  while (UserButtonPressed == RESET)
  {
    if (BSP_MOTION_SENSOR_GetAxes(0, MOTION_GYRO, &axes) != BSP_ERROR_NONE)
    {
      Error_Handler();
    }
    if (BSP_MOTION_SENSOR_GetAxesRaw(0, MOTION_GYRO, &axesRaw) != BSP_ERROR_NONE)
    {
      Error_Handler();
    }
    sprintf((char*)string, "X = %ld      ", (signed long)axes.x);
    UTIL_LCD_DisplayStringAt(20, 115, string, LEFT_MODE);
    sprintf((char*)string, "Y = %ld      ", (signed long)axes.y);
    UTIL_LCD_DisplayStringAt(20, 130, string, LEFT_MODE);
    sprintf((char*)string, "Z = %ld      ", (signed long)axes.z);
    UTIL_LCD_DisplayStringAt(20, 145, string, LEFT_MODE);
    sprintf((char*)string, "Xraw = %d      ", axesRaw.x);
    UTIL_LCD_DisplayStringAt(20, 160, string, LEFT_MODE);
    sprintf((char*)string, "Yraw = %d      ", axesRaw.y);
    UTIL_LCD_DisplayStringAt(20, 175, string, LEFT_MODE);
    sprintf((char*)string, "Zraw = %d      ", axesRaw.z);
    UTIL_LCD_DisplayStringAt(20, 190, string, LEFT_MODE);
    HAL_Delay(500);
  }
  HAL_Delay(1000);
  UserButtonPressed = RESET;

  /* Disable function */
  if (BSP_MOTION_SENSOR_Disable(0, MOTION_GYRO) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  
  /* De-initialize function */
  if (BSP_MOTION_SENSOR_DeInit(0) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }

  /***************/
  /* End of test */
  /***************/
}

效果展示

展示了部分测试效果。

加速度计

Accelerometer.jpg

陀螺仪

Gyroscope.jpg

LCD 显示测试

LCD_test.jpg

LCD_test3.jpg

总结

本文介绍了 STM32L562E-DK 开发板官方 Demo 例程的测试流程,BSP 例程的代码解析和效果展示,为后续深入研究提供必要的素材支持,也为相关开发提供了参考。

收藏 评论0 发布时间:2025-3-9 12:58

举报

0个回答
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版