實驗現象:
上電即開始讀寫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連結: