[应用相关]

STM32F429开发之 外部sdram读写测试

[复制链接]
1888|1
手机看帖
扫描二维码
随时随地手机跟帖
Rollo|  楼主 | 2018-5-26 19:16 | 显示全部楼层 |阅读模式
硬件平台:STM32F429I-DISCORVERY
软件平台:KEIL MDK5.10

知识点:标准的SDRAM一般都是4个BANK,stm32f429-diso开发板使用的是IS42S16400J这个芯片。
IS42S16400J也有4个Bank,总容量为1Mbitx 16-bit x 4-bank = 67,108,864 bits = 64-Mbit ,每个BANK的组成
4096rows x 256 columns x 16 bits(=16Mbit), 对应的外部引线是12行8列,请参看datasheet.

实验目的:由于TM32F429I-DISCORVERY扩展了sdram,这对于视频播放,图片解码,音频解码,usb大容量数据缓冲
是非常有利的!

实验结果:
1.8Bit 测试成功率为100%,16Bit测试成功率为100%
#define IS42S16400J_SIZE     0x400000   // 4M x 16Bit(存储宽度)=16Mbit(每个Bank的容量)

int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f429_439xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
  */  
        
        uint8_t ubWritedata_8b = 0x3C, ubReaddata_8b = 0;  
  uint16_t uhWritedata_16b = 0x1E5A, uhReaddata_16b = 0;  
  uint32_t uwReadwritestatus = 0;
  uint32_t counter = 0x0;
        
  SysTick_Init();
  STM_EVAL_LED_Config();
  STM_EVAL_PBInit(BUTTON_MODE_EXTI);
        
  /* Initialize the LCD */
  LCD_Init();
  LCD_LayerInit();
  LTDC_Cmd(ENABLE);
  LCD_SetLayer(LCD_FOREGROUND_LAYER);
  LCD_Clear(LCD_COLOR_BLUE);
         
  /* Disable write protection */
  FMC_SDRAMWriteProtectionConfig(FMC_Bank2_SDRAM,DISABLE);
        

  while (1)
  {
               
                /*********************** 8-bits AHB transaction test ************************/   
                /* Wait for User button to be pressed */
                while (STM_EVAL_PBGetState() != Bit_SET)
                {}
                STM_EVAL_LEDOff(LED3);
                STM_EVAL_LEDOff(LED4);
                /* Wait for User button is released */
                while (STM_EVAL_PBGetState() != Bit_RESET)
                {}
        
                /* Erase SDRAM memory */
                for (counter = 0x00; counter < IS42S16400J_SIZE; counter++)
                {
                        *(__IO uint8_t*) (SDRAM_BANK_ADDR + counter) = (uint8_t)0x0;
                }
               
                /* Write data value to all SDRAM memory */
                for (counter = 0; counter < IS42S16400J_SIZE; counter++)
                {
                        *(__IO uint8_t*) (SDRAM_BANK_ADDR + counter) = (uint8_t)(ubWritedata_8b + counter);
                }
               
                /* Read back SDRAM memory and check content correctness*/
                counter = 0;
                uwReadwritestatus = 0;
                while ((counter < IS42S16400J_SIZE) && (uwReadwritestatus == 0))
                {
                        ubReaddata_8b = *(__IO uint8_t*)(SDRAM_BANK_ADDR + counter);
                        if ( ubReaddata_8b != (uint8_t)(ubWritedata_8b + counter))
                        {
                                uwReadwritestatus = 1;                                                
                        }
                        counter++;
                }
          if(uwReadwritestatus == 0)
                {
                          STM_EVAL_LEDOn(LED3);
                                STM_EVAL_LEDOff(LED4);
                                LCD_Clear(LCD_COLOR_GREEN);
                                LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"  8-bits AHB    ");
                                LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"  Transaction   ");
                                LCD_DisplayStringLine(LCD_LINE_6, (uint8_t *)"  Test-> OK     ");         
                }
                else
                {
                    STM_EVAL_LEDOn(LED4);
                                STM_EVAL_LEDOff(LED3);
                                LCD_Clear(LCD_COLOR_RED);
                                LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"    8-bits AHB   ");
                                LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"   Transaction   ");
                                LCD_DisplayStringLine(LCD_LINE_6, (uint8_t *)"   Test-> Failed ");         
                }
               
                /*********************** 16-bits AHB transaction test ***********************/   
                /* Wait for User button to be pressed */
                while (STM_EVAL_PBGetState() != Bit_SET)
                {}
                                /* Turn Off Leds */   
                STM_EVAL_LEDOff(LED3);
                STM_EVAL_LEDOff(LED4);
               
                /* Wait for User button is released */
                while (STM_EVAL_PBGetState() != Bit_RESET)
                {}
               
        
                /* Erase SDRAM memory */
                for (counter = 0x00; counter < IS42S16400J_SIZE; counter++)
                {
                        *(__IO uint16_t*) (SDRAM_BANK_ADDR + 2*counter) = (uint16_t)0x00;
                }
               
                /* Write data value to all SDRAM memory */
                for (counter = 0; counter < IS42S16400J_SIZE; counter++)
                {
                        *(__IO uint16_t*) (SDRAM_BANK_ADDR + 2*counter) = (uint16_t)(uhWritedata_16b + counter);
                }
               
                /* Read back SDRAM memory and check content correctness*/
                counter = 0;
                uwReadwritestatus = 0;
                while ((counter < IS42S16400J_SIZE) && (uwReadwritestatus == 0))
                {
                        uhReaddata_16b = *(__IO uint16_t*)(SDRAM_BANK_ADDR + 2*counter);
                        if ( uhReaddata_16b != (uint16_t)(uhWritedata_16b + counter))
                        {
                                uwReadwritestatus = 1;                        
                        }
                        counter++;
                }
                if(uwReadwritestatus == 0)
                {
                        STM_EVAL_LEDOn(LED3);
                        STM_EVAL_LEDOff(LED4);
                        LCD_Clear(LCD_COLOR_GREEN);
                        LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"  16-bits AHB   ");
                        LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"  Transaction   ");
                        LCD_DisplayStringLine(LCD_LINE_6, (uint8_t *)"  Test-> OK     ");   
                }
                else
                {
                        STM_EVAL_LEDOn(LED4);
                        STM_EVAL_LEDOff(LED3);
                        LCD_Clear(LCD_COLOR_RED);
                        LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"  16-bits AHB    ");
                        LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)" Transaction     ");
                        LCD_DisplayStringLine(LCD_LINE_6, (uint8_t *)" Test-> Failed   ");     
                }        
  }
}
wahahaheihei| | 2018-5-27 13:51 | 显示全部楼层
牛X,音频解码这个支撑吗

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

115

主题

730

帖子

1

粉丝