Skip to content

Commit a9fe912

Browse files
authored
Merge pull request #8 from arduino/new_targets_preps
Cleanup/Refactor and prepera project for new targets
2 parents 6afa709 + 9f42fa2 commit a9fe912

12 files changed

+403
-265
lines changed

app/board.h

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,10 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19-
#ifndef __TARGET_INIT_H
20-
#define __TARGET_INIT_H
21-
22-
#include "stm32h7xx_hal.h"
23-
#include "stm32h7xx_hal_mdma.h"
24-
#include "stm32h7xx_hal_qspi.h"
25-
#if MCUBOOT_APPLICATION_DFU
26-
#include "usbd_core.h"
27-
#include "usbd_desc.h"
28-
#include "usbd_dfu.h"
29-
#include "usbd_dfu_flash.h"
30-
#endif
19+
#ifndef __BOARD_H
20+
#define __BOARD_H
3121

32-
#if MCUBOOT_APPLICATION_DFU
33-
#define APP_DEFAULT_ADD USBD_DFU_APP_DEFAULT_ADD
34-
#else
35-
#define APP_DEFAULT_ADD 0x08040000
36-
#endif
22+
#define BOARD_APP_DEFAULT_ADD 0x08040000
3723

3824
#define BOOTLOADER_CONFIG_MAGIC 0xA0
3925
#define BOOTLOADER_VERSION 4
@@ -77,10 +63,76 @@
7763
#define BOARD_EXTCLOCK 25
7864
#endif
7965

80-
int target_debug_init(void);
81-
int target_loop(void);
82-
int target_debug(void);
83-
int target_led_off(void);
84-
int target_empty_keys(void);
66+
#define BOARD_GREEN_LED PK_6
67+
#define BOARD_RED_LED PK_5
68+
#define BOARD_BLUE_LED PK_7
69+
70+
#define BOARD_BOOT_SEL PI_8
71+
#define BOARD_USB_RESET PJ_4
72+
73+
#ifdef BOARD_HAS_VIDEO
74+
#define BOARD_VIDEO_ENABLE PJ_2
75+
#define BOARD_VIDEO_RESET PJ_3
76+
#endif
8577

86-
#endif /* __TARGET_INIT_H */
78+
#define BOARD_I2C_SCL PB_6
79+
#define BOARD_I2C_SDA PB_7
80+
81+
#define BOARD_USBD_VID 0x2341
82+
#define BOARD_USBD_PID 0x035B
83+
84+
#define BOARD_USBD_STRING "Portenta H7 MCUboot"
85+
86+
#define BOARD_QSPI_SO0 PD_11
87+
#define BOARD_QSPI_SO1 PD_12
88+
#define BOARD_QSPI_SO2 PF_7
89+
#define BOARD_QSPI_SO3 PD_13
90+
#define BOARD_QSPI_SCK PF_10
91+
#define BOARD_QSPI_CS PG_6
92+
93+
#define BOARD_USB_OTG_FS_DM_DP_PIN (GPIO_PIN_11 | GPIO_PIN_12)
94+
#define BOARD_USB_OTG_FS_DM_DP_MODE (GPIO_MODE_AF_PP)
95+
#define BOARD_USB_OTG_FS_DM_DP_PULL (GPIO_NOPULL)
96+
#define BOARD_USB_OTG_FS_DM_DP_SPEED (GPIO_SPEED_FREQ_VERY_HIGH)
97+
#define BOARD_USB_OTG_FS_DM_DP_ALTERNATE (GPIO_AF10_OTG1_FS)
98+
#define BOARD_USB_OTG_FS_DM_DP_GPIO (GPIOA)
99+
100+
#define BOARD_USB_OTG_HS_CLK_PIN (GPIO_PIN_5)
101+
#define BOARD_USB_OTG_HS_CLK_MODE (GPIO_MODE_AF_PP)
102+
#define BOARD_USB_OTG_HS_CLK_PULL (GPIO_NOPULL)
103+
#define BOARD_USB_OTG_HS_CLK_SPEED (GPIO_SPEED_FREQ_VERY_HIGH)
104+
#define BOARD_USB_OTG_HS_CLK_ALTERNATE (GPIO_AF10_OTG2_HS)
105+
#define BOARD_USB_OTG_HS_CLK_GPIO (GPIOA)
106+
107+
#define BOARD_USB_OTG_HS_D0_PIN (GPIO_PIN_3)
108+
#define BOARD_USB_OTG_HS_D0_MODE (GPIO_MODE_AF_PP)
109+
#define BOARD_USB_OTG_HS_D0_PULL (GPIO_NOPULL)
110+
#define BOARD_USB_OTG_HS_D0_SPEED (GPIO_SPEED_FREQ_VERY_HIGH)
111+
#define BOARD_USB_OTG_HS_D0_ALTERNATE (GPIO_AF10_OTG2_HS)
112+
#define BOARD_USB_OTG_HS_D0_GPIO (GPIOA)
113+
114+
#define BOARD_USB_OTG_HS_D1_D7_PIN (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13)
115+
#define BOARD_USB_OTG_HS_D1_D7_MODE (GPIO_MODE_AF_PP)
116+
#define BOARD_USB_OTG_HS_D1_D7_PULL (GPIO_NOPULL)
117+
#define BOARD_USB_OTG_HS_D1_D7_ALTERNATE (GPIO_AF10_OTG2_HS)
118+
#define BOARD_USB_OTG_HS_D1_D7_GPIO (GPIOB)
119+
120+
#define BOARD_USB_OTG_HS_STP_PIN (GPIO_PIN_0)
121+
#define BOARD_USB_OTG_HS_STP_MODE (GPIO_MODE_AF_PP)
122+
#define BOARD_USB_OTG_HS_STP_PULL (GPIO_NOPULL)
123+
#define BOARD_USB_OTG_HS_STP_ALTERNATE (GPIO_AF10_OTG2_HS)
124+
#define BOARD_USB_OTG_HS_STP_GPIO (GPIOC)
125+
126+
#define BOARD_USB_OTG_HS_NXT_PIN (GPIO_PIN_4)
127+
#define BOARD_USB_OTG_HS_NXT_MODE (GPIO_MODE_AF_PP)
128+
#define BOARD_USB_OTG_HS_NXT_PULL (GPIO_NOPULL)
129+
#define BOARD_USB_OTG_HS_NXT_ALTERNATE (GPIO_AF10_OTG2_HS)
130+
#define BOARD_USB_OTG_HS_NXT_GPIO (GPIOH)
131+
132+
#define BOARD_USB_OTG_HS_DIR_PIN (GPIO_PIN_11)
133+
#define BOARD_USB_OTG_HS_DIR_MODE (GPIO_MODE_AF_PP)
134+
#define BOARD_USB_OTG_HS_DIR_PULL (GPIO_NOPULL)
135+
#define BOARD_USB_OTG_HS_DIR_ALTERNATE (GPIO_AF10_OTG2_HS)
136+
#define BOARD_USB_OTG_HS_DIR_GPIO (GPIOI)
137+
138+
#endif /* __BOARD_H */

app/bootutil/bootutil_extra.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,21 @@ int boot_set_debug(int enable) {
3131

3232
return RTCSetBKPRegister(RTC_BKP_DR7, rtc_reg);
3333
}
34+
35+
int boot_empty_keys() {
36+
unsigned int i;
37+
uint8_t* encript_key = (uint8_t*)(0x08000300);
38+
uint8_t* signing_key = (uint8_t*)(0x08000400);
39+
40+
for(i = 0; i < 256; i++) {
41+
if(encript_key[i] != 0xFF)
42+
return 0;
43+
}
44+
45+
for(i = 0; i < 256; i++) {
46+
if(signing_key[i] != 0xFF)
47+
return 0;
48+
}
49+
50+
return 1;
51+
}

app/bootutil/bootutil_extra.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@
2121

2222
int boot_set_debug(int enable);
2323

