Hardcode a default config, which is written to flash on first boot. v4.02.04
authorMichael McMaster <michael@codesrc.com>
Mon, 4 May 2015 13:51:11 +0000 (23:51 +1000)
committerMichael McMaster <michael@codesrc.com>
Mon, 4 May 2015 13:51:11 +0000 (23:51 +1000)
The bootloader fails checksums if the config is defined within a
code section, then later modified.
Hacking the .hex file isn't possible either because PSoC Programmer
checks that the non-bootloadable part of the flash is empty.

software/SCSI2SD/src/config.c

index 26f0fe8..bb31e0d 100755 (executable)
 \r
 static const uint16_t FIRMWARE_VERSION = 0x0424;\r
 \r
+// 1 flash row\r
+static const uint8_t DEFAULT_CONFIG[256] =\r
+{\r
+       0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x3F, 0x00,\r
+       0x00, 0x02, 0x3F, 0x00, 0xFF, 0x00, 0x20, 0x63, 0x6F, 0x64, 0x65, 0x73,\r
+       0x72, 0x63, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x53,\r
+       0x43, 0x53, 0x49, 0x32, 0x53, 0x44, 0x20, 0x31, 0x2E, 0x30, 0x31, 0x32,\r
+       0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,\r
+       0x37, 0x38, 0x00, 0x00\r
+};\r
+\r
 enum USB_ENDPOINTS\r
 {\r
        USB_EP_OUT = 1,\r
@@ -61,6 +72,24 @@ void configInit()
        USBFS_Start(0, USBFS_5V_OPERATION);\r
        usbInEpState = usbDebugEpState = USB_IDLE;\r
        usbReady = 0; // We don't know if host is connected yet.\r
+\r
+       int invalid = 1;\r
+       uint8_t* rawConfig = getConfigByIndex(0);\r
+       int i;\r
+       for (i = 0; i < 64; ++i)\r
+       {\r
+               if (rawConfig[i])\r
+               {\r
+                       invalid = 0;\r
+                       break;\r
+               }\r
+       }\r
+       if (invalid)\r
+       {\r
+               // Save a default config.\r
+               CySetTemp();\r
+               CyWriteRowData(SCSI_CONFIG_ARRAY, SCSI_CONFIG_0_ROW, DEFAULT_CONFIG);\r
+       }\r
 }\r
 \r
 static void\r