HACK: Add EEPROM writing at boot of SAM3 on qmod
This is not for production use, but just for hardware verification
diff --git a/firmware/src_simtrace/main.c b/firmware/src_simtrace/main.c
index c4e6f3c..c4df7bc 100644
--- a/firmware/src_simtrace/main.c
+++ b/firmware/src_simtrace/main.c
@@ -133,24 +133,72 @@
g_unique_id[2], g_unique_id[3]);
#if 1
+
+static const unsigned char __eeprom_bin[] = {
+ 0x23, 0x42, 0x17, 0x25, 0x00, 0x00, 0x9b, 0x20, 0x01, 0xa0, 0x00, 0x5e,
+ 0x01, 0x32, 0x01, 0x32, 0x32, 0x04, 0x09, 0x18, 0x0d, 0x00, 0x73, 0x00,
+ 0x79, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x6f, 0x00, 0x63, 0x00, 0x6f, 0x00,
+ 0x6d, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x73, 0x00, 0x2e, 0x00,
+ 0x66, 0x00, 0x2e, 0x00, 0x6d, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x2e, 0x00,
+ 0x20, 0x00, 0x47, 0x00, 0x6d, 0x00, 0x62, 0x00, 0x48, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x71, 0x00, 0x75, 0x00, 0x61, 0x00, 0x64, 0x00, 0x20, 0x00, 0x6d, 0x00,
+ 0x6f, 0x00, 0x64, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x76, 0x00,
+ 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+};
+static const unsigned int __eeprom_bin_len = 256;
+
static const Pin pin_hub_rst = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT};
PIO_Configure(&pin_hub_rst, 1);
i2c_pin_init();
- while (1) {
- for (i = 0; i < 256; i ++) {
- int byte = eeprom_read_byte(0x50, i);
- TRACE_INFO("0x%02x: %02x\r\n", i, byte);
- }
+
+ /* wait */
+ volatile int v;
+ /* 440ns per cycle here */
+ for (i = 0; i < 1000000; i++) {
+ v = 0;
}
+
+ /* write the EEPROM once */
+ for (i = 0; i < 256; i++) {
+ int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]);
+ /* if the result was negative, repeat that write */
+ if (rc < 0)
+ i--;
+ }
+
+ /* then pursue re-reading it again and again */
+ for (i = 0; i < 256; i++) {
+ int byte = eeprom_read_byte(0x50, i);
+ TRACE_INFO("0x%02x: %02x\r\n", i, byte);
+ if (byte != __eeprom_bin[i])
+ TRACE_ERROR("Byte %u is wrong, expected 0x%02x, found 0x%02x\r\n",
+ i, __eeprom_bin[i], byte);
+ }
+ PIO_Clear(&pin_hub_rst);
#endif
TRACE_INFO("USB init...\r\n");
while (USBD_GetState() < USBD_STATE_CONFIGURED) {
+#if 0
if (i >= MAX_USB_ITER * 3) {
TRACE_ERROR("Resetting board (USB could "
"not be configured)\r\n");
NVIC_SystemReset();
}
+#endif
i++;
}