eeprom not yet working correctly
This commit is contained in:
		| @@ -223,7 +223,10 @@ static void MX_GPIO_Init(void) | |||||||
|   HAL_GPIO_WritePin(GPIOC, LED_Pin|ERROR_Pin, GPIO_PIN_RESET); |   HAL_GPIO_WritePin(GPIOC, LED_Pin|ERROR_Pin, GPIO_PIN_RESET); | ||||||
|  |  | ||||||
|   /*Configure GPIO pin Output Level */ |   /*Configure GPIO pin Output Level */ | ||||||
|   HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin|OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET); |   HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin, GPIO_PIN_SET); | ||||||
|  |  | ||||||
|  |   /*Configure GPIO pin Output Level */ | ||||||
|  |   HAL_GPIO_WritePin(GPIOB, OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET); | ||||||
|  |  | ||||||
|   /*Configure GPIO pins : LED_Pin ERROR_Pin */ |   /*Configure GPIO pins : LED_Pin ERROR_Pin */ | ||||||
|   GPIO_InitStruct.Pin = LED_Pin|ERROR_Pin; |   GPIO_InitStruct.Pin = LED_Pin|ERROR_Pin; | ||||||
|   | |||||||
| @@ -90,13 +90,15 @@ PB5.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING | |||||||
| PB5.GPIO_PuPd=GPIO_PULLUP | PB5.GPIO_PuPd=GPIO_PULLUP | ||||||
| PB5.Locked=true | PB5.Locked=true | ||||||
| PB5.Signal=GPXTI5 | PB5.Signal=GPXTI5 | ||||||
| PB6.GPIOParameters=GPIO_Label | PB6.GPIOParameters=PinState,GPIO_Label | ||||||
| PB6.GPIO_Label=EEPROM_CS | PB6.GPIO_Label=EEPROM_CS | ||||||
| PB6.Locked=true | PB6.Locked=true | ||||||
|  | PB6.PinState=GPIO_PIN_SET | ||||||
| PB6.Signal=GPIO_Output | PB6.Signal=GPIO_Output | ||||||
| PB7.GPIOParameters=GPIO_Label | PB7.GPIOParameters=PinState,GPIO_Label | ||||||
| PB7.GPIO_Label=OLED_CS | PB7.GPIO_Label=OLED_CS | ||||||
| PB7.Locked=true | PB7.Locked=true | ||||||
|  | PB7.PinState=GPIO_PIN_SET | ||||||
| PB7.Signal=GPIO_Output | PB7.Signal=GPIO_Output | ||||||
| PB8.GPIOParameters=GPIO_Label | PB8.GPIOParameters=GPIO_Label | ||||||
| PB8.GPIO_Label=OLED_DC | PB8.GPIO_Label=OLED_DC | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ | |||||||
|  |  | ||||||
| #include "eeprom.h" | #include "eeprom.h" | ||||||
| #include "stm32f1xx_hal.h" | #include "stm32f1xx_hal.h" | ||||||
|  | #include <string.h> | ||||||
|  |  | ||||||
|  |  | ||||||
| #define HIGH GPIO_PIN_SET | #define HIGH GPIO_PIN_SET | ||||||
| @@ -28,28 +29,46 @@ static void __EEPROM_CS(GPIO_PinState v) { | |||||||
| } | } | ||||||
|  |  | ||||||
| static void __HAL_SPI_Transmit_One_ByValue(SPI_HandleTypeDef *hspi, uint8_t c) { | static void __HAL_SPI_Transmit_One_ByValue(SPI_HandleTypeDef *hspi, uint8_t c) { | ||||||
|   HAL_SPI_Transmit(hspi, &c, 1, 0); |   HAL_SPI_Transmit(hspi, &c, 1, HAL_MAX_DELAY); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len) { | void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len) { | ||||||
|  |   struct { | ||||||
|  |     uint8_t wren; | ||||||
|  |     uint8_t write; | ||||||
|  |     uint16_t addr; | ||||||
|  |     uint8_t data[32]; | ||||||
|  |   } msg = { | ||||||
|  |       .wren = EEPROM_WREN, | ||||||
|  |       .write = EEPROM_WRITE, | ||||||
|  |       .addr = addr | ||||||
|  |   }; | ||||||
|  |   memcpy(msg.data, buf, len); | ||||||
|  |  | ||||||
|   __EEPROM_CS(LOW); |   __EEPROM_CS(LOW); | ||||||
|  |   HAL_SPI_Transmit(&hspi1, &msg, ((uint16_t)(len+4)), HAL_MAX_DELAY); | ||||||
|   __HAL_SPI_Transmit_One_ByValue(&hspi1, EEPROM_WREN); |  | ||||||
|   __HAL_SPI_Transmit_One_ByValue(&hspi1, EEPROM_WRITE); |  | ||||||
|   HAL_SPI_Transmit(&hspi1, (uint8_t*)&addr, 2, 0); |  | ||||||
|   HAL_SPI_Transmit(&hspi1, buf, len, 0); |  | ||||||
|  |  | ||||||
|   __EEPROM_CS(HIGH); |   __EEPROM_CS(HIGH); | ||||||
| } | } | ||||||
|  |  | ||||||
| void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len) { | void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len) { | ||||||
|  |   struct { | ||||||
|  |     uint8_t read; | ||||||
|  |     uint16_t addr; | ||||||
|  |     uint8_t data[32]; | ||||||
|  |   } txMsg = { | ||||||
|  |       .read = EEPROM_READ, | ||||||
|  |       .addr = addr | ||||||
|  |   }, | ||||||
|  |     rxMsg; | ||||||
|  |  | ||||||
|   __EEPROM_CS(LOW); |   __EEPROM_CS(LOW); | ||||||
|  |   HAL_SPI_TransmitReceive(&hspi1, &txMsg, &rxMsg, ((uint16_t)(len+3)), HAL_MAX_DELAY); | ||||||
|   __HAL_SPI_Transmit_One_ByValue(&hspi1, EEPROM_READ); |  | ||||||
|   HAL_SPI_Transmit(&hspi1, (uint8_t*)&addr, 2, 0); |  | ||||||
|   HAL_SPI_Receive(&hspi1, buf, len, 0); |  | ||||||
|  |  | ||||||
|   __EEPROM_CS(HIGH); |   __EEPROM_CS(HIGH); | ||||||
|  |  | ||||||
|  | //  __EEPROM_CS(LOW); | ||||||
|  | //  __HAL_SPI_Transmit_One_ByValue(&hspi1, EEPROM_READ); | ||||||
|  | //  HAL_SPI_Transmit(&hspi1, &addr, 2, HAL_MAX_DELAY); | ||||||
|  | //  HAL_SPI_Receive(&hspi1, buf, ((uint16_t)len), HAL_MAX_DELAY); | ||||||
|  | //  __EEPROM_CS(HIGH); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -11,6 +11,8 @@ | |||||||
| #include "stm32f1xx_hal.h" | #include "stm32f1xx_hal.h" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #define STORAGE_ADDRESS 0x10 | ||||||
|  |  | ||||||
| void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len); | void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len); | ||||||
| void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len); | void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len); | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										55
									
								
								my_src/hmi.c
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								my_src/hmi.c
									
									
									
									
									
								
							| @@ -11,6 +11,11 @@ | |||||||
