From 8f5aaad3d6e3f2429442417fa2b479c5b635bf99 Mon Sep 17 00:00:00 2001 From: bsongis Date: Sun, 6 Jan 2013 12:49:46 +0000 Subject: [PATCH] [X9D] EEPROM bug fixes --- src/eeprom_avr.cpp | 8 ++- src/open9x.cpp | 6 +- src/sky9x/board_sky9x.cpp | 18 ++++-- .../Source/Templates/system_stm32f2xx.c | 12 +++- src/x9d/board_x9d.cpp | 58 +++++++++++++++++++ src/x9d/hal.h | 2 +- src/x9d/i2c_ee.c | 12 ++++ 7 files changed, 103 insertions(+), 13 deletions(-) diff --git a/src/eeprom_avr.cpp b/src/eeprom_avr.cpp index b69b6a90f..3a220257d 100644 --- a/src/eeprom_avr.cpp +++ b/src/eeprom_avr.cpp @@ -244,7 +244,9 @@ void EeFsFormat() eeFs.mySize = sizeof(eeFs); eeFs.freeList = 0; eeFs.bs = BS; - for (blkid_t i=FIRSTBLK; iTC_CHANNEL[2].TC_SR; - (void) dummy ; // Discard value - prevents compiler warning - HAPTIC_HEARTBEAT(); AUDIO_HEARTBEAT(); @@ -395,6 +390,17 @@ extern "C" void TC2_IRQHandler() } } +extern "C" void TC2_IRQHandler() +{ + register uint32_t dummy; + + /* Clear status bit to acknowledge interrupt */ + dummy = TC0->TC_CHANNEL[2].TC_SR; + (void) dummy ; // Discard value - prevents compiler warning + + interrupt5ms(); +} + // Settings for mode register ADC_MR // USEQ off - silicon problem, doesn't work // TRANSFER = 1 diff --git a/src/x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c b/src/x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c index cdc57fbd6..d67799794 100644 --- a/src/x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c +++ b/src/x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c @@ -148,8 +148,9 @@ /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */ -#define PLL_M 25 -#define PLL_N 240 +// Gives 60MHz +#define PLL_M 12 +#define PLL_N 120 /* SYSCLK = PLL_VCO / PLL_P */ #define PLL_P 2 @@ -185,6 +186,10 @@ * @{ */ +extern uint32_t Master_frequency ; +uint32_t Peri1_frequency ; +uint32_t Peri2_frequency ; + static void SetSysClock(void); #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); @@ -400,6 +405,9 @@ static void SetSysClock(void) configuration. User can add here some code to deal with this error */ } + Master_frequency = 60000000 ; + Peri1_frequency = 30000000 ; + Peri2_frequency = 15000000 ; } /** diff --git a/src/x9d/board_x9d.cpp b/src/x9d/board_x9d.cpp index 6eadcf52d..9bfa3d591 100644 --- a/src/x9d/board_x9d.cpp +++ b/src/x9d/board_x9d.cpp @@ -38,8 +38,14 @@ uint8_t temperature = 0; // Raw temp reading uint8_t maxTemperature = 0 ; // Raw temp reading volatile uint32_t Tenms ; // TODO to remove everywhere / use a #define +// TODO why not here the Peri1_frequency ... (to avoid modifications in system_stm32f2xx.c) +uint32_t Master_frequency ; +extern uint32_t Peri1_frequency ; +extern uint32_t Peri2_frequency ; + void keysInit(); void pwrInit(); +void eepromInit(); // TODO check it's not in another include uint8_t getTemperature() { @@ -63,11 +69,63 @@ void usbMassStorage() { } +// Starts TIMER at 200Hz, 5mS period +void init5msTimer() +{ + // Timer14 + RCC->APB1ENR |= RCC_APB1ENR_TIM14EN ; // Enable clock + TIM14->ARR = 4999 ; // 5mS + TIM14->PSC = Peri1_frequency / 1000000 ; // 1uS from 30MHz + TIM14->CCER = 0 ; + TIM14->CCMR1 = 0 ; + TIM14->EGR = 0 ; + TIM14->CR1 = 5 ; + TIM14->DIER |= 1 ; + NVIC_EnableIRQ(TIM8_TRG_COM_TIM14_IRQn) ; +} + +void stop5msTimer( void ) +{ + TIM14->CR1 = 0 ; // stop timer + NVIC_DisableIRQ(TIM8_TRG_COM_TIM14_IRQn) ; + RCC->APB1ENR &= ~RCC_APB1ENR_TIM14EN ; // Disable clock +} + +// TODO use the same than board_sky9x.cpp +void interrupt5ms() +{ + static uint32_t pre_scale ; // Used to get 10 Hz counter + + // HAPTIC_HEARTBEAT(); + // AUDIO_HEARTBEAT(); + + if ( ++pre_scale >= 2 ) { + Tenms |= 1 ; // 10 mS has passed + /* if ( Buzzer_count ) { + if ( --Buzzer_count == 0 ) + buzzer_off() ; + } */ + pre_scale = 0 ; + per10ms(); + } +} + +extern "C" void TIM8_TRG_COM_TIM14_IRQHandler() +{ + TIM14->SR &= ~TIM_SR_UIF ; + interrupt5ms() ; +} + #if !defined(SIMU) void boardInit() { pwrInit(); keysInit(); + init5msTimer(); + + __enable_irq() ; + + eepromInit(); } #endif diff --git a/src/x9d/hal.h b/src/x9d/hal.h index d60d45f8c..77508b909 100644 --- a/src/x9d/hal.h +++ b/src/x9d/hal.h @@ -169,7 +169,7 @@ // EEPROM and CAT5137 #define I2C_Speed 200000 #define I2C_FLASH_PAGESIZE 64 -#define I2C_EEPROM_ADDRESS 0xA0 +#define I2C_EEPROM_ADDRESS 0xA2 #define I2C_CAT5137_ADDRESS 0x5C //0101110 // SD card----SPI2 diff --git a/src/x9d/i2c_ee.c b/src/x9d/i2c_ee.c index 3775841ce..98309cc7f 100644 --- a/src/x9d/i2c_ee.c +++ b/src/x9d/i2c_ee.c @@ -252,7 +252,19 @@ void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteTo /* If NumByteToWrite < I2C_FLASH_PAGESIZE */ if (NumOfPage == 0) { I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle); + + lcd_clear(); + lcd_putsAtt(100, 10, "WaitStdby", GREY1); + lcd_putsAtt(100, 20, "WaitStdby", GREY2); + lcd_putsAtt(100, 30, "WaitStdby", 0); + lcdRefresh(); + I2C_EE_WaitEepromStandbyState(); + + lcd_clear(); + lcd_putsAtt(100, 10, "Fin WaitStdby", GREY2); + lcdRefresh(); + } /* If NumByteToWrite > I2C_FLASH_PAGESIZE */ else {