diff options
author | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-04-29 18:02:57 +0200 |
---|---|---|
committer | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-04-29 18:02:57 +0200 |
commit | 76c12726e85d0bb25d7f015ee6e515ad7084d36d (patch) | |
tree | 5c7afedd107d7ad1751b325df59faa61feaf7281 /controller | |
parent | 3dd578980020ebf01cf97b0b34ddb8bf61126666 (diff) | |
download | master-thesis-76c12726e85d0bb25d7f015ee6e515ad7084d36d.tar.gz master-thesis-76c12726e85d0bb25d7f015ee6e515ad7084d36d.tar.bz2 master-thesis-76c12726e85d0bb25d7f015ee6e515ad7084d36d.zip |
MSP430 reflash working
Diffstat (limited to 'controller')
-rw-r--r-- | controller/fw/src/main.c | 28 | ||||
-rw-r--r-- | controller/fw/src/mspdebug_wrapper.c | 39 |
2 files changed, 41 insertions, 26 deletions
diff --git a/controller/fw/src/main.c b/controller/fw/src/main.c index aec1fdc..6e117f6 100644 --- a/controller/fw/src/main.c +++ b/controller/fw/src/main.c @@ -187,12 +187,23 @@ static struct jtag_img_descriptor { } jtag_img = { .devmem_img_start = 0x00c000, .spiflash_img_start = 0x000000, - .img_len = 0x060000, + .img_len = 0x004000, +}; + +const char fw_dump[0x4000] = { +#include "EasyMeter_Q3DA1002_V3.03_fw_dump_0xc000.h" }; ssize_t jt_spi_flash_read_block(void *usr, int addr, size_t len, uint8_t *out) { + /* struct jtag_img_descriptor *desc = (struct jtag_img_descriptor *)usr; return spif_read(&spif, desc->spiflash_img_start + addr, len, (char *)out); + */ + + for (size_t i=0; i<len; i++) + out[i] = fw_dump[addr - 0xc000 + i]; + + return len; } static unsigned int measurement_errors = 0; @@ -240,15 +251,16 @@ int main(void) int i=0; while (23) { mspd_jtag_init(); - con_printf("%d flash result: %d\r\n", i, - mspd_jtag_flash_and_reset(jtag_img.devmem_img_start, jtag_img.img_len, jt_spi_flash_read_block, &jtag_img)); - for (int i=0; i<168*1000*5; i++) + int rv = mspd_jtag_flash_and_reset(jtag_img.devmem_img_start, jtag_img.img_len, jt_spi_flash_read_block, &jtag_img); + con_printf("%d flash result: %d\r\n", i, rv); + while (!rv) {} + for (int j=0; j<168*1000*5; j++) asm volatile ("nop"); i++; } while (23) { if (adc_fft_buf_ready_idx != -1) { - for (int i=0; i<168*1000*2; i++) + for (int j=0; j<168*1000*2; j++) asm volatile ("nop"); GPIOA->BSRR = 1<<11; memcpy(adc_fft_buf[!adc_fft_buf_ready_idx], adc_fft_buf[adc_fft_buf_ready_idx] + FMEAS_FFT_LEN/2, sizeof(adc_fft_buf[0][0]) * FMEAS_FFT_LEN/2); @@ -257,8 +269,8 @@ int main(void) bool clip_low=false, clip_high=false; const int clip_thresh = 100; - for (size_t i=FMEAS_FFT_LEN/2; i<FMEAS_FFT_LEN; i++) { - int val = adc_fft_buf[adc_fft_buf_ready_idx][i]; + for (size_t j=FMEAS_FFT_LEN/2; j<FMEAS_FFT_LEN; j++) { + int val = adc_fft_buf[adc_fft_buf_ready_idx][j]; if (val < clip_thresh) clip_low = true; if (val > FMEAS_ADC_MAX-clip_thresh) @@ -266,7 +278,7 @@ int main(void) } GPIOB->ODR = (GPIOB->ODR & ~(3<<11)) | (!clip_low<<11) | (!clip_high<<12); - for (int i=0; i<168*1000*2; i++) + for (int j=0; j<168*1000*2; j++) asm volatile ("nop"); GPIOA->BSRR = 1<<11; diff --git a/controller/fw/src/mspdebug_wrapper.c b/controller/fw/src/mspdebug_wrapper.c index aada33a..aaf75ab 100644 --- a/controller/fw/src/mspdebug_wrapper.c +++ b/controller/fw/src/mspdebug_wrapper.c @@ -1,6 +1,7 @@ #include <unistd.h> #include <errno.h> +#include <string.h> #include "output.h" #include "jtaglib.h" @@ -53,6 +54,18 @@ void mspd_jtag_init() { gpio_pin_setup(gpios[i].gpio, gpios[i].pin, gpios[i].mode, 3, 0, 0); } +static void sr_gpio_write(int num, int out) { + if (out) + gpios[num].gpio->BSRR = 1<<gpios[num].pin; + else + gpios[num].gpio->BSRR = 1<<gpios[num].pin<<16; +} + +static void sr_jtdev_rst(struct jtdev *p, int out) { + UNUSED(p); + sr_gpio_write(SR_GPIO_RST, out); +} + int mspd_jtag_flash_and_reset(size_t img_start, size_t img_len, ssize_t (*read_block)(void *usr, int addr, size_t len, uint8_t *out), void *usr) { union { @@ -73,18 +86,17 @@ int mspd_jtag_flash_and_reset(size_t img_start, size_t img_len, ssize_t (*read_b if (jtag_id != 0x89 && jtag_id != 0x91) return -EINVAL; - /* FIXME DEBUG */ - +#if 0 con_printf("Memory dump:\r\n"); - for (size_t i=0; i<256;) { + for (size_t i=0x1000; i<=0x10ff;) { con_printf("%04x: ", i); - for (size_t j=0; j<16; i+=2, j+=2) { - con_printf("%04x ", jtag_read_mem(&sr_jtdev, 16, 0xc000 + i)); + for (size_t j=0; j<16; i+=1, j+=1) { + con_printf("%02x ", jtag_read_mem(&sr_jtdev, 8, i)); } con_printf("\r\n"); } return 0; - /* END DEBUG */ +#endif /* Clear flash */ jtag_erase_flash(&sr_jtdev, JTAG_ERASE_MAIN, 0); @@ -93,6 +105,7 @@ int mspd_jtag_flash_and_reset(size_t img_start, size_t img_len, ssize_t (*read_b /* Write flash */ for (size_t p = img_start; p < img_start + img_len; p += BLOCK_SIZE) { + con_printf("Writing block %04zx\r\n", p); ssize_t nin = read_block(usr, p, BLOCK_SIZE, block.bytes); if (nin < 0) @@ -122,6 +135,8 @@ int mspd_jtag_flash_and_reset(size_t img_start, size_t img_len, ssize_t (*read_b if (sr_jtdev.failed) return -EPIPE; + jtag_release_device(&sr_jtdev, 0xfffe); + return 0; } @@ -153,13 +168,6 @@ static void sr_jtdev_connect(struct jtdev *p) { /* ignore */ } -static void sr_gpio_write(int num, int out) { - if (out) - gpios[num].gpio->BSRR = 1<<gpios[num].pin; - else - gpios[num].gpio->BSRR = 1<<gpios[num].pin<<16; -} - static void sr_jtdev_tck(struct jtdev *p, int out) { UNUSED(p); sr_gpio_write(SR_GPIO_TCK, out); @@ -175,11 +183,6 @@ static void sr_jtdev_tdi(struct jtdev *p, int out) { sr_gpio_write(SR_GPIO_TDI, out); } -static void sr_jtdev_rst(struct jtdev *p, int out) { - UNUSED(p); - sr_gpio_write(SR_GPIO_RST, out); -} - static void sr_jtdev_tst(struct jtdev *p, int out) { UNUSED(p); sr_gpio_write(SR_GPIO_TST, out); |