Change in simtrace2[master]: DFU: switch green LED on to indicate DFU mode, and red LED to indicat...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Kévin Redon gerrit-no-reply at lists.osmocom.org
Wed Jul 4 08:58:50 UTC 2018


Kévin Redon has uploaded this change for review. ( https://gerrit.osmocom.org/9862


Change subject: DFU: switch green LED on to indicate DFU mode, and red LED to indicate flashing activity
......................................................................

DFU: switch green LED on to indicate DFU mode, and red LED to indicate flashing activity

Change-Id: I8e34fd869ed94ad122d6a17f5a432f5a09b820bb
---
M firmware/apps/dfu/main.c
1 file changed, 39 insertions(+), 23 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/62/9862/1

diff --git a/firmware/apps/dfu/main.c b/firmware/apps/dfu/main.c
index 3d55fdc..26cbb8c 100644
--- a/firmware/apps/dfu/main.c
+++ b/firmware/apps/dfu/main.c
@@ -13,6 +13,12 @@
 /* remember if the watchdog has been configured in the main loop so we can kick it in the ISR */
 static bool watchdog_configured = false;
 
+/* There is not enough space in the 16 KiB DFU bootloader to include led.h functions */
+#ifdef PINS_LEDS
+/** LED pin configurations */
+static const Pin pinsLeds[] = { PINS_LEDS } ;
+#endif
+
 /*----------------------------------------------------------------------------
  *       Callbacks
  *----------------------------------------------------------------------------*/
@@ -42,53 +48,62 @@
 
 	printf("dnload(altif=%u, offset=%u, len=%u)\n\r", altif, offset, len);
 
+#ifdef PINS_LEDS
+	PIO_Clear(&pinsLeds[LED_NUM_RED]);
+#endif
+
 	switch (altif) {
 	case ALTIF_RAM:
 		addr = RAM_ADDR(offset);
 		if (addr < IRAM_ADDR || addr + len >= IRAM_ADDR + IRAM_SIZE || addr + len >= stack_addr) {
 			g_dfu->state = DFU_STATE_dfuERROR;
 			g_dfu->status = DFU_STATUS_errADDRESS;
-			return DFU_RET_STALL;
+			rc = DFU_RET_STALL;
+			break;
 		}
 		memcpy((void *)addr, data, len);
-		return DFU_RET_ZLP;
+		rc = DFU_RET_ZLP;
+		break;
 	case ALTIF_FLASH:
 		addr = FLASH_ADDR(offset);
 		if (addr < IFLASH_ADDR || addr + len >= IFLASH_ADDR + IFLASH_SIZE) {
 			g_dfu->state = DFU_STATE_dfuERROR;
 			g_dfu->status = DFU_STATUS_errADDRESS;
-			return DFU_RET_STALL;
+			rc = DFU_RET_STALL;
+			break;
 		}
 		rc = FLASHD_Unlock(addr, addr + len, 0, 0);
 		if (rc != 0) {
 			TRACE_ERROR("DFU download flash unlock failed\n\r");
-			/* FIXME: set error codes */
-			return DFU_RET_STALL;
+			rc =  DFU_RET_STALL;
+			break;
 		}
 		rc = FLASHD_Write(addr, data, len);
 		if (rc != 0) {
 			TRACE_ERROR("DFU download flash erase failed\n\r");
-			/* FIXME: set error codes */
-			return DFU_RET_STALL;
+			rc = DFU_RET_STALL;
+			break;
 		}
 		for (i = 0; i < len; i++) {
 			if (((uint8_t*)addr)[i]!=data[i]) {
 				TRACE_ERROR("DFU download flash data written not correct\n\r");
-				return DFU_RET_STALL;
+				rc = DFU_RET_STALL;
+				break;
 			}
 		}
-		rc = FLASHD_Lock(addr, addr + len, 0, 0);
-		if (rc != 0) {
-			TRACE_ERROR("DFU download flash lock failed\n\r");
-			/* FIXME: set error codes */
-			return DFU_RET_STALL;
-		}
-		return DFU_RET_ZLP;
+		rc = DFU_RET_ZLP;
+		break;
 	default:
-		/* FIXME: set error codes */
 		TRACE_ERROR("DFU download for unknown AltIf %d\n\r", altif);
-		return DFU_RET_STALL;
+		rc = DFU_RET_STALL;
+		break;
 	}
+
+#ifdef PINS_LEDS
+	PIO_Set(&pinsLeds[LED_NUM_RED]);
+#endif
+
+	return rc;
 }
 
 /* incoming call-back: Host has requested to read back 'req_len' bytes
@@ -187,17 +202,18 @@
 	unsigned int i = 0;
 	uint32_t reset_cause = (RSTC->RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos;
 
-#if 0
-	led_init();
-	led_blink(LED_GREEN, BLINK_3O_30F);
-	led_blink(LED_RED, BLINK_3O_30F);
-#endif
-
 	/* Enable watchdog for 2000ms, with no window */
 	WDT_Enable(WDT, WDT_MR_WDRSTEN | WDT_MR_WDDBGHLT | WDT_MR_WDIDLEHLT |
 		   (WDT_GetPeriod(2000) << 16) | WDT_GetPeriod(2000));
 	watchdog_configured = true;
 
+#ifdef PINS_LEDS
+	/* Configure LED */
+	PIO_Configure(pinsLeds, sizeof(pinsLeds));
+	PIO_Set(&pinsLeds[LED_NUM_RED]);
+	PIO_Clear(&pinsLeds[LED_NUM_GREEN]);
+#endif
+
 	PIO_InitializeInterrupts(0);
 
 	EEFC_ReadUniqueID(g_unique_id);

-- 
To view, visit https://gerrit.osmocom.org/9862
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e34fd869ed94ad122d6a17f5a432f5a09b820bb
Gerrit-Change-Number: 9862
Gerrit-PatchSet: 1
Gerrit-Owner: Kévin Redon <kredon at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180704/f7f1e5d2/attachment.htm>


More information about the gerrit-log mailing list