Other Parts Discussed in Thread: CC1350
Hi I've created 2 functions to load and store a single byte from the external flash using the driver in contiki-ng.
I noticed there are lots of errors in the read value, and they depend on the CONFIG_FLASH_OFFSET (Where do I start writing into the flash) Is there a reason for that?
Functions:
#include "contiki.h" #include <stdio.h> #include <stdlib.h> #include "clock.h" #include "ext_flash_array.h" #include "ext-flash.h" bool save_byte(UBYTE byte, UWORD addr) { /* Save byte to flash */ if(!ext_flash_open(NULL)) { clock_delay_usec(1000); if(!ext_flash_open(NULL)) { printf("Could not open flash to read byte addr %d\n", addr); ext_flash_close(NULL); return false; } } if (0) { // if (!ext_flash_erase(NULL, addr*4, sizeof(UBYTE))) { printf("Error erasing byte\n"); } else { if(!ext_flash_write(NULL, addr*8, sizeof(UBYTE), (uint8_t *)&byte)) { clock_delay_usec(1000); if(!ext_flash_write(NULL, addr*8, sizeof(UBYTE), (uint8_t *)&byte)) { printf("Error writing byte\n"); } } } ext_flash_close(NULL); Debug("save_byte(%d, %d) saved the value %d to %d in ext_flash\n", byte, addr, byte, addr); clock_delay_usec(1000); return true; } bool load_byte(UBYTE *rv, UWORD addr) { UBYTE buf; /* Read from flash into a buffer */ if(!ext_flash_open(NULL)) { if(!ext_flash_open(NULL)) { clock_delay_usec(1000); printf("Could not open flash to read byte addr %d\n", addr); ext_flash_close(NULL); return false; } } if(!ext_flash_read(NULL, addr*8, sizeof(buf), (uint8_t *)&buf)) { if(!ext_flash_read(NULL, addr*8, sizeof(buf), (uint8_t *)&buf)) { clock_delay_usec(1000); printf("Error reading from flash\n"); ext_flash_close(NULL); return false; } } ext_flash_close(NULL); *rv = buf; Debug("load_byte(*rv, %d) loaded the value %d from %d in ext_flash\n", addr, buf, addr); return true; }
main:
/*-----------------------------------------------------------*/ PROCESS(epd_process, "Epd process"); AUTOSTART_PROCESSES(&epd_process); /*-----------------------------------------------------------*/ PROCESS_THREAD(epd_process, ev, data) { PROCESS_BEGIN(); UBYTE tmp; for(UWORD cnt=0; cnt<IMAGESIZE; cnt++) { save_byte(0xCC, cnt+CONFIG_FLASH_OFFSET); watchdog_periodic(); } for(UWORD cnt=0; cnt<IMAGESIZE; cnt++) { load_byte(&tmp, cnt+CONFIG_FLASH_OFFSET); watchdog_periodic(); } for(UWORD cnt=0; cnt<IMAGESIZE; cnt++) { save_byte(0xCC, cnt+CONFIG_FLASH_OFFSET); load_byte(&tmp, cnt+CONFIG_FLASH_OFFSET); watchdog_periodic(); } PROCESS_END(); }
Result:
Debug: save_byte(204, 1000) saved the value 204 to 1000 in ext_flash
Debug: save_byte(204, 1001) saved the value 204 to 1001 in ext_flash
Debug: save_byte(204, 1002) saved the value 204 to 1002 in ext_flash
Debug: save_byte(204, 1003) saved the value 204 to 1003 in ext_flash
Debug: save_byte(204, 1004) saved the value 204 to 1004 in ext_flash
Debug: save_byte(204, 1005) saved the value 204 to 1005 in ext_flash
Debug: save_byte(204, 1006) saved the value 204 to 1006 in ext_flash
Debug: save_byte(204, 1007) saved the value 204 to 1007 in ext_flash
Debug: save_byte(204, 1008) saved the value 204 to 1008 in ext_flash
Debug: save_byte(204, 1009) saved the value 204 to 1009 in ext_flash
Debug: save_byte(204, 1010) saved the value 204 to 1010 in ext_flash
Debug: save_byte(204, 1011) saved the value 204 to 1011 in ext_flash
Debug: save_byte(204, 1012) saved the value 204 to 1012 in ext_flash
Debug: save_byte(204, 1013) saved the value 204 to 1013 in ext_flash
Debug: save_byte(204, 1014) saved the value 204 to 1014 in ext_flash
Debug: save_byte(204, 1015) saved the value 204 to 1015 in ext_flash
Debug: save_byte(204, 1016) saved the value 204 to 1016 in ext_flash
Debug: save_byte(204, 1017) saved the value 204 to 1017 in ext_flash
Debug: save_byte(204, 1018) saved the value 204 to 1018 in ext_flash
Debug: save_byte(204, 1019) saved the value 204 to 1019 in ext_flash
Debug: save_byte(204, 1020) saved the value 204 to 1020 in ext_flash
Debug: save_byte(204, 1021) saved the value 204 to 1021 in ext_flash
Debug: save_byte(204, 1022) saved the value 204 to 1022 in ext_flash
Debug: save_byte(204, 1023) saved the value 204 to 1023 in ext_flash
Debug: save_byte(204, 1024) saved the value 204 to 1024 in ext_flash
Debug: save_byte(204, 1025) saved the value 204 to 1025 in ext_flash
Debug: save_byte(204, 1026) saved the value 204 to 1026 in ext_flash
Debug: save_byte(204, 1027) saved the value 204 to 1027 in ext_flash
Debug: save_byte(204, 1028) saved the value 204 to 1028 in ext_flash
Debug: save_byte(204, 1029) saved the value 204 to 1029 in ext_flash
Debug: save_byte(204, 1030) saved the value 204 to 1030 in ext_flash
Debug: save_byte(204, 1031) saved the value 204 to 1031 in ext_flash
Debug: save_byte(204, 1032) saved the value 204 to 1032 in ext_flash
Debug: save_byte(204, 1033) saved the value 204 to 1033 in ext_flash
Debug: save_byte(204, 1034) saved the value 204 to 1034 in ext_flash
Debug: save_byte(204, 1035) saved the value 204 to 1035 in ext_flash
Debug: save_byte(204, 1036) saved the value 204 to 1036 in ext_flash
Debug: save_byte(204, 1037) saved the value 204 to 1037 in ext_flash
Debug: save_byte(204, 1038) saved the value 204 to 1038 in ext_flash
Debug: save_byte(204, 1039) saved the value 204 to 1039 in ext_flash
Debug: save_byte(204, 1040) saved the value 204 to 1040 in ext_flash
Debug: save_byte(204, 1041) saved the value 204 to 1041 in ext_flash
Debug: save_byte(204, 1042) saved the value 204 to 1042 in ext_flash
Debug: save_byte(204, 1043) saved the value 204 to 1043 in ext_flash
Debug: save_byte(204, 1044) saved the value 204 to 1044 in ext_flash
Debug: save_byte(204, 1045) saved the value 204 to 1045 in ext_flash
Debug: save_byte(204, 1046) saved the value 204 to 1046 in ext_flash
Debug: save_byte(204, 1047) saved the value 204 to 1047 in ext_flash
Debug: save_byte(204, 1048) saved the value 204 to 1048 in ext_flash
Debug: save_byte(204, 1049) saved the value 204 to 1049 in ext_flash
Debug: save_byte(204, 1050) saved the value 204 to 1050 in ext_flash
Debug: save_byte(204, 1051) saved the value 204 to 1051 in ext_flash
Debug: save_byte(204, 1052) saved the value 204 to 1052 in ext_flash
Debug: save_byte(204, 1053) saved the value 204 to 1053 in ext_flash
Debug: save_byte(204, 1054) saved the value 204 to 1054 in ext_flash
Debug: save_byte(204, 1055) saved the value 204 to 1055 in ext_flash
Debug: save_byte(204, 1056) saved the value 204 to 1056 in ext_flash
Debug: save_byte(204, 1057) saved the value 204 to 1057 in ext_flash
Debug: save_byte(204, 1058) saved the value 204 to 1058 in ext_flash
Debug: save_byte(204, 1059) saved the value 204 to 1059 in ext_flash
Debug: load_byte(*rv, 1000) loaded the value 0 from 1000 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1001) loaded the value 64 from 1001 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1002) loaded the value 64 from 1002 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1003) loaded the value 64 from 1003 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1004) loaded the value 64 from 1004 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1005) loaded the value 64 from 1005 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1006) loaded the value 64 from 1006 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1007) loaded the value 64 from 1007 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1008) loaded the value 64 from 1008 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1009) loaded the value 64 from 1009 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1010) loaded the value 64 from 1010 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1011) loaded the value 64 from 1011 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1012) loaded the value 64 from 1012 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1013) loaded the value 64 from 1013 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1014) loaded the value 64 from 1014 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1015) loaded the value 64 from 1015 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1016) loaded the value 64 from 1016 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1017) loaded the value 64 from 1017 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1018) loaded the value 64 from 1018 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1019) loaded the value 64 from 1019 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1020) loaded the value 64 from 1020 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1021) loaded the value 64 from 1021 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1022) loaded the value 64 from 1022 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1023) loaded the value 64 from 1023 in ext_flash //Wrong Val
Debug: load_byte(*rv, 1024) loaded the value 204 from 1024 in ext_flash
Debug: load_byte(*rv, 1025) loaded the value 204 from 1025 in ext_flash
Debug: load_byte(*rv, 1026) loaded the value 204 from 1026 in ext_flash
Debug: load_byte(*rv, 1027) loaded the value 204 from 1027 in ext_flash
Debug: load_byte(*rv, 1028) loaded the value 204 from 1028 in ext_flash
Debug: load_byte(*rv, 1029) loaded the value 204 from 1029 in ext_flash
Debug: load_byte(*rv, 1030) loaded the value 204 from 1030 in ext_flash
Debug: load_byte(*rv, 1031) loaded the value 204 from 1031 in ext_flash
Debug: load_byte(*rv, 1032) loaded the value 204 from 1032 in ext_flash
Debug: load_byte(*rv, 1033) loaded the value 204 from 1033 in ext_flash
Debug: load_byte(*rv, 1034) loaded the value 204 from 1034 in ext_flash
Debug: load_byte(*rv, 1035) loaded the value 204 from 1035 in ext_flash
Debug: load_byte(*rv, 1036) loaded the value 204 from 1036 in ext_flash
Debug: load_byte(*rv, 1037) loaded the value 204 from 1037 in ext_flash
Debug: load_byte(*rv, 1038) loaded the value 204 from 1038 in ext_flash
Debug: load_byte(*rv, 1039) loaded the value 204 from 1039 in ext_flash
Debug: load_byte(*rv, 1040) loaded the value 204 from 1040 in ext_flash
Debug: load_byte(*rv, 1041) loaded the value 204 from 1041 in ext_flash
Debug: load_byte(*rv, 1042) loaded the value 204 from 1042 in ext_flash
Debug: load_byte(*rv, 1043) loaded the value 204 from 1043 in ext_flash
Debug: load_byte(*rv, 1044) loaded the value 204 from 1044 in ext_flash
Debug: load_byte(*rv, 1045) loaded the value 204 from 1045 in ext_flash
Debug: load_byte(*rv, 1046) loaded the value 204 from 1046 in ext_flash
Debug: load_byte(*rv, 1047) loaded the value 204 from 1047 in ext_flash
Debug: load_byte(*rv, 1048) loaded the value 204 from 1048 in ext_flash
Debug: load_byte(*rv, 1049) loaded the value 204 from 1049 in ext_flash
Debug: load_byte(*rv, 1050) loaded the value 204 from 1050 in ext_flash
Debug: load_byte(*rv, 1051) loaded the value 204 from 1051 in ext_flash
Debug: load_byte(*rv, 1052) loaded the value 204 from 1052 in ext_flash
Debug: load_byte(*rv, 1053) loaded the value 204 from 1053 in ext_flash
Debug: load_byte(*rv, 1054) loaded the value 204 from 1054 in ext_flash
Debug: load_byte(*rv, 1055) loaded the value 204 from 1055 in ext_flash
Debug: load_byte(*rv, 1056) loaded the value 204 from 1056 in ext_flash
Debug: load_byte(*rv, 1057) loaded the value 204 from 1057 in ext_flash
Debug: load_byte(*rv, 1058) loaded the value 204 from 1058 in ext_flash
Debug: load_byte(*rv, 1059) loaded the value 204 from 1059 in ext_flash