24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
int boot_empty_keys();
29+
30+
#ifdef __cplusplus
31+
}
32+
#endif
33+
2434
#endif //__BOOTUTIL_EXTRA_H

app/default_bd.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "ota.h"
2222
#include "rtc.h"
2323
#include "board.h"
24+
#include "bootutil/bootutil_extra.h"
2425
#include "bootutil/bootutil_log.h"
2526

2627
#include "SlicingBlockDevice.h"
@@ -362,7 +363,7 @@ static void initBlockTable(void) {
362363

363364
mbed::BlockDevice* get_secondary_bd(void) {
364365

365-
if(!target_empty_keys()) {
366+
if(!boot_empty_keys()) {
366367
if(!BlockTableLoaded) {
367368
initBlockTable();
368369
BlockTableLoaded = true;
@@ -379,7 +380,7 @@ mbed::BlockDevice* get_secondary_bd(void) {
379380

380381
mbed::BlockDevice* get_scratch_bd(void) {
381382

382-
if(!target_empty_keys()) {
383+
if(!boot_empty_keys()) {
383384
if(!BlockTableLoaded) {
384385
initBlockTable();
385386
BlockTableLoaded = true;
@@ -396,7 +397,7 @@ mbed::BlockDevice* get_scratch_bd(void) {
396397

397398
mbed::BlockDevice* BlockDevice::get_default_instance()
398399
{
399-
static QSPIFBlockDevice default_bd(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
400+
static QSPIFBlockDevice default_bd(BOARD_QSPI_SO0, BOARD_QSPI_SO1, BOARD_QSPI_SO2, BOARD_QSPI_SO3, BOARD_QSPI_SCK, BOARD_QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000);
400401
return &default_bd;
401402
}
402403

app/dfu/usbd_conf.c

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
/* Includes ------------------------------------------------------------------ */
2323
#include "board.h"
24+
#include "usbd_core.h"
25+
#include "usbd_desc.h"
26+
#include "usbd_conf.h"
2427

2528
/* Private typedef ----------------------------------------------------------- */
2629
/* Private define ------------------------------------------------------------ */
@@ -34,6 +37,10 @@ PCD_HandleTypeDef hpcd;
3437
/*******************************************************************************
3538
PCD BSP Routines
3639
*******************************************************************************/
40+
PCD_HandleTypeDef * HAL_PCD_GetHandle(void)
41+
{
42+
return &hpcd;
43+
}
3744

3845
/**
3946
* @brief Initializes the PCD MSP.
@@ -49,12 +56,12 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef * hpcd)
4956
__HAL_RCC_GPIOA_CLK_ENABLE();
5057

5158
/* Configure DM DP Pins */
52-
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
53-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
54-
GPIO_InitStruct.Pull = GPIO_NOPULL;
55-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
56-
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
57-
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
59+
GPIO_InitStruct.Pin = BOARD_USB_OTG_FS_DM_DP_PIN;
60+
GPIO_InitStruct.Mode = BOARD_USB_OTG_FS_DM_DP_MODE;
61+
GPIO_InitStruct.Pull = BOARD_USB_OTG_FS_DM_DP_PULL;
62+
GPIO_InitStruct.Speed = BOARD_USB_OTG_FS_DM_DP_SPEED;
63+
GPIO_InitStruct.Alternate = BOARD_USB_OTG_FS_DM_DP_ALTERNATE;
64+
HAL_GPIO_Init(BOARD_USB_OTG_FS_DM_DP_GPIO, &GPIO_InitStruct);
5865

5966
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
6067

@@ -103,49 +110,48 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef * hpcd)
103110
__GPIOI_CLK_ENABLE();
104111

105112
/* CLK */
106-
GPIO_InitStruct.Pin = GPIO_PIN_5;
107-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
108-
GPIO_InitStruct.Pull = GPIO_NOPULL;
109-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
110-
GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS;
111-
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
113+
GPIO_InitStruct.Pin = BOARD_USB_OTG_HS_CLK_PIN;
114+
GPIO_InitStruct.Mode = BOARD_USB_OTG_HS_CLK_MODE;
115+
GPIO_InitStruct.Pull = BOARD_USB_OTG_HS_CLK_PULL;
116+
GPIO_InitStruct.Speed = BOARD_USB_OTG_HS_CLK_SPEED;
117+
GPIO_InitStruct.Alternate = BOARD_USB_OTG_HS_CLK_ALTERNATE;
118+
HAL_GPIO_Init(BOARD_USB_OTG_HS_CLK_GPIO, &GPIO_InitStruct);
112119

113120
/* D0 */
114-
GPIO_InitStruct.Pin = GPIO_PIN_3;
115-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
116-
GPIO_InitStruct.Pull = GPIO_NOPULL;
117-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
118-
GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS;
119-
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
121+
GPIO_InitStruct.Pin = BOARD_USB_OTG_HS_D0_PIN;
122+
GPIO_InitStruct.Mode = BOARD_USB_OTG_HS_D0_MODE;
123+
GPIO_InitStruct.Pull = BOARD_USB_OTG_HS_D0_PULL;
124+
GPIO_InitStruct.Speed = BOARD_USB_OTG_HS_D0_SPEED;
125+
GPIO_InitStruct.Alternate = BOARD_USB_OTG_HS_D0_ALTERNATE;
126+
HAL_GPIO_Init(BOARD_USB_OTG_HS_D0_GPIO, &GPIO_InitStruct);
120127

121128
/* D1 D2 D3 D4 D5 D6 D7 */
122-
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 |
123-
GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
124-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
125-
GPIO_InitStruct.Pull = GPIO_NOPULL;
126-
GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS;
127-
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
129+
GPIO_InitStruct.Pin = BOARD_USB_OTG_HS_D1_D7_PIN;
130+
GPIO_InitStruct.Mode = BOARD_USB_OTG_HS_D1_D7_MODE;
131+
GPIO_InitStruct.Pull = BOARD_USB_OTG_HS_D1_D7_PULL;
132+
GPIO_InitStruct.Alternate = BOARD_USB_OTG_HS_D1_D7_ALTERNATE;
133+
HAL_GPIO_Init(BOARD_USB_OTG_HS_D1_D7_GPIO, &GPIO_InitStruct);
128134

129135
/* STP */
130-
GPIO_InitStruct.Pin = GPIO_PIN_0;
131-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
132-
GPIO_InitStruct.Pull = GPIO_NOPULL;
133-
GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS;
134-
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
136+
GPIO_InitStruct.Pin = BOARD_USB_OTG_HS_STP_PIN;
137+
GPIO_InitStruct.Mode = BOARD_USB_OTG_HS_STP_MODE;
138+
GPIO_InitStruct.Pull = BOARD_USB_OTG_HS_STP_PULL;
139+
GPIO_InitStruct.Alternate = BOARD_USB_OTG_HS_STP_ALTERNATE;
140+
HAL_GPIO_Init(BOARD_USB_OTG_HS_STP_GPIO, &GPIO_InitStruct);
135141

136142
/* NXT */
137-
GPIO_InitStruct.Pin = GPIO_PIN_4;
138-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
139-
GPIO_InitStruct.Pull = GPIO_NOPULL;
140-
GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS;
141-
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
143+
GPIO_InitStruct.Pin = BOARD_USB_OTG_HS_NXT_PIN;
144+
GPIO_InitStruct.Mode = BOARD_USB_OTG_HS_NXT_MODE;
145+
GPIO_InitStruct.Pull = BOARD_USB_OTG_HS_NXT_PULL;
146+
GPIO_InitStruct.Alternate = BOARD_USB_OTG_HS_NXT_ALTERNATE;
147+
HAL_GPIO_Init(BOARD_USB_OTG_HS_NXT_GPIO, &GPIO_InitStruct);
142148

143149
/* DIR */
144-
GPIO_InitStruct.Pin = GPIO_PIN_11;
145-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
146-
GPIO_InitStruct.Pull = GPIO_NOPULL;
147-
GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS;
148-
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
150+
GPIO_InitStruct.Pin = BOARD_USB_OTG_HS_DIR_PIN;
151+
GPIO_InitStruct.Mode = BOARD_USB_OTG_HS_DIR_MODE;
152+
GPIO_InitStruct.Pull = BOARD_USB_OTG_HS_DIR_PULL;
153+
GPIO_InitStruct.Alternate = BOARD_USB_OTG_HS_DIR_ALTERNATE;
154+
HAL_GPIO_Init(BOARD_USB_OTG_HS_DIR_GPIO, &GPIO_InitStruct);
149155
__HAL_RCC_USB1_OTG_HS_ULPI_CLK_ENABLE();
150156

151157
/* Enable USB HS Clocks */

app/dfu/usbd_conf.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define __USBD_CONF_H
2323

2424
/* Includes ------------------------------------------------------------------*/
25+
#include "board.h"
2526
#include "stm32h7xx_hal.h"
2627
#include <stdio.h>
2728
#include <stdlib.h>
@@ -40,7 +41,7 @@
4041
/* DFU Class Config */
4142
#define USBD_DFU_MAX_ITF_NUM 4
4243
#define USBD_DFU_XFER_SIZE 4096 /* Max DFU Packet Size = 4096 bytes */
43-
#define USBD_DFU_APP_DEFAULT_ADD 0x08040000 /* The first sector (32 KB) is reserved for DFU code */
44+
#define USBD_DFU_APP_DEFAULT_ADD BOARD_APP_DEFAULT_ADD /* The first sector (32 KB) is reserved for DFU code */
4445
#define USBD_DFU_MAX_NB_OF_SECTORS 16 /* Max number of sectors */
4546

4647
#define CDC_CLASS_DESC_SIZE (8 + 58)
@@ -80,6 +81,7 @@
8081
#endif
8182

8283
/* Exported functions ------------------------------------------------------- */
84+
extern PCD_HandleTypeDef * HAL_PCD_GetHandle(void);
8385

8486
#endif /* __USBD_CONF_H */
8587

app/dfu/usbd_desc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@
2020
#if MCUBOOT_APPLICATION_HOOKS && MCUBOOT_APPLICATION_DFU
2121

2222
/* Includes ------------------------------------------------------------------ */
23+
#include "board.h"
2324
#include "usbd_core.h"
2425
#include "usbd_desc.h"
2526
#include "usbd_conf.h"
2627

2728
/* Private typedef ----------------------------------------------------------- */
2829
/* Private define ------------------------------------------------------------ */
29-
#define USBD_VID 0x2341
30-
#define USBD_PID 0x035B
30+
#define USBD_VID BOARD_USBD_VID
31+
#define USBD_PID BOARD_USBD_PID
3132
#define USBD_LANGID_STRING 0x409
3233
#define USBD_MANUFACTURER_STRING "Arduino SA"
33-
#define USBD_PRODUCT_HS_STRING "Portenta MCUBoot"
34-
#define USBD_PRODUCT_FS_STRING "Portenta MCUBoot"
34+
#define USBD_PRODUCT_HS_STRING BOARD_USBD_STRING
35+
#define USBD_PRODUCT_FS_STRING BOARD_USBD_STRING
3536
#define USBD_CONFIGURATION_HS_STRING "DFU Config"
3637
#define USBD_INTERFACE_HS_STRING "DFU Interface"
3738
#define USBD_CONFIGURATION_FS_STRING "DFU Config"

app/dfu/usbd_dfu_flash.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extern USBD_DFU_MediaTypeDef USBD_DFU_Flash_fops;
5353
#define FLASH_END_ADDR (uint32_t)(0x081FFFFF)
5454

5555
/* Exported functions ------------------------------------------------------- */
56+
extern void init_Memories(void);
5657

5758
#endif /* __USBD_DFU_FLASH_H_ */
5859

0 commit comments

Comments
 (0)