/**************************************************************************//** * @brief GPIO Interrupt handler (PB11) * Saves the number to the userpage *****************************************************************************/ void GPIO_ODD_IRQHandler(void) { msc_Return_TypeDef ret; /* Acknowledge interrupt */ GPIO_IntClear(1 << 11); /* Initialize the MSC for writing */ MSC_Init(); /* Erase the page */ //ret = MSC_ErasePage((uint32_t *) (USERPAGE + userData.numWrites * 256 ) ); /* Check for errors. If there are errors, set the global error variable and * deinitialize the MSC */ /*if (ret != mscReturnOk) { currentError = ret; MSC_Deinit(); return; }*/ /* Write data to the userpage */ memset(userData.payload, userData.numWrites, 256); ret = MSC_WriteWord((uint32_t *) (USERPAGE + userData.numWrites * 256 ), (void *) &userData.payload, sizeof(UserData_TypeDef)); /* Increase the number of saves */ userData.numWrites++; /* Check for errors. If there are errors, set the global error variable and * deinitialize the MSC */ if (ret != mscReturnOk) { currentError = ret; MSC_Deinit(); return; } /* Deinitialize the MSC. This disables writing and locks the MSC */ MSC_Deinit(); /* Signal completion of save. The number of saves will be displayed */ recentlySaved = true; }
msc_Return_TypeDef Serialnum_write (uint32_t number) { msc_Return_TypeDef ret; uint32_t *addr = (uint32_t *)USER_PAGE_ADDR; MSC_Init(); ret = MSC_WriteWord(addr, &number, sizeof(number)); MSC_Deinit(); return ret; }
void ANIM_prerenderFrames(void) { uint32_t i; uint32_t magicWord = 0xef32; /* Get the starting address of the prerendered frames */ uint32_t *addr = (uint32_t *)FRAMES_START; /* Get the end of the prerendered frames */ uint32_t *lastAddr = addr + FRAME_BUFFER_SIZE_WORDS * NUM_FRAMES; /* Get the address of the current frame buffer */ uint16_t *frameBuffer = FB_getActiveBuffer(); /* Check the last address for the magic word. * If this has been written the frames are already in flash * and we can skip the entire prerendering step */ if ( *lastAddr == magicWord ) { return; } MSC_Init(); /* Make emWin draw to the frame buffer */ FB_activateFrameBuffer(); /* Add meta data to frame buffer */ FB_writeControlSignals((uint8_t*)frameBuffer); /* Erase all the pages we are going to write to */ while ( addr < lastAddr ) { MSC_ErasePage(addr); addr += FRAME_BUFFER_SIZE_WORDS; } addr = (uint32_t *)FRAMES_START; for ( i=0; i<NUM_FRAMES; i++ ) { /* Render a frame */ GUI_DrawBitmap(frames[i], 0, 0); /* Copy entire frame buffer to flash */ MSC_WriteWord(addr, frameBuffer, FRAME_BUFFER_SIZE_BYTES); addr += FRAME_BUFFER_SIZE_WORDS; } /* Write magic word to indicate that the frames are ready in Flash */ MSC_WriteWord(lastAddr, &magicWord, 4); MSC_Deinit(); }
/**************************************************************************//** * @brief * Initialize the storage media interface. *****************************************************************************/ bool MSDDMEDIA_Init( void ) { #if ( MSD_MEDIA != MSD_SDCARD_MEDIA ) && ( MSD_MEDIA != MSD_NORFLASH_MEDIA ) numSectors = MEDIA_SIZE / 512; #endif #if ( MSD_MEDIA == MSD_PSRAM_MEDIA ) storage = (uint8_t*)EBI_BankAddress( EBI_BANK2 ); storage[0] = 0; /* To force new "format disk" when host detects disk. */ #endif #if ( MSD_MEDIA == MSD_SDCARD_MEDIA ) /* Enable SPI access to MicroSD card */ BSP_PeripheralAccess( BSP_MICROSD, true ); MICROSD_Init(); if ( disk_initialize( 0 ) != 0 ) return false; /* Get numSectors from media. */ if ( disk_ioctl( 0, GET_SECTOR_COUNT, &numSectors ) != RES_OK ) return false; #endif #if ( MSD_MEDIA == MSD_FLASH_MEDIA ) flashStatus.pendingWrite = false; MSC_Init(); /* Unlock and calibrate flash timing */ MSC_Deinit(); /* Lock flash */ #endif #if ( MSD_MEDIA == MSD_NORFLASH_MEDIA ) flashStatus.pendingWrite = false; NORFLASH_Init(); /* Initialize NORFLASH interface */ storage = (uint8_t*)NORFLASH_DeviceInfo()->baseAddress; flashPageSize = NORFLASH_DeviceInfo()->sectorSize; /* Use external PSRAM as page (flash sector) buffer */ flashPageBuf = (uint8_t*)EBI_BankAddress( EBI_BANK2 ); numSectors = NORFLASH_DeviceInfo()->deviceSize / 512; #endif return true; }
/***************************************************************************//** * @brief * De-initialize NVM . * * @details * This function is run when the API deinit function is run. This should be * done before any graceful halts. ******************************************************************************/ void NVMHAL_DeInit(void) { MSC_Deinit(); }
rt_err_t fvs_end_write(void *addr) { MSC_Deinit(); return RT_EOK; }