From 69ed847740e3efb5c5ff6319629c93d236150959 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Fri, 23 Sep 2022 20:08:02 +0200 Subject: i2s driver fixed; added uart programming; --- fw/fe310/phone/Makefile | 6 +- fw/fe310/phone/flash.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++ fw/fe310/phone/flash.h | 3 + fw/fe310/phone/main.c | 18 +++++- fw/fe310/phone/phone.c | 2 - fw/fe310/phone/test.c | 23 ++++--- fw/fe310/phone/test.h | 1 + 7 files changed, 196 insertions(+), 17 deletions(-) create mode 100644 fw/fe310/phone/flash.c create mode 100644 fw/fe310/phone/flash.h (limited to 'fw/fe310/phone') diff --git a/fw/fe310/phone/Makefile b/fw/fe310/phone/Makefile index 8624962..65de081 100644 --- a/fw/fe310/phone/Makefile +++ b/fw/fe310/phone/Makefile @@ -1,5 +1,5 @@ include ../common.mk -DEPS = main.o mem.o wifi.o cell.o phone.o modem.o timer.o test.o +DEPS = main.o mem.o wifi.o cell.o phone.o modem.o timer.o test.o flash.o lib_eos = eve eos eos-soc eos-dev eos-net eos-ext eos-bsp lib_ecp = @@ -30,3 +30,7 @@ upload: $(TARGET) upload_jlink: $(TARGET) $(OBJCOPY) $(TARGET) -O binary $(TARGET).bin ../bsp/upload --bin ./$(TARGET).bin --addr 0x20000000 --jlink JLinkExe + +upload_my: $(TARGET) + $(OBJCOPY) $(TARGET) -O binary $(TARGET).bin + ../../../util/upload /dev/cu.usbserial-14140 $(TARGET).bin diff --git a/fw/fe310/phone/flash.c b/fw/fe310/phone/flash.c new file mode 100644 index 0000000..e78576a --- /dev/null +++ b/fw/fe310/phone/flash.c @@ -0,0 +1,160 @@ +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "app/app.h" +#include "app/status.h" + +#include "flash.h" + +static const uint8_t magic[] = + {0x2D, 0xC0, 0x3B, 0x5F, 0xEA, 0xE3, 0x1A, 0x3A, 0x83, 0x11, 0x6A, 0x33, 0x98, 0x46, 0x1C, 0x47}; + +#define ACK 0x05 +#define NACK 0x0A +#define BLK_SIZE 256 + +__attribute__ ((section (".itim"))) +static uint32_t crc32x(unsigned char *buf, size_t len, uint32_t crc) { + int i; + + crc = ~crc; + while (len--) { + crc ^= *buf++; + for (i=0; i<8; i++) { + uint32_t t = ~((crc & 1) - 1); + crc = (crc >> 1) ^ (0xEDB88320 & t); + } + } + + return ~crc; +} + +__attribute__ ((section (".itim"))) +void flash_write(void) { + volatile uint32_t r; + uint32_t crc32, crc32_b; + uint32_t addr; + uint8_t buf[BLK_SIZE + 2 * sizeof(uint32_t)]; + int i; + + clear_csr(mstatus, MSTATUS_MIE); + SPI0_REG(SPI_REG_FCTRL) = 0; + SPI0_REG(SPI_REG_FMT) &= ~SPI_FMT_DIR(SPI_DIR_TX); + + do { + for (i=0; i #include +#include +#include #include #include +#include +#include +#include #include #include @@ -23,6 +28,7 @@ #include "phone.h" #include "modem.h" #include "timer.h" +#include "flash.h" #include "test.h" static const uint32_t touch_matrix[6] = {0xf7ac,0x440,0x3e704,0xfffff718,0x108a3,0xfff76d42}; @@ -53,6 +59,12 @@ static int home_page(EVEWindow *window, EVEViewStack *stack) { .widget.tspec.page.title = "Timer", .widget.tspec.page.constructor = timer_app, }, + { + .widget.type = EVE_WIDGET_TYPE_PAGE, + .widget.g.w = APP_SCREEN_W, + .widget.tspec.page.title = "Flash", + .widget.tspec.page.constructor = flash_app, + }, { .widget.type = EVE_WIDGET_TYPE_PAGE, .widget.g.w = APP_SCREEN_W, @@ -69,9 +81,8 @@ static int home_page(EVEWindow *window, EVEViewStack *stack) { void mem_print(void); -#include - int main() { + int i; uint8_t wakeup_cause; wakeup_cause = eos_init(); @@ -80,9 +91,12 @@ int main() { printf("FREQ:%lu\n", PRCI_get_cpu_freq()); printf("\nREADY.\n"); + mem_print(); eos_gt911_cfg_print(); + // eos_flash_fast(); + wifi_init(); cell_init(); phone_init(); diff --git a/fw/fe310/phone/phone.c b/fw/fe310/phone/phone.c index 53d36ae..a8d5a86 100644 --- a/fw/fe310/phone/phone.c +++ b/fw/fe310/phone/phone.c @@ -29,7 +29,6 @@ static uint8_t spk_arr[ABUF_SIZE]; static unsigned char phone_state = 0; -__attribute__ ((section (".itim"))) static void handle_mic(unsigned char type) { uint16_t offset, size; unsigned char *buf; @@ -39,7 +38,6 @@ static void handle_mic(unsigned char type) { eos_cell_send_buffer(buf, size, offset, 0); } -__attribute__ ((section (".itim"))) static void handle_cell_voice(unsigned char type, unsigned char *buffer, uint16_t len) { switch (type) { case EOS_CELL_MTYPE_VOICE_RING: { diff --git a/fw/fe310/phone/test.c b/fw/fe310/phone/test.c index df3871e..72f575f 100644 --- a/fw/fe310/phone/test.c +++ b/fw/fe310/phone/test.c @@ -28,6 +28,17 @@ static int reg_write(uint8_t reg, uint8_t data) { return eos_i2c_write8(BQ25895_ADDR, reg, &data, 1); } +int test_app(EVEWindow *window, EVEViewStack *stack) { + EVEFormSpec spec[] = { + APP_SPACERW(1,1), + }; + EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), test_uievt, test_close); + if (page == NULL) return EVE_ERR_NOMEM; + app_status_set_msg("TEST!"); + + return EVE_OK; +} + int test_uievt(EVEPage *page, uint16_t evt, void *param) { int ret = 0; @@ -36,7 +47,6 @@ int test_uievt(EVEPage *page, uint16_t evt, void *param) { uint8_t data = 0; int rv, i; - printf("PAGE TOUCH\n"); printf("BQ25895:\n"); for (i=0; i<0x15; i++) { rv = reg_read(i, &data); @@ -54,17 +64,6 @@ int test_uievt(EVEPage *page, uint16_t evt, void *param) { return ret; } -int test_app(EVEWindow *window, EVEViewStack *stack) { - EVEFormSpec spec[] = { - APP_SPACERW(1,1), - }; - EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), test_uievt, test_close); - if (page == NULL) return EVE_ERR_NOMEM; - app_status_set_msg("TEST!"); - - return EVE_OK; -} - void test_close(EVEPage *page) { eve_form_destroy(page); } diff --git a/fw/fe310/phone/test.h b/fw/fe310/phone/test.h index 66b380d..61bc5e2 100644 --- a/fw/fe310/phone/test.h +++ b/fw/fe310/phone/test.h @@ -1,2 +1,3 @@ int test_app(EVEWindow *window, EVEViewStack *stack); +int test_uievt(EVEPage *page, uint16_t evt, void *param); void test_close(EVEPage *page); \ No newline at end of file -- cgit v1.2.3