|
|
@ -1,5 +1,11 @@ |
|
|
|
#include <stdlib.h> |
|
|
|
#include "eeprom.h" |
|
|
|
#include "stm32f4xx.h" |
|
|
|
#include "serial.h" |
|
|
|
#include "cmd.h" |
|
|
|
#include "gpio.h" |
|
|
|
#include "dwt.h" |
|
|
|
#include "tick.h" |
|
|
|
|
|
|
|
int console_read(void *ptr, int len) |
|
|
|
{ |
|
|
@ -9,17 +15,36 @@ int console_read(void *ptr, int len) |
|
|
|
int console_write(const void *_ptr, int len) |
|
|
|
{ |
|
|
|
const uint8_t *ptr = _ptr; |
|
|
|
#if 0 |
|
|
|
int n = len, x = len; |
|
|
|
while (len > 0) { |
|
|
|
n = serial_send_buffered(&serial0, ptr, len); |
|
|
|
len -= n; |
|
|
|
ptr += n; |
|
|
|
} |
|
|
|
return (x); |
|
|
|
#else |
|
|
|
return serial_send_blocking(&serial0, ptr, len); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
static void init_board(void) |
|
|
|
{ |
|
|
|
bkp_sram_init(); |
|
|
|
|
|
|
|
eeprom_init_with_io(PB8, PB9, 0x50, 0); |
|
|
|
cmd_init(); |
|
|
|
/* debug console */ |
|
|
|
serial_setup(&serial0, CONSOLE_BAUDRATE, 8, SERIAL_STOPBITS_1); |
|
|
|
|
|
|
|
gpio_init(WDI, GPIO_OUTPUT); |
|
|
|
gpio_init(JPB1_VCC18_EN, GPIO_OUTPUT); |
|
|
|
|
|
|
|
gpio_init(JPB1_VCC13_PG, GPIO_INPUT | GPIO_FLAG_PP | GPIO_FLAG_PU); |
|
|
|
|
|
|
|
gpio_init(NAND_WP, GPIO_OUTPUT); |
|
|
|
/* disable nand write protected */ |
|
|
|
gpio_set(NAND_WP); |
|
|
|
|
|
|
|
gpio_init(CLK_MUX_OE, GPIO_OUTPUT); |
|
|
|
gpio_set(CLK_MUX_OE); |
|
|
|
|
|
|
|
gpio_init(CLK_MUX_PD, GPIO_OUTPUT); |
|
|
|
gpio_set(CLK_MUX_PD); |
|
|
|
|
|
|
|
gpio_init(SC18IS602_RST, GPIO_OUTPUT); |
|
|
|
|
|
|
|
ticks_init(TICKS_PERIOD); |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef BOOT_FROM_APP |
|
|
@ -28,6 +53,82 @@ void lowlevel_init(void) |
|
|
|
NVIC_SetVectorTable(NVIC_VectTab_FLASH, (APP_ADDRESS - NVIC_VectTab_FLASH)); |
|
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); |
|
|
|
__enable_irq(); |
|
|
|
init_board(); |
|
|
|
} |
|
|
|
#else |
|
|
|
void lowlevel_init(void) |
|
|
|
{ |
|
|
|
init_board(); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
void target_uart4_setup() |
|
|
|
{ |
|
|
|
GPIO_InitTypeDef gpio_conf; |
|
|
|
|
|
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); |
|
|
|
|
|
|
|
GPIO_StructInit(&gpio_conf); |
|
|
|
|
|
|
|
gpio_conf.GPIO_Pin = GPIO_Pin_10; |
|
|
|
gpio_conf.GPIO_OType = GPIO_OType_PP; |
|
|
|
gpio_conf.GPIO_Mode = GPIO_Mode_AF; |
|
|
|
gpio_conf.GPIO_Speed = GPIO_Speed_50MHz; |
|
|
|
gpio_conf.GPIO_PuPd = GPIO_PuPd_UP; |
|
|
|
GPIO_Init(GPIOC, &gpio_conf); |
|
|
|
|
|
|
|
gpio_conf.GPIO_Pin = GPIO_Pin_11; |
|
|
|
gpio_conf.GPIO_OType = GPIO_OType_OD; |
|
|
|
gpio_conf.GPIO_PuPd = GPIO_PuPd_NOPULL; |
|
|
|
GPIO_Init(GPIOC, &gpio_conf); |
|
|
|
|
|
|
|
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4); |
|
|
|
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4); |
|
|
|
} |
|
|
|
|
|
|
|
static int do_eer(cmd_tbl_t s, int argc, char *argv[]) |
|
|
|
{ |
|
|
|
uint16_t addr; |
|
|
|
uint8_t val; |
|
|
|
if (argc >= 2) { |
|
|
|
addr = strtoul(argv[1], NULL, 0); |
|
|
|
val = eeprom_read(addr); |
|
|
|
printf("%04x: %02x\r\n", addr, val); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
CON_CMD(eer, 2, "read from eeprom", do_eer); |
|
|
|
|
|
|
|
|
|
|
|
static int do_eew(cmd_tbl_t s, int argc, char *argv[]) |
|
|
|
{ |
|
|
|
uint16_t addr; |
|
|
|
uint8_t val; |
|
|
|
if (argc >= 3) { |
|
|
|
addr = strtoul(argv[1], NULL, 0); |
|
|
|
val = strtoul(argv[2], NULL, 0); |
|
|
|
eeprom_write(addr, val); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
CON_CMD(eew, 3, "write to eeprom", do_eew); |
|
|
|
|
|
|
|
static int do_vcc13(cmd_tbl_t s, int argc, char *argv[]) |
|
|
|
{ |
|
|
|
int r = gpio_read(JPB1_VCC13_PG); |
|
|
|
printf("vcc1.3_pwr_good: %d %s\n", r, r ? "fault" : "good"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
CON_CMD(vcc13, 1, "vcc 1.3v power good", do_vcc13); |
|
|
|
|
|
|
|
static int do_sc18is_rst(cmd_tbl_t s, int argc, char *argv[]) |
|
|
|
{ |
|
|
|
gpio_clear(SC18IS602_RST); |
|
|
|
delay(20); |
|
|
|
gpio_set(SC18IS602_RST); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
CON_CMD(sc18is_rst, 1, "reset sc18is602", do_sc18is_rst); |
|
|
|
|
|
|
|