Internal_Datalogger but with USB support removed (for MAX40108 Demo board), proof of concept that MAX32625 can be used successfully with VDDB(USB) left unpowered, as long as the USB library is not used.
Dependencies: max32625pico CmdLine
Diff: DataLogger_Internal.cpp
- Revision:
- 48:18647e0516f2
- Parent:
- 47:f1a56afb4aca
- Child:
- 49:359a6b9df7c1
--- a/DataLogger_Internal.cpp Fri Oct 29 23:05:44 2021 -0700 +++ b/DataLogger_Internal.cpp Sun Oct 31 22:40:15 2021 -0700 @@ -2616,23 +2616,93 @@ // { 0x00000000, NULL, 0, "wiped" }, // Ignore 0x00000000 wiped records; end of table }; +const uint32_t save_arg_01_pageErase = 0x00000001; // page erase and rewrite +const uint32_t load_arg_01_brief = 0x00000001; // brief list loaded values +const uint32_t save_arg_02_verbose = 0x00000002; // verbose diagnostic messages +const uint32_t save_arg_04_reserved = 0x00000004; // reserved +const uint32_t save_arg_08_reserved = 0x00000008; // reserved +const uint32_t save_arg_10_calibration = 0x00000010; // save board ID and calibration +const uint32_t save_arg_20_action_table = 0x00000020; // save Datalogger_action_table +const uint32_t save_arg_40_command_table = 0x00000040; // save onButtonX_command_table +const uint32_t save_arg_80_reserved = 0x00000080; // reserved +const uint32_t save_arg_default = 0 + | save_arg_01_pageErase + // | save_arg_02_verbose + // | save_arg_04_reserved + // | save_arg_08_reserved + | save_arg_10_calibration + | save_arg_20_action_table + | save_arg_40_command_table + // | save_arg_80_reserved + ; +const uint32_t load_arg_default = 0 + | load_arg_01_brief + | save_arg_02_verbose + // | save_arg_04_reserved + // | save_arg_08_reserved + | save_arg_10_calibration + | save_arg_20_action_table + | save_arg_40_command_table + // | save_arg_80_reserved + ; +const uint32_t load_arg_startup = 0 + | load_arg_01_brief + // | save_arg_02_verbose + // | save_arg_04_reserved + // | save_arg_08_reserved + | save_arg_10_calibration + | save_arg_20_action_table + | save_arg_40_command_table + // | save_arg_80_reserved + ; // WIP #312 store values into flash_page_configuration_back_up[] from calibration_05_V[] etc. Default save everything. -// @param[in] save_arg 0x000000FF = erase flash file before saving values; 0xFFFFFF00 = filter items to save +// @param[in] save_arg %F save=0x00000001 = page erase and rewrite, else append in next available blank space within page +// @param[in] save_arg %F save=0x00000002 = verbose diagnostic messages +// @param[in] save_arg %F save=0x00000004 = reserved +// @param[in] save_arg %F save=0x00000008 = reserved +// @param[in] save_arg %F save=0x00000010 = save board ID and calibration +// @param[in] save_arg %F save=0x00000020 = save Datalogger_action_table +// @param[in] save_arg %F save=0x00000040 = save onButtonX_command_table +// @param[in] save_arg %F save=0x00000080 = reserved int Save_flash_page_configuration_back_up(CmdLine& cmdLine, uint32_t save_arg) { - cmdLine.serial().printf("\r\nSave_flash_page_configuration_back_up(0x%8.8lx)...", save_arg); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("\r\nSave_flash_page_configuration_back_up(0x%8.8lx)...", save_arg); + } + if ((save_arg & save_arg_02_verbose) != 0) + { + // @param[in] save_arg %F save=0x00000002 = verbose diagnostic messages + if ((save_arg & save_arg_01_pageErase) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_01_pageErase", save_arg_01_pageErase); } + if ((save_arg & save_arg_02_verbose) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_02_verbose", save_arg_02_verbose); } + if ((save_arg & save_arg_04_reserved) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_04_reserved", save_arg_04_reserved); } + if ((save_arg & save_arg_08_reserved) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_08_reserved", save_arg_08_reserved); } + if ((save_arg & save_arg_10_calibration) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_10_calibration", save_arg_10_calibration); } + if ((save_arg & save_arg_20_action_table) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_20_action_table", save_arg_20_action_table); } + if ((save_arg & save_arg_40_command_table) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_40_command_table", save_arg_40_command_table); } + if ((save_arg & save_arg_80_reserved) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_80_reserved", save_arg_80_reserved); } + } // WIP #312 %F save=save_arg could filter which items to append to flash file // initialize flash memory interface // FlashIAP: FlashIAP flash; flash.init(); // int FLC_Init(void); // returns E_NO_ERROR or E_BUSY or E_UNKNOWN - cmdLine.serial().printf("FLC_Init "); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("FLC_Init "); + } if (FLC_Init() != E_NO_ERROR) { - cmdLine.serial().printf("FAIL "); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("FAIL "); + } return 1; // can't perform the command } - cmdLine.serial().printf("PASS "); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("PASS "); + } // uint32_t file_addr = (uint32_t)&flash_page_configuration_back_up[0]; @@ -2640,16 +2710,20 @@ uint32_t file_addr_end = file_addr + 256 - 4; // development: reduce listing size int poke_access_list_index = search_poke_access_list(file_addr); - cmdLine.serial().printf("\r\npoke_access_list[%d] %5s 0x%8.8lx - 0x%8.8lx access %x ", - poke_access_list_index, - poke_access_list[poke_access_list_index].name, - poke_access_list[poke_access_list_index].addr_min, - poke_access_list[poke_access_list_index].addr_max, - poke_access_list[poke_access_list_index].can_flash_write_read); - cmdLine.serial().printf("\r\n%5s 0x%8.8lx: ", poke_access_list[poke_access_list_index].name, file_addr); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("\r\npoke_access_list[%d] %5s 0x%8.8lx - 0x%8.8lx access %x ", + poke_access_list_index, + poke_access_list[poke_access_list_index].name, + poke_access_list[poke_access_list_index].addr_min, + poke_access_list[poke_access_list_index].addr_max, + poke_access_list[poke_access_list_index].can_flash_write_read); + cmdLine.serial().printf("\r\n%5s 0x%8.8lx: ", poke_access_list[poke_access_list_index].name, file_addr); + } - if ((save_arg & 0x000000FF) == 0xFF) + if ((save_arg & save_arg_01_pageErase) != 0) { + // @param[in] save_arg %F save=0x00000001 = page erase and rewrite, else append in next available blank space within page // erase flash file before saving configuration // cmdLine.serial().printf("\r\n%5s 0x%8.8lx: erase page ...", @@ -2669,14 +2743,42 @@ } cmdLine.serial().printf("PASS "); } - // WIP #312: save_arg 0xFFFFFF00 = filter items to save - // if (save_arg & 0xFFFFFF00 == _____) - // { - // } + if ((save_arg & save_arg_02_verbose) != 0) + { + // @param[in] save_arg %F save=0x00000002 = verbose diagnostic messages + } + if ((save_arg & save_arg_04_reserved) != 0) + { + // @param[in] save_arg %F save=0x00000004 = reserved + } + if ((save_arg & save_arg_08_reserved) != 0) + { + // @param[in] save_arg %F save=0x00000008 = reserved + } + if ((save_arg & save_arg_10_calibration) != 0) + { + // @param[in] save_arg %F save=0x00000010 = save board ID and calibration + } + if ((save_arg & save_arg_20_action_table) != 0) + { + // @param[in] save_arg %F save=0x00000020 = save Datalogger_action_table + } + if ((save_arg & save_arg_40_command_table) != 0) + { + // @param[in] save_arg %F save=0x00000040 = save onButtonX_command_table + } + if ((save_arg & save_arg_80_reserved) != 0) + { + // @param[in] save_arg %F save=0x00000080 = reserved + } + + // address of next 16-byte-aligned record start address + uint32_t file_addr_next = (file_addr + 16) &~ 0x0000000F; // scan configuration_back_up_list[] for recordType for (int i = 0; configuration_back_up_list[i].recordType != 0x00000000; i++) { + file_addr_next = (file_addr + 16) &~ 0x0000000F; if (configuration_back_up_list[i].recordType == 0xFFFFFFFF) continue; // // configuration_back_up_list[i].recordType @@ -2685,11 +2787,14 @@ // configuration_back_up_list[i].name // WIP #312 %F save=save_arg could filter which items to append to flash file // - cmdLine.serial().printf("\r\n save 0x%8.8lx %s address 0x%8.8lx length 0x%lx bytes", - configuration_back_up_list[i].recordType, - configuration_back_up_list[i].name, - (uint32_t)configuration_back_up_list[i].addr, - configuration_back_up_list[i].length_bytes); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("\r\n save 0x%8.8lx %s address 0x%8.8lx length 0x%lx bytes", + configuration_back_up_list[i].recordType, + configuration_back_up_list[i].name, + (uint32_t)configuration_back_up_list[i].addr, + configuration_back_up_list[i].length_bytes); + } // // find next free space to store record in flash file cmdLine.serial().printf("\r\n%5s 0x%8.8lx: ", poke_access_list[poke_access_list_index].name, file_addr); @@ -2700,21 +2805,26 @@ { return 1; // fail: no room to write file } - file_addr = file_addr + 4; + file_addr_next = (file_addr + 16) &~ 0x0000000F; + file_addr = file_addr_next; cmdLine.serial().printf("\r\n%5s 0x%8.8lx: 0x%8.8lx ", poke_access_list[poke_access_list_index].name, file_addr, *((uint32_t*)file_addr) ); } + file_addr_next = (file_addr + configuration_back_up_list[i].length_bytes + 16) &~ 0x0000000F; // // copy data from RAM into flash file // not_memcpy(file_addr + 4, configuration_back_up_list[i].addr, configuration_back_up_list[i].length_bytes); // pageBuf[0..3] = configuration_back_up_list[i].recordType; // pageBuf[4...] = configuration_back_up_list[i].addr, configuration_back_up_list[i].length_bytes // WIP #312: FLC_Write(...) in Save_flash_page_configuration_back_up - cmdLine.serial().printf("\r\n%5s 0x%8.8lx: write page buffer ...", - poke_access_list[poke_access_list_index].name, file_addr); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("\r\n%5s 0x%8.8lx: write page buffer ...", + poke_access_list[poke_access_list_index].name, file_addr); + } // page write using flash.program(page_buffer, addr, page_size); // int FLC_Write(uint32_t address, const void *data, uint32_t length, MXC_V_FLC_FLSH_UNLOCK_KEY); // @param address Start address for desired write. @note This address @@ -2729,28 +2839,55 @@ sizeof(uint32_t), MXC_V_FLC_FLSH_UNLOCK_KEY) != E_NO_ERROR) { - cmdLine.serial().printf("FAIL "); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("FAIL "); + } break; // can't perform the command } - cmdLine.serial().printf("PASS "); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("PASS "); + } if (FLC_Write(file_addr + 4, (uint32_t*)(configuration_back_up_list[i].addr), configuration_back_up_list[i].length_bytes, MXC_V_FLC_FLSH_UNLOCK_KEY) != E_NO_ERROR) { - cmdLine.serial().printf("FAIL "); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("FAIL "); + } break; // can't perform the command } - cmdLine.serial().printf("PASS "); + if ((save_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("PASS "); + } // advance to next 16-byte-aligned record start address - file_addr = (file_addr + configuration_back_up_list[i].length_bytes + 16) &~ 0x0000000F; + file_addr = file_addr_next; } // end for each configuration_back_up_list[...] return 0; } // end Save_flash_page_configuration_back_up // WIP #312 load values from flash_page_configuration_back_up[] into calibration_05_V[] etc. Default load everything. int Load_flash_page_configuration_back_up(CmdLine& cmdLine, uint32_t load_arg) { - cmdLine.serial().printf("\r\nLoad_flash_page_configuration_back_up(0x%8.8lx)...", load_arg); + if ((load_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("\r\nLoad_flash_page_configuration_back_up(0x%8.8lx)...", load_arg); + } + if ((load_arg & save_arg_02_verbose) != 0) + { + // @param[in] save_arg %F save=0x00000002 = verbose diagnostic messages + if ((load_arg & load_arg_01_brief) != 0) { cmdLine.serial().printf("\r\n 0x%x: load_arg_01_brief", load_arg_01_brief); } + if ((load_arg & save_arg_02_verbose) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_02_verbose", save_arg_02_verbose); } + if ((load_arg & save_arg_04_reserved) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_04_reserved", save_arg_04_reserved); } + if ((load_arg & save_arg_08_reserved) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_08_reserved", save_arg_08_reserved); } + if ((load_arg & save_arg_10_calibration) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_10_calibration", save_arg_10_calibration); } + if ((load_arg & save_arg_20_action_table) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_20_action_table", save_arg_20_action_table); } + if ((load_arg & save_arg_40_command_table) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_40_command_table", save_arg_40_command_table); } + if ((load_arg & save_arg_80_reserved) != 0) { cmdLine.serial().printf("\r\n 0x%x: save_arg_80_reserved", save_arg_80_reserved); } + } // WIP #312 %F load=load_arg could filter which items to accept from flash file uint32_t file_addr = (uint32_t)&flash_page_configuration_back_up[0]; @@ -2760,22 +2897,28 @@ // diagnostic print int poke_access_list_index = search_poke_access_list(file_addr); - cmdLine.serial().printf("\r\npoke_access_list[%d] %5s 0x%8.8lx - 0x%8.8lx access %x ", - poke_access_list_index, - poke_access_list[poke_access_list_index].name, - poke_access_list[poke_access_list_index].addr_min, - poke_access_list[poke_access_list_index].addr_max, - poke_access_list[poke_access_list_index].can_flash_write_read); - cmdLine.serial().printf("\r\n%5s 0x%8.8lx: ", poke_access_list[poke_access_list_index].name, file_addr); + if ((load_arg & save_arg_02_verbose) != 0) + { + cmdLine.serial().printf("\r\npoke_access_list[%d] %5s 0x%8.8lx - 0x%8.8lx access %x ", + poke_access_list_index, + poke_access_list[poke_access_list_index].name, + poke_access_list[poke_access_list_index].addr_min, + poke_access_list[poke_access_list_index].addr_max, + poke_access_list[poke_access_list_index].can_flash_write_read); + cmdLine.serial().printf("\r\n%5s 0x%8.8lx: ", poke_access_list[poke_access_list_index].name, file_addr); + } // Scan backup configuration file while (file_addr < file_addr_end) { - // diagnostic print - cmdLine.serial().printf("\r\n%5s 0x%8.8lx: 0x%8.8lx ", - poke_access_list[poke_access_list_index].name, - file_addr, - *((uint32_t*)file_addr)); + if ((load_arg & save_arg_02_verbose) != 0) + { + // diagnostic print + cmdLine.serial().printf("\r\n%5s 0x%8.8lx: 0x%8.8lx ", + poke_access_list[poke_access_list_index].name, + file_addr, + *((uint32_t*)file_addr)); + } // address of next 16-byte-aligned record start address uint32_t file_addr_next = (file_addr + 16) &~ 0x0000000F; @@ -2799,21 +2942,28 @@ break; // Ignore blank record, stop searching } // found a matching recordHeader - // diagnostic print - cmdLine.serial().printf("\r\n%5s 0x%8.8lx: 0x%8.8lx load %s", - poke_access_list[poke_access_list_index].name, - file_addr, - *((uint32_t*)file_addr), - configuration_back_up_list[i].name - ); - for (int j = 0; j <= configuration_back_up_list[i].length_bytes; j += 4) + if ((load_arg & load_arg_01_brief) != 0) { - cmdLine.serial().printf("\r\n%5s 0x%8.8lx: 0x%8.8lx", + // diagnostic print + cmdLine.serial().printf("\r\n%5s 0x%8.8lx: 0x%8.8lx load %s", poke_access_list[poke_access_list_index].name, - (file_addr + 4 + j), - *((uint32_t*)(file_addr + 4 + j)) + file_addr, + *((uint32_t*)file_addr), + configuration_back_up_list[i].name ); } + if ((load_arg & save_arg_02_verbose) != 0) + { + + for (int j = 0; j <= configuration_back_up_list[i].length_bytes; j += 4) + { + cmdLine.serial().printf("\r\n%5s 0x%8.8lx: 0x%8.8lx", + poke_access_list[poke_access_list_index].name, + (file_addr + 4 + j), + *((uint32_t*)(file_addr + 4 + j)) + ); + } + } // cmdLine.serial().printf("\r\n load %s 0x%8.8lx length 0x%lx address 0x%8.8lx", // configuration_back_up_list[i].name, // configuration_back_up_list[i].recordType, @@ -4244,11 +4394,22 @@ # endif // HAS_FLASH_PEEK # if HAS_FLASH_POKE // flash poke memory %F poke=0x0007ff00 0xab 0xcd 0xef 0x27 0x18 0x28 -- erase/write flash page - cmdLine.serial().printf("\r\n %%F poke=0x%8.8lx ab cd ef 27 18 28 -- erase/write flash page", (uint32_t)&flash_page_configuration_back_up[0]); + cmdLine.serial().printf("\r\n %%F poke=0x%8.8lx 12 34 56 78 -- erase/write flash page", (uint32_t)&flash_page_configuration_back_up[0]); # endif // HAS_FLASH_POKE # if HAS_FLASH_LOAD_SAVE - cmdLine.serial().printf("\r\n %%F save=0xFF -- erase config; %%F save=0 -- save all config"); - cmdLine.serial().printf("\r\n %%F load -- load all config"); + // cmdLine.serial().printf("\r\n %%F save=0xFF -- erase config; %%F save=0 -- save all config"); + // const uint32_t save_arg_01_pageErase = 0x00000001; // page erase and rewrite + // const uint32_t save_arg_02_verbose = 0x00000002; // verbose diagnostic messages + // const uint32_t save_arg_04_reserved = 0x00000004; // reserved + // const uint32_t save_arg_08_reserved = 0x00000008; // reserved + // const uint32_t save_arg_10_calibration = 0x00000010; // save board ID and calibration + // const uint32_t save_arg_20_action_table = 0x00000020; // save Datalogger_action_table + // const uint32_t save_arg_40_command_table = 0x00000040; // save onButtonX_command_table + // const uint32_t save_arg_80_reserved = 0x00000080; // reserved + cmdLine.serial().printf("\r\n %%F load=0x%x ; %%F save=0x%x -- calibration", + (load_arg_default | save_arg_02_verbose), (save_arg_default | save_arg_02_verbose)); + //~ cmdLine.serial().printf("\r\n %%F save=0x11 -- erase; config; %%F save=0 -- save all config"); + //~ cmdLine.serial().printf("\r\n %%F load -- load all config"); # endif // HAS_FLASH_LOAD_SAVE #endif @@ -4674,12 +4835,12 @@ } # endif // HAS_FLASH_POKE # if HAS_FLASH_LOAD_SAVE - uint32_t save_arg = 0; + uint32_t save_arg = save_arg_default; if (cmdLine.parse_uint32_hex("save", save_arg)) { Save_flash_page_configuration_back_up(cmdLine, save_arg); } - uint32_t load_arg = 0; + uint32_t load_arg = load_arg_default; if (cmdLine.parse_uint32_hex("load", load_arg)) { Load_flash_page_configuration_back_up(cmdLine, load_arg); @@ -5043,11 +5204,23 @@ // %A avg=%d -- help string display Platform_AIN_Average_N cmdLine.serial().printf("\r\n %%A avg=%d -- average", Platform_AIN_Average_N); #endif // USE_Platform_AIN_Average +#ifdef BOARD_SERIAL_NUMBER + // %A sn= set g_board_serial_number ; use with %F save during calibration #312 + cmdLine.serial().printf("\r\n %%A sn=%d -- serial number", g_board_serial_number); +#endif // BOARD_SERIAL_NUMBER cmdLine.serial().printf("\r\n\r\n"); // } // end if (cmdLine.parse_and_remove_key("cal?", valueBuf, sizeof(valueBuf))) } #endif // HAS_Platform_AIN_Calibration +#ifdef BOARD_SERIAL_NUMBER + { + // %A sn= set g_board_serial_number ; use with %F save during calibration #312 + if (cmdLine.parse_uint32_dec("sn", g_board_serial_number)) + { + } + } +#endif // BOARD_SERIAL_NUMBER #if HAS_Platform_AIN_Calibration { // %A calreset -- reset all calibration data @@ -5836,7 +6009,7 @@ #if USE_DATALOGGER_CommandTable if (g_Run_command_table_running == false) { #endif // USE_DATALOGGER_CommandTable - cmdLine.serial().printf("\r\nCmdLine buf:\"%s\"\r\n", cmdLine.str()); + //~ cmdLine.serial().printf("\r\nCmdLine buf:\"%s\"\r\n", cmdLine.str()); #if USE_DATALOGGER_CommandTable } // if (g_Run_command_table_running) #endif // USE_DATALOGGER_CommandTable @@ -7788,7 +7961,7 @@ #if HAS_FLASH_LOAD_SAVE // WIP #312 load values from flash_page_configuration_back_up[] during init - const uint32_t load_arg = 1; + const uint32_t load_arg = load_arg_startup; Load_flash_page_configuration_back_up(cmdLine, load_arg); #endif // HAS_FLASH_LOAD_SAVE