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.
Diff: eeprom_flash.cpp
- Revision:
- 2:68c9ff91504c
- Parent:
- 0:ea2bec485611
- Child:
- 3:46c0511e25af
--- a/eeprom_flash.cpp Mon Aug 29 21:29:20 2016 +0000
+++ b/eeprom_flash.cpp Mon Feb 04 15:06:07 2019 +0000
@@ -1,29 +1,14 @@
#include "mbed.h"
#include "eeprom_flash.h"
-
-/*
- * Debug option
- */
-#if 0
-//Enable debug
-#include <cstdio>
-#define DBG(x, ...) std::printf("[eeprom: DBG]"x"\r\n", ##__VA_ARGS__);
-#define WARN(x, ...) std::printf("[eeprom: WARN]"x"\r\n", ##__VA_ARGS__);
-#define ERR(x, ...) std::printf("[eeprom: ERR]"x"\r\n", ##__VA_ARGS__);
-#else
-//Disable debug
-#define DBG(x, ...)
-#define WARN(x, ...)
-#define ERR(x, ...)
-#endif
-
+Serial pc(USBTX, USBRX); //Initalise PC serial comms
+DigitalOut myled(LED1);
/*
* Must call this first to enable writing
*/
void enableEEPROMWriting() {
HAL_StatusTypeDef status = HAL_FLASH_Unlock();
FLASH_PageErase(EEPROM_START_ADDRESS); // required to re-write
- CLEAR_BIT(FLASH->CR, FLASH_CR_PER); // Bug fix: bit PER has been set in Flash_PageErase(), must clear it here
+ CLEAR_BIT(FLASH->CR, FLASH_CR_PER); // Bug fix: bit PER has been set in Flash_PageErase(), must clear it here
}
void disableEEPROMWriting() {
@@ -37,18 +22,7 @@
HAL_StatusTypeDef writeEEPROMHalfWord(uint32_t address, uint16_t data) {
HAL_StatusTypeDef status;
address = address + EEPROM_START_ADDRESS;
-
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, address, data);
-
- return status;
-}
-
-HAL_StatusTypeDef writeEEPROMWord(uint32_t address, uint32_t data) {
- HAL_StatusTypeDef status;
- address = address + EEPROM_START_ADDRESS;
-
- status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data);
-
return status;
}
@@ -59,14 +33,47 @@
uint16_t val = 0;
address = address + EEPROM_START_ADDRESS;
val = *(__IO uint16_t*)address;
-
- return val;
+ return val;
}
-uint32_t readEEPROMWord(uint32_t address) {
- uint32_t val = 0;
- address = address + EEPROM_START_ADDRESS;
- val = *(__IO uint32_t*)address;
-
- return val;
-}
+//Programme de test
+
+int main() {
+int adresse = 0x00;
+char donnee1 = 11;
+char donnee2 = 22;
+char donnee3 = 33;
+int lecture;
+pc.baud(9600);
+
+/* Ecriture*/
+enableEEPROMWriting(); //autorisation d'ecriture dans l'eeprom
+writeEEPROMHalfWord(adresse, donnee1);
+writeEEPROMHalfWord(adresse+2, donnee2);
+writeEEPROMHalfWord(adresse+4, donnee3);
+disableEEPROMWriting(); //Interdiction d'ecriture
+
+ myled=!myled;
+ wait(0.5);
+ myled=!myled;
+ wait(0.5);
+
+/*lecture et affichage*/
+lecture=readEEPROMHalfWord(adresse);
+if (lecture==11)
+ {
+ myled=!myled;
+ wait(0.5);
+ myled=!myled;
+ wait(0.5);
+ myled=!myled;
+ wait(0.5);
+ }
+pc.printf ("valeur lue: %d\n\r",lecture);
+
+lecture=readEEPROMHalfWord(adresse+2);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+4);
+pc.printf ("valeur lue: %d\n\r",lecture);
+ while(1);
+}
\ No newline at end of file