diff --git a/TODO.md b/TODO.md index 82576228b..e8f558262 100644 --- a/TODO.md +++ b/TODO.md @@ -26,6 +26,7 @@ * [ ] posix sema支持 * [ ] vfork + exec实现 * [ ] 几大组件稳定性测试 +* [ ] 删除之前用于log的sem ### mid prio * [x] net server support * [x] block driver @@ -35,7 +36,7 @@ * [x] pca9555 driver * [x] pin drvier * [x] snd drvier -* [ ] ymodem support +* [x] ymodem support * [x] vi support ### low prio - [ ] toybox support diff --git a/armv7_8.cmake b/armv7_8.cmake index 268ae3b6b..b75fea67d 100644 --- a/armv7_8.cmake +++ b/armv7_8.cmake @@ -1,6 +1,6 @@ message("========use armv7_8.cmake") -set(CMAKE_C_FLAGS "-mcpu=${CONFIG_ARCH} -O0 -g3 -mfloat-abi=${CONFIG_FLOAT_TYPE} -mthumb -DMKRTOS \ +set(CMAKE_C_FLAGS "-mcpu=${CONFIG_ARCH} -Ofast -g3 -mfloat-abi=${CONFIG_FLOAT_TYPE} -mthumb -DMKRTOS \ -std=gnu11 -ffunction-sections -fdata-sections -fno-builtin -u=_printf_float \ -nostartfiles -nodefaultlibs -nostdlib -nostdinc \ -fno-stack-protector -Wl,--gc-section -D__ARM_ARCH_7M__ \ diff --git a/mkrtos_configs/ATSURFF437_defconfig b/mkrtos_configs/ATSURFF437_defconfig index f267f8103..969475464 100644 --- a/mkrtos_configs/ATSURFF437_defconfig +++ b/mkrtos_configs/ATSURFF437_defconfig @@ -40,7 +40,7 @@ CONFIG_SIG_THREAD_PRIO=3 CONFIG_CPU_TYPE="at32f437" CONFIG_ARCH="cortex-m4" -CONFIG_FLOAT_TYPE="hard" +CONFIG_FLOAT_TYPE="soft" CONFIG_BOARD_NAME="ATSURFF437" CONFIG_BUDDY_SLAB=n CONFIG_SMP=n diff --git a/mkrtos_knl/arch/cortex-m/at32f437/uart/at32f437_uart.c b/mkrtos_knl/arch/cortex-m/at32f437/uart/at32f437_uart.c index 8265d478c..ec138a294 100755 --- a/mkrtos_knl/arch/cortex-m/at32f437/uart/at32f437_uart.c +++ b/mkrtos_knl/arch/cortex-m/at32f437/uart/at32f437_uart.c @@ -25,30 +25,44 @@ uart_t *uart_get_global(void) { return &uart; } -#define QUEUE_LEN 129 +#define QUEUE_LEN 257 static queue_t queue; static uint8_t queue_data[QUEUE_LEN]; static bool_t uart_is_init; + +static void uart_wakeup_waiter(irq_entry_t *irq) +{ + if (irq->irq->wait_thread && thread_get_status(irq->irq->wait_thread) == THREAD_SUSPEND) + { + thread_ready_remote(irq->irq->wait_thread, TRUE); + } +} void uart_tigger(irq_entry_t *irq) { if (usart_interrupt_flag_get(PRINT_USARTx, USART_RDBF_FLAG) != RESET) { /* read one byte from the receive data register */ - q_enqueue(&queue, usart_data_receive(PRINT_USARTx)); + if (q_enqueue(&queue, usart_data_receive(PRINT_USARTx)) < 0) + { + uart_wakeup_waiter(irq); + } usart_interrupt_enable(PRINT_USARTx, USART_IDLE_INT, TRUE); } + // if (q_queue_len(&queue) >= queue.size / 2) + // { + // uart_wakeup_waiter(irq); + // } if (usart_interrupt_flag_get(PRINT_USARTx, USART_IDLEF_FLAG) != RESET) { - if (irq->irq->wait_thread && thread_get_status(irq->irq->wait_thread) == THREAD_SUSPEND) - { - thread_ready_remote(irq->irq->wait_thread, TRUE); - } + uart_wakeup_waiter(irq); usart_interrupt_enable(PRINT_USARTx, USART_IDLE_INT, FALSE); } } void uart_init(void) { + uart_is_init = 1; + q_init(&queue, queue_data, QUEUE_LEN); gpio_init_type gpio_init_struct; @@ -77,10 +91,9 @@ void uart_init(void) usart_interrupt_enable(PRINT_USARTx, USART_RDBF_INT, TRUE); usart_interrupt_enable(PRINT_USARTx, USART_IDLE_INT, TRUE); - + usart_enable(PRINT_USARTx, TRUE); - - uart_is_init=1; + } INIT_HIGH_HAD(uart_init); @@ -92,8 +105,9 @@ void uart_set(uart_t *uart) } void uart_putc(uart_t *uart, int data) { - if (!uart_is_init) { - return ; + if (!uart_is_init) + { + return; } while (usart_flag_get(USART1, USART_TDBE_FLAG) == RESET) ; diff --git a/mkrtos_knl/inc/knl/vma.h b/mkrtos_knl/inc/knl/vma.h index e9fb9c9d6..457f81cd2 100644 --- a/mkrtos_knl/inc/knl/vma.h +++ b/mkrtos_knl/inc/knl/vma.h @@ -146,6 +146,9 @@ typedef struct task_vma mln_rbtree_t alloc_tree; //!< 分配了那些内存 #if IS_ENABLED(MPU_PAGE_FAULT_SUPPORT) region_info_t *mem_pages_pt_regions[MPU_PAGE_FAULT_REGIONS_NUM]; //!< 用多少个regions模拟缺页 +#if MPU_PAGE_FAULT_REGIONS_NUM == 0 +#error "MPU_PAGE_FAULT_REGIONS_NUM not is 0." +#endif int pt_regions_sel; //!< 用于确定下次选用那个region进行映射 #endif } task_vma_t; diff --git a/mkrtos_knl/inc/lib/xprintf.h b/mkrtos_knl/inc/lib/xprintf.h index 7d9f0ce15..885ef8a6f 100755 --- a/mkrtos_knl/inc/lib/xprintf.h +++ b/mkrtos_knl/inc/lib/xprintf.h @@ -11,7 +11,7 @@ extern "C" #endif #include "stdarg.h" #define XF_USE_OUTPUT 1 /* 1: Enable output functions */ -#define XF_CRLF 0 /* 1: Convert \n ==> \r\n in the output char */ +#define XF_CRLF 1 /* 1: Convert \n ==> \r\n in the output char */ #define XF_USE_DUMP 0 /* 1: Enable put_dump function */ #define XF_USE_LLI 0 /* 1: Enable long long integer in size prefix ll */ #define XF_USE_FP 0 /* 1: Enable support for floating point in type e and f */ diff --git a/mkrtos_knl/knl/log.c b/mkrtos_knl/knl/log.c index f65996d4f..c53a5d011 100755 --- a/mkrtos_knl/knl/log.c +++ b/mkrtos_knl/knl/log.c @@ -10,6 +10,7 @@ */ #include "log.h" +#include "arch.h" #include "factory.h" #include "kobject.h" #include "globals.h" @@ -49,6 +50,7 @@ static void log_reg(void) log.kobj.kobj.put_func = kobject_put; global_reg_kobj(&log.kobj.kobj, LOG_PROT); irq_alloc(LOG_INTR_NO, &log.kobj, log_trigger); + arch_set_enable_irq_prio(LOG_INTR_NO, 0, 0); arch_enable_irq(LOG_INTR_NO); } INIT_KOBJ(log_reg); @@ -106,7 +108,7 @@ log_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, entry_frame break; case READ_DATA: { - int ret = log_read_data((log_t *)kobj, (uint8_t *)(&f->regs[1]), MIN(f->regs[1], WORD_BYTES * 5)); + int ret = log_read_data((log_t *)kobj, (uint8_t *)(&f->regs[1]), MIN(f->regs[1], WORD_BYTES * 3)); tag = msg_tag_init4(0, 0, 0, ret); } break; diff --git a/mkrtos_script/build_at32f437.sh b/mkrtos_script/build_at32f437.sh index d8cb5a7a2..0bb59e96d 100755 --- a/mkrtos_script/build_at32f437.sh +++ b/mkrtos_script/build_at32f437.sh @@ -9,7 +9,7 @@ # mac compile export TOOLCHAIN=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/bin/ -export TOOLCHAIN_LIB=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard +export TOOLCHAIN_LIB=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/thumb/v7-m/nofp # windows compile # export TOOLCHAIN=/d/GNUArmEmbeddedToolchain/102021.10/bin/ diff --git a/mkrtos_user/lib/letter-shell/src/shell_cfg.h b/mkrtos_user/lib/letter-shell/src/shell_cfg.h index 0018dcd3b..1da1ad8c4 100644 --- a/mkrtos_user/lib/letter-shell/src/shell_cfg.h +++ b/mkrtos_user/lib/letter-shell/src/shell_cfg.h @@ -115,7 +115,7 @@ * @brief shell命令参数最大数量 * 包含命令名在内,超过16个参数并且使用了参数自动转换的情况下,需要修改源码 */ -#define SHELL_PARAMETER_MAX_NUMBER 8 +#define SHELL_PARAMETER_MAX_NUMBER 16 #endif /** SHELL_PARAMETER_MAX_NUMBER */ #ifndef SHELL_HISTORY_MAX_NUMBER diff --git a/mkrtos_user/lib/libc_backend/src/fs_backend.c b/mkrtos_user/lib/libc_backend/src/fs_backend.c index 0ae329b14..5cca17a21 100644 --- a/mkrtos_user/lib/libc_backend/src/fs_backend.c +++ b/mkrtos_user/lib/libc_backend/src/fs_backend.c @@ -22,12 +22,15 @@ #include #include #include "kstat.h" -AUTO_CALL(101) +#define FS_PATH_LEN 64 +static char cur_path[FS_PATH_LEN] = "/"; +// AUTO_CALL(101) void fs_backend_init(void) { umword_t cur_pid; msg_tag_t tag; + char *pwd; tag = task_get_pid(TASK_THIS, (umword_t *)(&cur_pid)); assert(msg_tag_get_val(tag) >= 0); @@ -43,9 +46,13 @@ void fs_backend_init(void) assert(fd_map_alloc(0, 1, FD_TTY) >= 0); assert(fd_map_alloc(0, 2, FD_TTY) >= 0); } + pwd = getenv("PWD"); + if (pwd) + { + be_chdir(pwd); + } } -#define FS_PATH_LEN 64 -static char cur_path[FS_PATH_LEN] = "/"; + int be_open(const char *path, int flags, mode_t mode) { int fd; diff --git a/mkrtos_user/lib/mlibc/src/unistd/chdir.c b/mkrtos_user/lib/mlibc/src/unistd/chdir.c index 2659cae2e..6802a013a 100644 --- a/mkrtos_user/lib/mlibc/src/unistd/chdir.c +++ b/mkrtos_user/lib/mlibc/src/unistd/chdir.c @@ -9,6 +9,6 @@ int chdir(const char *path) #ifdef NO_LITTLE_MODE return syscall(SYS_chdir, path); #else - return be_chdir(path); + return __syscall_ret(be_chdir(path)); #endif } diff --git a/mkrtos_user/lib/mlibc/src/unistd/read.c b/mkrtos_user/lib/mlibc/src/unistd/read.c index 7b07247d3..67030cb34 100644 --- a/mkrtos_user/lib/mlibc/src/unistd/read.c +++ b/mkrtos_user/lib/mlibc/src/unistd/read.c @@ -8,6 +8,6 @@ ssize_t read(int fd, void *buf, size_t count) #ifdef NO_LITTLE_MODE return syscall_cp(SYS_read, fd, buf, count); #else - return be_read(fd, buf, count); + return __syscall_ret(be_read(fd, buf, count)); #endif } diff --git a/mkrtos_user/lib/sys_svr/src/ns_cli.c b/mkrtos_user/lib/sys_svr/src/ns_cli.c index b88e11ffa..d56d0de49 100644 --- a/mkrtos_user/lib/sys_svr/src/ns_cli.c +++ b/mkrtos_user/lib/sys_svr/src/ns_cli.c @@ -178,8 +178,10 @@ next: if (reg_hd(path, newfd, msg_tag_get_val(tag)) == FALSE) { printf("The client service cache is full.\n"); + #if 0 handler_free_umap(newfd); return -ENOMEM; + #endif } *svr_hd = newfd; return msg_tag_get_val(tag); diff --git a/mkrtos_user/lib/sys_svr/src/pm_cli.c b/mkrtos_user/lib/sys_svr/src/pm_cli.c index e3d1ce76d..5d52485ef 100644 --- a/mkrtos_user/lib/sys_svr/src/pm_cli.c +++ b/mkrtos_user/lib/sys_svr/src/pm_cli.c @@ -20,7 +20,7 @@ int pm_run_app(const char *path, int flags, uint8_t *params, int params_len) { rpc_ref_file_array_t rpc_path = { .data = (uint8_t *)path, - .len = strlen(path) + 1, + .len = MIN(strlen(path) + 1, FS_RPC_BUF_LEN), }; rpc_int_t rpc_flags = { .data = flags, diff --git a/mkrtos_user/lib/sys_util/inc/u_rpc.h b/mkrtos_user/lib/sys_util/inc/u_rpc.h index 188e318ad..bf23aed3e 100644 --- a/mkrtos_user/lib/sys_util/inc/u_rpc.h +++ b/mkrtos_user/lib/sys_util/inc/u_rpc.h @@ -311,6 +311,7 @@ RPC_ARRAY_DEF(uint32_t, uint8_t, 32) RPC_ARRAY_DEF(uint32_t, uint8_t, 64) RPC_ARRAY_DEF(uint32_t, uint8_t, 96) RPC_ARRAY_DEF(uint32_t, uint8_t, 128) +RPC_ARRAY_DEF(uint32_t, uint8_t, 160) RPC_ARRAY_DEF(uint32_t, uint8_t, 256) RPC_ARRAY_DEF(uint32_t, uint8_t, 400) RPC_ARRAY_DEF(uint32_t, uint8_t, 512) diff --git a/mkrtos_user/lib/sys_util/src/u_app_loader.c b/mkrtos_user/lib/sys_util/src/u_app_loader.c index 6a2d5fbc9..c35e52bee 100644 --- a/mkrtos_user/lib/sys_util/src/u_app_loader.c +++ b/mkrtos_user/lib/sys_util/src/u_app_loader.c @@ -324,7 +324,7 @@ int app_load(const char *name, uenv_t *cur_env, pid_t *pid, { cp_args[i] = app_stack_push_str(hd_task, &usp_top, argv[i]); params_envp_len += ALIGN(strlen(argv[i]) + 1, sizeof(void *)); - printf("app_load 1 cp_args:%p\n", cp_args[i]); + // printf("app_load 1 cp_args:%p\n", cp_args[i]); } for (int i = 0; i < envp_cn; i++) { @@ -358,7 +358,7 @@ int app_load(const char *name, uenv_t *cur_env, pid_t *pid, app_stack_push_umword(hd_task, &usp_top, 0); for (int i = arg_cn - 1; i >= 0; i--) { - printf("app_load 2 cp_args:%p\n", cp_args[i]); + // printf("app_load 2 cp_args:%p\n", cp_args[i]); app_stack_push_umword(hd_task, &usp_top, (umword_t)cp_args[i]); } app_stack_push_umword(hd_task, &usp_top, arg_cn); diff --git a/mkrtos_user/server/fs/appfs/CMakeLists.txt b/mkrtos_user/server/fs/appfs/CMakeLists.txt index 8010827c5..7df0dc3d8 100644 --- a/mkrtos_user/server/fs/appfs/CMakeLists.txt +++ b/mkrtos_user/server/fs/appfs/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.13) - +# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0") #appfs lib file(GLOB appfs_src src/appfs.c src/appfs_open.c) add_library( diff --git a/mkrtos_user/server/init/board/ATSURFF437/init.cfg b/mkrtos_user/server/init/board/ATSURFF437/init.cfg index 4cb83eba6..ee48e0cf8 100644 --- a/mkrtos_user/server/init/board/ATSURFF437/init.cfg +++ b/mkrtos_user/server/init/board/ATSURFF437/init.cfg @@ -1,13 +1,13 @@ #一次读取一行,每行代表启动的应用程序 block /dev/block appfs -m /bin -d /dev/block -# fatfs -# pin -# i2c -# pca9555 -# display -# eth -# snd -# net +fatfs | 1 +pin +i2c +pca9555 +display +snd +a_eth +a_net # nes /bin/sm.nes sh \ No newline at end of file diff --git a/mkrtos_user/server/init/src/pm.c b/mkrtos_user/server/init/src/pm.c index 5d2460302..4292486e8 100644 --- a/mkrtos_user/server/init/src/pm.c +++ b/mkrtos_user/server/init/src/pm.c @@ -225,13 +225,13 @@ int pm_rpc_run_app(const char *path, int flags, char *params, int params_len) { pid_t pid; int ret; + obj_handler_t sem; + int i; + int j = 0; printf("pm run %s.\n", path); char *args[CMD_PARAMS_CN] = { (char *)path, }; - obj_handler_t sem; - int i; - int j = 0; for (i = 1; *params && i < CMD_PARAMS_CN; i++) { diff --git a/mkrtos_user/server/init/src/tty.c b/mkrtos_user/server/init/src/tty.c index 20369c71f..b762c0a7b 100644 --- a/mkrtos_user/server/init/src/tty.c +++ b/mkrtos_user/server/init/src/tty.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "cons.h" #include "u_hd_man.h" #include "u_prot.h" @@ -65,7 +66,7 @@ static inline void cons_read_unlock(void) static void console_read_func(void) { - uint8_t data[32]; + uint8_t data[12]; while (1) { @@ -147,7 +148,8 @@ static int cons_init(void) static int tty_open(const char *path, int flags, int mode) { - ulog_write_str(LOG_PROT, "tty init...\n"); + ulog_write_str(LOG_PROT, "tty open..\n"); + sys_tty.fd_flags = flags; return 0; } @@ -478,6 +480,10 @@ static int tty_read(int fd, void *buf, size_t len) } if (q_queue_len(&sys_tty.pre_queue) == 0) { + if (sys_tty.fd_flags & O_NONBLOCK) + { + return -EAGAIN; + } u_sema_down(sem_th, 0, NULL); } again: @@ -630,6 +636,28 @@ static int tty_ioctl(int fd, int req, void *args) } } break; + case TCIOFLUSH: + { + cons_read_lock(); + q_queue_clear(&sys_tty.pre_queue); + q_queue_clear(&sys_tty.w_queue); + cons_read_unlock(); + } + break; + case TCIFLUSH: + { + cons_read_lock(); + q_queue_clear(&sys_tty.pre_queue); + cons_read_unlock(); + } + break; + case TCOFLUSH: + { + cons_read_lock(); + q_queue_clear(&sys_tty.w_queue); + cons_read_unlock(); + } + break; default: ret = -ENOSYS; break; diff --git a/mkrtos_user/server/init/src/tty.h b/mkrtos_user/server/init/src/tty.h index 4b5a4d991..6a3da2278 100644 --- a/mkrtos_user/server/init/src/tty.h +++ b/mkrtos_user/server/init/src/tty.h @@ -3,7 +3,7 @@ #include #include "u_queue.h" #include "u_types.h" -#define TTY_QUEUE_DATA_SIZE 128 +#define TTY_QUEUE_DATA_SIZE 257 typedef struct tty_struct { struct termios termios; //!< 当前使用的终端信息 @@ -24,6 +24,9 @@ typedef struct tty_struct // 是否成行了 uint8_t is_nl; pid_t fg_pid; + + //FIXME: + int fd_flags;//!<暂时这样 } tty_struct_t; #define C_CC_INIT "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0" diff --git a/mkrtos_user/server/net/src/heap_stack.c b/mkrtos_user/server/net/src/heap_stack.c index e6240ec65..03992e589 100644 --- a/mkrtos_user/server/net/src/heap_stack.c +++ b/mkrtos_user/server/net/src/heap_stack.c @@ -1,7 +1,7 @@ #include #if !IS_ENABLED(CONFIG_MMU) -#define HEAP_SIZE (16 * 1024) +#define HEAP_SIZE (10 * 1024) #define STACK_SIZE (2048) #if defined(__CC_ARM) diff --git a/mkrtos_user/server/net/src/main.c b/mkrtos_user/server/net/src/main.c index c807c25d7..1fdd1f7ff 100644 --- a/mkrtos_user/server/net/src/main.c +++ b/mkrtos_user/server/net/src/main.c @@ -24,7 +24,7 @@ static umword_t size; obj_handler_t net_drv_hd = HANDLER_INVALID; #define STACK_COM_ITME_SIZE (2 * 1024 /*sizeof(struct pthread) + TP_OFFSET*/) -#define STACK_NUM 4 +#define STACK_NUM 3 ATTR_ALIGN(8) static uint8_t stack_coms[STACK_COM_ITME_SIZE * STACK_NUM]; static uint8_t msg_buf_coms[MSG_BUG_LEN * STACK_NUM]; @@ -64,7 +64,7 @@ again: // 0代表根节点 u_sleep_ms(50); count_net_link++; - if (count_net_link < 20) + if (count_net_link < 20 * 3) { goto again; } diff --git a/mkrtos_user/user/app/ATSURFF437/nes_simulator/heap_stack.c b/mkrtos_user/user/app/ATSURFF437/nes_simulator/heap_stack.c index b616d06e3..8c5329f07 100644 --- a/mkrtos_user/user/app/ATSURFF437/nes_simulator/heap_stack.c +++ b/mkrtos_user/user/app/ATSURFF437/nes_simulator/heap_stack.c @@ -1,5 +1,5 @@ - -#define HEAP_SIZE (32 * 1024) +#include +#define HEAP_SIZE (30 * 1024) #define STACK_SIZE (1024 * 3) #if defined(__CC_ARM) diff --git a/mkrtos_user/user/app/Ymodem/CMakeLists.txt b/mkrtos_user/user/app/Ymodem/CMakeLists.txt index 8fdd9fd26..d02187198 100644 --- a/mkrtos_user/user/app/Ymodem/CMakeLists.txt +++ b/mkrtos_user/user/app/Ymodem/CMakeLists.txt @@ -1,20 +1,17 @@ cmake_minimum_required(VERSION 3.13) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ") file( GLOB deps *.c - source/*.c - porting/*.c ) add_executable( - ym.elf + rb.elf ${deps} ${START_SRC} ) target_link_libraries( - ym.elf + rb.elf PUBLIC -Bstatic ${LIBC_NAME} @@ -28,7 +25,7 @@ target_link_libraries( ${GCC_LIB_PATH}/libgcc.a ) target_include_directories( - ym.elf + rb.elf PUBLIC ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys/inc ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc @@ -38,27 +35,27 @@ target_include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/porting ) add_dependencies( - ym.elf + rb.elf ${START_LIB} sys sys_util ) set_target_properties( - ym.elf PROPERTIES LINK_FLAGS + rb.elf PROPERTIES LINK_FLAGS "-T ${CMAKE_CURRENT_LIST_DIR}/${ARCH_NAME}/link.lds ${CORTEX_M_LINK_FLAGS} --gc-section -no-dynamic-linker " #--no-warn-rwx-segments ) add_custom_target( - ym_dump ALL + rb_dump ALL COMMAND - ${CMAKE_OBJCOPY} -O binary -S ym.elf ym.bin + ${CMAKE_OBJCOPY} -O binary -S rb.elf rb.bin COMMAND - ${CMAKE_SIZE} ym.elf + ${CMAKE_SIZE} rb.elf COMMAND - ${CMAKE_COMMAND} -E copy ym.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/ym + ${CMAKE_COMMAND} -E copy rb.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/rb COMMAND - cp ym.elf ${CMAKE_SOURCE_DIR}/build/output/ym.elf + cp rb.elf ${CMAKE_SOURCE_DIR}/build/output/rb.elf ) -add_dependencies(ym_dump ym.elf) +add_dependencies(rb_dump rb.elf) \ No newline at end of file diff --git a/mkrtos_user/user/app/Ymodem/main.c b/mkrtos_user/user/app/Ymodem/main.c deleted file mode 100644 index aaddf31ee..000000000 --- a/mkrtos_user/user/app/Ymodem/main.c +++ /dev/null @@ -1,8 +0,0 @@ - -#include "ymodem_export.h" - -int main(int argv, char *argc[]) -{ - Ymodem_Main_Entrance(); - return 0; -} \ No newline at end of file diff --git a/mkrtos_user/user/app/Ymodem/porting/ymodem_export.c b/mkrtos_user/user/app/Ymodem/porting/ymodem_export.c deleted file mode 100644 index 60ad2ca0f..000000000 --- a/mkrtos_user/user/app/Ymodem/porting/ymodem_export.c +++ /dev/null @@ -1,265 +0,0 @@ -/** - ****************************************************************************** - * @file STM32F0xx_IAP/src/common.c - * @author MCD Application Team - * @version V1.0.0 - * @date 29-May-2012 - * @brief Main program body - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -// #include "ymodem_port.h" -// #include "ff.h" -#include -#include -#include -#include -#include -#include -#include -/** @addtogroup STM32F0xx_IAP - * @{ - */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/* Private function prototypes -----------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ - -/******************************************************************************** - * Porting APIs - ********************************************************************************/ -typedef enum { - TRANS_FILE = 0, - IAP_IMAGE = 1, -} YMODEM_ACTION_E; - -typedef struct { - int ymodem_tty_fd; - YMODEM_ACTION_E ymodem_action; - uint32_t ymodem_receive_supported_maxsize; - uint32_t ymodem_transmit_size; - - bool_t ymodem_file_inited; - uint32_t ymodem_file_total_size; - uint32_t ymodem_file_handled_size; - int ymodem_file_handle; - // uint8_t ymodem_file_tmppath[128]; -} YMODEM_DATA_T; - -static YMODEM_DATA_T s_ymodem_data; -static void tty_init(void) -{ - struct termios old_settings; - struct termios new_settings; - tcgetattr(STDIN_FILENO, &old_settings); - new_settings = old_settings; - new_settings.c_lflag &= ~(ICANON | ECHO); // 禁用规范模式和回显 - new_settings.c_cc[VMIN] = 1; // 读取的最小字符数 - new_settings.c_cc[VTIME] = 0; // 读取的超时时间(以10ms为单位) - tcsetattr(STDIN_FILENO, TCSANOW, &new_settings); -} -void ymodem_init(void) -{ - tty_init(); - memset(&s_ymodem_data, 0, sizeof(YMODEM_DATA_T)); - s_ymodem_data.ymodem_tty_fd = STDIN_FILENO; - - s_ymodem_data.ymodem_action = TRANS_FILE; - - switch (s_ymodem_data.ymodem_action) { - case TRANS_FILE: - s_ymodem_data.ymodem_receive_supported_maxsize = 1024 * 1024 * 5; - s_ymodem_data.ymodem_transmit_size = 0; - break; -#if 0 - case IAP_IMAGE: -#warning "MUST implement GOT transmit SIZE!" - s_ymodem_data.ymodem_receive_supported_maxsize = 1024 * 1024 * 5; - s_ymodem_data.ymodem_transmit_size = 0; - break; -#endif - default: - // Not supported - break; - } -} -uint32_t ymodem_get_receive_maxsize(void) -{ - return s_ymodem_data.ymodem_receive_supported_maxsize; -} - -uint32_t ymodem_get_transmit_size(void) -{ - return s_ymodem_data.ymodem_transmit_size; -} -#include -// 0 - success ; -1 - fail -int ymodem_recv_start_cb(const char *filename, const uint32_t filesize) -{ - // FRESULT fres; - int ret; - - switch (s_ymodem_data.ymodem_action) { - case TRANS_FILE: - ret = open(filename, O_RDWR | O_CREAT, 0777); - if (ret < 0) { - //logd("Ymodem Start: create file(%s) fail(%d)...\n", filename, ret); - return -1; - } else { - //logd("Ymodem Start: create file(%s) ok(%d)...\n", filename, ret); - - s_ymodem_data.ymodem_file_inited = TRUE; - s_ymodem_data.ymodem_file_total_size = filesize; - s_ymodem_data.ymodem_file_handled_size = 0; - s_ymodem_data.ymodem_file_handle = ret; - return 0; - } - // break; - - case IAP_IMAGE: - /* erase user application area */ - // FLASH_If_Erase(APPLICATION_ADDRESS); - - break; - - default: - // Not supported - break; - } - return -1; -} - -int ymodem_recv_processing_cb(const uint8_t *buffer, const uint32_t buff_size) -{ - int ret; - uint32_t to_write_size = 0; - uint32_t writted_size = 0; - - switch (s_ymodem_data.ymodem_action) { - case TRANS_FILE: - to_write_size = s_ymodem_data.ymodem_file_total_size - s_ymodem_data.ymodem_file_handled_size; - to_write_size = (buff_size > to_write_size) ? to_write_size : buff_size; - - ret = write(s_ymodem_data.ymodem_file_handle, buffer, to_write_size); - if (ret != to_write_size) { - //loge("Ymodem process: write file(%d - %d) fail(%d)...\n", to_write_size, writted_size, ret); - return -1; - } else { - s_ymodem_data.ymodem_file_handled_size += to_write_size; - // logi("Ymodem process: write file(%d/%d) ok(%d)...\n", s_ymodem_data.ymodem_file_handled_size, - // s_ymodem_data.ymodem_file_total_size, ret); - return 0; - } - // break; - - case IAP_IMAGE: - // if (FLASH_If_Write(&flashdestination, (uint32_t*) ramsource, (uint16_t) packet_length/4) == 0) - break; - - default: - // Not supported - break; - } - return -1; -} - -int ymodem_recv_end_cb(void) -{ - int fres; - // FILINFO fno; - - switch (s_ymodem_data.ymodem_action) { - case TRANS_FILE: - if (TRUE != s_ymodem_data.ymodem_file_inited) - return -1; - - fres = close(s_ymodem_data.ymodem_file_handle); - //logd("Ymodem End: close file res(%d)...\n", fres); -#if 0 - fres = stat((const TCHAR *)s_ymodem_data.ymodem_file_tmppath, &fno); - if (fres != RES_OK) { - logw("Get File Status Fail(%d)...\n", fres); - } else { - logi("Get File Status ok(%d), file size(%d) Bytes...\n", fres, fno.fsize); - } -#endif - s_ymodem_data.ymodem_file_handle = -1; - s_ymodem_data.ymodem_file_total_size = 0; - s_ymodem_data.ymodem_file_handled_size = 0; - s_ymodem_data.ymodem_file_inited = FALSE; - return 0; - // break; - - case IAP_IMAGE: - /* erase user application area */ - // FLASH_If_Erase(APPLICATION_ADDRESS); - - break; - - default: - // Not supported - break; - } - return -1; -} -/** - * @brief Test to see if a key has been pressed on the HyperTerminal - * @param key: The key pressed - * @retval 1: Correct - * 0: Error - */ -uint32_t SerialKeyPressed(uint8_t *key) -{ - int ret; - - ret = read(STDIN_FILENO, key, 1); - if (ret < 0) { - return 0; - } - return 1; -} -// fail - 0xff; success -other value -uint8_t SerialReadByte(void) -{ - int ret; - uint8_t byte; - - ret = read(STDIN_FILENO, &byte, 1); - if (ret < 0) { - return 0xff; - } - return byte; -} - -/** - * @brief Print a character on the HyperTerminal - * @param c: The character to be printed - * @retval None - */ -void SerialPutChar(uint8_t c) -{ - write(STDIN_FILENO, &c, 1); -} - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/mkrtos_user/user/app/Ymodem/porting/ymodem_export.h b/mkrtos_user/user/app/Ymodem/porting/ymodem_export.h deleted file mode 100644 index b57d5875c..000000000 --- a/mkrtos_user/user/app/Ymodem/porting/ymodem_export.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - ****************************************************************************** - * @file STM32F0xx_IAP/inc/common.h - * @author MCD Application Team - * @version V1.0.0 - * @date 29-May-2012 - * @brief Header for main.c module - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -#ifndef __YMODEM_EXPORT_H__ -#define __YMODEM_EXPORT_H__ - -/******************************************************************************** - * The Public APIs * - ********************************************************************************/ -void Ymodem_Main_Entrance(void); - - - -/******************************************************************************** - * The Porting APIs Must Be Implemented * - ********************************************************************************/ -extern unsigned int SerialKeyPressed(unsigned char *key); -extern void SerialPutChar(unsigned char c); -extern unsigned char SerialReadByte(void); - -extern void ymodem_init(void); -extern unsigned int ymodem_get_receive_maxsize(void); -extern unsigned int ymodem_get_transmit_size(void); - -//0 - success ; -1 - fail -extern int ymodem_recv_start_cb(const char * filename, const unsigned int filesize); -extern int ymodem_recv_processing_cb(const unsigned char * buffer, const unsigned int buff_size); -extern int ymodem_recv_end_cb(void); - -#endif /* __YMODEM_EXPORT_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/mkrtos_user/user/app/Ymodem/readme.md b/mkrtos_user/user/app/Ymodem/readme.md deleted file mode 100644 index f97eb9f1b..000000000 --- a/mkrtos_user/user/app/Ymodem/readme.md +++ /dev/null @@ -1,37 +0,0 @@ -#### About Source Code: - - - source : source code Of Ymodem Protocol Implemention - -```c -source -- - |_____ common.h : compile system header files needed to include - | - |_____ ymodem.c : protocol implemention - |_____ ymodem.h : header file of protocol implemention - | - |_____ ymodem_util.c/.h : Tool Functions - | - |_____ ymodem_menu.c/.h : man - machine interaction menu - -porting -- - | - |_____ ymodem_export.h : All porting APIs should be Implemented by USER for different System or For different Usuage - |_____ ymodem_export.c : a demo implemention for porting APIs, For reference only, compile error exist - -``` - - - porting : Porting file. porting APIs declare in ymodem_export.h, and ymodem_export.c is one implemention for Keil5/STM32. and compile errors exist - - keil : keil(v5) project, for STM32 - ---- - - -#### And Attention: - - - the origin source code is from Project\STM32F0xx_IAP Demo Project in ST.com - - - And you may read the blog-article to known more about Ymodem: [Ymodem Procotol Porting](https://nixlong.github.io/2017/08/14/svm/Ymodem%E5%8D%8F%E8%AE%AE%E7%A7%BB%E6%A4%8D/#more) - ---- - -By nix.long@126.com \ No newline at end of file diff --git a/mkrtos_user/user/app/Ymodem/receive.c b/mkrtos_user/user/app/Ymodem/receive.c new file mode 100644 index 000000000..90d715548 --- /dev/null +++ b/mkrtos_user/user/app/Ymodem/receive.c @@ -0,0 +1,347 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ymodem.h" +#include "serial.h" +#include "u_sleep.h" + +#define RESEND 0 +#define SENDED 1 +#define PACKET_SIZE 128 + +enum STATE +{ + START, + RECEIVE_DATA, + END, + STOP +}; +#define PRINTF +static char buf[150] = {0}; + +/** + * @brief Update CRC16 for input byte + * @param CRC input value + * @param input byte + * @retval Updated CRC value + */ +uint16_t update_CRC16(uint16_t crcIn, uint8_t byte) +{ + uint32_t crc = crcIn; + uint32_t in = byte | 0x100; + + do + { + crc <<= 1; + in <<= 1; + + if (in & 0x100) + { + ++crc; + } + + if (crc & 0x10000) + { + crc ^= 0x1021; + } + } while (!(in & 0x10000)); + + return (crc & 0xffffu); +} + +/** + * @brief Cal CRC16 for YModem Packet + * @param data + * @param length + * @retval CRC value + */ +static inline uint16_t cal_CRC16(const uint8_t *data, uint32_t size) +{ + uint32_t crc = 0; + const uint8_t *dataEnd = data + size; + + while (data < dataEnd) + { + crc = update_CRC16(crc, *data++); + } + crc = update_CRC16(crc, 0); + crc = update_CRC16(crc, 0); + + return (crc & 0xffffu); +} + +int ymodem_receive(const char *path, int fd) +{ + int fd_file; + char start_char, tmp_char; + int state, len, i; + int trans_end = 0; + int ret; + char packet_num; + int packet_size; + int file_size = 0; + int eot_cn = 0; + uint16_t crc; + uint16_t recv_crc; + + + + packet_num = 0; + packet_size = 0; + state = START; + while (1) + { + + if (trans_end == 1) + break; + switch (state) + { + case START: + again: + ret = try_get_char(fd, &start_char); + if (ret == -EAGAIN) + { + sleep(1); + put_char(fd, 'C'); + goto again; + } + if (start_char == SOH || start_char == STX) + { + tmp_char = get_char(fd); + if (tmp_char != 0x00) + return -1; // not 00 + + tmp_char = get_char(fd); + if (tmp_char != 0xff) + { + return -1; // not ff + } + int r_b = 0; + int timeout = 0; + while (r_b < PACKET_SIZE) + { + int ret; + ret = get_bytes(fd, buf + r_b, PACKET_SIZE - r_b); + if (ret == -EAGAIN) + { + u_sleep_ms(1); + if (timeout++>500) + { + close(fd); + exit(-1); + } + continue; + } + r_b += ret; + } + crc = cal_CRC16((uint8_t *)buf, PACKET_SIZE); + + // crc + recv_crc = get_char(fd) << 8; + recv_crc |= get_char(fd); + if (recv_crc != crc) + { + put_char(fd, NAK); + goto again; + } + else + { + put_char(fd, ACK); + state = RECEIVE_DATA; + } + // to get name and file size + PRINTF("receive file name: %s, length :%d\n", buf, strlen(buf)); + file_size = atoi((buf + strlen(buf) + 1)); + PRINTF("file size: %d\n", file_size); + + fd_file = open(path, O_RDWR | O_CREAT | O_TRUNC, 0777); + if (fd_file < 0) + { + perror("open() file"); + return -1; + } + put_char(fd, 'C'); + } + else + { + exit(-1); + } + packet_num = 1; + break; + case RECEIVE_DATA: + start_char = get_char(fd); + switch (start_char) + { + case EOT: + eot_cn++; + if (eot_cn == 1) + { + put_char(fd, NAK); + continue; + } + else if (eot_cn == 2) + { + state = END; + put_char(fd, ACK); + } + break; + case STX: + packet_size = 1024; + break; + case SOH: + packet_size = 128; + break; + case CAN: + break; + default: + break; + } + if (state == END) + break; + + tmp_char = get_char(fd); + tmp_char = get_char(fd); + + int r_b = 0; + int timeout = 0; + while (r_b < PACKET_SIZE) + { + int ret; + + ret = get_bytes(fd, buf + r_b, PACKET_SIZE - r_b); + if (ret == -EAGAIN) + { + u_sleep_ms(1); + if (timeout++>500) + { + close(fd); + exit(-1); + } + continue; + } + r_b += ret; + } + crc = cal_CRC16(buf, PACKET_SIZE); + // crc + recv_crc = get_char(fd) << 8; + recv_crc |= get_char(fd); + if (recv_crc != crc) + { + // while (try_get_char(fd, &tmp_char) > 0); + tcflush(fd, TCIOFLUSH); + put_char(fd, NAK); + } + else + { + if (file_size < packet_size) + { + len = write(fd_file, buf, file_size); + if (len != file_size) + { + exit(-1); + } + file_size -= len; + } + else + { + len = write(fd_file, buf, PACKET_SIZE); + if (len != PACKET_SIZE) + { + exit(-1); + } + file_size -= PACKET_SIZE; + } + put_char(fd, ACK); + } + // state = END; + break; + case END: + put_char(fd, 'C'); + + start_char = get_char(fd); + switch (start_char) + { + case STX: + packet_size = 1024; + break; + case SOH: + packet_size = 128; + break; + case CAN: + break; + default: + break; + } + // if (state == ) break; + + tmp_char = get_char(fd); + tmp_char = get_char(fd); + + for (i = 0; i < packet_size; i++) + { + buf[i] = get_char(fd); + } + + tmp_char = get_char(fd); + tmp_char = get_char(fd); + + put_char(fd, ACK); + state = STOP; + break; + case STOP: + close(fd_file); + put_char(fd, 'O'); + trans_end = 1; + break; + } + } + + return 0; +} + +int main(int argc, char **argv) +{ + int fd; + int ret; + // if (argc < 2) + // { + // printf("example:ym /mnt/1.txt"); + // return -1; + // } + // char *path = argv[1]; + char *path = "/mnt/1.txt"; + ret = 0; + printf("recv file is %.\n", path); + fd = open("/dev/tty", O_RDWR | O_NONBLOCK); + if (fd < 0) + { + perror("open()"); + exit(1); + } + + if (set_serial(fd) < 0) + { + PRINTF("set_serial() failed!\n"); + close(fd); + return -1; + } + + ret = ymodem_receive(path, fd); + if (ret < 0) + { + PRINTF("ymodem_receive() error\n"); + return -1; + } + + close_serial(fd); + close(fd); + printf("ymodem end.\n"); + + return 0; +} diff --git a/mkrtos_user/user/app/Ymodem/serial.c b/mkrtos_user/user/app/Ymodem/serial.c new file mode 100644 index 000000000..98f5e0241 --- /dev/null +++ b/mkrtos_user/user/app/Ymodem/serial.c @@ -0,0 +1,108 @@ +#include "serial.h" +#include "u_sleep.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +int put_char(int fd, unsigned char c) +{ + int ret = 0; + +again: + ret = write(fd, &c, 1); + if (ret < 0) { + if (errno == EAGAIN) { + u_sleep_ms(1); + goto again; + } + printf("write() in put_char(), errno:%d\n", errno); + } + + return ret; +} +int get_bytes(int fd, char *buf, int len) +{ + int ret = read(fd, buf, len); + if (ret < 0) { + ret = -errno; + } + return ret; +} +int try_get_char(int fd, char *res_char) +{ + int ret = read(fd, res_char, 1); + if (ret < 0) { + ret = -errno; + } + return ret; +} +char get_char(int fd) +{ + int len = 0; + char c; +again: + len = read(fd, &c, 1); + if (len < 0) { + if (errno == EAGAIN) { + u_sleep_ms(1); + goto again; + } + perror("read() in get_char()"); + } + return c; +} +static struct termios opt; +int set_serial(int fd) +{ + struct termios tmp; + tcgetattr(fd, &opt); + tcflush(fd, TCIOFLUSH); + tmp = opt; + // cfsetispeed(&tmp, B115200); // 115200Bps + tmp.c_lflag &= ~ICANON; + tmp.c_lflag &= ~IEXTEN; + tmp.c_lflag &= ~ISIG; + tmp.c_lflag &= ~ECHO; + tmp.c_iflag = 0; + tmp.c_oflag = 0; + if (tcsetattr(fd, TCSANOW, &tmp) == -1) { + perror("tcsetattr()"); + return -1; + } + + return 0; +} + +void close_serial(int fd) +{ + if (tcsetattr(fd, TCSANOW, &opt) == -1) { + perror("tcsetattr()"); + } + close(fd); +} + +unsigned int get_file_size(const char *path) +{ + unsigned long filesize = -1; + struct stat statbuff; + if (stat(path, &statbuff) < 0) { + return filesize; + } else { + filesize = statbuff.st_size; + } +#if 0 + FILE *fp; + fp = fopen(path, "r"); + if (fp == NULL) + return filesize; + fseek(fp, 0L, SEEK_END); + filesize = ftell(fp); + fclose(fp); +#endif + return filesize; +} diff --git a/mkrtos_user/user/app/Ymodem/serial.h b/mkrtos_user/user/app/Ymodem/serial.h new file mode 100644 index 000000000..f3810d903 --- /dev/null +++ b/mkrtos_user/user/app/Ymodem/serial.h @@ -0,0 +1,19 @@ +#ifndef __SERIAL_H__ +#define __SERIAL_H__ + +#define PACKET_128 128 +#define PACKET_1k 1024 + +char get_char(int fd); + +int put_char(int , const unsigned char ); + +int get_bytes(int fd, char *buf, int len); + +int try_get_char(int fd, char *res_char); + +int set_serial(int ); + +void close_serial(int ); + +#endif diff --git a/mkrtos_user/user/app/Ymodem/source/common.h b/mkrtos_user/user/app/Ymodem/source/common.h deleted file mode 100644 index e1706d1f1..000000000 --- a/mkrtos_user/user/app/Ymodem/source/common.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __COMMON_H__ -#define __COMMON_H__ - -/*System Include Files depended*/ -#include "stdint.h" -#include "string.h" - -#endif /*__COMMON_H__*/ diff --git a/mkrtos_user/user/app/Ymodem/source/ymodem.c b/mkrtos_user/user/app/Ymodem/source/ymodem.c deleted file mode 100644 index e4c67e58d..000000000 --- a/mkrtos_user/user/app/Ymodem/source/ymodem.c +++ /dev/null @@ -1,726 +0,0 @@ -/** - ****************************************************************************** - * @file STM32F0xx_IAP/src/ymodem.c - * @author MCD Application Team - * @version V1.0.0 - * @date 29-May-2012 - * @brief Main program body - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -//#include "common.h" -#include "ymodem.h" -#include "ymodem_util.h" -#include "ymodem_export.h" - - -/** @addtogroup STM32F0xx_IAP - * @{ - */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -extern uint8_t FileName[]; - -/* Private function prototypes -----------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ - -/** - * @brief Receive byte from sender - * @param c: Character - * @param timeout: Timeout - * @retval 0: Byte received - * -1: Timeout - */ -static int32_t Receive_Byte (uint8_t *c, uint32_t timeout) -{ - while (timeout-- > 0) - { - if (SerialKeyPressed(c) == 1) - { - return 0; - } - } - return -1; -} - -/** - * @brief Send a byte - * @param c: Character - * @retval 0: Byte sent - */ -static uint32_t Send_Byte (uint8_t c) -{ - SerialPutChar(c); - return 0; -} - -/** - * @brief Update CRC16 for input byte - * @param CRC input value - * @param input byte - * @retval Updated CRC value - */ -uint16_t UpdateCRC16(uint16_t crcIn, uint8_t byte) -{ - uint32_t crc = crcIn; - uint32_t in = byte|0x100; - - do - { - crc <<= 1; - in <<= 1; - - if(in&0x100) - { - ++crc; - } - - if(crc&0x10000) - { - crc ^= 0x1021; - } - } while(!(in&0x10000)); - - return (crc&0xffffu); -} - -/** - * @brief Cal CRC16 for YModem Packet - * @param data - * @param length - * @retval CRC value - */ -uint16_t Cal_CRC16(const uint8_t* data, uint32_t size) -{ - uint32_t crc = 0; - const uint8_t* dataEnd = data+size; - - while(data0: packet length - * @retval 0: normally return - * -1: timeout or packet error - * 1: abort by user - */ -static int32_t Receive_Packet (uint8_t *data, int32_t *length, uint32_t timeout) -{ - uint16_t i, packet_size, computedcrc; - uint8_t c; - *length = 0; - if (Receive_Byte(&c, timeout) != 0) - { - return -1; - } - switch (c) - { - case SOH: - packet_size = PACKET_SIZE; - break; - case STX: - packet_size = PACKET_1K_SIZE; - break; - case EOT: - return 0; - case CA: - if ((Receive_Byte(&c, timeout) == 0) && (c == CA)) - { - *length = -1; - return 0; - } - else - { - return -1; - } - case ABORT1: - case ABORT2: - return 1; - default: - return -1; - } - *data = c; - for (i = 1; i < (packet_size + PACKET_OVERHEAD); i ++) - { - if (Receive_Byte(data + i, timeout) != 0) - { - return -1; - } - } - if (data[PACKET_SEQNO_INDEX] != ((data[PACKET_SEQNO_COMP_INDEX] ^ 0xff) & 0xff)) - { - return -1; - } - - /* Compute the CRC */ - computedcrc = Cal_CRC16(&data[PACKET_HEADER], (uint32_t)packet_size); - /* Check that received CRC match the already computed CRC value - data[packet_size+3]<<8) | data[packet_size+4] contains the received CRC - computedcrc contains the computed CRC value */ - if (computedcrc != (uint16_t)((data[packet_size+3]<<8) | data[packet_size+4])) - { - /* CRC error */ - return -1; - } - - *length = packet_size; - return 0; -} - -/** - * @brief Receive a file using the ymodem protocol - * @param buf: Address of the first byte - * @retval The size of the file - */ -int32_t Ymodem_Receive (uint8_t *buf) -{ - uint8_t packet_data[PACKET_1K_SIZE + PACKET_OVERHEAD], file_size[FILE_SIZE_LENGTH], *file_ptr, *buf_ptr; - int32_t i, packet_length, session_done, file_done, packets_received, errors, session_begin, size = 0; - uint32_t flashdestination, ramsource; - - uint32_t YMODEM_MAX_SIZE = ymodem_get_receive_maxsize(); - - flashdestination = flashdestination; - ramsource = ramsource; -#if 0 - /* Initialize flashdestination variable */ - flashdestination = APPLICATION_ADDRESS; -#endif - - for (session_done = 0, errors = 0, session_begin = 0; ;) - { - for (packets_received = 0, file_done = 0, buf_ptr = buf; ;) - { - switch (Receive_Packet(packet_data, &packet_length, NAK_TIMEOUT)) - { - case 0: - errors = 0; - switch (packet_length) - { - /* Abort by sender */ - case - 1: - Send_Byte(ACK); - return 0; - - /* End of transmission */ - case 0: - Send_Byte(ACK); - file_done = 1; - break; - - /* Normal packet */ - default: - if ((packet_data[PACKET_SEQNO_INDEX] & 0xff) != (packets_received & 0xff)) - { - Send_Byte(NAK); - } - else - { - if (packets_received == 0) - { - /* Filename packet */ - if (packet_data[PACKET_HEADER] != 0) - { - /* Filename packet has valid data */ - for (i = 0, file_ptr = packet_data + PACKET_HEADER; (*file_ptr != 0) && (i < FILE_NAME_LENGTH);) - { - FileName[i++] = *file_ptr++; - } - FileName[i++] = '\0'; - for (i = 0, file_ptr ++; (*file_ptr != ' ') && (i < (FILE_SIZE_LENGTH - 1));) - { - file_size[i++] = *file_ptr++; - } - file_size[i++] = '\0'; - Str2Int(file_size, &size); - - /* Test the size of the image to be sent */ - /* Image size is greater than Flash size */ - if (size > (YMODEM_MAX_SIZE + 1)) - { - /* End session */ - Send_Byte(CA); - Send_Byte(CA); - return -1; - } - #if 0 - /* erase user application area */ - FLASH_If_Erase(APPLICATION_ADDRESS); - #else - //start fail - if(-1 == ymodem_recv_start_cb((char*)FileName, size)){ - /* End session */ - Send_Byte(CA); - Send_Byte(CA); - return -1; - } - #endif - Send_Byte(ACK); - Send_Byte(CRC16); - } - /* Filename packet is empty, end session */ - else - { - Send_Byte(ACK); - file_done = 1; - session_done = 1; - break; - } - } - /* Data packet */ - else - { - memcpy((uint8_t*)buf_ptr, (uint8_t*)packet_data + PACKET_HEADER, packet_length); - ramsource = (uint32_t)buf; - - /* Write received data in Flash */ - #if 0 - if (FLASH_If_Write(&flashdestination, (uint32_t*) ramsource, (uint16_t) packet_length/4) == 0) - #else - if(0 == ymodem_recv_processing_cb((const uint8_t *)buf, packet_length)) - #endif - { - Send_Byte(ACK); - } - else /* An error occurred while writing to Flash memory */ - { - /* End session */ - Send_Byte(CA); - Send_Byte(CA); - return -2; - } - } - packets_received ++; - session_begin = 1; - } - } - break; - - case 1: - Send_Byte(CA); - Send_Byte(CA); - return -3; - - default: - if (session_begin > 0) - { - errors ++; - } - if (errors > MAX_ERRORS) - { - Send_Byte(CA); - Send_Byte(CA); - return 0; - } - Send_Byte(CRC16); - break; - } - if (file_done != 0) - { - break; - } - } - if (session_done != 0) - { - break; - } - } - return (int32_t)size; -} - -/** - * @brief check response using the ymodem protocol - * @param buf: Address of the first byte - * @retval The size of the file - */ -int32_t Ymodem_CheckResponse(uint8_t c) -{ - return 0; -} - -/** - * @brief Prepare the first block - * @param timeout - * @retval None - */ -void Ymodem_PrepareIntialPacket(uint8_t *data, const uint8_t* fileName, uint32_t *length) -{ - uint16_t i, j; - uint8_t file_ptr[10]; - - /* Make first three packet */ - data[0] = SOH; - data[1] = 0x00; - data[2] = 0xff; - - /* Filename packet has valid data */ - for (i = 0; (fileName[i] != '\0') && (i < FILE_NAME_LENGTH);i++) - { - data[i + PACKET_HEADER] = fileName[i]; - } - - data[i + PACKET_HEADER] = 0x00; - - Int2Str (file_ptr, *length); - for (j =0, i = i + PACKET_HEADER + 1; file_ptr[j] != '\0' ; ) - { - data[i++] = file_ptr[j++]; - } - - for (j = i; j < PACKET_SIZE + PACKET_HEADER; j++) - { - data[j] = 0; - } -} - -/** - * @brief Prepare the data packet - * @param timeout - * @retval None - */ -void Ymodem_PreparePacket(uint8_t *SourceBuf, uint8_t *data, uint8_t pktNo, uint32_t sizeBlk) -{ - uint16_t i, size, packetSize; - uint8_t* file_ptr; - - /* Make first three packet */ - packetSize = sizeBlk >= PACKET_1K_SIZE ? PACKET_1K_SIZE : PACKET_SIZE; - size = sizeBlk < packetSize ? sizeBlk :packetSize; - if (packetSize == PACKET_1K_SIZE) - { - data[0] = STX; - } - else - { - data[0] = SOH; - } - data[1] = pktNo; - data[2] = (~pktNo); - file_ptr = SourceBuf; - - /* Filename packet has valid data */ - for (i = PACKET_HEADER; i < size + PACKET_HEADER;i++) - { - data[i] = *file_ptr++; - } - if ( size <= packetSize) - { - for (i = size + PACKET_HEADER; i < packetSize + PACKET_HEADER; i++) - { - data[i] = 0x1A; /* EOF (0x1A) or 0x00 */ - } - } -} - -/** - * @brief Transmit a data packet using the ymodem protocol - * @param data - * @param length - * @retval None - */ -void Ymodem_SendPacket(uint8_t *data, uint16_t length) -{ - uint16_t i; - i = 0; - while (i < length) - { - Send_Byte(data[i]); - i++; - } -} - -/** - * @brief Transmit a file using the ymodem protocol - * @param buf: Address of the first byte - * @retval The size of the file - */ -uint8_t Ymodem_Transmit (uint8_t *buf, const uint8_t* sendFileName, uint32_t sizeFile) -{ - uint8_t packet_data[PACKET_1K_SIZE + PACKET_OVERHEAD]; - uint8_t FileName[FILE_NAME_LENGTH]; - uint8_t *buf_ptr, tempCheckSum ; - uint16_t tempCRC, blkNumber; - uint8_t receivedC[2], CRC16_F = 0, i; - uint32_t errors = 0, ackReceived = 0, size = 0, pktSize; - - uint32_t YMODEM_TRANSMIT_SIZE = ymodem_get_transmit_size(); - - for (i = 0; i < (FILE_NAME_LENGTH - 1); i++) - { - FileName[i] = sendFileName[i]; - } - CRC16_F = 1; - - /* Prepare first block */ - Ymodem_PrepareIntialPacket(&packet_data[0], FileName, &sizeFile); - - do - { - /* Send Packet */ - Ymodem_SendPacket(packet_data, PACKET_SIZE + PACKET_HEADER); - - /* Send CRC or Check Sum based on CRC16_F */ - if (CRC16_F) - { - tempCRC = Cal_CRC16(&packet_data[3], PACKET_SIZE); - Send_Byte(tempCRC >> 8); - Send_Byte(tempCRC & 0xFF); - } - else - { - tempCheckSum = CalChecksum (&packet_data[3], PACKET_SIZE); - Send_Byte(tempCheckSum); - } - - /* Wait for Ack and 'C' */ - if (Receive_Byte(&receivedC[0], 1000000) == 0) - { - if (receivedC[0] == ACK) - { - /* Packet transfered correctly */ - ackReceived = 1; - } - } - else - { - errors++; - } - }while (!ackReceived && (errors < 0x0A)); - - if (errors >= 0x0A) - { - return errors; - } - buf_ptr = buf; - size = sizeFile; - blkNumber = 0x01; - - /* Here 1024 bytes package is used to send the packets */ - while (size) - { - /* Prepare next packet */ - Ymodem_PreparePacket(buf_ptr, &packet_data[0], blkNumber, size); - ackReceived = 0; - receivedC[0]= 0; - errors = 0; - do - { - /* Send next packet */ - if (size >= PACKET_1K_SIZE) - { - pktSize = PACKET_1K_SIZE; - - } - else - { - pktSize = PACKET_SIZE; - } - Ymodem_SendPacket(packet_data, pktSize + PACKET_HEADER); - /* Send CRC or Check Sum based on CRC16_F */ - if (CRC16_F) - { - tempCRC = Cal_CRC16(&packet_data[3], pktSize); - Send_Byte(tempCRC >> 8); - Send_Byte(tempCRC & 0xFF); - } - else - { - tempCheckSum = CalChecksum (&packet_data[3], pktSize); - Send_Byte(tempCheckSum); - } - - /* Wait for Ack */ - if (Receive_Byte(&receivedC[0], 1000000) == 0) - { - - if (receivedC[0] == ACK) - { - ackReceived = 1; - if (size > pktSize) - { - buf_ptr += pktSize; - size -= pktSize; - if (blkNumber == (YMODEM_TRANSMIT_SIZE/1024)) - { - return 0xFF; /* error */ - } - else - { - blkNumber++; - } - } - else - { - buf_ptr += pktSize; - size = 0; - } - } - } - else - { - errors++; - } - }while(!ackReceived && (errors < 0x0A)); - - /* Resend packet if NAK for a count of 10 else end of commuincation */ - if (errors >= 0x0A) - { - return errors; - } - - } - ackReceived = 0; - receivedC[0] = 0x00; - receivedC[1] = 0x00; - errors = 0; - do - { - Send_Byte(EOT); - /* Send (EOT); */ - /* Wait for Ack */ - receivedC[0] = SerialReadByte(); - if (receivedC[0] == ACK) - { - ackReceived = 1; - } - else - { - errors++; - } - - }while (!ackReceived && (errors < 0x0A)); - - if (errors >= 0x0A) - { - return errors; - } - - /* Last packet preparation */ - ackReceived = 0; - receivedC[0] = 0x00; - receivedC[1] = 0x00; - errors = 0; - - packet_data[0] = SOH; - packet_data[1] = 0; - packet_data [2] = 0xFF; - - for (i = PACKET_HEADER; i < (PACKET_SIZE + PACKET_HEADER); i++) - { - packet_data [i] = 0x00; - } - - do - { - /* Send Packet */ - Ymodem_SendPacket(packet_data, PACKET_SIZE + PACKET_HEADER); - - /* Send CRC or Check Sum based on CRC16_F */ - tempCRC = Cal_CRC16(&packet_data[3], PACKET_SIZE); - Send_Byte(tempCRC >> 8); - Send_Byte(tempCRC & 0xFF); - - /* Wait for Ack and 'C' */ - if (Receive_Byte(&receivedC[1], 1000000) == 0) - { - if (receivedC[1] == ACK) - { - /* Packet transfered correctly */ - ackReceived = 1; - } - } - else - { - errors++; - } - }while (!ackReceived && (errors < 0x0A)); - - /* Resend packet if NAK for a count of 10 else end of commuincation */ - if (errors >= 0x0A) - { - return errors; - } - receivedC[0] = 0x00; - do - { - Send_Byte(EOT); - /* Send (EOT); */ - /* Wait for Ack */ - if ((Receive_Byte(&receivedC[0], 1000000) == 0) && receivedC[0] == ACK) - { - ackReceived = 1; - } - - else - { - errors++; - } - /* Clear Overrun flag of the USART2 */ - //USART_ClearFlag(EVAL_COM1, USART_FLAG_ORE); - }while (!ackReceived && (errors < 0x0A)); - - if (errors >= 0x0A) - { - return errors; - } - return 0; /* file trasmitted successfully */ -} - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/mkrtos_user/user/app/Ymodem/source/ymodem.h b/mkrtos_user/user/app/Ymodem/source/ymodem.h deleted file mode 100644 index 03fe2f467..000000000 --- a/mkrtos_user/user/app/Ymodem/source/ymodem.h +++ /dev/null @@ -1,78 +0,0 @@ -/** - ****************************************************************************** - * @file STM32F0xx_IAP/inc/ymodem.h - * @author MCD Application Team - * @version V1.0.0 - * @date 29-May-2012 - * @brief Header for main.c module - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef _YMODEM_H_ -#define _YMODEM_H_ - -#include "common.h" - -/* Includes ------------------------------------------------------------------*/ - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -#define PACKET_SEQNO_INDEX (1) -#define PACKET_SEQNO_COMP_INDEX (2) - -#define PACKET_HEADER (3) -#define PACKET_TRAILER (2) -#define PACKET_OVERHEAD (PACKET_HEADER + PACKET_TRAILER) -#define PACKET_SIZE (128) -#define PACKET_1K_SIZE (1024) - -#define FILE_NAME_LENGTH (256) -#define FILE_SIZE_LENGTH (16) - -#define SOH (0x01) /* start of 128-byte data packet */ -#define STX (0x02) /* start of 1024-byte data packet */ -#define EOT (0x04) /* end of transmission */ -#define ACK (0x06) /* acknowledge */ -#define NAK (0x15) /* negative acknowledge */ -#define CA (0x18) /* two of these in succession aborts transfer */ -#define CRC16 (0x43) /* 'C' == 0x43, request 16-bit CRC */ - -#define ABORT1 (0x41) /* 'A' == 0x41, abort by user */ -#define ABORT2 (0x61) /* 'a' == 0x61, abort by user */ - -#define NAK_TIMEOUT (5000) -#define MAX_ERRORS (5) - -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -int32_t Ymodem_Receive (uint8_t *); -uint8_t Ymodem_Transmit (uint8_t *,const uint8_t* , uint32_t ); -uint16_t UpdateCRC16(uint16_t crcIn, uint8_t byte); -uint16_t Cal_CRC16(const uint8_t* data, uint32_t size); -uint8_t CalChecksum(const uint8_t* data, uint32_t size); -int32_t Ymodem_CheckResponse(uint8_t c); -void Ymodem_PrepareIntialPacket(uint8_t *data, const uint8_t* fileName, uint32_t *length); -void Ymodem_PreparePacket(uint8_t *SourceBuf, uint8_t *data, uint8_t pktNo, uint32_t sizeBlk); -void Ymodem_SendPacket(uint8_t *data, uint16_t length); - -#endif /* _YMODEM_H_ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/mkrtos_user/user/app/Ymodem/source/ymodem_menu.c b/mkrtos_user/user/app/Ymodem/source/ymodem_menu.c deleted file mode 100644 index 33da118d4..000000000 --- a/mkrtos_user/user/app/Ymodem/source/ymodem_menu.c +++ /dev/null @@ -1,186 +0,0 @@ -/** - ****************************************************************************** - * @file STM32F0xx_IAP/src/menu.c - * @author MCD Application Team - * @version V1.0.0 - * @date 29-May-2012 - * @brief Main program body - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "ymodem.h" -#include "ymodem_menu.h" -#include "ymodem_util.h" -#include "ymodem_export.h" - -/** @addtogroup STM32F0xx_IAP - * @{ - */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -uint32_t JumpAddress; -extern uint32_t UserMemoryMask; -uint32_t FlashProtection = 0; -uint8_t tab_1024[1024] = {0}; -uint8_t FileName[FILE_NAME_LENGTH]; - -/* Private function prototypes -----------------------------------------------*/ -void SerialDownload(void); -void SerialUpload(void); - - -// #warning "avoid errors" -#define APPLICATION_ADDRESS 0x08000000 -#define USER_FLASH_SIZE 1024 - -/* Private functions ---------------------------------------------------------*/ - -/** - * @brief Download a file via serial port - * @param None - * @retval None - */ -void SerialDownload(void) -{ - uint8_t Number[10] = {0}; - int32_t Size = 0; - - SerialPutString("Waiting for the file to be sent ... (press 'a' to abort)\n\r"); - Size = Ymodem_Receive(&tab_1024[0]); - ymodem_recv_end_cb(); - if (Size > 0) - { - SerialPutString("\n\n\r Download File Successfully!\n\r--------------------------------\r\n Name: "); - SerialPutString(FileName); - Int2Str(Number, Size); - SerialPutString("\n\r Size: "); - SerialPutString(Number); - SerialPutString(" Bytes\r\n"); - SerialPutString("--------------------------------\n"); - } - else if (Size == -1) - { - SerialPutString("\n\n\rThe file size is higher than the allowed space memory!\n\r"); - } - else if (Size == -2) - { - SerialPutString("\n\n\rVerification failed!\n\r"); - } - else if (Size == -3) - { - SerialPutString("\r\n\nAborted by user.\n\r"); - } - else - { - SerialPutString("\n\rFailed to receive the file!\n\r"); - } -} -#if 0 -/** - * @brief Upload a file via serial port. - * @param None - * @retval None - */ -void SerialUpload(void) -{ - uint8_t status = 0 ; - - SerialPutString("\n\n\rSelect Receive File\n\r"); - - if (GetKey() == CRC16) - { - /* Transmit the flash image through ymodem protocol */ - status = Ymodem_Transmit((uint8_t*)APPLICATION_ADDRESS, (const uint8_t*)"UploadedFlashImage.bin", USER_FLASH_SIZE); - - if (status != 0) - { - SerialPutString("\n\rError Occurred while Transmitting File\n\r"); - } - else - { - SerialPutString("\n\rFile uploaded successfully \n\r"); - } - } -} -#endif -/** - * @brief Display the Main Menu on HyperTerminal - * @param None - * @retval None - */ -void Ymodem_Main_Entrance(void) -{ - uint8_t key = 0; - - ymodem_init(); - SerialPutString("\r\n======================================================================"); - SerialPutString("\r\n= (C) COPYRIGHT 2012 STMicroelectronics ="); - SerialPutString("\r\n= ="); - SerialPutString("\r\n= MKRTOS In-Application Programming Application (Version 1.0.0) ="); - SerialPutString("\r\n= ="); - SerialPutString("\r\n= By MCD Application Team ="); - SerialPutString("\r\n======================================================================"); - SerialPutString("\r\n\r\n"); - - while (1) - { - SerialPutString("\r\n================== Ymodem Menu =========================\r\n\n"); - SerialPutString(" Download File from PC to Board ------- 1\r\n\n"); - // SerialPutString(" Upload File from Board to PC ------- 2\r\n\n"); - SerialPutString(" Exit Y-modem ------- 2\r\n\n"); - SerialPutString("==========================================================\r\n\n"); - - /* Receive key */ - key = GetKey(); - - if (key == 0x31) - { - /* Download user application in the Flash */ - SerialDownload(); - } - #if 0 - else if (key == 0x32) - { - /* Upload user application from the Flash */ - SerialUpload(); - } - #endif - else if (key == 0x32) /* execute the new program */ - { - SerialPutString("Exit Y-modem ....\r\n"); - break; - } - else - { - SerialPutString("Invalid Number ! ==> The number should be either 1, 2 or 3\r"); - } - } -} - - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/mkrtos_user/user/app/Ymodem/source/ymodem_menu.h b/mkrtos_user/user/app/Ymodem/source/ymodem_menu.h deleted file mode 100644 index c3f2420b6..000000000 --- a/mkrtos_user/user/app/Ymodem/source/ymodem_menu.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - ****************************************************************************** - * @file STM32F0xx_IAP/inc/menu.h - * @author MCD Application Team - * @version V1.0.0 - * @date 29-May-2012 - * @brief Header for main.c module - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __MENU_H -#define __MENU_H - -/* Includes ------------------------------------------------------------------*/ - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ - - -#endif /* __MENU_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/mkrtos_user/user/app/Ymodem/source/ymodem_util.c b/mkrtos_user/user/app/Ymodem/source/ymodem_util.c deleted file mode 100644 index 655231930..000000000 --- a/mkrtos_user/user/app/Ymodem/source/ymodem_util.c +++ /dev/null @@ -1,264 +0,0 @@ -/** - ****************************************************************************** - * @file STM32F0xx_IAP/src/common.c - * @author MCD Application Team - * @version V1.0.0 - * @date 29-May-2012 - * @brief Main program body - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "ymodem_util.h" -#include "ymodem_export.h" - - - -/******************************************************************************** - * ANSI-C APIs - ********************************************************************************/ - -/** - * @brief Get a key from the HyperTerminal - * @param None - * @retval The Key Pressed - */ -uint8_t GetKey(void) -{ - uint8_t key = 0; - - /* Waiting for user input */ - while (1) - { - if (SerialKeyPressed((uint8_t*)&key)) break; - } - return key; -} - -/** - * @brief Convert an Integer to a string - * @param str: The string - * @param intnum: The intger to be converted - * @retval None - */ -void Int2Str(uint8_t* str, int32_t intnum) -{ - uint32_t i, Div = 1000000000, j = 0, Status = 0; - - for (i = 0; i < 10; i++) - { - str[j++] = (intnum / Div) + 48; - - intnum = intnum % Div; - Div /= 10; - if ((str[j-1] == '0') & (Status == 0)) - { - j = 0; - } - else - { - Status++; - } - } -} - -/** - * @brief Convert a string to an integer - * @param inputstr: The string to be converted - * @param intnum: The intger value - * @retval 1: Correct - * 0: Error - */ -uint32_t Str2Int(uint8_t *inputstr, int32_t *intnum) -{ - uint32_t i = 0, res = 0; - uint32_t val = 0; - - if (inputstr[0] == '0' && (inputstr[1] == 'x' || inputstr[1] == 'X')) - { - if (inputstr[2] == '\0') - { - return 0; - } - for (i = 2; i < 11; i++) - { - if (inputstr[i] == '\0') - { - *intnum = val; - /* return 1; */ - res = 1; - break; - } - if (ISVALIDHEX(inputstr[i])) - { - val = (val << 4) + CONVERTHEX(inputstr[i]); - } - else - { - /* return 0, Invalid input */ - res = 0; - break; - } - } - /* over 8 digit hex --invalid */ - if (i >= 11) - { - res = 0; - } - } - else /* max 10-digit decimal input */ - { - for (i = 0;i < 11;i++) - { - if (inputstr[i] == '\0') - { - *intnum = val; - /* return 1 */ - res = 1; - break; - } - else if ((inputstr[i] == 'k' || inputstr[i] == 'K') && (i > 0)) - { - val = val << 10; - *intnum = val; - res = 1; - break; - } - else if ((inputstr[i] == 'm' || inputstr[i] == 'M') && (i > 0)) - { - val = val << 20; - *intnum = val; - res = 1; - break; - } - else if (ISVALIDDEC(inputstr[i])) - { - val = val * 10 + CONVERTDEC(inputstr[i]); - } - else - { - /* return 0, Invalid input */ - res = 0; - break; - } - } - /* Over 10 digit decimal --invalid */ - if (i >= 11) - { - res = 0; - } - } - - return res; -} - -/** - * @brief Get an integer from the HyperTerminal - * @param num: The inetger - * @retval 1: Correct - * 0: Error - */ -uint32_t GetIntegerInput(int32_t * num) -{ - uint8_t inputstr[16]; - - while (1) - { - GetInputString(inputstr); - if (inputstr[0] == '\0') continue; - if ((inputstr[0] == 'a' || inputstr[0] == 'A') && inputstr[1] == '\0') - { - SerialPutString("User Cancelled \r\n"); - return 0; - } - - if (Str2Int(inputstr, num) == 0) - { - SerialPutString("Error, Input again: \r\n"); - } - else - { - return 1; - } - } -} - - -/** - * @brief Print a string on the HyperTerminal - * @param s: The string to be printed - * @retval None - */ -void Serial_PutString(uint8_t *s) -{ - while (*s != '\0') - { - SerialPutChar(*s); - s++; - } -} - -/** - * @brief Get Input string from the HyperTerminal - * @param buffP: The input string - * @retval None - */ -void GetInputString (uint8_t * buffP) -{ - uint32_t bytes_read = 0; - uint8_t c = 0; - do - { - c = GetKey(); - if (c == '\r') - break; - if (c == '\b') /* Backspace */ - { - if (bytes_read > 0) - { - SerialPutString("\b \b"); - bytes_read --; - } - continue; - } - if (bytes_read >= CMD_STRING_SIZE ) - { - SerialPutString("Command string size overflow\r\n"); - bytes_read = 0; - continue; - } - if (c >= 0x20 && c <= 0x7E) - { - buffP[bytes_read++] = c; - SerialPutChar(c); - } - } - while (1); - SerialPutString(("\n\r")); - buffP[bytes_read] = '\0'; -} - - - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/mkrtos_user/user/app/Ymodem/source/ymodem_util.h b/mkrtos_user/user/app/Ymodem/source/ymodem_util.h deleted file mode 100644 index 1e9b5b4c4..000000000 --- a/mkrtos_user/user/app/Ymodem/source/ymodem_util.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - ****************************************************************************** - * @file STM32F0xx_IAP/inc/common.h - * @author MCD Application Team - * @version V1.0.0 - * @date 29-May-2012 - * @brief Header for main.c module - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __YMODEM_UTIL_H__ -#define __YMODEM_UTIL_H__ - -/* Includes ------------------------------------------------------------------*/ -#include "common.h" - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Constants used by Serial Command Line Mode */ -#define CMD_STRING_SIZE 128 - -/* Exported macro ------------------------------------------------------------*/ -/* Common routines */ -#define IS_AF(c) ((c >= 'A') && (c <= 'F')) -#define IS_af(c) ((c >= 'a') && (c <= 'f')) -#define IS_09(c) ((c >= '0') && (c <= '9')) -#define ISVALIDHEX(c) IS_AF(c) || IS_af(c) || IS_09(c) -#define ISVALIDDEC(c) IS_09(c) -#define CONVERTDEC(c) (c - '0') - -#define CONVERTHEX_alpha(c) (IS_AF(c) ? (c - 'A'+10) : (c - 'a'+10)) -#define CONVERTHEX(c) (IS_09(c) ? (c - '0') : CONVERTHEX_alpha(c)) - -#define SerialPutString(x) Serial_PutString((uint8_t*)(x)) - -/* Exported functions ------------------------------------------------------- */ -void Int2Str(uint8_t* str,int32_t intnum); -uint32_t Str2Int(uint8_t *inputstr,int32_t *intnum); -uint32_t GetIntegerInput(int32_t * num); -uint8_t GetKey(void); -void SerialPutChar(uint8_t c); -void Serial_PutString(uint8_t *s); -void GetInputString(uint8_t * buffP); - - - -#endif /* __YMODEM_UTIL_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/mkrtos_user/user/app/Ymodem/ymodem.h b/mkrtos_user/user/app/Ymodem/ymodem.h new file mode 100644 index 000000000..e8718e245 --- /dev/null +++ b/mkrtos_user/user/app/Ymodem/ymodem.h @@ -0,0 +1,40 @@ +#ifndef __YMODEM_H__ +#define __YMODEM_H__ + +#define HEAD 1 +#define DATA 0 + +enum mode { + SOH = 0x01, + STX, + EOT = 0x04, + ACK = 0x06, + NAK = 0x15, + CAN = 0x18, + C = 0x43 +}; + +struct mcu_hex { + unsigned char *name; + const unsigned char *path; + unsigned int size; + unsigned char *idx; + unsigned char *idx_save; +}; + +struct packet { + int fd; //serial file descripter + + unsigned int size; //packet size 128 or 1024 + unsigned char head; //1: head packet 0:data packet + unsigned char sno; //packet number + unsigned char *buf; //packet data buffer + unsigned int crc1; //crc check code + unsigned int crc2; + + struct mcu_hex *file; //mcu hex file +}; + +unsigned int get_file_size(const char *); + +#endif diff --git a/mkrtos_user/user/drv/ATSURFF437/block/heap_stack.c b/mkrtos_user/user/drv/ATSURFF437/block/heap_stack.c index 96929978c..df3e769ca 100644 --- a/mkrtos_user/user/drv/ATSURFF437/block/heap_stack.c +++ b/mkrtos_user/user/drv/ATSURFF437/block/heap_stack.c @@ -1,3 +1,4 @@ +#include #define HEAP_SIZE (1024 + 512) #define STACK_SIZE (1024 + 512) diff --git a/mkrtos_user/user/drv/ATSURFF437/display/heap_stack.c b/mkrtos_user/user/drv/ATSURFF437/display/heap_stack.c index 96929978c..df3e769ca 100644 --- a/mkrtos_user/user/drv/ATSURFF437/display/heap_stack.c +++ b/mkrtos_user/user/drv/ATSURFF437/display/heap_stack.c @@ -1,3 +1,4 @@ +#include #define HEAP_SIZE (1024 + 512) #define STACK_SIZE (1024 + 512) diff --git a/mkrtos_user/user/drv/ATSURFF437/eth/heap_stack.c b/mkrtos_user/user/drv/ATSURFF437/eth/heap_stack.c index 96929978c..df3e769ca 100644 --- a/mkrtos_user/user/drv/ATSURFF437/eth/heap_stack.c +++ b/mkrtos_user/user/drv/ATSURFF437/eth/heap_stack.c @@ -1,3 +1,4 @@ +#include #define HEAP_SIZE (1024 + 512) #define STACK_SIZE (1024 + 512) diff --git a/mkrtos_user/user/drv/ATSURFF437/eth/main.c b/mkrtos_user/user/drv/ATSURFF437/eth/main.c index a4b3cecae..1bac3bcce 100644 --- a/mkrtos_user/user/drv/ATSURFF437/eth/main.c +++ b/mkrtos_user/user/drv/ATSURFF437/eth/main.c @@ -96,8 +96,8 @@ int main(int argc, char *argv[]) blk_drv_init(&net_drv); ret = rpc_meta_init_def(TASK_THIS, &hd); assert(ret >= 0); - ns_register("/dev/eth", hd, 0); meta_reg_svr_obj(&net_drv.svr, BLK_DRV_PROT); + ns_register("/dev/eth", hd, 0); while (1) { u_sleep_ms(U_SLEEP_ALWAYS); diff --git a/mkrtos_user/user/drv/ATSURFF437/i2c/heap_stack.c b/mkrtos_user/user/drv/ATSURFF437/i2c/heap_stack.c index 96929978c..f5125e94e 100644 --- a/mkrtos_user/user/drv/ATSURFF437/i2c/heap_stack.c +++ b/mkrtos_user/user/drv/ATSURFF437/i2c/heap_stack.c @@ -1,4 +1,4 @@ - +#include #define HEAP_SIZE (1024 + 512) #define STACK_SIZE (1024 + 512) diff --git a/mkrtos_user/user/drv/ATSURFF437/pca9555/heap_stack.c b/mkrtos_user/user/drv/ATSURFF437/pca9555/heap_stack.c index 96929978c..df3e769ca 100644 --- a/mkrtos_user/user/drv/ATSURFF437/pca9555/heap_stack.c +++ b/mkrtos_user/user/drv/ATSURFF437/pca9555/heap_stack.c @@ -1,3 +1,4 @@ +#include #define HEAP_SIZE (1024 + 512) #define STACK_SIZE (1024 + 512) diff --git a/mkrtos_user/user/drv/ATSURFF437/pin/heap_stack.c b/mkrtos_user/user/drv/ATSURFF437/pin/heap_stack.c index b2468f193..df3e769ca 100644 --- a/mkrtos_user/user/drv/ATSURFF437/pin/heap_stack.c +++ b/mkrtos_user/user/drv/ATSURFF437/pin/heap_stack.c @@ -1,3 +1,5 @@ +#include + #define HEAP_SIZE (1024 + 512) #define STACK_SIZE (1024 + 512) diff --git a/mkrtos_user/user/drv/ATSURFF437/snd/heap_stack.c b/mkrtos_user/user/drv/ATSURFF437/snd/heap_stack.c index 96929978c..df3e769ca 100644 --- a/mkrtos_user/user/drv/ATSURFF437/snd/heap_stack.c +++ b/mkrtos_user/user/drv/ATSURFF437/snd/heap_stack.c @@ -1,3 +1,4 @@ +#include #define HEAP_SIZE (1024 + 512) #define STACK_SIZE (1024 + 512)