finish test app

This commit is contained in:
Michele Balistreri 2023-10-25 14:20:39 +09:00
parent 91772ee84a
commit bf54bc7c1b
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
3 changed files with 204 additions and 9 deletions

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="com.st.stm32cube.ide.mcu.debug.launch.launchConfigurationType">
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.access_port_id" value="1"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.cubeprog_external_loaders" value="[]"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.debug_auth_certif_path" value=""/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.debug_auth_check_enable" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.debug_auth_key_path" value=""/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.debug_auth_permission" value="debug_non_secure_L3"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_live_expr" value="true"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_swv" value="true"/>
<intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.formatVersion" value="2"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.ip_address_local" value="localhost"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.enabled" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.value" value=""/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.loadList" value="{&quot;fItems&quot;:[{&quot;fIsFromMainTab&quot;:true,&quot;fPath&quot;:&quot;TestApp/stm32.elf&quot;,&quot;fProjectName&quot;:&quot;stm32&quot;,&quot;fPerformBuild&quot;:true,&quot;fDownload&quot;:true,&quot;fLoadSymbols&quot;:true}]}"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.override_start_address_mode" value="pc"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.remoteCommand" value="target remote"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startServer" value="true"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.divby0" value="true"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.unaligned" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.haltonexception" value="true"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swd_mode" value="true"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_port" value="61235"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_trace_hclk" value="250000000"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.useRemoteTarget" value="true"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.vector_table" value=""/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.verify_flash_download" value="true"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.cti_allow_halt" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.cti_signal_halt" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_logging" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_max_halt_delay" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_shared_stlink" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.frequency" value="0"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.halt_all_on_reset" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.log_file" value="C:\Users\tanuki\git\keycard-pro\stm32\Debug\st-link_gdbserver_log.txt"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.low_power_debug" value="enable"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.max_halt_delay" value="2"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.reset_strategy" value="connect_under_reset"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_check_serial_number" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value=""/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="none"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkenable_rtos" value="true"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{&quot;fVersion&quot;:1,&quot;fItems&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fIsSuppressible&quot;:false,&quot;fResetAttribute&quot;:&quot;Software system reset&quot;,&quot;fResetStrategies&quot;:[{&quot;fDisplayName&quot;:&quot;Software system reset&quot;,&quot;fLaunchAttribute&quot;:&quot;system_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Hardware reset&quot;,&quot;fLaunchAttribute&quot;:&quot;hardware_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset hardware\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Core reset&quot;,&quot;fLaunchAttribute&quot;:&quot;core_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset core\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;None&quot;,&quot;fLaunchAttribute&quot;:&quot;no_reset&quot;,&quot;fGdbCommands&quot;:[],&quot;fCmdOptions&quot;:[&quot;-g&quot;]}],&quot;fGdbCommandGroup&quot;:{&quot;name&quot;:&quot;Additional commands&quot;,&quot;commands&quot;:[]},&quot;fStartApplication&quot;:true}]}"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.enableRtosProxy" value="true"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyCustomProperties" value=""/>
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriver" value="freertos"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriverAuto" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriverPort" value="ARM_CM33_NTZ"/>
<intAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyPort" value="60000"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doHalt" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doReset" value="false"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.initCommands" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDeviceId" value="com.st.stm32cube.ide.mcu.debug.stlink"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value="08000000"/>
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="61234"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.runCommands" value=""/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="arm-none-eabi-gdb"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="false"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="remote"/>
<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="TestApp/stm32.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="stm32"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.816735289.712006256"/>
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/stm32"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;"/>
<stringAttribute key="process_factory_id" value="com.st.stm32cube.ide.mcu.debug.launch.HardwareDebugProcessFactory"/>
</launchConfiguration>

View File

