参考野火给的程序移植而成,需要的可以下载来使用,代码已经调试好,打开串口助手查看结果
单片机源程序如下:
- #include "stm32f4xx.h"
- #include "./usart/bsp_debug_usart.h"
- #include "./led/bsp_led.h"
- #include "./internalFlash/bsp_internalFlash.h"
- void delay(unsigned int x)
- {
- while(x--);
- }
- /**
- * @brief 主函数
- * @param 无
- * @retval 无
- */
- int main(void)
- {
- unsigned int m;
- uint32_t aa[2] = {0x12345678,0x11111111};
- uint32_t bb[2] = {0};
- uint16_t aa1[5] = {400,500,600,700,800};
- uint16_t bb1[5] = {0};
- uint8_t aa2[10] = {0,1,2,3,4,5,6,7,8,9};
- uint8_t bb2[10] = {0};
-
- /*初始化USART,配置模式为 115200 8-N-1*/
- Debug_USART_Config();
- LED_GPIO_Config();
-
- LED_BLUE;
- /*调用printf函数,因为重定向了fputc,printf的内容会输出到串口*/
- printf("正在进行读写内部FLASH实验,请耐心等待 \r\n");
- printf("开始写入32位数据\r\n:");
- if(Write_Wordbyte(ADDR_FLASH_SECTOR_8,ADDR_FLASH_SECTOR_9,aa,2) == 1)
- {
- LED_GREEN;
- }
- for(m = 0;m < 2;m++)
- {
- printf("写入的32位数据为 = %X\r\n",aa[m]);
- delay(0xfffff);
- }
- if(Read_Wordbyte(ADDR_FLASH_SECTOR_8,2,bb) == 1)
- {
- LED_RED;
- }
- for(m = 0;m < 2;m++)
- {
- printf("读出的32位数据为 = %X\r\n",bb[m]);
- delay(0xfffff);
- }
- ////////////////////////////////////////
- printf("开始写入16位数据r\n");
- if(Write_HalfWordbyte(ADDR_FLASH_SECTOR_8,ADDR_FLASH_SECTOR_9,aa1,5) == 1)
- {
- LED_GREEN;
- }
- for(m = 0;m < 5;m++)
- {
- printf("写入的16位数据为 = %d\r\n",aa1[m]);
- delay(0xfffff);
- }
- if(Read_HalfWordbyte(ADDR_FLASH_SECTOR_8,5,bb1) == 1)
- {
- LED_RED;
- }
- for(m = 0;m < 5;m++)
- {
- printf("读出的16位数据为 = %d\r\n",bb1[m]);
- delay(0xfffff);
- }
- ///////////////////////////////////
- printf("开始写入8位数据\r\n");
- if(Write_Byte(ADDR_FLASH_SECTOR_8,ADDR_FLASH_SECTOR_9,aa2,10) == 1)
- {
- LED_GREEN;
- }
- for(m = 0;m < 10;m++)
- {
- printf("写入的8位数据为 = %d\r\n",aa2[m]);
- delay(0xfffff);
- }
- if(Read_Byte(ADDR_FLASH_SECTOR_8,10,bb2) == 1)
- {
- LED_RED;
- }
- for(m = 0;m < 10;m++)
- {
- printf("读出的8位数据为 = %d\r\n",bb2[m]);
- delay(0xfffff);
- }
-
- while(1)
- { }
- }
- /*********************************************END OF FILE**********************/
复制代码
所有程序51hei提供下载:
读写内部FLASH.7z
(359.98 KB, 下载次数: 155)
|