Skip to content

Commit 04105b2

Browse files
authored
Merge pull request #52 from bcmi-labs/conf_debug
Serial debug and LED feedback improvements
2 parents d08b797 + 162bde0 commit 04105b2

File tree

4 files changed

+110
-56
lines changed

4 files changed

+110
-56
lines changed

app/target.cpp

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -51,52 +51,19 @@ volatile uint8_t ledTargetValue = 20;
5151
volatile int8_t ledDirection = 1;
5252
volatile int divisor = 0;
5353

54+
DigitalOut red(PK_5, 1);
5455
DigitalOut green(PK_6, 1);
5556
DigitalOut blue(PK_7, 1);
5657

58+
DigitalIn boot_sel(PI_8,PullDown);
59+
5760
Ticker swap_ticker;
58-
int mcuboot_swap_index = -1;
5961

60-
static inline void swap_feedback() {
62+
bool debug_enabled = false;
6163

62-
static int blink_idx = 0;
63-
static int blink_state = 0;
64-
65-
if(mcuboot_swap_index >= 0){
66-
switch(blink_state) {
67-
case 0: {
68-
if(blink_idx < mcuboot_swap_index) {
69-
if(blue == 0){
70-
blue = 1;
71-
} else {
72-
blue = 0;
73-
blink_idx++;
74-
}
75-
} else {
76-
blink_idx = 0;
77-
blink_state = 1;
78-
}
79-
green = 1;
80-
}
81-
break;
82-
83-
case 1: {
84-
if(blink_idx < (15 - mcuboot_swap_index)) {
85-
if(green == 0){
86-
green = 1;
87-
} else {
88-
green = 0;
89-
blink_idx++;
90-
}
91-
} else {
92-
blink_idx = 0;
93-
blink_state = 0;
94-
}
95-
blue = 1;
96-
}
97-
break;
98-
}
99-
}
64+
static inline void swap_feedback() {
65+
blue = !blue;
66+
red = !red;
10067
}
10168

10269
static inline void LED_pulse(DigitalOut* led)
@@ -137,7 +104,6 @@ static bool valid_application() {
137104

138105
}
139106

140-
141107
static bool empty_keys() {
142108
unsigned int i;
143109
extern const unsigned char enc_priv_key[];
@@ -158,20 +124,29 @@ static bool empty_keys() {
158124
return true;
159125
}
160126

127+
int target_debug_init(void) {
128+
RTCInit();
129+
debug_enabled = ((RTCGetBKPRegister(RTC_BKP_DR7) & 0x00000001) || boot_sel);
130+
return 0;
131+
}
132+
133+
int target_led_off(void) {
134+
swap_ticker.detach();
135+
red = 1;
136+
green = 1;
137+
blue = 1;
138+
return 0;
139+
}
161140

162141
int target_init(void) {
163-
DigitalIn boot_sel(PI_8,PullDown);
164-
165142
int magic = RTCGetBKPRegister(RTC_BKP_DR0);
166-
BOOT_LOG_DBG("Envie magic 0x%x", magic);
167143

168144
// in case we have been reset let's wait 500 ms to see if user is trying to stay in bootloader
169145
if (ResetReason::get() == RESET_REASON_PIN_RESET) {
170146
// now that we've been reset let's set magic. resetting with this set will
171147
// flag we need to stay in bootloader.
172148
RTCSetBKPRegister(RTC_BKP_DR0, 0xDF59);
173149
HAL_Delay(500);
174-
BOOT_LOG_DBG("Envie magic set 0x%x", RTCGetBKPRegister( RTC_BKP_DR0));
175150
}
176151

177152
DigitalOut usb_reset(PJ_4, 0);
@@ -263,25 +238,19 @@ int target_init(void) {
263238

264239
HAL_Delay(10);
265240

266-
if (magic != 0xDF59 && magic != 0x07AA && boot_sel==0) {
241+
if (magic != 0xDF59 && magic != 0x07AA) {
267242
RTCSetBKPRegister(RTC_BKP_DR0, 0);
268243
HAL_FLASH_Lock();
269244
if(valid_application() && empty_keys()) {
270-
BOOT_LOG_INF("MCUBoot not configured, but valid image found.");
245+
BOOT_LOG_INF("MCUboot not configured, but valid image found.");
271246
BOOT_LOG_INF("Booting firmware image at 0x%x\n", USBD_DFU_APP_DEFAULT_ADD);
272247
mbed_start_application(USBD_DFU_APP_DEFAULT_ADD);
273248
}
274-
BOOT_LOG_DBG("Envie app magic 0x%x", RTCGetBKPRegister(RTC_BKP_DR0));
275249
swap_ticker.attach(&swap_feedback, 250ms);
276250
return 0;
277251

278252
} else {
279-
BOOT_LOG_DBG("Envie loop magic 0x%x", RTCGetBKPRegister(RTC_BKP_DR0));
280-
if(boot_sel) {
281-
return 1;
282-
} else {
283-
return 2;
284-
}
253+
return 1;
285254
}
286255
}
287256

@@ -301,6 +270,8 @@ int target_loop(void) {
301270
SetSysClock_PLL_HSE(1, false);
302271
SystemCoreClockUpdate();
303272

273+
target_led_off();
274+
304275
//turnDownEthernet();
305276

306277
#if MCUBOOT_APPLICATION_DFU

app/target.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@
7171
#define BOARD_EXTCLOCK 25
7272
#endif
7373

74-
int target_init(void);
74+
int target_debug_init(void);
7575
int target_loop(void);
76+
int target_debug(void);
77+
int target_led_off(void);
7678

7779
#endif /* __TARGET_INIT_H */

generate_lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
rm -rf BUILD/PORTENTA_H7_M7/GCC_ARM/
3-
mbed compile -m PORTENTA_H7_M7 -t GCC_ARM
3+
mbed compile -m PORTENTA_H7_M7 -t GCC_ARM --app=mbed_app_log_off.json
44
cd BUILD/PORTENTA_H7_M7/GCC_ARM/
55
rm -rf mbed-os/
66
find . -name "*.o" | xargs arm-none-eabi-ar -csr libbootutil.a

mbed_app_log_off.json

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"requires": ["bare-metal", "mbedtls", "mcuboot", "flashiap-block-device", "spif-driver", "qspif", "mbed-trace", "filesystem", "fat_chan", "littlefs", "rtos", "cmsis-cmsis5-rtos2", "events"],
3+
"macros": ["MBED_FAULT_HANDLER_DISABLED", "USE_USB_HS", "LOWSPEED=1", "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\""],
4+
"config": {
5+
"serial-bootloader-enable": {
6+
"help": "Build bootloader with serial update support",
7+
"value": 0
8+
}
9+
},
10+
"target_overrides": {
11+
"*": {
12+
"target.restrict_size": "0x20000",
13+
"target.c_lib": "small",
14+
"mcuboot.log-level": "MCUBOOT_LOG_LEVEL_OFF",
15+
"mbed-trace.enable": false,
16+
"mbed-trace.fea-ipv6": false
17+
},
18+
"NRF52840_DK": {
19+
"target.features_remove": ["CRYPTOCELL310"],
20+
"target.macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"],
21+
"mcuboot.primary-slot-address": "0x20000",
22+
"mcuboot.slot-size": "0xC0000",
23+
"mcuboot.scratch-address": "0xE0000",
24+
"mcuboot.scratch-size": "0x20000",
25+
"mcuboot.max-img-sectors": "0x180",
26+
"mcuboot.read-granularity": 4,
27+
"qspif.QSPI_MIN_PROG_SIZE": 4
28+
},
29+
"EP_AGORA": {
30+
"target.features_remove": ["CRYPTOCELL310"],
31+
"target.macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"],
32+
"mcuboot.primary-slot-address": "0x20000",
33+
"mcuboot.slot-size": "0xC0000",
34+
"mcuboot.scratch-address": "0xE0000",
35+
"mcuboot.scratch-size": "0x20000",
36+
"mcuboot.max-img-sectors": "0x180",
37+
"mcuboot.read-granularity": 4,
38+
"qspif.QSPI_MIN_PROG_SIZE": 4
39+
},
40+
"DISCO_L475VG_IOT01A": {
41+
"mcuboot.primary-slot-address": "0x8020000",
42+
"mcuboot.slot-size": "0xC0000",
43+
"mcuboot.scratch-address": "0x80E0000",
44+
"mcuboot.scratch-size": "0x20000",
45+
"mcuboot.max-img-sectors": "0x180",
46+
"mcuboot.read-granularity": 1,
47+
"qspif.QSPI_MIN_PROG_SIZE": 1
48+
},
49+
"PORTENTA_H7_M7": {
50+
"target.clock_source": "USE_PLL_HSE_EXTC",
51+
"target.use-mpu": false,
52+
"target.components_remove" : ["WHD", "4343W_FS", "CYW43XXX"],
53+
"target.extra_labels_remove" : ["CORDIO"],
54+
"target.features_remove" : ["BLE"],
55+
"target.device_has_remove": ["USBDEVICE", "EMAC", "CAN", "SPI_ASYNCH", "SPISLAVE", "SPI","SERIAL_FC", "PWMOUT", "ANALOGIN", "ANALOGOUT", "I2CSLAVE", "I2C_ASYNC", "OSPI", "TRNG", "DAC", "CRC", "WATCHDOG", "RTC", "LPTICKER", "SLEEP"],
56+
"target.printf_lib": "minimal-printf",
57+
"target.i2c_timing_value_algo": false,
58+
"platform.minimal-printf-enable-floating-point": false,
59+
"platform.minimal-printf-enable-64-bit": false,
60+
"platform.stdio-flush-at-exit": false,
61+
"platform.stdio-baud-rate": 115200,
62+
"fat_chan.ff_use_mkfs": 0,
63+
"fat_chan.ff_use_lfn": 0,
64+
"fat_chan.ff_fs_rpath": 0,
65+
"mcuboot.primary-slot-address": "0x8020000",
66+
"mcuboot.slot-size": "0x1E0000",
67+
"mcuboot.scratch-address": "0x9000000",
68+
"mcuboot.scratch-size": "0x20000",
69+
"mcuboot.max-img-sectors": "0x3C0",
70+
"mcuboot.max-align": 32,
71+
"mcuboot.bootstrap": true,
72+
"mcuboot.application-hooks": true,
73+
"mcuboot.application-littlefs": true,
74+
"mcuboot.application-sdcard": null,
75+
"mcuboot.application-dfu": true,
76+
"mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
77+
"mcuboot.encrypt-ec256": true,
78+
"mcuboot.include-keys": null
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)