Browse Source

add rx to lib/commands.c

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 6 years ago
parent
commit
72d2309674
  1. 47
      lib/commands.c
  2. 2
      lib/serial.c
  3. 42
      targets/stm32f429-disc/retarget.c
  4. 43
      targets/vocoder/retarget.c

47
lib/commands.c

@ -4,6 +4,8 @@
#include <stdint.h> #include <stdint.h>
#include "stm32f4xx.h" #include "stm32f4xx.h"
#include "bkp_sram.h" #include "bkp_sram.h"
#include "flash_if.h"
#include "ymodem.h"
#include "cmd.h" #include "cmd.h"
static int do_md(cmd_tbl_t s, int argc, char *argv[]) static int do_md(cmd_tbl_t s, int argc, char *argv[])
@ -69,3 +71,48 @@ static int do_upgrade(cmd_tbl_t s, int argc, char *argv[])
CON_CMD(upgrade, 2, "update firmware", do_upgrade); CON_CMD(upgrade, 2, "update firmware", do_upgrade);
struct fileinfo {
unsigned int start_address;
unsigned int total;
unsigned int received;
};
static int on_info(void *ud, const char *name, unsigned int size)
{
struct fileinfo *fi = ud;
(void)name;
fi->total = size;
return flash_if_erase(fi->start_address, fi->total);
}
static int on_data(void *ud, const void *data, unsigned int len)
{
struct fileinfo *fi = ud;
int err;
if (fi->received + len > fi->total) {
len = fi->total - fi->received;
}
err = flash_if_write(fi->start_address + fi->received, data, len);
fi->received += len;
return err;
}
static int do_rx(cmd_tbl_t s, int argc, char *argv[])
{
struct fileinfo fi;
int err = -1;
if (argc >= 2) {
fi.start_address = strtoul(argv[1], NULL, 0);
fi.total = 0;
fi.received = 0;
err = stdio_ymodem_recv(&fi, on_info, on_data);
}
return (err);
}
CON_CMD(rx, 2, "receive file over ymodem", do_rx);

2
lib/serial.c

@ -748,7 +748,7 @@ void __attribute__((weak)) target_usart6_setup()
static void usart6_setup(struct serial *uart) static void usart6_setup(struct serial *uart)
{ {
RCC_APB2PeriphClockCmd(uart->rcc_uart, ENABLE); RCC_APB2PeriphClockCmd(uart->rcc_uart, ENABLE);
target_usart7_setup(); target_usart6_setup();
} }
static volatile uint8_t __usart6_rx_buffer[TARGET_USART6_RX_BUFFER_SIZE] __attribute__((section(".rxdma.usart6,\"aw\",%nobits@"))); static volatile uint8_t __usart6_rx_buffer[TARGET_USART6_RX_BUFFER_SIZE] __attribute__((section(".rxdma.usart6,\"aw\",%nobits@")));

42
targets/stm32f429-disc/retarget.c

@ -51,48 +51,6 @@ static int do_sr2(cmd_tbl_t s, int argc, char *argv[])
CON_CMD(sr2, 2, "read stmpe811 register 2", do_sr2); CON_CMD(sr2, 2, "read stmpe811 register 2", do_sr2);
struct fileinfo {
char name[256];
unsigned int total;
unsigned int received;
};
static int __on_info(void *user, const char *file, unsigned int _size)
{
struct fileinfo *fi = user;
snprintf(fi->name, sizeof fi->name - 1, "%s", file);
fi->total = _size;
fi->received = 0;
return 0;
}
static int __on_data(void *user, const void *ptr, unsigned int len)
{
struct fileinfo *fi = user;
memcpy((void *)(0xd0000000 + fi->received), ptr, len);
iis_send_blocking(&i2s0, ptr, len);
fi->received += len;
return 0;
}
static int do_ymodem_recv(cmd_tbl_t s, int argc, char *argv[])
{
struct fileinfo fi;
memset(&fi, 0, sizeof fi);
serial_ymodem_recv(&serial0, &fi, __on_info, __on_data);
printf("name: %s, size: %d, recv: %d\r\n", fi.name, fi.total, fi.received);
return 0;
}
CON_CMD(rx, 1, "recv from ymodem", do_ymodem_recv);
static int do_play(cmd_tbl_t s, int argc, char *argv[]) static int do_play(cmd_tbl_t s, int argc, char *argv[])
{ {
volatile uint8_t *addr = (volatile uint8_t *)0xd0000000; volatile uint8_t *addr = (volatile uint8_t *)0xd0000000;

43
targets/vocoder/retarget.c

@ -71,49 +71,6 @@ static int do_rom_read(cmd_tbl_t s, int argc, char *argv[])
CON_CMD(rr, 3, "rom read", do_rom_read); CON_CMD(rr, 3, "rom read", do_rom_read);
struct fileinfo {
char name[256];
unsigned int total;
unsigned int received;
};
static int __on_info(void *user, const char *file, unsigned int _size)
{
struct fileinfo *fi = user;
snprintf(fi->name, sizeof fi->name - 1, "%s", file);
fi->total = _size;
fi->received = 0;
return 0;
}
static int __on_data(void *user, const void *ptr, unsigned int len)
{
struct fileinfo *fi = user;
memcpy((void *)(0xc0000000 + fi->received), ptr, len);
fi->received += len;
return 0;
}
static int do_ymodem_recv(cmd_tbl_t s, int argc, char *argv[])
{
struct fileinfo fi;
memset(&fi, 0, sizeof fi);
iwdg_set_period_ms(60000);
serial_ymodem_recv(&serial0, &fi, __on_info, __on_data);
iwdg_set_period_ms(1000);
printf("name: %s, size: %d, recv: %d\r\n", fi.name, fi.total, fi.received);
return 0;
}
CON_CMD(rx, 1, "recv from ymodem", do_ymodem_recv);
static int do_eer(cmd_tbl_t s, int argc, char *argv[]) static int do_eer(cmd_tbl_t s, int argc, char *argv[])
{ {
uint16_t addr; uint16_t addr;

Loading…
Cancel
Save