0

I am also working on the bootloader.

I had the problem in the following:

Once the cmd 'B' is received, later, 'F' is received, then I would start to call block load.

static void start_block_flash_load(uint16_t size, uint32_t *addr) {
  uint16_t data_word;
  uint8_t sreg = SREG;
  uint16_t temp;
  int i;
  uint8_t my_size;

  fprintf(lcdout, "B");
  cli();
// Disable interrupts

  (*addr) <<= 1;

  if (size <= SPM_PAGESIZE) {
      boot_page_erase(*addr);
      boot_spm_busy_wait();
      fprintf(lcdout, "%"PRIu16, size);
      uint16_t i;
//store all values.  PROBLEM here!!!
      my_size = 208;
      uint8_t buf[SPM_PAGESIZE] = { 0 };
      for (i = 0; i < my_size; i++) {
      //for (i=0; i<size; i++){
          buf[i] = uart_getc();
//        lcd_clear();
//        lcd_setCursor(0, 2);
//        fprintf(lcdout, "%3d", i);
//        _delay_ms(500);
      }

      for (i = 0; i < my_size; i += 2) { //if size is odd, then use do-while

        uint16_t w = buf[i];
        w += buf[i + 1] << 8;  //first one is low byte, second is high???
        boot_page_fill((*addr)+i, w);

      }

      boot_page_write(*addr);
      boot_spm_busy_wait();

      (*addr) >>= 1;

      uart_putc('\r');
  } else
      uart_putc('?');

  boot_rww_enable ();
  SREG = sreg;
}

I can see on the lcd that the size of the block is 256. However, when entering the loop to collect data, it will get stuck. I tested with my_size and I found that only if my_size=208 the program will run further. The strange thing is that if I put some statements inside the loop, e.g.

lcd_clear();
lcd_setCursor(0, 2);

then 'i' which I printed out on lcd will not go up to 140 something. I put different statements, the 'i' will give different value. That is very strange, since the uart_getc() will not lose data. What I expect is that the loop will go up to 256. I cannot figure out what happened there.

Please help if you have any idea. Thanks

jiadong
  • 135
  • 7
  • The program is probably hanging in uart_getc(). Did you send enough data? – David Grayson Jul 06 '16 at 19:35
  • I think I send enough data. I looked into the hex file of the project, which is a simple alarm clock. There, I have more than 800 lines, each has 21 bytes. – jiadong Jul 06 '16 at 19:44
  • @DavidGrayson But I cannot decide how much data should be sent. avrDude has already sent the information to bootloader that the size of the block is 256 bytes. But it seems avrDude did not really send 256 Bytes. I don't know why. – jiadong Jul 06 '16 at 19:48

0 Answers0