[关闭]
@armink 2016-11-08T08:24:06.000000Z 字数 1975 阅读 1824

ART_WiFi 串行 Flash 下载器

EasyFlash


1、源码

Flash 设备初始化

  1. rt_spi_flash_device_t w25q128;
  2. w25q128 = rt_sfud_flash_probe("W25Q128", "spi30");

ymodem MSH 命令,直接使用 SFUD 的 Flash 操作方法,默认从 0 地址开始下载

  1. #include <rthw.h>
  2. #include <rtthread.h>
  3. #include <ymodem.h>
  4. #include <finsh.h>
  5. #include <shell.h>
  6. #include <spi_flash.h>
  7. #include <sfud.h>
  8. #define FILE_FLASH_ADDR 0 /* 传输的 Flash 目标地址 */
  9. #define FILE_SFUD_INDEX SFUD_W25Q128_DEVICE_INDEX
  10. static uint32_t ymodem_file_total_size, ymodem_file_cur_size;
  11. extern rt_spi_flash_device_t w25q128;
  12. static enum rym_code ymodem_on_begin(struct rym_ctx *ctx, rt_uint8_t *buf, rt_size_t len) {
  13. char *file_name, *file_size;
  14. /* calculate and store file size */
  15. file_name = (char *) &buf[0];
  16. file_size = (char *) &buf[rt_strlen(file_name) + 1];
  17. ymodem_file_total_size = atol(file_size);
  18. ymodem_file_cur_size = 0;
  19. /* erase flash */
  20. if (sfud_erase((sfud_flash_t)(w25q128->user_data), FILE_FLASH_ADDR, ymodem_file_total_size)
  21. != SFUD_SUCCESS) {
  22. /* if erase fail then quit this session */
  23. return RYM_CODE_CAN;
  24. }
  25. return RYM_CODE_ACK;
  26. }
  27. static enum rym_code ymodem_on_data(struct rym_ctx *ctx, rt_uint8_t *buf, rt_size_t len) {
  28. /* write file to flash */
  29. if (sfud_write((sfud_flash_t)(w25q128->user_data), FILE_FLASH_ADDR + ymodem_file_cur_size, len, buf)
  30. != SFUD_SUCCESS) {
  31. /* if write fail then quit this session */
  32. return RYM_CODE_CAN;
  33. }
  34. ymodem_file_cur_size += len;
  35. return RYM_CODE_ACK;
  36. }
  37. static void ymodem(uint8_t argc, char **argv) {
  38. struct rym_ctx rctx;
  39. rt_kprintf("Please select a file and use Ymodem to send.\r\n");
  40. /* close finsh echo */
  41. finsh_set_echo(false);
  42. if (!rym_recv_on_device(&rctx, rt_device_find(RT_CONSOLE_DEVICE_NAME), RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
  43. ymodem_on_begin, ymodem_on_data, NULL, RT_TICK_PER_SECOND)) {
  44. /* wait some time for terminal response finish */
  45. rt_thread_delay(RT_TICK_PER_SECOND);
  46. rt_kprintf("Write file to flash success.\n");
  47. } else {
  48. /* wait some time for terminal response finish */
  49. rt_thread_delay(RT_TICK_PER_SECOND);
  50. rt_kprintf("Write file to flash failed.\n");
  51. }
  52. /* reopen finsh echo */
  53. finsh_set_echo(true);
  54. }
  55. MSH_CMD_EXPORT(ymodem, save file to flash by ymodem)

2、与 IotCamera 连接方法

RTT_ART_WiFi

引脚 ART_WiFi IotCamera
MISO A1 底板 MISO
MOSI A0 底板 MOSI
SCK A2 底板 SCK
CS A3 核心板 P7:3
GND GND 底板 GND
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注