From 4afdc1cd1fe09ddcf7fc1bd2b52ad2a92658991e Mon Sep 17 00:00:00 2001 From: Daniel Lublin Date: Wed, 1 Mar 2023 11:50:24 +0100 Subject: [PATCH] fw: Steady white led while waiting cmd; led off while loading app Signed-off-by: Daniel Lublin --- doc/quickstart.md | 21 +++++++++++---------- doc/toolchain_setup.md | 2 +- hw/application_fpga/fw/tk1/led.c | 2 +- hw/application_fpga/fw/tk1/led.h | 7 ++++--- hw/application_fpga/fw/tk1/main.c | 8 ++------ hw/application_fpga/fw/tk1/proto.c | 15 --------------- hw/application_fpga/fw/tk1/proto.h | 1 - 7 files changed, 19 insertions(+), 37 deletions(-) diff --git a/doc/quickstart.md b/doc/quickstart.md index bdc9f5f..d1f246c 100644 --- a/doc/quickstart.md +++ b/doc/quickstart.md @@ -31,14 +31,15 @@ The USB stick can remain in the jig during repeated development, programming and testing cycles. The USB stick should then be connected to the computer using the provided USB-C cable (use the USB-C-to-A adapter if needed). The jig also has a cutout to allow touching where -the touch sensor is located (next to the LED). Note that connecting -the USB stick to the computer is not required for programming it. Note -also that with this setup, to reset the USB stick back to firmware -mode after loading an app, you need to unplug both the USB cable to -the stick and the one to the programmer. Alternatively, you can try -the script in `../hw/application_fpga/tools/reset-tk1` which pokes at -the TKey that's sitting in the jig, leaving it in firmware mode so -that a new app can be loaded. +the touch sensor is located (next to the LED on the outer edge). Note +that connecting the USB stick to the computer is not required for +programming it. Note also that with this setup, to reset the USB stick +back to firmware mode after loading an app, you need to unplug both +the USB cable to the stick and the one to the programmer. +Alternatively, you can try the script in +`../hw/application_fpga/tools/reset-tk1` which pokes at the TKey +that's sitting in the jig, leaving it in firmware mode so that a new +app can be loaded. On Linux, `lsusb` should list the connected programmer as `cafe:4004 Blinkinlabs ICE40 programmer`. If the USB stick is also connected it @@ -65,8 +66,8 @@ $ make prog_flash After programming, the TKey can be connected to your computer (use the USB-C-to-A adapter if needed) and will boot the firmware. When boot -has completed it will start flashing the LED white. This indicates -that it is ready to receive and measure an app. +has completed the LED will be steady white. This indicates that it is +ready to receive and measure an app. To try out an app, continue to the README.md the apps repo: https://github.com/tillitis/tillitis-key1-apps#readme diff --git a/doc/toolchain_setup.md b/doc/toolchain_setup.md index c35ac41..f52faaa 100644 --- a/doc/toolchain_setup.md +++ b/doc/toolchain_setup.md @@ -29,7 +29,7 @@ sudo apt install build-essential clang lld llvm bison flex libreadline-dev \ ## Gateware: Yosys/Icestorm toolchain -If the LED of your TKey is flashing white when you plug it, then the +If the LED of your TKey is steady white when you plug it, then the firmware is running and it's already usable! If you want to develop TKey apps, then only the above general development environment is needed. diff --git a/hw/application_fpga/fw/tk1/led.c b/hw/application_fpga/fw/tk1/led.c index d205700..41e5ec2 100644 --- a/hw/application_fpga/fw/tk1/led.c +++ b/hw/application_fpga/fw/tk1/led.c @@ -13,7 +13,7 @@ void forever_redflash() int led_on = 0; for (;;) { - *led = led_on ? LED_RED : 0; + *led = led_on ? LED_RED : LED_BLACK; for (volatile int i = 0; i < 800000; i++) { } led_on = !led_on; diff --git a/hw/application_fpga/fw/tk1/led.h b/hw/application_fpga/fw/tk1/led.h index 6d34818..eafb486 100644 --- a/hw/application_fpga/fw/tk1/led.h +++ b/hw/application_fpga/fw/tk1/led.h @@ -11,12 +11,13 @@ // clang-format off static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED; -// clang-format on -#define LED_RED (1 << TK1_MMIO_TK1_LED_R_BIT) +#define LED_BLACK 0 +#define LED_RED (1 << TK1_MMIO_TK1_LED_R_BIT) #define LED_GREEN (1 << TK1_MMIO_TK1_LED_G_BIT) -#define LED_BLUE (1 << TK1_MMIO_TK1_LED_B_BIT) +#define LED_BLUE (1 << TK1_MMIO_TK1_LED_B_BIT) #define LED_WHITE (LED_RED | LED_GREEN | LED_BLUE) +// clang-format on void forever_redflash(); #endif diff --git a/hw/application_fpga/fw/tk1/main.c b/hw/application_fpga/fw/tk1/main.c index f5cdf76..0671ae9 100644 --- a/hw/application_fpga/fw/tk1/main.c +++ b/hw/application_fpga/fw/tk1/main.c @@ -234,12 +234,8 @@ int main() } uint8_t in; - if (state == FW_STATE_LOADING) { - *led = LED_WHITE; - in = readbyte(); - } else { - in = readbyte_ledflash(LED_WHITE, 800000); - } + *led = (state == FW_STATE_LOADING) ? LED_BLACK : LED_WHITE; + in = readbyte(); if (parseframe(in, &hdr) == -1) { htif_puts("Couldn't parse header\n"); diff --git a/hw/application_fpga/fw/tk1/proto.c b/hw/application_fpga/fw/tk1/proto.c index 6c9e18a..8f2c823 100644 --- a/hw/application_fpga/fw/tk1/proto.c +++ b/hw/application_fpga/fw/tk1/proto.c @@ -13,7 +13,6 @@ static volatile uint32_t *can_rx = (volatile uint32_t *)TK1_MMIO_UART_RX_STATUS; static volatile uint32_t *rx = (volatile uint32_t *)TK1_MMIO_UART_RX_DATA; static volatile uint32_t *can_tx = (volatile uint32_t *)TK1_MMIO_UART_TX_STATUS; static volatile uint32_t *tx = (volatile uint32_t *)TK1_MMIO_UART_TX_DATA; -static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED; // clang-format on uint8_t genhdr(uint8_t id, uint8_t endpoint, uint8_t status, enum cmdlen len) @@ -134,20 +133,6 @@ uint8_t readbyte() } } -uint8_t readbyte_ledflash(int ledvalue, int loopcount) -{ - int led_on = 0; - for (;;) { - *led = led_on ? ledvalue : 0; - for (int i = 0; i < loopcount; i++) { - if (*can_rx) { - return *rx; - } - } - led_on = !led_on; - } -} - int read(uint8_t *buf, size_t bufsize, size_t nbytes) { if (nbytes > bufsize) { diff --git a/hw/application_fpga/fw/tk1/proto.h b/hw/application_fpga/fw/tk1/proto.h index 039048e..db26d0a 100644 --- a/hw/application_fpga/fw/tk1/proto.h +++ b/hw/application_fpga/fw/tk1/proto.h @@ -56,7 +56,6 @@ void fwreply(struct frame_header hdr, enum fwcmd rspcode, uint8_t *buf); void writebyte(uint8_t b); void write(uint8_t *buf, size_t nbytes); uint8_t readbyte(); -uint8_t readbyte_ledflash(int ledvalue, int loopcount); int read(uint8_t *buf, size_t bufsize, size_t nbytes); #endif