Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: easy-connect-v16 Watchdog FP MQTTPacket RecordType-v-16 watersenor_and_temp_code
Diff: Flash/flash_programming.cpp
- Revision:
- 50:5a19fc4b41d9
- Parent:
- 43:dcde0e66874a
--- a/Flash/flash_programming.cpp Sun Mar 18 04:30:18 2018 +0000 +++ b/Flash/flash_programming.cpp Sun Mar 18 17:54:50 2018 +0000 @@ -271,4 +271,94 @@ } HAL_FLASH_Lock(); return PASSED; +} + +int FP_SetAlarmValues(uint32_t WriteTimeValue, uint8_t SetRelayState1, uint8_t SetRelayState2) { + uint8_t CurrentPage = FP_GetPage(ALRM_BASE_ADDRESS); + uint32_t CurrentAddress = ALARM_TIME_ADDRESS; + + EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; + EraseInitStruct.Banks = FLASH_BANK_1; + EraseInitStruct.Page = CurrentPage; + EraseInitStruct.NbPages = 1; + + if (FP_ClearFlags() != PASSED) { + return FAILED; + } + HAL_FLASH_Unlock(); + + if ((FP_ReadValue(ALARM_TIME_ADDRESS) == WriteTimeValue) && + (FP_ReadValue(SET_RELAY_1_ADDRESS) == SetRelayState1) && + (FP_ReadValue(SET_RELAY_2_ADDRESS) == SetRelayState2)) { + printf("Relay values don't change, no need to write\r\n"); + HAL_FLASH_Lock(); + return PASSED; + } + if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK) { + printf("Erase error, error num %d\r\n", HAL_FLASH_GetError()); + } + while (CurrentAddress < (SET_RELAY_2_ADDRESS + STEP_ADDRESS)) { + switch (CurrentAddress) { + case (ALARM_TIME_ADDRESS): if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, CurrentAddress, WriteTimeValue) == HAL_OK) { + printf("Write WriteTimeValue OK\r\n"); + } + else { + printf("Write WriteTimeValue failed, error num %d\r\n", HAL_FLASH_GetError()); + } + break; + case (SET_RELAY_1_ADDRESS): if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, CurrentAddress, SetRelayState1) == HAL_OK) { + printf("Write SetRelayState1 OK\r\n"); + } + else { + printf("Write SetRelayState1 failed, error num %d\r\n", HAL_FLASH_GetError()); + } + break; + case (SET_RELAY_2_ADDRESS): if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, CurrentAddress, SetRelayState2) == HAL_OK) { + printf("Write SetRelayState2 OK\r\n"); + } + else { + printf("Write SetRelayState2 failed, error num %d\r\n", HAL_FLASH_GetError()); + } + break; + default: break; + } + CurrentAddress = CurrentAddress + STEP_ADDRESS; + } + + CurrentAddress = ALARM_TIME_ADDRESS; + while (CurrentAddress < (SET_RELAY_2_ADDRESS + STEP_ADDRESS)) { + switch (CurrentAddress) { + case (ALARM_TIME_ADDRESS): if (FP_ReadValue(CurrentAddress) == WriteTimeValue) { + printf("Read back WriteTimeValue: %d\r\n", FP_ReadValue(CurrentAddress)); + } + else { + printf("Write WriteTimeValue failed, wrong read back value\r\n"); + HAL_FLASH_Lock(); + return FAILED; + } + break; + case (SET_RELAY_1_ADDRESS): if (FP_ReadValue(CurrentAddress) == SetRelayState1) { + printf("Read back SetRelayState1: %d\r\n", FP_ReadValue(CurrentAddress)); + } + else { + printf("Write SetRelayState1 failed, wrong read back value\r\n"); + HAL_FLASH_Lock(); + return FAILED; + } + break; + case (SET_RELAY_2_ADDRESS): if (FP_ReadValue(CurrentAddress) == SetRelayState2) { + printf("Read back SetRelayState2: %d\r\n", FP_ReadValue(CurrentAddress)); + } + else { + printf("Write SetRelayState2 failed, wrong read back value\r\n"); + HAL_FLASH_Lock(); + return FAILED; + } + break; + default: break; + } + CurrentAddress = CurrentAddress + STEP_ADDRESS; + } + HAL_FLASH_Lock(); + return PASSED; } \ No newline at end of file