| #include "alarm.h" | #include "alarm.h" | ||||||
| #include <PontCoopScheduler.h> | #include <PontCoopScheduler.h> | ||||||
| #include "oled.h" | #include "oled.h" | ||||||
|  | #include "eeprom.h" | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | const uint32_t STORAGE_MAGIC = 0xaffe0001; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -23,8 +28,30 @@ volatile tDisplay display = { | |||||||
|     .overrunTime = 0 |     .overrunTime = 0 | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | typedef struct { | ||||||
|  |   uint32_t magic; | ||||||
|  |   uint32_t savedTemperature; | ||||||
|  |   uint32_t savedTime; | ||||||
|  | } tStorage; | ||||||
|  |  | ||||||
|  | tStorage storage; | ||||||
|  |  | ||||||
| void updateDisplay(void *handle) { | void updateDisplay(void *handle) { | ||||||
|  |   static uint8_t eetoggle = 0; | ||||||
|  |  | ||||||
|  |   if (eetoggle == 0) { | ||||||
|  |     eetoggle = 1; | ||||||
|  |     eepromRead(STORAGE_ADDRESS, &storage, sizeof(storage)); | ||||||
|  |   } else { | ||||||
|  |     eetoggle = 0; | ||||||
|  |     storage.magic = STORAGE_MAGIC; | ||||||
|  |     storage.savedTemperature = 1; | ||||||
|  |     storage.savedTime = 2; | ||||||
|  |     eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage)); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   tDisplay *lDisplay = (tDisplay*) handle; |   tDisplay *lDisplay = (tDisplay*) handle; | ||||||
|   lDisplay->toggle ^= 0x01; |   lDisplay->toggle ^= 0x01; | ||||||
|   char buf[32]; |   char buf[32]; | ||||||
| @@ -46,13 +73,31 @@ void updateDisplay(void *handle) { | |||||||
|   } |   } | ||||||
|   LED_P8x16Str(0, 4, buf); |   LED_P8x16Str(0, 4, buf); | ||||||
|  |  | ||||||
|   sprintf(buf, "      %5ds", lDisplay->overrunTime); | //  sprintf(buf, "      %5ds", lDisplay->overrunTime); | ||||||
|  |   static uint32_t h = 0; | ||||||
|  |   static uint32_t c = 0; | ||||||
|  |   uint32_t i = HAL_GetTick(); | ||||||
|  |   sprintf(buf, "%d %d %d", c, i, i-h); | ||||||
|  |   h = i; | ||||||
|  |   c++; | ||||||
|   LED_P8x16Str(0, 6, buf); |   LED_P8x16Str(0, 6, buf); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void hmiInit() { | void hmiInit() { | ||||||
|  |   eepromRead(STORAGE_ADDRESS, &storage, sizeof(storage)); | ||||||
|  |   if (storage.magic == STORAGE_MAGIC) { | ||||||
|  |     display.targetTemperature = storage.savedTemperature; | ||||||
|  |     display.targetTime = storage.savedTime; | ||||||
|  |   } else { | ||||||
|  |     storage.magic = STORAGE_MAGIC; | ||||||
|  |     storage.savedTemperature = 0; | ||||||
|  |     storage.savedTime = 0; | ||||||
|  |     eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage)); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   schAdd(updateDisplay, &display, 0, 250); |   schAdd(updateDisplay, &display, 0, 250); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void clearSetMode(void *handle) { | void clearSetMode(void *handle) { | ||||||
| @@ -100,12 +145,16 @@ void displayIncValue() { | |||||||
|     reEnableSetModeTimer(); |     reEnableSetModeTimer(); | ||||||
|     if (display.targetTemperature < 100) { |     if (display.targetTemperature < 100) { | ||||||
|       display.targetTemperature++; |       display.targetTemperature++; | ||||||
|  | //      storage.savedTemperature = display.targetTemperature; | ||||||
|  | //      eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage)); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   if (display.setModeTime == 1) { |   if (display.setModeTime == 1) { | ||||||
|     reEnableSetModeTimer(); |     reEnableSetModeTimer(); | ||||||
|     if (display.targetTime < 999) { |     if (display.targetTime < 999) { | ||||||
|       display.targetTime += 10; |       display.targetTime += 10; | ||||||
|  | //      storage.savedTime = display.targetTime; | ||||||
|  | //      eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage)); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @@ -115,12 +164,16 @@ void displayDecValue() { | |||||||
|     reEnableSetModeTimer(); |     reEnableSetModeTimer(); | ||||||
|     if (display.targetTemperature > 0) { |     if (display.targetTemperature > 0) { | ||||||
|       display.targetTemperature--; |       display.targetTemperature--; | ||||||
|  | //      storage.savedTemperature = display.targetTemperature; | ||||||
|  | //      eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage)); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   if (display.setModeTime == 1) { |   if (display.setModeTime == 1) { | ||||||
|     reEnableSetModeTimer(); |     reEnableSetModeTimer(); | ||||||
|     if (display.targetTime >= 10) { |     if (display.targetTime >= 10) { | ||||||
|       display.targetTime -= 10; |       display.targetTime -= 10; | ||||||
|  | //      storage.savedTime = display.targetTime; | ||||||
|  | //      eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage)); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -14,11 +14,11 @@ | |||||||
|  |  | ||||||
|  |  | ||||||
| typedef struct { | typedef struct { | ||||||
|   uint8_t toggle; |   uint32_t toggle; | ||||||
|   uint8_t setModeTemperature; |   uint32_t setModeTemperature; | ||||||
|   uint8_t setModeTime; |   uint32_t setModeTime; | ||||||
|   tTimerState timerState; |   tTimerState timerState; | ||||||
|   uint8_t toggleModeState; |   uint32_t toggleModeState; | ||||||
|   uint32_t targetTemperature; |   uint32_t targetTemperature; | ||||||
|   uint32_t currentTemperature; |   uint32_t currentTemperature; | ||||||
|   uint32_t targetTime; |   uint32_t targetTime; | ||||||
|   | |||||||
| @@ -12,7 +12,8 @@ typedef enum { | |||||||
|   IDLE = 0, |   IDLE = 0, | ||||||
|   STARTED = 1, |   STARTED = 1, | ||||||
|   RUNNING = 2, |   RUNNING = 2, | ||||||
|   OVERRUN = 3 |   OVERRUN = 3, | ||||||
|  |   MAX = 0xffffffff | ||||||
| } tTimerState; | } tTimerState; | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -227,7 +227,10 @@ static void MX_GPIO_Init(void) | |||||||
|   HAL_GPIO_WritePin(GPIOC, LED_Pin|ERROR_Pin, GPIO_PIN_RESET); |   HAL_GPIO_WritePin(GPIOC, LED_Pin|ERROR_Pin, GPIO_PIN_RESET); | ||||||
|  |  | ||||||
|   /*Configure GPIO pin Output Level */ |   /*Configure GPIO pin Output Level */ | ||||||
|   HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin|OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET); |   HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin, GPIO_PIN_SET); | ||||||
|  |  | ||||||
|  |   /*Configure GPIO pin Output Level */ | ||||||
|  |   HAL_GPIO_WritePin(GPIOB, OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET); | ||||||
|  |  | ||||||
|   /*Configure GPIO pins : LED_Pin ERROR_Pin */ |   /*Configure GPIO pins : LED_Pin ERROR_Pin */ | ||||||
|   GPIO_InitStruct.Pin = LED_Pin|ERROR_Pin; |   GPIO_InitStruct.Pin = LED_Pin|ERROR_Pin; | ||||||
|   | |||||||
| @@ -223,7 +223,10 @@ static void MX_GPIO_Init(void) | |||||||
|   HAL_GPIO_WritePin(GPIOC, LED_Pin|ERROR_Pin, GPIO_PIN_RESET); |   HAL_GPIO_WritePin(GPIOC, LED_Pin|ERROR_Pin, GPIO_PIN_RESET); | ||||||
|  |  | ||||||
|   /*Configure GPIO pin Output Level */ |   /*Configure GPIO pin Output Level */ | ||||||
|   HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin|OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET); |   HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin, GPIO_PIN_SET); | ||||||
|  |  | ||||||
|  |   /*Configure GPIO pin Output Level */ | ||||||
|  |   HAL_GPIO_WritePin(GPIOB, OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET); | ||||||
|  |  | ||||||
|   /*Configure GPIO pins : LED_Pin ERROR_Pin */ |   /*Configure GPIO pins : LED_Pin ERROR_Pin */ | ||||||
|   GPIO_InitStruct.Pin = LED_Pin|ERROR_Pin; |   GPIO_InitStruct.Pin = LED_Pin|ERROR_Pin; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Wolfgang Hottgenroth
					Wolfgang Hottgenroth