Exemplo n.º 1
0
void main()
{
  // set as output
  mmio32(GPIO_FSEL_ADDR + GPFSEL1_OFFS) |= (1<<LED_BIT_SET);

  mailbox[0] = 1024;
  mailbox[1] = 768;
  mailbox[2] = 1024;
  mailbox[3] = 768;
  mailbox[4] = 0;
  mailbox[5] = 16;
  mailbox[6] = 0;
  mailbox[7] = 0;
  mailbox[8] = 0;
  mailbox[9] = 0;

  mbox_write((uint32_t)mailbox);
  if(mbox_read()==0)
  {
    uint16_t* start = (uint16_t*)(mailbox[8]);
    if(start == 0)
      mmio32(GPIO_FSEL_ADDR + GPCLR0_OFFS) |= (1<<GPIO_PIN_OFFS);  // switch on led
    uint16_t color = 0;
    uint32_t x = 0;
    uint32_t y = 0;
    while(1){
      for(y=0; y < 768; ++y)
      {
        for(x=0; x < 1024; ++x)
        {
          start[y*1024+x] = color;
        }
        ++color;
        if(color > 65000) color = 0;
      }

      // switch on led
      mmio32(GPIO_FSEL_ADDR + GPCLR0_OFFS) |= (1<<GPIO_PIN_OFFS);

      // wait 1
      delay_with_loop(WAIT_DELAY);

      // switch off led
      mmio32(GPIO_FSEL_ADDR + GPSET0_OFFS) |= (1<<GPIO_PIN_OFFS);

      // wait 2
      delay_with_loop(WAIT_DELAY);
    }
  }
}
Exemplo n.º 2
0
int loader(void) {

    uint32_t i, from, to;
    uint32_t erased_sectors = 0;
    for (i=0; i < PARAMS_LEN ; i+=4) { // Clear parameters
        mmio32(PARAMS_ADDR+i) = 0;
    }

    FLASH_SetLatency(FLASH_Latency_0);

    while (1) {

        asm volatile ("bkpt"); // Halt core after init and before writing to flash.
        asm volatile ("nop");

        PARAMS->STATUS &= ~MASK_STRT; // Clear start bit
        PARAMS->STATUS  &= ~MASK_ERR; // Clear error bit
        PARAMS->STATUS  &= ~MASK_SUCCESS; // Clear success bit
        PARAMS->STATUS &= ~MASK_DEL; // Clear delete success bit
        PARAMS->POS = PARAMS->DEST;

        FLASH_Unlock();

        from = PARAMS->DEST;
        to = from + PARAMS->LEN;
        uint32_t a;

        // Erase flash where needed
#if defined(STM32F2) || defined(STM32F4)
        FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
        // Get the number of the start and end sectors
        const uint32_t StartSector = GetSector(from);
        const uint32_t EndSector = GetSector(to-1);
        for (a = StartSector ; a <= EndSector ; a+=8) {
            if (erased_sectors & (1 << a/8)) continue; // Skip sectors already erased
            if (FLASH_EraseSector(a, VoltageRange_3) != FLASH_COMPLETE) {
                PARAMS->STATUS |= MASK_ERR;
                break;
            }
            erased_sectors |= 1 << a/8;
            PARAMS->STATUS |= MASK_DEL; // Set delete success bit
        }
#else
        FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPERR);
        uint32_t NbrOfPage = (to - from - 1) / FLASH_PAGE_SIZE;
        for (a = 0 ; a <= NbrOfPage ; a++) {
            if (erased_sectors >= from + (FLASH_PAGE_SIZE * a)) continue; // Skip sectors already erased
            if (FLASH_ErasePage(from + (FLASH_PAGE_SIZE * a))!= FLASH_COMPLETE) {
                PARAMS->STATUS |= MASK_ERR;
                break;
            }
            erased_sectors = from + (FLASH_PAGE_SIZE * a);
            PARAMS->STATUS |= MASK_DEL; // Set delete success bit
        }
#endif

        if (PARAMS->STATUS & MASK_ERR) { // If error during page delete, go back to breakpoint
            FLASH_Lock();
            continue;
        }

        // Flash programming
        uint32_t i=0;
        while (i < PARAMS->LEN) {

            if (FLASH_PGM(PARAMS->DEST+i,  mmio32(BUFFER_ADDR+i)) == FLASH_COMPLETE)
            {
                i+=FLASH_STEP;
                PARAMS->STATUS |= MASK_SUCCESS; // Set success bit
                PARAMS->POS = PARAMS->DEST+i;
            }
            else {
                /* Error occurred while writing data in Flash memory.
                User can add here some code to deal with this error */
                PARAMS->STATUS |= MASK_ERR; // Set error bit
                break;
            }
        }
        PARAMS->TEST =  PARAMS->DEST+i;

        FLASH_Lock(); // Lock flash after operations are done.
    }
    return 0;
}