实验现象:
上电即开始读写SDRAM测试,测试过程中,蓝色LED点亮,如果出现错误,红色LED闪烁,测试成功,绿色LED点亮。
核心代码:
int main(void) { /* USER CODE BEGIN 1 */ int i,j; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ //SDRAM³õʼ»¯ BSP_SDRAM_Init(); LED_BLUE_ON; //ÏòSDRAMÖÐдÈë0x5555²¢¶ÁȡУÑé for(i = 0;i < SDRAM_SIZE;i++){ write_sdram(i,0x5555); } for(i = 0;i < SDRAM_SIZE;i++){ if(0x5555 != read_sdram(i)){ while(1){ LED_RED_ON; HAL_Delay(500); LED_RED_OFF; HAL_Delay(500); } } } //ÏòSDRAMÖÐдÈë0xAAAA²¢¶ÁȡУÑé for(i = 0;i < SDRAM_SIZE;i++){ write_sdram(i,0xAAAA); } for(i = 0;i < SDRAM_SIZE;i++){ if(0xAAAA != read_sdram(i)){ while(1){ LED_RED_ON; HAL_Delay(500); LED_RED_OFF; HAL_Delay(500); } } } //ÏòSDRAMÖÐдÈë0x0000~0xFFFF²¢¶ÁȡУÑé for(j = 0; j < 256; j++){ for(i = 0;i < 65536;i++){ write_sdram((65536 * j + i),i); } } for(j = 0; j < 256; j ++){ for(i = 0;i < 65536;i++){ if(i != read_sdram((65536 * j + i))){ while(1){ LED_RED_ON; HAL_Delay(500); LED_RED_OFF; HAL_Delay(500); } } } } //²âÊԳɹ¦ LED_BLUE_OFF; LED_GREEN_ON; /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
源代码下载链接:
链接:http://pan.baidu.com/s/1i5kqcst 密码:d03o
iCore4链接: