STM32CubeMX + HAL库学习「附工程源码」( 四 )


STM32CubeMX + HAL库学习「附工程源码」文章插图

  1. 生成代码 , GENERATE CODE ,用KEIL打开
uint8_t temp[100]__attribute__((at(0xD0000000)));for(int i=0;i<100;i++){temp[i] = i; } for(int i=0;i<100;i++){printf("%d", temp[i]); }
  1. 到这里只是借助Cube完成了引脚配置 , 还需要SDRAM初始化操作和读写函数 , 可从官方例程里获取 , 路径:C:\Users\10617\STM32Cube\Repository\STM32Cube_FW_F4_V1.25.0\Drivers\BSP\STM32F429I-Discovery\XXX
/*****************************SDRAM使能函数******************************//*** @brief对SDRAM芯片进行初始化配置* @paramNone.* @retval None.*/ static void USER_SDRAM_ENABLE(void) {FMC_SDRAM_CommandTypeDef Command;__IO uint32_t tmpmrd =0;/* Step 1:Configure a clock configuration enable command */Command.CommandMode= FMC_SDRAM_CMD_CLK_ENABLE;Command.CommandTarget= FMC_SDRAM_CMD_TARGET_BANK2;Command.AutoRefreshNumber= 1;Command.ModeRegisterDefinition= 0;/* Send the command */HAL_SDRAM_SendCommand(/* Step 2: Insert 100 us minimum delay *//* Inserted delay is equal to 1 ms due to systick time base unit (ms) */HAL_Delay(1);/* Step 3: Configure a PALL (precharge all) command */Command.CommandMode= FMC_SDRAM_CMD_PALL;Command.CommandTarget= FMC_SDRAM_CMD_TARGET_BANK2;Command.AutoRefreshNumber= 1;Command.ModeRegisterDefinition= 0;/* Send the command */HAL_SDRAM_SendCommand(/* Step 4: Configure an Auto Refresh command */Command.CommandMode= FMC_SDRAM_CMD_AUTOREFRESH_MODE;Command.CommandTarget= FMC_SDRAM_CMD_TARGET_BANK2;Command.AutoRefreshNumber= 4;Command.ModeRegisterDefinition= 0;/* Send the command */HAL_SDRAM_SendCommand(/* Step 5: Program the external memory mode register */tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2|SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL|SDRAM_MODEREG_CAS_LATENCY_3|SDRAM_MODEREG_OPERATING_MODE_STANDARD |SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;Command.CommandMode= FMC_SDRAM_CMD_LOAD_MODE;Command.CommandTarget= FMC_SDRAM_CMD_TARGET_BANK2;Command.AutoRefreshNumber= 1;Command.ModeRegisterDefinition= tmpmrd;/* Send the command */HAL_SDRAM_SendCommand(/* Step 6: Set the refresh rate counter *//* Set the device refresh rate */HAL_SDRAM_ProgramRefreshRate(} /*****************************使能函数结束******************************/或者以我的野火STM32F429IGT6的版本SDRAM为8M , 源码链接:
密码:bf5q添加到工程Core路径下 , 然后在KEIL中初始化操作:
(注意这个SDRAM_InitSequence();不能加在HAL_SDRAM_MspInit()后面!!! 因为它这里还没FMC初始化完成!!!! 加在这里是没有用的!!!)
#include "bsp_sdram.h" MX_FMC_Init(); SDRAM_InitSequence();SDRAM_Test();LTDC + DMA2D务必在上面SDRAM配置成功后 , 再来搞这个!!!
详细教程看这个:
但他给的源码还有点问题 , 运行处理没效果 。
我提供的源码链接:
密码:bf5q注意: