EEPROM demo

Dependencies:   BSP_DISCO_F429ZI EEPROM_DISCO_F429ZI mbed

Committer:
jeromecoutant
Date:
Tue Jul 04 16:11:36 2017 +0000
Revision:
3:c4ccfae2ac0a
Parent:
0:b8722d2c0036
Update with MBED rev145

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:b8722d2c0036 1 #include "mbed.h"
bcostm 0:b8722d2c0036 2 #include "EEPROM_DISCO_F429ZI.h"
bcostm 0:b8722d2c0036 3
bcostm 0:b8722d2c0036 4 EEPROM_DISCO_F429ZI eep;
bcostm 0:b8722d2c0036 5
bcostm 0:b8722d2c0036 6 DigitalOut led_green(LED1);
bcostm 0:b8722d2c0036 7 DigitalOut led_red(LED2);
bcostm 0:b8722d2c0036 8
bcostm 0:b8722d2c0036 9 Serial pc(USBTX, USBRX);
bcostm 0:b8722d2c0036 10
bcostm 0:b8722d2c0036 11 #define BUFFER_SIZE ((uint32_t)32)
bcostm 0:b8722d2c0036 12 #define WRITE_READ_ADDR ((uint32_t)0x50)
bcostm 0:b8722d2c0036 13
bcostm 0:b8722d2c0036 14 int main()
bcostm 0:b8722d2c0036 15 {
bcostm 0:b8722d2c0036 16 // 12345678901234567890123456789012
bcostm 0:b8722d2c0036 17 uint8_t WriteBuffer[BUFFER_SIZE+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
bcostm 0:b8722d2c0036 18 uint8_t ReadBuffer[BUFFER_SIZE+1];
bcostm 0:b8722d2c0036 19 uint16_t bytes_rd;
bcostm 0:b8722d2c0036 20
bcostm 0:b8722d2c0036 21 pc.printf("\n\n*** EEPROM demo started ***\n");
bcostm 0:b8722d2c0036 22 led_red = 0;
bcostm 0:b8722d2c0036 23
bcostm 0:b8722d2c0036 24 // Check initialization
bcostm 0:b8722d2c0036 25 if (eep.Init() != EEPROM_OK) {
bcostm 0:b8722d2c0036 26 led_red = 1;
bcostm 0:b8722d2c0036 27 error("Initialization FAILED\n");
bcostm 0:b8722d2c0036 28 } else {
bcostm 0:b8722d2c0036 29 pc.printf("Initialization PASSED\n");
bcostm 0:b8722d2c0036 30 }
bcostm 0:b8722d2c0036 31
bcostm 0:b8722d2c0036 32 // Write buffer
bcostm 0:b8722d2c0036 33 if (eep.WriteBuffer(WriteBuffer, WRITE_READ_ADDR, BUFFER_SIZE) != EEPROM_OK) {
bcostm 0:b8722d2c0036 34 led_red = 1;
bcostm 0:b8722d2c0036 35 error("Write buffer FAILED\n");
bcostm 0:b8722d2c0036 36 } else {
bcostm 0:b8722d2c0036 37 pc.printf("Write buffer PASSED\n");
bcostm 0:b8722d2c0036 38 }
bcostm 0:b8722d2c0036 39
bcostm 0:b8722d2c0036 40 eep.WaitEepromStandbyState();
bcostm 0:b8722d2c0036 41
bcostm 0:b8722d2c0036 42 // Read buffer
bcostm 0:b8722d2c0036 43 bytes_rd = BUFFER_SIZE;
bcostm 0:b8722d2c0036 44 if (eep.ReadBuffer(ReadBuffer, WRITE_READ_ADDR, &bytes_rd) != EEPROM_OK) {
bcostm 0:b8722d2c0036 45 led_red = 1;
bcostm 0:b8722d2c0036 46 error("Read buffer FAILED\n");
bcostm 0:b8722d2c0036 47 } else {
bcostm 0:b8722d2c0036 48 ReadBuffer[BUFFER_SIZE] = '\0';
bcostm 0:b8722d2c0036 49 pc.printf("Read buffer PASSED\n");
bcostm 0:b8722d2c0036 50 pc.printf("Buffer read = [%s]\n", ReadBuffer);
bcostm 0:b8722d2c0036 51 pc.printf("Bytes read = %d\n", bytes_rd);
bcostm 0:b8722d2c0036 52 }
bcostm 0:b8722d2c0036 53
bcostm 0:b8722d2c0036 54 eep.WaitEepromStandbyState();
bcostm 0:b8722d2c0036 55
bcostm 0:b8722d2c0036 56 while(1) {
bcostm 0:b8722d2c0036 57 led_green = !led_green;
bcostm 0:b8722d2c0036 58 wait(1);
bcostm 0:b8722d2c0036 59 }
bcostm 0:b8722d2c0036 60 }