@@ -296,28 +296,48 @@ hal_status_t FRAM_Erase(uint8_t spiBank, uint32_t addr, uint32_t len)
296296
297297void RAMFUNCTION hal_flash_unlock (void )
298298{
299-
299+ /* Enable writes to code memory space */
300+ VOR_SYSCONFIG -> ROM_PROT |= SYSCONFIG_ROM_PROT_WREN_Msk ;
300301}
301302
302303void RAMFUNCTION hal_flash_lock (void )
303304{
304-
305+ /* Disable writes to code memory space */
306+ VOR_SYSCONFIG -> ROM_PROT &= ~SYSCONFIG_ROM_PROT_WREN_Msk ;
305307}
306308
307309int RAMFUNCTION hal_flash_write (uint32_t address , const uint8_t * data , int len )
308310{
309- /* no internal flash */
310- (void )address ;
311- (void )data ;
312- (void )len ;
313- return 0 ;
311+ hal_status_t status ;
312+ #ifdef DEBUG_EXT_FLASH
313+ wolfBoot_printf ("ext write: addr 0x%x, dst 0x%x, len %d\n" ,
314+ address , data , len );
315+ #endif
316+ status = FRAM_Write (ROM_SPI_BANK , address , (uint8_t * )data , len );
317+ if (status == hal_status_ok ) {
318+ /* update the shadow IRAM */
319+ memcpy ((void * )address , data , len );
320+ }
321+ else {
322+ return - (int )status ; /* convert to negative error code */
323+ }
324+ return len ;
314325}
315326
316327int RAMFUNCTION hal_flash_erase (uint32_t address , int len )
317328{
318- /* no internal flash */
319- (void )address ;
320- (void )len ;
329+ hal_status_t status ;
330+ #ifdef DEBUG_EXT_FLASH
331+ wolfBoot_printf ("ext erase: addr 0x%x, len %d\n" , address , len );
332+ #endif
333+ status = FRAM_Erase (ROM_SPI_BANK , address , len );
334+ if (status == hal_status_ok ) {
335+ /* update the shadow IRAM */
336+ memset ((void * )address , 0xFF , len );
337+ }
338+ else {
339+ return - (int )status ; /* convert to negative error code */
340+ }
321341 return 0 ;
322342}
323343
@@ -461,14 +481,14 @@ void hal_init(void)
461481 hal_status_t status ;
462482
463483#ifdef __WOLFBOOT /* build for wolfBoot only */
464- /* Configure PLL to set CPU clock to 100MHz */
484+ /* Configure PLL to set CPU clock to 100MHz - 40MHz crystal * 2.5 */
465485 status = HAL_Clkgen_PLL (CLK_CTRL0_XTAL_N_PLL2P5X );
466486 if (status != hal_status_ok ) {
467487 wolfBoot_printf ("HAL_Clkgen_PLL failed\n" );
468488 /* continue anyways */
469489 }
470490
471- /* Disable Watchdog */
491+ /* Disable Watchdog - should be already disabled out of reset */
472492 VOR_WATCH_DOG -> WDOGLOCK = 0x1ACCE551 ;
473493 VOR_WATCH_DOG -> WDOGCONTROL = 0x0 ;
474494 NVIC_ClearPendingIRQ (WATCHDOG_IRQn );
@@ -477,7 +497,7 @@ void hal_init(void)
477497 SCB -> CPACR |= ((0x3 << 20 )|(0x3 << 22 ));
478498
479499 /* Init EDAC */
480- ConfigEdac (1000 , 125 );
500+ ConfigEdac (WOLFBOOT_EDAC_RAM_SCRUB , WOLFBOOT_EDAC_ROM_SCRUB );
481501#else
482502 /* get clock settings and update SystemCoreClock */
483503 SystemCoreClockUpdate ();
@@ -518,6 +538,6 @@ void hal_init(void)
518538
519539void hal_prepare_boot (void )
520540{
521-
541+ /* Restore clock to hear-beat oscillator */
542+ (void )HAL_Clkgen_PLL (CLK_CFG_HBO );
522543}
523-
0 commit comments