Browse Source

fix a3k, app irq bug

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 6 years ago
parent
commit
3eb1521eb1
  1. 8
      Makefile
  2. 58
      lib/a3k.c
  3. 4
      lib/utils.c
  4. 2
      src/flash.ld
  5. 19
      src/iap.c
  6. 26
      src/iap.ld
  7. 5
      src/main.c
  8. 1
      targets.mk

8
Makefile

@ -9,11 +9,11 @@ SIZE := $(CROSS)size
GDB := $(CROSS)gdb
OOCD ?= openocd
OOCD_INTERFACE ?= stlink-v2-1
OOCD_TRANSPORT ?= hla_swd
#OOCD_INTERFACE ?= stlink-v2-1
#OOCD_TRANSPORT ?= hla_swd
#OOCD_INTERFACE ?= cmsis-dap
#OOCD_INTERFACE ?= jlink
#OOCD_TRANSPORT ?= swd
OOCD_INTERFACE ?= jlink
OOCD_TRANSPORT ?= swd
OOCD_TARGET ?= stm32f4x
top_dir := $(shell pwd)

58
lib/a3k.c

@ -6,7 +6,9 @@
#include "a3kpacket.h"
#include "gpio.h"
#include "a3k.h"
#include "tick.h"
#define WAIT_TIMEOUT (50) /* 500ms */
#define RATE_PINS (6)
struct fifo_tag {
@ -73,7 +75,7 @@ static void __send_all(a3k_t tag, const uint8_t *p, int len)
while (len > 0) {
n = serial_send_buffered(tag->uart, p, len);
p += n;
len -= 0;
len -= n;
}
}
@ -182,13 +184,18 @@ static void put_packet(a3k_t a3k, char *packet, char *end, char type, char parit
* that the fifo contains at leas one character. If it does not the
* function returns a null character.
*/
static void __fifo_waitpacket(a3k_t tag)
static int __fifo_waitpacket(a3k_t tag)
{
int n, len;
char *old;
FIFO *f = &tag->rx;
uint64_t end = millis() + WAIT_TIMEOUT;
restart:
if (millis() > end) {
return -1;
}
/* try to receive from serial */
while (f->blen != f->nelem) {
len = f->bend - f->pnew;
@ -228,6 +235,8 @@ restart:
if (f->nelem < (len + 4)) {
goto restart;
}
return 0;
}
static int get_packet(a3k_t a3k, char *packet)
@ -235,7 +244,9 @@ static int get_packet(a3k_t a3k, char *packet)
#if 0
return __getpacket(a3k, packet);
#else
__fifo_waitpacket(a3k);
if (__fifo_waitpacket(a3k)) {
return 0;
}
return __getpacket(a3k, packet);
#endif
}
@ -243,10 +254,9 @@ static int get_packet(a3k_t a3k, char *packet)
static int wait_a3k_ready(a3k_t tag)
{
char packet[30];
short i;
for (i = 0;i < 30; i++)
packet[i] = 0xFF;
memset(packet, 0, sizeof packet);
get_packet(tag, packet);
if (packet[0] != 0x61)
@ -303,13 +313,12 @@ int get_cfg(a3k_t a3k, short * cfg0, short * cfg1, short * cfg2)
static int packet_reset_a3k(a3k_t a3k)
{
int i;
uint64_t end = millis() + 5;
gpio_clear(a3k->rst);
for (i = 0; i < 1024; ++i) {
__asm__ volatile ("nop");
}
while (millis() < end)
;
serial_rx_buffer_clear(a3k->uart);
serial_tx_buffer_clear(a3k->uart);
@ -839,7 +848,10 @@ start:
int a3k_setup(a3k_t tag, int baudrate)
{
int i;
int err = 0;
#ifdef STM32F429_439xx
int i;
#endif
__fifo_init(&tag->rx, FORMAT3KBLEN, (void *)tag->_buf);
@ -853,6 +865,7 @@ int a3k_setup(a3k_t tag, int baudrate)
return 0;
}
#ifdef STM32F429_439xx
gpio_init(tag->rst, GPIO_OUTPUT | GPIO_FLAG_PP | GPIO_FLAG_PU);
gpio_init(tag->rts, GPIO_INPUT | GPIO_FLAG_PP | GPIO_FLAG_PU | GPIO_SPEED_FAST);
@ -865,10 +878,14 @@ int a3k_setup(a3k_t tag, int baudrate)
}
pins_set(tag, 0x2c, 0, 1, 0); //ec, ns, es
#endif
ticks_init(1);
if (packet_reset_a3k(tag)) {
printf("reset a3k failed.\r\n");
return -1;
err = -1;
goto tail;
}
/*
if (stop_a3k_codec(tag)) {
@ -877,22 +894,27 @@ int a3k_setup(a3k_t tag, int baudrate)
*/
if (config_a3k(tag, -1, 0, 0)) { /* ratet, input_gain, output_gain */
printf("config a3k failed.\r\n");
return -2;
err = -2;
goto tail;
}
if (config_a3k_codec(tag)) {
printf("config a3k codec failed.\r\n");
return -3;
err = -3;
goto tail;
}
read_cfg(tag);
// read_cfg(tag);
if (start_a3k_codec(tag, 0, 0, 0)) {
printf("start a3k codec mode failed.\r\n");
return -4;
err = -4;
goto tail;
}
return 0;
tail:
ticks_close();
return err;
}
void a3k_close(a3k_t tag)

4
lib/utils.c

@ -58,7 +58,9 @@ int go(unsigned long vect)
register unsigned int stack = ptr[0];
register unsigned int addr = ptr[1];
if (((ptr[0] & 0x2FFE0000 ) == 0x20000000) /* SRAM */ || ((ptr[0] & 0x1FFE0000) == 0x10000000) /* CCMRAM */) {
// printf("stack: %x, entry: %x, [%x, %x]\r\n", stack, addr, (stack & 0x2ffC0000), (stack & 0x1ffe0000));
// printf("off: %x\n", (vect - NVIC_VectTab_FLASH));
if (((stack & 0x2ffc0000) == 0x20000000) /* SRAM */ || ((stack & 0x1ffe0000) == 0x10000000) /* CCMRAM */) {
__disable_irq();
NVIC_SetVectorTable(NVIC_VectTab_FLASH, (vect - NVIC_VectTab_FLASH));
__set_MSP(stack);

2
src/flash.ld

@ -14,7 +14,7 @@ SECTIONS {
. = ALIGN(4);
KEEP(*(.isr_vector))
. = ALIGN(4);
} >flash
} > flash
.text : {
. = ALIGN(4);

19
src/iap.c

@ -43,7 +43,8 @@ static int do_upgrade()
int dev, n;
struct serial *rx;
printf("upgrade image ...\r\n");
printf("\r\nupgrade image\r\n");
memset(&fi, 0, sizeof fi);
dev = bkp_sram_read(MAGIC_DEV);
@ -64,8 +65,10 @@ static int do_upgrade()
ticks_init(2);
flash_if_init();
#ifdef STM32F429_439xx
gpio_init(LED_D4 | LED_D5, GPIO_OUTPUT);
gpio_write(LED_D4 | LED_D5, 0);
#endif
if (flash_if_get_write_protection_status(APP_ADDRESS)) {
flash_if_disable_write_protection(APP_ADDRESS);
@ -75,7 +78,9 @@ static int do_upgrade()
ticks_close();
#ifdef STM32F429_439xx
gpio_write(LED_D4 | LED_D5, 1);
#endif
printf("\r\nupgrade image %s.\r\n", n <= 0 ? "failed" : "success");
printf("%s size = %d, total: %d, received: %d\r\n", fi.name, n, fi.total, fi.received);
@ -89,7 +94,10 @@ static int do_upgrade()
bkp_sram_write(MAGIC_POS, 0);
NVIC_SystemReset();
return 0;
for (;;)
;
return -1;
}
int console_read(void *ptr, int len)
@ -110,20 +118,23 @@ int main()
bkp_sram_init();
serial_setup(UART, 115200, 8, 1);
printf("\r\n................");
magic = bkp_sram_read(MAGIC_POS);
if (magic == MAGIC_BOOT) {
return do_upgrade();
}
printf("\r\n................\r\n");
printf("................\r\n");
serial_close(UART);
// serial_close(UART);
bkp_sram_write(MAGIC_DEV, 0);
bkp_sram_write(MAGIC_POS, MAGIC_BOOT);
go(APP_ADDRESS);
serial_setup(UART, 115200, 8, 1);
do_upgrade();
return 0;

26
src/iap.ld

@ -2,8 +2,8 @@ ENTRY(Reset_Handler)
_MIN_HEAP_SIZE = 0x200;
_MIN_STACK_SIZE = 0x400;
MEMORY {
flash (rx) : org = 0x08000000, len = 16K
ram (xrw) : org = 0x20000000, len = 192K
flash (rx) : org = 0x08000000, len = 16K
ram (xrw): org = 0x20000000, len = 112K
ccmram (rw): org = 0x10000000, len = 64K
sdram (rw): org = 0xc0000000, len = 32M
}
@ -26,12 +26,14 @@ SECTIONS {
. = ALIGN(4);
_etext = .;
} > flash
.rodata : {
. = ALIGN(4);
*(.rodata)
*(.rodata*)
. = ALIGN(4);
} > flash
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >flash
.ARM : {
__exidx_start = .;
@ -59,6 +61,16 @@ SECTIONS {
PROVIDE_HIDDEN (__fini_array_end = .);
} >flash
_sidata = LOADADDR(.data);
.data : {
. = ALIGN(4);
_sdata = .;
*(.data)
*(.data*)
. = ALIGN(4);
_edata = .;
} >ram AT> flash
.cmdline_cmd : {
. = ALIGN(0x4);
__cmdline_cmd_start = .;
@ -100,16 +112,6 @@ SECTIONS {
*(.rxdma.*)
} > ram
_sidata = LOADADDR(.data);
.data : {
. = ALIGN(4);
_sdata = .;
*(.data)
*(.data*)
. = ALIGN(4);
_edata = .;
} >ram AT> flash
._user_heap_stack : {
. = ALIGN(4);
PROVIDE ( end = . );

5
src/main.c

@ -410,7 +410,9 @@ static int __on_40ms(struct timer *tm, void *user)
int main()
{
NVIC_SetVectorTable(NVIC_VectTab_FLASH, (APP_ADDRESS - NVIC_VectTab_FLASH));
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
__enable_irq();
/*
* recovery from bad image.
@ -434,6 +436,7 @@ int main()
/* eeprom */
eeprom_init();
#ifdef STM32F429_439xx
gpio_init(Y1_OUT, GPIO_OUTPUT);
gpio_init(Y1_IN, GPIO_INPUT);
gpio_init(Y2_OUT, GPIO_OUTPUT);
@ -443,6 +446,7 @@ int main()
gpio_write(LED_D4 | LED_D5 | LED_D6, 1);
gpio_init(LED_D3, GPIO_OUTPUT);
gpio_write(LED_D3, 1);
#endif
init_frames(&rx[0], __rxbuf[0], PKT_LEN);
init_frames(&rx[1], __rxbuf[1], PKT_LEN);
@ -450,6 +454,7 @@ int main()
init_frames(&tx[1], NULL, 0);
printf("setup vocode 0\r\n");
iwdg_reset();
a3k_setup(&a3k0, -1);
iwdg_reset();
printf("setup vocode 1\r\n");

1
targets.mk

@ -1,5 +1,6 @@
ifeq ($(TARGET),f407)
cmsis_startup += $(cmsis_dir)/src/startup_stm32f40xx.S
ROMBASE := 0x08004000
ROMSZ := 256k
RAMSZ := 128k
TARGET_CFLAGS += -DSTM32F40_41xxx -DHSE_VALUE=8000000

Loading…
Cancel
Save