完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
前言
是STM32F407,为STM32F407的硬件开发者提供了有用的,到SD Flash,Z开发板的开发板参考教程6正点原子F407的Bootloader 。 ,具体并不需要为 OTA 做多使用 设计设计 因为 RT-Thread 的需求和网络需要进行更新,如果需要升级,个人很少存在稳定的服务器。人能执行这些。是完全对不认识的人面对使用呢?为什么说什么 卡存储和拷贝SD对象该怎样接SD对象呢?该开发的设备进行升级。(直接下载到个人的测试方案,可能会通过网络下载等方式) 功能实现过程 的教程是直接使用RT-Thread Studio开发工具进行开发的,下面是_ board.h文件中使用以下宏定义 #define BSP_USING_SPI1 #define BSP_USING_SDIO #define BSP_USING_ON_CHIP_FLASH stm32f4xx_hal_conf.h文件中使用以下宏定义 #define HAL_MODULE_ENABLED #define HAL_SD_MODULE_ENABLED #define HAL_SPI_MODULE_ENABLED #define HAL_FLASH_MODULE_ENABLED 使用STM32CUBEMX配置片外Flash和SD卡的接口,本人的配置如下 /** * @brief SD MSP Initialization * This function configures the hardware resources used in this example * @param hsd: SD handle pointer * @retval None */ void HAL_SD_MspInit(SD_HandleTypeDef* hsd) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(hsd->Instance==SDIO) { /* USER CODE BEGIN SDIO_MspInit 0 */ /* USER CODE END SDIO_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_SDIO_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /**SDIO GPIO Configuration PC8 ------> SDIO_D0 PC9 ------> SDIO_D1 PC10 ------> SDIO_D2 PC11 ------> SDIO_D3 PC12 ------> SDIO_CK PD2 ------> SDIO_CMD */ GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 |GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF12_SDIO; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF12_SDIO; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /* USER CODE BEGIN SDIO_MspInit 1 */ /* USER CODE END SDIO_MspInit 1 */ } } /** * @brief SD MSP De-Initialization * This function freeze the hardware resources used in this example * @param hsd: SD handle pointer * @retval None */ void HAL_SD_MspDeInit(SD_HandleTypeDef* hsd) { if(hsd->Instance==SDIO) { /* USER CODE BEGIN SDIO_MspDeInit 0 */ /* USER CODE END SDIO_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_SDIO_CLK_DISABLE(); /**SDIO GPIO Configuration PC8 ------> SDIO_D0 PC9 ------> SDIO_D1 PC10 ------> SDIO_D2 PC11 ------> SDIO_D3 PC12 ------> SDIO_CK PD2 ------> SDIO_CMD */ HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 |GPIO_PIN_12); HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2); /* USER CODE BEGIN SDIO_MspDeInit 1 */ /* USER CODE END SDIO_MspDeInit 1 */ } } /** * @brief SPI MSP Initialization * This function configures the hardware resources used in this example * @param hspi: SPI handle pointer * @retval None */ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(hspi->Instance==SPI1) { /* USER CODE BEGIN SPI1_MspInit 0 */ /* USER CODE END SPI1_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /**SPI1 GPIO Configuration PB3 ------> SPI1_SCK PB4 ------> SPI1_MISO PB5 ------> SPI1_MOSI */ GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* SPI1 interrupt Init */ HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(SPI1_IRQn); /* USER CODE BEGIN SPI1_MspInit 1 */ /* USER CODE END SPI1_MspInit 1 */ } else if(hspi->Instance==SPI2) { /* USER CODE BEGIN SPI2_MspInit 0 */ /* USER CODE END SPI2_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_SPI2_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /**SPI2 GPIO Configuration PC2 ------> SPI2_MISO PC3 ------> SPI2_MOSI PB13 ------> SPI2_SCK */ GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_13; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* USER CODE BEGIN SPI2_MspInit 1 */ /* USER CODE END SPI2_MspInit 1 */ } } /** * @brief SPI MSP De-Initialization * This function freeze the hardware resources used in this example * @param hspi: SPI handle pointer * @retval None */ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) { if(hspi->Instance==SPI1) { /* USER CODE BEGIN SPI1_MspDeInit 0 */ /* USER CODE END SPI1_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_SPI1_CLK_DISABLE(); /**SPI1 GPIO Configuration PB3 ------> SPI1_SCK PB4 ------> SPI1_MISO PB5 ------> SPI1_MOSI */ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5); /* SPI1 interrupt DeInit */ HAL_NVIC_DisableIRQ(SPI1_IRQn); /* USER CODE BEGIN SPI1_MspDeInit 1 */ /* USER CODE END SPI1_MspDeInit 1 */ } else if(hspi->Instance==SPI2) { /* USER CODE BEGIN SPI2_MspDeInit 0 */ /* USER CODE END SPI2_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_SPI2_CLK_DISABLE(); /**SPI2 GPIO Configuration PC2 ------> SPI2_MISO PC3 ------> SPI2_MOSI PB13 ------> SPI2_SCK */ HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_3); HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13); /* USER CODE BEGIN SPI2_MspDeInit 1 */ /* USER CODE END SPI2_MspDeInit 1 */ } } 分区表配置如下 #define RT_APP_PART_ADDR 0x08020000 #define NOR_FLASH_DEV_NAME "W25Q128" /* ===================== Flash device Configuration ========================= */ extern const struct fal_flash_dev stm32_onchip_flash_16k; extern const struct fal_flash_dev stm32_onchip_flash_64k; extern const struct fal_flash_dev stm32_onchip_flash_128k; extern struct fal_flash_dev nor_flash0; #define FLASH_SIZE_GRANULARITY_16K (4 * 16 * 1024) #define FLASH_SIZE_GRANULARITY_64K (1 * 64 * 1024) #define FLASH_SIZE_GRANULARITY_128K (1 * 128 * 1024) #define STM32_FLASH_START_ADRESS_16K STM32_FLASH_START_ADRESS #define STM32_FLASH_START_ADRESS_64K (STM32_FLASH_START_ADRESS_16K + FLASH_SIZE_GRANULARITY_16K) #define STM32_FLASH_START_ADRESS_128K (STM32_FLASH_START_ADRESS_64K + FLASH_SIZE_GRANULARITY_64K) /* flash device table */ #define FAL_FLASH_DEV_TABLE { &stm32_onchip_flash_16k, &stm32_onchip_flash_64k, &stm32_onchip_flash_128k, &nor_flash0, } /* ====================== Partition Configuration ========================== */ #ifdef FAL_PART_HAS_TABLE_CFG /* partition table */ #define FAL_PART_TABLE { {FAL_PART_MAGIC_WORD, "app", "onchip_flash_128k", 0, 896*1024, 0}, {FAL_PART_MAGIC_WORD, "download", NOR_FLASH_DEV_NAME, 0, 1024*1024, 0}, } #endif /* FAL_PART_HAS_TABLE_CFG */ 中断向量偏移配置如下 static int ota_app_vtor_reconfig(void) { #define NVIC_VTOR_MASK 0x3FFFFF80 SCB->VTOR = RT_APP_PART_ADDR & NVIC_VTOR_MASK; return 0; } INIT_BOARD_EXPORT(ota_app_vtor_reconfig); 片外SPI Flash挂载款设备(fal才能发现)如下 #include "spi_flash.h" #include "spi_flash_sfud.h" #include "drv_spi.h" static int rt_hw_spi_flash_init(void) { __HAL_RCC_GPIOB_CLK_ENABLE(); rt_hw_spi_device_attach("spi1", "spi10", GPIOB, GPIO_PIN_14); if (RT_NULL == rt_sfud_flash_probe("W25Q128", "spi10")) { return -RT_ERROR; }; return RT_EOK; } INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init); SD卡挂载文件系统如下 #include "dfs_fs.h" static int sd_mount(void) { rt_thread_mdelay(500); if(dfs_mount("sd0", "/", "elm", 0, 0) == 0) { rt_kprintf("sd0 mount successrn"); } else { rt_kprintf("sd0 mount failrn"); } return RT_EOK; } INIT_APP_EXPORT(sd_mount); 根据上面的需求加入一下,则可以从SD卡实现功能升级固件,使用finish实现命令文件(可以通过控制代码和直接选择触摸屏)子板上直接选择文件升级) #include void upgrade(int argc, char **argv) { fal_partition_t fal_dev = RT_NULL; int fd, buffsize, writecnt, fal_addr, len; unsigned char *ucData = RT_NULL; char *filename = RT_NULL; if (argc < 2) { rt_kprintf("upgrade [filename]n"); return ; } filename = argv[1]; rt_kprintf("start upgrade %sn", filename); fd = open(filename, O_RDONLY); if(fd < 0) { rt_kprintf("open %s file failn"); return ; } fal_dev = fal_partition_find("download"); if(fal_dev == RT_NULL) { rt_kprintf("can not find download partitionn"); return ; } if(fal_partition_erase_all(fal_dev) < 0) { rt_kprintf("erase download partition all failn"); return ; } buffsize = fal_dev->len; ucData = rt_malloc(buffsize);//try malloc max buff if (ucData == RT_NULL) { ucData = rt_malloc(4096); if(ucData == RT_NULL) { rt_kprintf("No memoryn"); return; } buffsize = 4096; } writecnt = 0; fal_addr = 0; while(writecnt < fal_dev->len) { len = read(fd, ucData, buffsize); if(len < 0)break; if(fal_partition_write(fal_dev, fal_addr, ucData, buffsize) < 0) { rt_kprintf("fal write download partition addr:%x size:%d failn"); return ; } writecnt += buffsize; fal_addr += buffsize; } rt_kprintf("write upgrade %s file successn", filename); rt_kprintf("reboot systemn"); NVIC_SystemReset(); return; } MSH_CMD_EXPORT(upgrade, a sd card upgrade sample); 载后,将需要将升级的固件下载到sd卡根中,设备接入SD卡重启驱动程序执行SD卡,输入ls查看升级目录是否存在 输入升级 rtthread.rbl 选择应用程序可以继续进行升级 升级成功,然后开发其他应用程序升级成功 |
|
|
|
只有小组成员才能发言,加入小组>>
3310 浏览 9 评论
2991 浏览 16 评论
3492 浏览 1 评论
9057 浏览 16 评论
4086 浏览 18 评论
1176浏览 3评论
604浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
597浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2334浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1895浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 18:54 , Processed in 1.254880 second(s), Total 79, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号