@ -6,12 +6,17 @@
#include "core/core.h" #include "core/core.h"
#include "core/settings.h" #include "core/settings.h"
#include "keycard/keycard.h" #include "keycard/keycard.h"
#include "keycard/keycard_cmdset.h"
#include "mem.h" #include "mem.h"
#include "ui/ui_internal.h"
#include "usb/usb.h" #include "usb/usb.h"
#include "ur/ur.h" #include "ur/ur.h"
#include "ur/auth_types.h" #include "ur/auth_types.h"
#include "ur/auth_encode.h" #include "ur/auth_encode.h"
#define TEST_AID_LEN 9
const uint8_t TEST_AID[] = {0xa0, 0x00, 0x00, 0x08, 0x04, 0x00, 0x01, 0x01, 0x01};
static app_err_t core_keypad_test() { static app_err_t core_keypad_test() {
g_ui_cmd.type = UI_CMD_INPUT_STRING; g_ui_cmd.type = UI_CMD_INPUT_STRING;
if (ui_signal_wait(0) != CORE_EVT_UI_OK) { if (ui_signal_wait(0) != CORE_EVT_UI_OK) {
@ -22,19 +27,19 @@ static app_err_t core_keypad_test() {
} }
static app_err_t core_lcd_test() { static app_err_t core_lcd_test() {
hal_pwm_set_dutycycle(PWM_BACKLIGHT, 0); hal_pwm_set_dutycycle(PWM_BACKLIGHT, 5);
if (ui_info("Screen is at minimum brightness. Press is OK if readable, cancel otherwise", "Brightness test", 1) != CORE_EVT_UI_OK) { if (ui_info("Brightness test", "Screen is at minimum brightness. Press is OK if readable, cancel otherwise", 1) != CORE_EVT_UI_OK) {
return ERR_CANCEL; return ERR_CANCEL;
} }
hal_pwm_set_dutycycle(PWM_BACKLIGHT, 50); hal_pwm_set_dutycycle(PWM_BACKLIGHT, 50);
if (ui_info("Screen is at half brightness. Press is OK if brighter than before, cancel otherwise", "Brightness test", 1) != CORE_EVT_UI_OK) { if (ui_info("Brightness test", "Screen is at half brightness. Press is OK if brighter than before, cancel otherwise", 1) != CORE_EVT_UI_OK) {
return ERR_CANCEL; return ERR_CANCEL;
} }
hal_pwm_set_dutycycle(PWM_BACKLIGHT, 100); hal_pwm_set_dutycycle(PWM_BACKLIGHT, 100);
if (ui_info("Screen is at full brightness. Press is OK if very bright, cancel otherwise", "Brightness test", 1) != CORE_EVT_UI_OK) { if (ui_info("Brightness test", "Screen is at full brightness. Press is OK if very bright, cancel otherwise", 1) != CORE_EVT_UI_OK) {
return ERR_CANCEL; return ERR_CANCEL;
} }
@ -56,6 +61,7 @@ static app_err_t core_camera_test() {
} }
if (memcmp(auth._dev_auth_challenge._dev_auth_challenge.value, "0123456789abcdefABCDEF9876543210", 32)) { if (memcmp(auth._dev_auth_challenge._dev_auth_challenge.value, "0123456789abcdefABCDEF9876543210", 32)) {
ui_info("Invalid QR", "The scanned QR code is invalid", 1);
return ERR_CANCEL; return ERR_CANCEL;
} }
@ -63,16 +69,78 @@ static app_err_t core_camera_test() {
} }
static app_err_t core_card_test() { static app_err_t core_card_test() {
while (hal_gpio_get(GPIO_SMARTCARD_PRESENT) == GPIO_RESET) {
ui_info("Insert card", "Insert card and press OK", 1);
}
keycard_init(&g_core.keycard);
smartcard_activate(&g_core.keycard.sc);
if (g_core.keycard.sc.state != SC_READY) {
ui_info("Card error", "Couldn't start communication with the card", 1);
return ERR_CANCEL; return ERR_CANCEL;
} }
if (keycard_cmd_select(&g_core.keycard, TEST_AID, TEST_AID_LEN) != ERR_OK) {
ui_info("Card error", "Couldn't send SELECT APDU", 1);
return ERR_CANCEL;
}
if (APDU_SW(&g_core.keycard.apdu) != SW_OK) {
ui_keycard_wrong_card();
return ERR_CANCEL;
}
app_info_t info;
if (application_info_parse(APDU_RESP(&g_core.keycard.apdu), &info) != ERR_OK) {
ui_keycard_wrong_card();
return ERR_CANCEL;
}
return ERR_OK;
}
static app_err_t core_usb_test() { static app_err_t core_usb_test() {
usb_start_if_connected();
while (!usb_connected()) {
ui_info("Plug USB", "Plug USB and press OK", 1);
}
g_ui_cmd.type = UI_CMD_INFO;
g_ui_cmd.params.info.dismissable = 1;
g_ui_cmd.params.info.title = "Waiting USB command";
g_ui_cmd.params.info.msg = "Send a GET_APP_CONF command via USB";
while (ui_signal_wait(1) != CORE_EVT_USB_CMD) {
continue;
}
apdu_t* apdu = &g_core.usb_command.apdu;
if ((APDU_CLA(apdu) != 0xe0) || (APDU_INS(apdu) != INS_GET_APP_CONF)) {
ui_info("USB Error", "Invalid USB command received", 1);
return ERR_CANCEL; return ERR_CANCEL;
} }
void core_task_entry(void* pvParameters) { uint8_t* data = APDU_RESP(apdu);
g_settings.enable_usb = false; data[0] = FW_VERSION[0];
data[1] = FW_VERSION[1];
data[2] = FW_VERSION[2];
data[3] = 0x01;
data[4] = 0x34;
data[5] = 0xb3;
data[6] = 0x71;
data[7] = 0x90;
data[8] = 0x00;
apdu->lr = 9;
command_init_send(&g_core.usb_command);
vTaskDelay(pdMS_TO_TICKS(20));
return ERR_OK;
}
void core_task_entry(void* pvParameters) {
if (core_keypad_test() != ERR_OK) { if (core_keypad_test() != ERR_OK) {
vTaskSuspend(NULL); vTaskSuspend(NULL);
} }
@ -95,7 +163,9 @@ void core_task_entry(void* pvParameters) {
vTaskSuspend(NULL); vTaskSuspend(NULL);
} }
ui_info("Test OK", "All tests passed, press any key to reboot to application firmware", 1);
g_bootcmd = BOOTCMD_SWITCH_FW; g_bootcmd = BOOTCMD_SWITCH_FW;
pwr_reboot(); hal_reboot();
} }
#endif #endif

View File

@ -13,7 +13,48 @@
struct ui_cmd g_ui_cmd; struct ui_cmd g_ui_cmd;
struct ui_ctx g_ui_ctx; struct ui_ctx g_ui_ctx;
#define TH_FIELD_MARGIN ((SCREEN_WIDTH - ((TH_PIN_FIELD_WIDTH * 3) + (TH_PIN_FIELD_DIGIT_MARGIN * 2))) / 2)
static app_err_t test_keypad() { static app_err_t test_keypad() {
dialog_title("Keypad test");
dialog_footer(TH_TITLE_HEIGHT);
screen_area_t area = {
.x = TH_FIELD_MARGIN,
.y = TH_TITLE_HEIGHT + TH_PIN_FIELD_VERTICAL_MARGIN,
.width = TH_PIN_FIELD_WIDTH,
.height = TH_PIN_FIELD_HEIGHT
};
for (int i = 0; i < 12; i++) {
screen_fill_area(&area, TH_COLOR_PIN_FIELD_BG);
if ((i % 3) == 2) {
area.x = TH_FIELD_MARGIN;
area.y += TH_PIN_FIELD_HEIGHT + TH_PIN_FIELD_VERTICAL_MARGIN;
} else {
area.x += TH_PIN_FIELD_WIDTH + TH_PIN_FIELD_DIGIT_MARGIN;
}
}
area.x = TH_FIELD_MARGIN;
area.y = TH_TITLE_HEIGHT + TH_PIN_FIELD_VERTICAL_MARGIN;
for (int i = 0; i < 12; i++) {
while(ui_wait_keypress(portMAX_DELAY) != i) {
continue;
}
screen_fill_area(&area, TH_COLOR_PIN_FIELD_SELECTED_BG);
if ((i % 3) == 2) {
area.x = TH_FIELD_MARGIN;
area.y += TH_PIN_FIELD_HEIGHT + TH_PIN_FIELD_VERTICAL_MARGIN;
} else {
area.x += TH_PIN_FIELD_WIDTH + TH_PIN_FIELD_DIGIT_MARGIN;
}
}
return ERR_OK; return ERR_OK;
} }
@ -26,6 +67,7 @@ static app_err_t test_colors() {
.width = (SCREEN_WIDTH / 3), .width = (SCREEN_WIDTH / 3),
.height = (SCREEN_HEIGHT - TH_TITLE_HEIGHT) .height = (SCREEN_HEIGHT - TH_TITLE_HEIGHT)
}; };
screen_fill_area(&area, SCREEN_COLOR_RED); screen_fill_area(&area, SCREEN_COLOR_RED);
area.x += (SCREEN_WIDTH / 3); area.x += (SCREEN_WIDTH / 3);