├── .gitignore
├── .mbedignore
├── README.md
├── app
├── board.h
├── bootutil
│ ├── bootutil_extra.c
│ └── bootutil_extra.h
├── default_bd.cpp
├── dfu
│ ├── STM32_USB_Device_Library
│ │ ├── Class
│ │ │ ├── DFU
│ │ │ │ ├── Inc
│ │ │ │ │ ├── usbd_dfu.h
│ │ │ │ │ └── usbd_dfu_media_template.h
│ │ │ │ └── Src
│ │ │ │ │ ├── usbd_dfu.cpp
│ │ │ │ │ └── usbd_dfu_media_template.c
│ │ │ └── Template
│ │ │ │ ├── Inc
│ │ │ │ └── usbd_template.h
│ │ │ │ └── Src
│ │ │ │ └── usbd_template.c
│ │ ├── Core
│ │ │ ├── Inc
│ │ │ │ ├── usbd_conf_template.h
│ │ │ │ ├── usbd_core.h
│ │ │ │ ├── usbd_ctlreq.h
│ │ │ │ ├── usbd_def.h
│ │ │ │ └── usbd_ioreq.h
│ │ │ └── Src
│ │ │ │ ├── usbd_core.c
│ │ │ │ ├── usbd_ctlreq.c
│ │ │ │ └── usbd_ioreq.c
│ │ └── Release_Notes.html
│ ├── usbd_conf.c
│ ├── usbd_conf.h
│ ├── usbd_desc.c
│ ├── usbd_desc.h
│ ├── usbd_dfu_flash.cpp
│ └── usbd_dfu_flash.h
├── fileblockdevice
│ ├── FileBlockDevice.cpp
│ └── FileBlockDevice.h
├── keys
│ ├── ecdsa-p256-encrypt-key.c
│ ├── ecdsa-p256-encrypt-key.pem
│ ├── ecdsa-p256-signing-key.c
│ └── ecdsa-p256-signing-key.pem
├── main.cpp
├── ota
│ ├── ota.cpp
│ └── ota.h
├── power
│ ├── power.cpp
│ └── power.h
├── rtc
│ ├── rtc.c
│ └── rtc.h
└── sdcard
│ ├── BSP.c
│ ├── BSP.h
│ ├── SDMMCBlockDevice.cpp
│ └── SDMMCBlockDevice.h
├── assets
└── current-layout.png
├── custom.json
├── generate_rel.sh
├── mbed-os.lib
├── mbed_app.json
├── mbed_app_bootutil.json
├── mbed_app_giga.json
├── mbed_app_giga_wifi.json
├── mbed_app_nicla_vision.json
├── mbed_app_opta.json
├── mbed_app_portenta.json
├── mbed_app_portenta_lite.json
├── mbed_app_portenta_lite_connected.json
├── mbedtls_config.h
└── mcuboot.lib
/.gitignore:
--------------------------------------------------------------------------------
1 | /Debug/
2 | BUILD/
3 | .cproject
4 | *~
5 | .mbed
6 | .project
7 | .settings/
8 | GettingStarted.html
9 | makefile.targets
10 | mbed_settings.py
11 | mbed_settings.pyc
12 | mbed_config.h
13 | *.hex
14 | mbed-os/*
15 | mbed-os/
16 | mcuboot/*
17 |
--------------------------------------------------------------------------------
/.mbedignore:
--------------------------------------------------------------------------------
1 | Debug/*
2 | Release/*
3 | Develop/*
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | `MCUboot Arduino`
4 | =================
5 | MCUboot bootloader porting for Arduino [Mbed OS](https://os.mbed.com/docs/mbed-os/latest/introduction/index.html) based boards.
6 |
7 | The following boards are supported:
8 | * [Portenta H7](https://store.arduino.cc/products/portenta-h7)
9 | * [Portenta H7 Lite](https://store.arduino.cc/products/portenta-h7-lite)
10 | * [Portenta H7 Lite Connected](https://store.arduino.cc/products/portenta-h7-lite)
11 | * [Nicla Vision](https://store.arduino.cc/products/nicla-vision)
12 |
13 | ## :grey_question: What
14 | MCUboot provides secure boot for 32-bit microcontrollers. For a detailed description on what MCUboot does and how it works please read the [official documentaion](https://docs.mcuboot.com/).
15 |
16 | ## :zap: Main features
17 | ### Signed and encrypted updates
18 | MCUboot has support for encrypting/decrypting images on-the-fly while upgrading; furthermore, before booting a Sketch, it will check if the computed signature is matching the one embedded in the image.
19 |
20 | ### Confirm or revert updates
21 | After an update the new Sketch can update the content of the flash at runtime to mark itself as `OK`. MCUboot will then still choose to run it during the next boot. When this happens, the swap is made `permanent`. If this doesn’t happen, MCUboot will perform a `revert` swap during the next boot by swapping the image back into its original location, and attempting to boot the old Sketch.
22 |
23 | ### Sketch bootstrap
24 | If no valid image is found in the primary slot MCUboot will search a valid image in the secondary slot and if any it will load it inside the primary slot.
25 |
26 | ### Reset recovery
27 | If a reset occurs in the middle of a swap operation, the two images may be discontiguous in flash. MCUboot recovers from this condition by using the image trailers to determine how the image parts are distributed in flash and restarting the swap.
28 |
29 | ### Backward compatible with default Arduino booloader
30 | If signing and encryption keys are not stored in flash alongside MCUboot, the Sketch signature verification is skipped and any valid Sketch can be booted.
31 |
32 | ## :gear: How
33 | ### Switch to MCUboot
34 | * Run this [Sketch](https://github.com/arduino/ArduinoCore-mbed/blob/master/libraries/STM32H747_System/examples/STM32H747_manageBootloader/STM32H747_manageBootloader.ino) to upload the latest released binary into your board
35 | * Flash the bootloader binary file with your preferred debugger @ flash address `0x08000000`
36 |
37 | ### Enable signature and encryption
38 | By default signature verification and encryption support are disabled. To enable them you have to write your signature and encryption keys inside your board.
39 | In this project MCUboot is configured to support `ecdsa-p256` keys for both signature and encryption.
40 |
41 | To write the default keys in flash you can use this [Sketch](https://github.com/arduino/ArduinoCore-mbed/blob/main/libraries/MCUboot/examples/enableSecurity/enableSecurity.ino)
42 |
43 | :warning: WARNING :warning: The default keys are public therefore is not safe to use them for production, they are included only for evaluation purpose.
44 |
45 | ### Customize signing and encryption keys
46 | You can use your preferred tool the generate your `ecdsa-p256` keys. With imgtool:
47 | ```
48 | imgtool keygen -k ecdsa-p256-signing-priv-key.pem -t ecdsa-p256
49 | imgtool keygen -k ecdsa-p256-encrypt-priv-key.pem -t ecdsa-p256
50 | ```
51 | The public signing key and the private encryption key have to be written in flash at this addresses:
52 | ```
53 | signing key @ 0x8000300
54 | encrypt key @ 0x8000400
55 | ```
56 | To get this data from the generated pem files with imgtool:
57 | ```
58 | imgtool getpub -k ecdsa-p256-signing-priv-key.pem > ecdsa-p256-signing-pub-key.h
59 | imgtool getpriv -k ecdsa-p256-encrypt-priv-key.pem > ecdsa-p256-encrypt-priv-key.h
60 | ```
61 | Copy and paste the key data in this [Sketch](https://github.com/arduino/ArduinoCore-mbed/blob/master/libraries/STM32H747_System/examples/STM32H747_manageBootloader/STM32H747_manageBootloader.ino) and run it to flash the keys alongside the bootloader.
62 |
63 | ### Substitute default keys for sketch generation
64 | By default the IDE uses the keys located in `{runtime.platform.path}/libraries/MCUboot/default_keys`
65 |
66 | To use your custom keys follow this steps:
67 | 1. Remove default keys
68 | ```
69 | cd {runtime.platform.path}/libraries/MCUboot/default_keys
70 | rm -f *.pem
71 | ```
72 | 2. Generate encryption public key
73 | ```
74 | openssl pkey -in ecdsa-p256-encrypt-priv-key.pem -pubout > ecdsa-p256-encrypt-pub-key.pem
75 | ```
76 | or
77 | ```
78 | ssh-keygen -e -f ecdsa-p256-encrypt-priv-key.pem -y -m "PEM" > ecdsa-p256-encrypt-pub-key.pem
79 | ```
80 | 3. Move keys in the MCUboot library folder
81 | ```
82 | mv ecsdsa-p256-signing-priv-key.pem `{runtime.platform.path}/libraries/MCUboot/default_keys/ecdsa-p256-signing-priv-key.pem`
83 | mv ecdsa-p256-encrypt-pub-key.pem `{runtime.platform.path}/libraries/MCUboot/default_keys/ecdsa-p256-encrypt-pub-key.pem`
84 | ```
85 | Alternatively you can customize your board.txt file following this [guide](https://arduino.github.io/arduino-cli/0.31/guides/secure-boot/)
86 |
87 | ### Manually create a signed and encrypted update Sketch
88 | To create a signed and encrypted Sketch an additional step is needed after the Sketch binary is generated. This additional step is done passing the binary through `imgtool`. The flags used by the board to create a secure Sketch are defined [here](https://github.com/arduino/ArduinoCore-mbed/blob/fa628e35011a92fb7e54fa6bfd9a69be33173bf8/boards.txt#L79-L86). The resulting command resembles as follows:
89 | ```
90 | imgtool sign --key ecdsa-p256-signing-priv-key.pem --encrypt ecdsa-p256-encrypt-pub-key.pem input.bin output.bin --align 32 --max-align 32 --version 1.2.3+4 --header-size 0x20000 --pad-header --slot-size 0x1E0000
91 | ```
92 |
93 | ### Load an update sketch
94 | The bootloader exposes a DFU interface that can be used to upload a sketch in the QSPI flash of the board as a file. The upload process ends setting the pending flag to the update binary file and resetting the board. After reset MCUboot takes care of applying the update.
95 | ```
96 | dfu-util --device 0x2341:0x035b -D update.ino.bin -a2 --dfuse-address=0xA0000000:leave
97 | ```
98 |
99 | ### Confirm an update sketch
100 | MCUboot expects that every update have to be confirmed otherwise it will revert to the previous running sketch as soon as the board is resetted. To confirm a sketch you have to call `MCUboot::confirmSketch()` in your `setup()`.
101 | ```
102 | void setup() {
103 | ...
104 |
105 | if(applicationSelfCheck() == OK) {
106 | MCUboot::confirmSketch()
107 | }
108 |
109 | ...
110 | }
111 | ```
112 |
113 | ### Flash is allocated
114 | The diagram below shows the default memory map configuration used for this project:
115 |
116 | ```
117 | INTERNAL FLASH QSPI FLASH
118 |
119 | Slot 0 Scratch
120 | 0x08020000 - 0x081FFFFF MBRBlockDevice partition 2 scratch.bin
121 | 0x08020000 header
122 | 0x08040000 Sketch Slot 1
123 | 0x081E0000 trailer MBRBlockDevice partition 2 update.bin
124 |
125 | Bootloader
126 | 0x08000000 - 0x0801FFF
127 | 0x080002F0 bootloader id
128 | 0x08000300 signing key
129 | 0x08000400 encrypt key
130 | 0x0801F000 board data
131 | ```
132 |
133 | ### Build MCUboot from source
134 | The following command will setup the mbed environment and clone the needed repositories before compile for Portenta H7.
135 |
136 | ```
137 | mbed config root . && mbed deploy
138 | mbed compile -m PORTENTA_H7_M7 -t GCC_ARM --profile=release --profile custom.json
139 | ```
140 | Additional flags are needed for [Lite](generate_rel.sh#L24), [Lite Connected](generate_rel.sh#L35) and [Nicla Vision](generate_rel.sh#L46) boards.
141 |
142 | ### Debug
143 |
144 | 1. LED
145 | - MCUboot operations: slot verify, copy, erase or swap the board LED will blink in violet (red+blue).
146 | - MCUboot idle: The board green LED will fade-in fade-out
147 |
148 | 2. Serial
149 | - MCUboot debug prints are disabled by default. They can be enabled putting `BT_SEL` (`PI8`) pin `HIGH` if available or calling `MCUboot::bootDebug(1);` in your Sketch.
150 |
151 | ## :mag_right: Other resources
152 |
153 | * [MCUboot repository](https://github.com/mcu-tools/mcuboot)
154 | * [MCUboot demo for nRF52840](https://github.com/AGlass0fMilk/mbed-mcuboot-demo)
155 | * [MCUboot documentation](https://docs.mcuboot.com/)
156 |
--------------------------------------------------------------------------------
/app/bootutil/bootutil_extra.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #include "bootutil_extra.h"
20 | #include "rtc.h"
21 |
22 | int boot_set_debug(int enable) {
23 | RTCInit();
24 | unsigned int rtc_reg = RTCGetBKPRegister(RTC_BKP_DR7);
25 |
26 | if(enable) {
27 | rtc_reg |= 0x00000001;
28 | } else {
29 | rtc_reg &= ~0x00000001;
30 | }
31 |
32 | return RTCSetBKPRegister(RTC_BKP_DR7, rtc_reg);
33 | }
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 | }
52 |
--------------------------------------------------------------------------------
/app/bootutil/bootutil_extra.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef __BOOTUTIL_EXTRA_H
20 | #define __BOOTUTIL_EXTRA_H
21 |
22 | int boot_set_debug(int enable);
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | int boot_empty_keys();
29 |
30 | #ifdef __cplusplus
31 | }
32 | #endif
33 |
34 | #endif //__BOOTUTIL_EXTRA_H
35 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_dfu.h
4 | * @author MCD Application Team
5 | * @brief Header file for the usbd_dfu.c file.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | *
© Copyright (c) 2015 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USB_DFU_H
22 | #define __USB_DFU_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_ioreq.h"
30 | #include "usbd_conf.h"
31 |
32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
33 | * @{
34 | */
35 |
36 | /** @defgroup USBD_DFU
37 | * @brief This file is the Header file for usbd_dfu.c
38 | * @{
39 | */
40 |
41 |
42 | /** @defgroup USBD_DFU_Exported_Defines
43 | * @{
44 | */
45 | #ifndef USBD_DFU_MAX_ITF_NUM
46 | #define USBD_DFU_MAX_ITF_NUM 1U
47 | #endif /* USBD_DFU_MAX_ITF_NUM */
48 |
49 | #ifndef USBD_DFU_XFER_SIZE
50 | #define USBD_DFU_XFER_SIZE 1024U
51 | #endif /* USBD_DFU_XFER_SIZE */
52 |
53 | #ifndef USBD_DFU_APP_DEFAULT_ADD
54 | #define USBD_DFU_APP_DEFAULT_ADD 0x08008000U /* The first sector (32 KB) is reserved for DFU code */
55 | #endif /* USBD_DFU_APP_DEFAULT_ADD */
56 |
57 | #define USB_DFU_CONFIG_DESC_SIZ (18U + (9U * USBD_DFU_MAX_ITF_NUM) + ARDUINO_BL_CDC_INTERFACE)
58 | #define USB_DFU_DESC_SIZ 9U
59 |
60 | #define DFU_DESCRIPTOR_TYPE 0x21U
61 |
62 |
63 | /**************************************************/
64 | /* DFU Requests DFU states */
65 | /**************************************************/
66 | #define APP_STATE_IDLE 0U
67 | #define APP_STATE_DETACH 1U
68 | #define DFU_STATE_IDLE 2U
69 | #define DFU_STATE_DNLOAD_SYNC 3U
70 | #define DFU_STATE_DNLOAD_BUSY 4U
71 | #define DFU_STATE_DNLOAD_IDLE 5U
72 | #define DFU_STATE_MANIFEST_SYNC 6U
73 | #define DFU_STATE_MANIFEST 7U
74 | #define DFU_STATE_MANIFEST_WAIT_RESET 8U
75 | #define DFU_STATE_UPLOAD_IDLE 9U
76 | #define DFU_STATE_ERROR 10U
77 |
78 | /**************************************************/
79 | /* DFU errors */
80 | /**************************************************/
81 | #define DFU_ERROR_NONE 0x00U
82 | #define DFU_ERROR_TARGET 0x01U
83 | #define DFU_ERROR_FILE 0x02U
84 | #define DFU_ERROR_WRITE 0x03U
85 | #define DFU_ERROR_ERASE 0x04U
86 | #define DFU_ERROR_CHECK_ERASED 0x05U
87 | #define DFU_ERROR_PROG 0x06U
88 | #define DFU_ERROR_VERIFY 0x07U
89 | #define DFU_ERROR_ADDRESS 0x08U
90 | #define DFU_ERROR_NOTDONE 0x09U
91 | #define DFU_ERROR_FIRMWARE 0x0AU
92 | #define DFU_ERROR_VENDOR 0x0BU
93 | #define DFU_ERROR_USB 0x0CU
94 | #define DFU_ERROR_POR 0x0DU
95 | #define DFU_ERROR_UNKNOWN 0x0EU
96 | #define DFU_ERROR_STALLEDPKT 0x0FU
97 |
98 | /**************************************************/
99 | /* DFU Manifestation State */
100 | /**************************************************/
101 | #define DFU_MANIFEST_COMPLETE 0x00U
102 | #define DFU_MANIFEST_IN_PROGRESS 0x01U
103 |
104 |
105 | /**************************************************/
106 | /* Special Commands with Download Request */
107 | /**************************************************/
108 | #define DFU_CMD_GETCOMMANDS 0x00U
109 | #define DFU_CMD_SETADDRESSPOINTER 0x21U
110 | #define DFU_CMD_ERASE 0x41U
111 |
112 | #define DFU_MEDIA_ERASE 0x00U
113 | #define DFU_MEDIA_PROGRAM 0x01U
114 |
115 | /**************************************************/
116 | /* Other defines */
117 | /**************************************************/
118 | /* Bit Detach capable = bit 3 in bmAttributes field */
119 | #define DFU_DETACH_MASK (uint8_t)(1 << 4)
120 | #define DFU_STATUS_DEPTH 6U
121 |
122 | typedef enum
123 | {
124 | DFU_DETACH = 0U,
125 | DFU_DNLOAD,
126 | DFU_UPLOAD,
127 | DFU_GETSTATUS,
128 | DFU_CLRSTATUS,
129 | DFU_GETSTATE,
130 | DFU_ABORT
131 | } DFU_RequestTypeDef;
132 |
133 | typedef void (*pFunction)(void);
134 |
135 |
136 | /********** Descriptor of DFU interface 0 Alternate setting n ****************/
137 | #define USBD_DFU_IF_DESC(n) 0x09, /* bLength: Interface Descriptor size */ \
138 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType */ \
139 | 0x00, /* bInterfaceNumber: Number of Interface */ \
140 | (n), /* bAlternateSetting: Alternate setting */ \
141 | 0x00, /* bNumEndpoints*/ \
142 | 0xFE, /* bInterfaceClass: Application Specific Class Code */ \
143 | 0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ \
144 | 0x02, /* nInterfaceProtocol: DFU mode protocol */ \
145 | USBD_IDX_INTERFACE_STR + (n) + 1U /* iInterface: Index of string descriptor */ \
146 |
147 | #define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), /* XFERSIZEB0 */\
148 | ((uint8_t)((size) >> 8)) /* XFERSIZEB1 */
149 |
150 | #define IS_PROTECTED_AREA(add) (uint8_t)((((add) >= 0x08000000) && ((add) < (APP_DEFAULT_ADD)))? 1:0)
151 |
152 | /**
153 | * @}
154 | */
155 |
156 |
157 | /** @defgroup USBD_CORE_Exported_TypesDefinitions
158 | * @{
159 | */
160 |
161 | typedef struct
162 | {
163 | union
164 | {
165 | uint32_t d32[USBD_DFU_XFER_SIZE / 4U];
166 | uint8_t d8[USBD_DFU_XFER_SIZE];
167 | } buffer;
168 |
169 | uint32_t wblock_num;
170 | uint32_t wlength;
171 | uint32_t data_ptr;
172 | uint32_t alt_setting;
173 |
174 | uint8_t dev_status[DFU_STATUS_DEPTH];
175 | uint8_t ReservedForAlign[2];
176 | uint8_t dev_state;
177 | uint8_t manif_state;
178 | }
179 | USBD_DFU_HandleTypeDef;
180 |
181 | typedef struct
182 | {
183 | const uint8_t *pStrDesc[USBD_DFU_MAX_ITF_NUM];
184 | uint16_t (* Init)(void);
185 | uint16_t (* DeInit)(void);
186 | uint16_t (* Erase)(uint32_t Add);
187 | uint16_t (* Write)(uint8_t *src, uint8_t *dest, uint32_t Len);
188 | uint8_t *(* Read)(uint8_t *src, uint8_t *dest, uint32_t Len);
189 | uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff);
190 | }
191 | USBD_DFU_MediaTypeDef;
192 | /**
193 | * @}
194 | */
195 |
196 |
197 |
198 | /** @defgroup USBD_CORE_Exported_Macros
199 | * @{
200 | */
201 |
202 | /**
203 | * @}
204 | */
205 |
206 | /** @defgroup USBD_CORE_Exported_Variables
207 | * @{
208 | */
209 |
210 | extern USBD_ClassTypeDef USBD_DFU;
211 | #define USBD_DFU_CLASS &USBD_DFU
212 | /**
213 | * @}
214 | */
215 |
216 | /** @defgroup USB_CORE_Exported_Functions
217 | * @{
218 | */
219 | uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
220 | USBD_DFU_MediaTypeDef *fops);
221 | /**
222 | * @}
223 | */
224 |
225 | #ifdef __cplusplus
226 | }
227 | #endif
228 |
229 | #endif /* __USB_DFU_H */
230 | /**
231 | * @}
232 | */
233 |
234 | /**
235 | * @}
236 | */
237 |
238 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
239 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu_media_template.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_dfu_media_template.h
4 | * @author MCD Application Team
5 | * @brief header file for the usbd_dfu_media_template.c file
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USBD_DFU_MEDIA_TEMPLATE_H
22 | #define __USBD_DFU_MEDIA_TEMPLATE_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_dfu.h"
30 |
31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
32 | * @{
33 | */
34 |
35 | /** @defgroup USBD_MEDIA
36 | * @brief header file for the usbd_dfu_media_template.c file
37 | * @{
38 | */
39 |
40 | /** @defgroup USBD_MEDIA_Exported_Defines
41 | * @{
42 | */
43 | /**
44 | * @}
45 | */
46 |
47 |
48 | /** @defgroup USBD_MEDIA_Exported_Types
49 | * @{
50 | */
51 |
52 |
53 | /**
54 | * @}
55 | */
56 |
57 |
58 |
59 | /** @defgroup USBD_MEDIA_Exported_Macros
60 | * @{
61 | */
62 |
63 | /**
64 | * @}
65 | */
66 |
67 | /** @defgroup USBD_MEDIA_Exported_Variables
68 | * @{
69 | */
70 | extern USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops;
71 | /**
72 | * @}
73 | */
74 |
75 | /** @defgroup USBD_MEDIA_Exported_FunctionsPrototype
76 | * @{
77 | */
78 |
79 |
80 | /**
81 | * @}
82 | */
83 |
84 | #ifdef __cplusplus
85 | }
86 | #endif
87 |
88 | #endif /* __USBD_DFU_MEDIA_TEMPLATE_H */
89 |
90 | /**
91 | * @}
92 | */
93 |
94 | /**
95 | * @}
96 | */
97 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
98 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Class/DFU/Src/usbd_dfu_media_template.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_dfu_media_template.c
4 | * @author MCD Application Team
5 | * @brief Memory management layer
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* BSPDependencies
21 | - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
22 | - "stm32xxxxx_{eval}{discovery}_io.c"
23 | EndBSPDependencies */
24 |
25 | /* Includes ------------------------------------------------------------------*/
26 | #include "usbd_dfu_media_template.h"
27 |
28 |
29 | /* Private typedef -----------------------------------------------------------*/
30 | /* Private define ------------------------------------------------------------*/
31 | /* Private macro -------------------------------------------------------------*/
32 | /* Private variables ---------------------------------------------------------*/
33 | /* Private function prototypes -----------------------------------------------*/
34 | /* Extern function prototypes ------------------------------------------------*/
35 | /* Private functions ---------------------------------------------------------*/
36 | uint16_t MEM_If_Init(void);
37 | uint16_t MEM_If_Erase(uint32_t Add);
38 | uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len);
39 | uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len);
40 | uint16_t MEM_If_DeInit(void);
41 | uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer);
42 |
43 | USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops =
44 | {
45 | (uint8_t *)"DFU MEDIA",
46 | MEM_If_Init,
47 | MEM_If_DeInit,
48 | MEM_If_Erase,
49 | MEM_If_Write,
50 | MEM_If_Read,
51 | MEM_If_GetStatus,
52 |
53 | };
54 | /**
55 | * @brief MEM_If_Init
56 | * Memory initialization routine.
57 | * @param None
58 | * @retval 0 if operation is successful, MAL_FAIL else.
59 | */
60 | uint16_t MEM_If_Init(void)
61 | {
62 | return 0;
63 | }
64 |
65 | /**
66 | * @brief MEM_If_DeInit
67 | * Memory deinitialization routine.
68 | * @param None
69 | * @retval 0 if operation is successful, MAL_FAIL else.
70 | */
71 | uint16_t MEM_If_DeInit(void)
72 | {
73 | return 0;
74 | }
75 |
76 | /**
77 | * @brief MEM_If_Erase
78 | * Erase sector.
79 | * @param Add: Address of sector to be erased.
80 | * @retval 0 if operation is successful, MAL_FAIL else.
81 | */
82 | uint16_t MEM_If_Erase(uint32_t Add)
83 | {
84 | return 0;
85 | }
86 |
87 | /**
88 | * @brief MEM_If_Write
89 | * Memory write routine.
90 | * @param Add: Address to be written to.
91 | * @param Len: Number of data to be written (in bytes).
92 | * @retval 0 if operation is successful, MAL_FAIL else.
93 | */
94 | uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len)
95 | {
96 | return 0;
97 | }
98 |
99 | /**
100 | * @brief MEM_If_Read
101 | * Memory read routine.
102 | * @param Add: Address to be read from.
103 | * @param Len: Number of data to be read (in bytes).
104 | * @retval Pointer to the physical address where data should be read.
105 | */
106 | uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len)
107 | {
108 | /* Return a valid address to avoid HardFault */
109 | return (uint8_t *)(0);
110 | }
111 |
112 | /**
113 | * @brief Flash_If_GetStatus
114 | * Memory read routine.
115 | * @param Add: Address to be read from.
116 | * @param cmd: Number of data to be read (in bytes).
117 | * @retval Pointer to the physical address where data should be read.
118 | */
119 | uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer)
120 | {
121 | switch (Cmd)
122 | {
123 | case DFU_MEDIA_PROGRAM:
124 |
125 | break;
126 |
127 | case DFU_MEDIA_ERASE:
128 | default:
129 |
130 | break;
131 | }
132 | return (0);
133 | }
134 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
135 |
136 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Class/Template/Inc/usbd_template.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_template_core.h
4 | * @author MCD Application Team
5 | * @brief Header file for the usbd_template_core.c file.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USB_TEMPLATE_CORE_H
22 | #define __USB_TEMPLATE_CORE_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_ioreq.h"
30 |
31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
32 | * @{
33 | */
34 |
35 | /** @defgroup USBD_TEMPLATE
36 | * @brief This file is the header file for usbd_template_core.c
37 | * @{
38 | */
39 |
40 |
41 | /** @defgroup USBD_TEMPLATE_Exported_Defines
42 | * @{
43 | */
44 | #define TEMPLATE_EPIN_ADDR 0x81
45 | #define TEMPLATE_EPIN_SIZE 0x10
46 |
47 | #define USB_TEMPLATE_CONFIG_DESC_SIZ 64
48 |
49 | /**
50 | * @}
51 | */
52 |
53 |
54 | /** @defgroup USBD_CORE_Exported_TypesDefinitions
55 | * @{
56 | */
57 |
58 | /**
59 | * @}
60 | */
61 |
62 |
63 |
64 | /** @defgroup USBD_CORE_Exported_Macros
65 | * @{
66 | */
67 |
68 | /**
69 | * @}
70 | */
71 |
72 | /** @defgroup USBD_CORE_Exported_Variables
73 | * @{
74 | */
75 |
76 | extern USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver;
77 | /**
78 | * @}
79 | */
80 |
81 | /** @defgroup USB_CORE_Exported_Functions
82 | * @{
83 | */
84 | /**
85 | * @}
86 | */
87 |
88 | #ifdef __cplusplus
89 | }
90 | #endif
91 |
92 | #endif /* __USB_TEMPLATE_CORE_H */
93 | /**
94 | * @}
95 | */
96 |
97 | /**
98 | * @}
99 | */
100 |
101 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
102 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Class/Template/Src/usbd_template.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_template.c
4 | * @author MCD Application Team
5 | * @brief This file provides the HID core functions.
6 | *
7 | * @verbatim
8 | *
9 | * ===================================================================
10 | * TEMPLATE Class Description
11 | * ===================================================================
12 | *
13 | *
14 | *
15 | *
16 | *
17 | *
18 | * @note In HS mode and when the DMA is used, all variables and data structures
19 | * dealing with the DMA during the transaction process should be 32-bit aligned.
20 | *
21 | *
22 | * @endverbatim
23 | *
24 | ******************************************************************************
25 | * @attention
26 | *
27 | * © Copyright (c) 2015 STMicroelectronics.
28 | * All rights reserved.
29 | *
30 | * This software component is licensed by ST under Ultimate Liberty license
31 | * SLA0044, the "License"; You may not use this file except in compliance with
32 | * the License. You may obtain a copy of the License at:
33 | * www.st.com/SLA0044
34 | *
35 | ******************************************************************************
36 | */
37 |
38 | /* Includes ------------------------------------------------------------------*/
39 | #include "usbd_template.h"
40 | #include "usbd_ctlreq.h"
41 |
42 |
43 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
44 | * @{
45 | */
46 |
47 |
48 | /** @defgroup USBD_TEMPLATE
49 | * @brief usbd core module
50 | * @{
51 | */
52 |
53 | /** @defgroup USBD_TEMPLATE_Private_TypesDefinitions
54 | * @{
55 | */
56 | /**
57 | * @}
58 | */
59 |
60 |
61 | /** @defgroup USBD_TEMPLATE_Private_Defines
62 | * @{
63 | */
64 |
65 | /**
66 | * @}
67 | */
68 |
69 |
70 | /** @defgroup USBD_TEMPLATE_Private_Macros
71 | * @{
72 | */
73 |
74 | /**
75 | * @}
76 | */
77 |
78 |
79 |
80 |
81 | /** @defgroup USBD_TEMPLATE_Private_FunctionPrototypes
82 | * @{
83 | */
84 |
85 |
86 | static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev,
87 | uint8_t cfgidx);
88 |
89 | static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev,
90 | uint8_t cfgidx);
91 |
92 | static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
93 | USBD_SetupReqTypedef *req);
94 |
95 | static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length);
96 |
97 | static uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length);
98 |
99 | static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
100 |
101 | static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
102 |
103 | static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev);
104 |
105 | static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev);
106 |
107 | static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev);
108 |
109 | static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
110 |
111 | static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
112 |
113 | /**
114 | * @}
115 | */
116 |
117 | /** @defgroup USBD_TEMPLATE_Private_Variables
118 | * @{
119 | */
120 |
121 | USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver =
122 | {
123 | USBD_TEMPLATE_Init,
124 | USBD_TEMPLATE_DeInit,
125 | USBD_TEMPLATE_Setup,
126 | USBD_TEMPLATE_EP0_TxReady,
127 | USBD_TEMPLATE_EP0_RxReady,
128 | USBD_TEMPLATE_DataIn,
129 | USBD_TEMPLATE_DataOut,
130 | USBD_TEMPLATE_SOF,
131 | USBD_TEMPLATE_IsoINIncomplete,
132 | USBD_TEMPLATE_IsoOutIncomplete,
133 | USBD_TEMPLATE_GetCfgDesc,
134 | USBD_TEMPLATE_GetCfgDesc,
135 | USBD_TEMPLATE_GetCfgDesc,
136 | USBD_TEMPLATE_GetDeviceQualifierDesc,
137 | };
138 |
139 | #if defined ( __ICCARM__ ) /*!< IAR Compiler */
140 | #pragma data_alignment=4
141 | #endif
142 | /* USB TEMPLATE device Configuration Descriptor */
143 | static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] =
144 | {
145 | 0x09, /* bLength: Configuation Descriptor size */
146 | USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, /* bDescriptorType: Configuration */
147 | USB_TEMPLATE_CONFIG_DESC_SIZ,
148 | /* wTotalLength: Bytes returned */
149 | 0x00,
150 | 0x01, /*bNumInterfaces: 1 interface*/
151 | 0x01, /*bConfigurationValue: Configuration value*/
152 | 0x02, /*iConfiguration: Index of string descriptor describing the configuration*/
153 | 0xC0, /*bmAttributes: bus powered and Supports Remote Wakeup */
154 | 0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
155 | /* 09 */
156 |
157 | /********** Descriptor of TEMPLATE interface 0 Alternate setting 0 **************/
158 |
159 | };
160 |
161 | #if defined ( __ICCARM__ ) /*!< IAR Compiler */
162 | #pragma data_alignment=4
163 | #endif
164 | /* USB Standard Device Descriptor */
165 | static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] =
166 | {
167 | USB_LEN_DEV_QUALIFIER_DESC,
168 | USB_DESC_TYPE_DEVICE_QUALIFIER,
169 | 0x00,
170 | 0x02,
171 | 0x00,
172 | 0x00,
173 | 0x00,
174 | 0x40,
175 | 0x01,
176 | 0x00,
177 | };
178 |
179 | /**
180 | * @}
181 | */
182 |
183 | /** @defgroup USBD_TEMPLATE_Private_Functions
184 | * @{
185 | */
186 |
187 | /**
188 | * @brief USBD_TEMPLATE_Init
189 | * Initialize the TEMPLATE interface
190 | * @param pdev: device instance
191 | * @param cfgidx: Configuration index
192 | * @retval status
193 | */
194 | static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev,
195 | uint8_t cfgidx)
196 | {
197 | uint8_t ret = 0;
198 |
199 |
200 | return ret;
201 | }
202 |
203 | /**
204 | * @brief USBD_TEMPLATE_Init
205 | * DeInitialize the TEMPLATE layer
206 | * @param pdev: device instance
207 | * @param cfgidx: Configuration index
208 | * @retval status
209 | */
210 | static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev,
211 | uint8_t cfgidx)
212 | {
213 |
214 | return USBD_OK;
215 | }
216 |
217 | /**
218 | * @brief USBD_TEMPLATE_Setup
219 | * Handle the TEMPLATE specific requests
220 | * @param pdev: instance
221 | * @param req: usb requests
222 | * @retval status
223 | */
224 | static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
225 | USBD_SetupReqTypedef *req)
226 | {
227 | USBD_StatusTypeDef ret = USBD_OK;
228 |
229 | switch (req->bmRequest & USB_REQ_TYPE_MASK)
230 | {
231 | case USB_REQ_TYPE_CLASS :
232 | switch (req->bRequest)
233 | {
234 | default:
235 | USBD_CtlError(pdev, req);
236 | ret = USBD_FAIL;
237 | break;
238 | }
239 | break;
240 |
241 | case USB_REQ_TYPE_STANDARD:
242 | switch (req->bRequest)
243 | {
244 | default:
245 | USBD_CtlError(pdev, req);
246 | ret = USBD_FAIL;
247 | break;
248 | }
249 | break;
250 |
251 | default:
252 | USBD_CtlError(pdev, req);
253 | ret = USBD_FAIL;
254 | break;
255 | }
256 |
257 | return ret;
258 | }
259 |
260 |
261 | /**
262 | * @brief USBD_TEMPLATE_GetCfgDesc
263 | * return configuration descriptor
264 | * @param length : pointer data length
265 | * @retval pointer to descriptor buffer
266 | */
267 | static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length)
268 | {
269 | *length = sizeof(USBD_TEMPLATE_CfgDesc);
270 | return USBD_TEMPLATE_CfgDesc;
271 | }
272 |
273 | /**
274 | * @brief DeviceQualifierDescriptor
275 | * return Device Qualifier descriptor
276 | * @param length : pointer data length
277 | * @retval pointer to descriptor buffer
278 | */
279 | uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor(uint16_t *length)
280 | {
281 | *length = sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
282 | return USBD_TEMPLATE_DeviceQualifierDesc;
283 | }
284 |
285 |
286 | /**
287 | * @brief USBD_TEMPLATE_DataIn
288 | * handle data IN Stage
289 | * @param pdev: device instance
290 | * @param epnum: endpoint index
291 | * @retval status
292 | */
293 | static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev,
294 | uint8_t epnum)
295 | {
296 |
297 | return USBD_OK;
298 | }
299 |
300 | /**
301 | * @brief USBD_TEMPLATE_EP0_RxReady
302 | * handle EP0 Rx Ready event
303 | * @param pdev: device instance
304 | * @retval status
305 | */
306 | static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev)
307 | {
308 |
309 | return USBD_OK;
310 | }
311 | /**
312 | * @brief USBD_TEMPLATE_EP0_TxReady
313 | * handle EP0 TRx Ready event
314 | * @param pdev: device instance
315 | * @retval status
316 | */
317 | static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev)
318 | {
319 |
320 | return USBD_OK;
321 | }
322 | /**
323 | * @brief USBD_TEMPLATE_SOF
324 | * handle SOF event
325 | * @param pdev: device instance
326 | * @retval status
327 | */
328 | static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev)
329 | {
330 |
331 | return USBD_OK;
332 | }
333 | /**
334 | * @brief USBD_TEMPLATE_IsoINIncomplete
335 | * handle data ISO IN Incomplete event
336 | * @param pdev: device instance
337 | * @param epnum: endpoint index
338 | * @retval status
339 | */
340 | static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
341 | {
342 |
343 | return USBD_OK;
344 | }
345 | /**
346 | * @brief USBD_TEMPLATE_IsoOutIncomplete
347 | * handle data ISO OUT Incomplete event
348 | * @param pdev: device instance
349 | * @param epnum: endpoint index
350 | * @retval status
351 | */
352 | static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
353 | {
354 |
355 | return USBD_OK;
356 | }
357 | /**
358 | * @brief USBD_TEMPLATE_DataOut
359 | * handle data OUT Stage
360 | * @param pdev: device instance
361 | * @param epnum: endpoint index
362 | * @retval status
363 | */
364 | static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev,
365 | uint8_t epnum)
366 | {
367 |
368 | return USBD_OK;
369 | }
370 |
371 | /**
372 | * @brief DeviceQualifierDescriptor
373 | * return Device Qualifier descriptor
374 | * @param length : pointer data length
375 | * @retval pointer to descriptor buffer
376 | */
377 | uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length)
378 | {
379 | *length = sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
380 | return USBD_TEMPLATE_DeviceQualifierDesc;
381 | }
382 |
383 | /**
384 | * @}
385 | */
386 |
387 |
388 | /**
389 | * @}
390 | */
391 |
392 |
393 | /**
394 | * @}
395 | */
396 |
397 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
398 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Core/Inc/usbd_conf_template.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_conf_template.h
4 | * @author MCD Application Team
5 | * @brief Header file for the usbd_conf_template.c file
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USBD_CONF_TEMPLATE_H
22 | #define __USBD_CONF_TEMPLATE_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "stm32fxxx.h" /* replace 'stm32xxx' with your HAL driver header filename, ex: stm32f4xx.h */
30 | #include
31 | #include
32 | #include
33 |
34 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
35 | * @{
36 | */
37 |
38 | /** @defgroup USBD_CONF
39 | * @brief USB device low level driver configuration file
40 | * @{
41 | */
42 |
43 | /** @defgroup USBD_CONF_Exported_Defines
44 | * @{
45 | */
46 |
47 | #define USBD_MAX_NUM_INTERFACES 1U
48 | #define USBD_MAX_NUM_CONFIGURATION 1U
49 | #define USBD_MAX_STR_DESC_SIZ 0x100U
50 | #define USBD_SUPPORT_USER_STRING_DESC 0U
51 | #define USBD_SELF_POWERED 1U
52 | #define USBD_DEBUG_LEVEL 2U
53 |
54 | /* MSC Class Config */
55 | #define MSC_MEDIA_PACKET 8192U
56 |
57 | /* CDC Class Config */
58 | #define USBD_CDC_INTERVAL 2000U
59 |
60 | /* DFU Class Config */
61 | #define USBD_DFU_MAX_ITF_NUM 1U
62 | #define USBD_DFU_XFERS_IZE 1024U
63 |
64 | /* AUDIO Class Config */
65 | #define USBD_AUDIO_FREQ 22100U
66 |
67 | /** @defgroup USBD_Exported_Macros
68 | * @{
69 | */
70 |
71 | /* Memory management macros */
72 | #define USBD_malloc malloc
73 | #define USBD_free free
74 | #define USBD_memset memset
75 | #define USBD_memcpy memcpy
76 |
77 | /* DEBUG macros */
78 | #if (USBD_DEBUG_LEVEL > 0U)
79 | #define USBD_UsrLog(...) do { \
80 | printf(__VA_ARGS__); \
81 | printf("\n"); \
82 | } while (0)
83 | #else
84 | #define USBD_UsrLog(...) do {} while (0)
85 | #endif
86 |
87 | #if (USBD_DEBUG_LEVEL > 1U)
88 |
89 | #define USBD_ErrLog(...) do { \
90 | printf("ERROR: ") ; \
91 | printf(__VA_ARGS__); \
92 | printf("\n"); \
93 | } while (0)
94 | #else
95 | #define USBD_ErrLog(...) do {} while (0)
96 | #endif
97 |
98 | #if (USBD_DEBUG_LEVEL > 2U)
99 | #define USBD_DbgLog(...) do { \
100 | printf("DEBUG : ") ; \
101 | printf(__VA_ARGS__); \
102 | printf("\n"); \
103 | } while (0)
104 | #else
105 | #define USBD_DbgLog(...) do {} while (0)
106 | #endif
107 |
108 | /**
109 | * @}
110 | */
111 |
112 |
113 |
114 | /**
115 | * @}
116 | */
117 |
118 |
119 | /** @defgroup USBD_CONF_Exported_Types
120 | * @{
121 | */
122 | /**
123 | * @}
124 | */
125 |
126 |
127 | /** @defgroup USBD_CONF_Exported_Macros
128 | * @{
129 | */
130 | /**
131 | * @}
132 | */
133 |
134 | /** @defgroup USBD_CONF_Exported_Variables
135 | * @{
136 | */
137 | /**
138 | * @}
139 | */
140 |
141 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype
142 | * @{
143 | */
144 | /**
145 | * @}
146 | */
147 |
148 | #ifdef __cplusplus
149 | }
150 | #endif
151 |
152 | #endif /* __USBD_CONF_TEMPLATE_H */
153 |
154 |
155 | /**
156 | * @}
157 | */
158 |
159 | /**
160 | * @}
161 | */
162 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
163 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Core/Inc/usbd_core.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_core.h
4 | * @author MCD Application Team
5 | * @brief Header file for usbd_core.c file
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USBD_CORE_H
22 | #define __USBD_CORE_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_conf.h"
30 | #include "usbd_def.h"
31 | #include "usbd_ioreq.h"
32 | #include "usbd_ctlreq.h"
33 |
34 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
35 | * @{
36 | */
37 |
38 | /** @defgroup USBD_CORE
39 | * @brief This file is the Header file for usbd_core.c file
40 | * @{
41 | */
42 |
43 |
44 | /** @defgroup USBD_CORE_Exported_Defines
45 | * @{
46 | */
47 | #ifndef USBD_DEBUG_LEVEL
48 | #define USBD_DEBUG_LEVEL 0U
49 | #endif /* USBD_DEBUG_LEVEL */
50 | /**
51 | * @}
52 | */
53 |
54 |
55 | /** @defgroup USBD_CORE_Exported_TypesDefinitions
56 | * @{
57 | */
58 |
59 |
60 | /**
61 | * @}
62 | */
63 |
64 |
65 |
66 | /** @defgroup USBD_CORE_Exported_Macros
67 | * @{
68 | */
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /** @defgroup USBD_CORE_Exported_Variables
75 | * @{
76 | */
77 | #define USBD_SOF USBD_LL_SOF
78 | /**
79 | * @}
80 | */
81 |
82 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype
83 | * @{
84 | */
85 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id);
86 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
87 | USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
88 | USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
89 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
90 |
91 | USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev);
92 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
93 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
94 |
95 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup);
96 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
97 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
98 |
99 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev);
100 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
101 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev);
102 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev);
103 |
104 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev);
105 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
106 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
107 |
108 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev);
109 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
110 |
111 | /* USBD Low Level Driver */
112 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev);
113 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev);
114 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
115 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev);
116 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev,
117 | uint8_t ep_addr,
118 | uint8_t ep_type,
119 | uint16_t ep_mps);
120 |
121 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
122 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
123 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
124 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
125 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
126 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr);
127 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev,
128 | uint8_t ep_addr,
129 | uint8_t *pbuf,
130 | uint16_t size);
131 |
132 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
133 | uint8_t ep_addr,
134 | uint8_t *pbuf,
135 | uint16_t size);
136 |
137 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
138 | void USBD_LL_Delay(uint32_t Delay);
139 |
140 | /**
141 | * @}
142 | */
143 |
144 | #ifdef __cplusplus
145 | }
146 | #endif
147 |
148 | #endif /* __USBD_CORE_H */
149 |
150 | /**
151 | * @}
152 | */
153 |
154 | /**
155 | * @}
156 | */
157 |
158 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
159 |
160 |
161 |
162 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_req.h
4 | * @author MCD Application Team
5 | * @brief Header file for the usbd_req.c file
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USB_REQUEST_H
22 | #define __USB_REQUEST_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_def.h"
30 |
31 |
32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
33 | * @{
34 | */
35 |
36 | /** @defgroup USBD_REQ
37 | * @brief header file for the usbd_req.c file
38 | * @{
39 | */
40 |
41 | /** @defgroup USBD_REQ_Exported_Defines
42 | * @{
43 | */
44 | /**
45 | * @}
46 | */
47 |
48 |
49 | /** @defgroup USBD_REQ_Exported_Types
50 | * @{
51 | */
52 | /**
53 | * @}
54 | */
55 |
56 |
57 |
58 | /** @defgroup USBD_REQ_Exported_Macros
59 | * @{
60 | */
61 | /**
62 | * @}
63 | */
64 |
65 | /** @defgroup USBD_REQ_Exported_Variables
66 | * @{
67 | */
68 | /**
69 | * @}
70 | */
71 |
72 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype
73 | * @{
74 | */
75 |
76 | USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
77 | USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
78 | USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
79 |
80 |
81 | void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
82 |
83 | void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata);
84 |
85 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len);
86 | /**
87 | * @}
88 | */
89 |
90 | #ifdef __cplusplus
91 | }
92 | #endif
93 |
94 | #endif /* __USB_REQUEST_H */
95 |
96 | /**
97 | * @}
98 | */
99 |
100 | /**
101 | * @}
102 | */
103 |
104 |
105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
106 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Core/Inc/usbd_def.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_def.h
4 | * @author MCD Application Team
5 | * @brief General defines for the usb device library
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USBD_DEF_H
22 | #define __USBD_DEF_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_conf.h"
30 |
31 | /** @addtogroup STM32_USBD_DEVICE_LIBRARY
32 | * @{
33 | */
34 |
35 | /** @defgroup USB_DEF
36 | * @brief general defines for the usb device library file
37 | * @{
38 | */
39 |
40 | /** @defgroup USB_DEF_Exported_Defines
41 | * @{
42 | */
43 |
44 | #ifndef NULL
45 | #define NULL 0U
46 | #endif /* NULL */
47 |
48 | #ifndef USBD_MAX_NUM_INTERFACES
49 | #define USBD_MAX_NUM_INTERFACES 1U
50 | #endif /* USBD_MAX_NUM_CONFIGURATION */
51 |
52 | #ifndef USBD_MAX_NUM_CONFIGURATION
53 | #define USBD_MAX_NUM_CONFIGURATION 1U
54 | #endif /* USBD_MAX_NUM_CONFIGURATION */
55 |
56 | #ifndef USBD_LPM_ENABLED
57 | #define USBD_LPM_ENABLED 0U
58 | #endif /* USBD_LPM_ENABLED */
59 |
60 | #ifndef USBD_SELF_POWERED
61 | #define USBD_SELF_POWERED 1U
62 | #endif /*USBD_SELF_POWERED */
63 |
64 | #ifndef USBD_SUPPORT_USER_STRING_DESC
65 | #define USBD_SUPPORT_USER_STRING_DESC 0U
66 | #endif /* USBD_SUPPORT_USER_STRING_DESC */
67 |
68 | #define USB_LEN_DEV_QUALIFIER_DESC 0x0AU
69 | #define USB_LEN_DEV_DESC 0x12U
70 | #define USB_LEN_CFG_DESC 0x09U
71 | #define USB_LEN_IF_DESC 0x09U
72 | #define USB_LEN_EP_DESC 0x07U
73 | #define USB_LEN_OTG_DESC 0x03U
74 | #define USB_LEN_LANGID_STR_DESC 0x04U
75 | #define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U
76 |
77 | #define USBD_IDX_LANGID_STR 0x00U
78 | #define USBD_IDX_MFC_STR 0x01U
79 | #define USBD_IDX_PRODUCT_STR 0x02U
80 | #define USBD_IDX_SERIAL_STR 0x03U
81 | #define USBD_IDX_CONFIG_STR 0x04U
82 | #define USBD_IDX_INTERFACE_STR 0x05U
83 |
84 | #define USB_REQ_TYPE_STANDARD 0x00U
85 | #define USB_REQ_TYPE_CLASS 0x20U
86 | #define USB_REQ_TYPE_VENDOR 0x40U
87 | #define USB_REQ_TYPE_MASK 0x60U
88 |
89 | #define USB_REQ_RECIPIENT_DEVICE 0x00U
90 | #define USB_REQ_RECIPIENT_INTERFACE 0x01U
91 | #define USB_REQ_RECIPIENT_ENDPOINT 0x02U
92 | #define USB_REQ_RECIPIENT_MASK 0x03U
93 |
94 | #define USB_REQ_GET_STATUS 0x00U
95 | #define USB_REQ_CLEAR_FEATURE 0x01U
96 | #define USB_REQ_SET_FEATURE 0x03U
97 | #define USB_REQ_SET_ADDRESS 0x05U
98 | #define USB_REQ_GET_DESCRIPTOR 0x06U
99 | #define USB_REQ_SET_DESCRIPTOR 0x07U
100 | #define USB_REQ_GET_CONFIGURATION 0x08U
101 | #define USB_REQ_SET_CONFIGURATION 0x09U
102 | #define USB_REQ_GET_INTERFACE 0x0AU
103 | #define USB_REQ_SET_INTERFACE 0x0BU
104 | #define USB_REQ_SYNCH_FRAME 0x0CU
105 |
106 | #define USB_DESC_TYPE_DEVICE 0x01U
107 | #define USB_DESC_TYPE_CONFIGURATION 0x02U
108 | #define USB_DESC_TYPE_STRING 0x03U
109 | #define USB_DESC_TYPE_INTERFACE 0x04U
110 | #define USB_DESC_TYPE_ENDPOINT 0x05U
111 | #define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U
112 | #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U
113 | #define USB_DESC_TYPE_BOS 0x0FU
114 |
115 | #define USB_CONFIG_REMOTE_WAKEUP 0x02U
116 | #define USB_CONFIG_SELF_POWERED 0x01U
117 |
118 | #define USB_FEATURE_EP_HALT 0x00U
119 | #define USB_FEATURE_REMOTE_WAKEUP 0x01U
120 | #define USB_FEATURE_TEST_MODE 0x02U
121 |
122 | #define USB_DEVICE_CAPABITY_TYPE 0x10U
123 |
124 | #define USB_HS_MAX_PACKET_SIZE 512U
125 | #define USB_FS_MAX_PACKET_SIZE 64U
126 | #define USB_MAX_EP0_SIZE 64U
127 |
128 | /* Device Status */
129 | #define USBD_STATE_DEFAULT 0x01U
130 | #define USBD_STATE_ADDRESSED 0x02U
131 | #define USBD_STATE_CONFIGURED 0x03U
132 | #define USBD_STATE_SUSPENDED 0x04U
133 |
134 |
135 | /* EP0 State */
136 | #define USBD_EP0_IDLE 0x00U
137 | #define USBD_EP0_SETUP 0x01U
138 | #define USBD_EP0_DATA_IN 0x02U
139 | #define USBD_EP0_DATA_OUT 0x03U
140 | #define USBD_EP0_STATUS_IN 0x04U
141 | #define USBD_EP0_STATUS_OUT 0x05U
142 | #define USBD_EP0_STALL 0x06U
143 |
144 | #define USBD_EP_TYPE_CTRL 0x00U
145 | #define USBD_EP_TYPE_ISOC 0x01U
146 | #define USBD_EP_TYPE_BULK 0x02U
147 | #define USBD_EP_TYPE_INTR 0x03U
148 |
149 |
150 | /**
151 | * @}
152 | */
153 |
154 |
155 | /** @defgroup USBD_DEF_Exported_TypesDefinitions
156 | * @{
157 | */
158 |
159 | typedef struct usb_setup_req
160 | {
161 | uint8_t bmRequest;
162 | uint8_t bRequest;
163 | uint16_t wValue;
164 | uint16_t wIndex;
165 | uint16_t wLength;
166 | } USBD_SetupReqTypedef;
167 |
168 | struct _USBD_HandleTypeDef;
169 |
170 | typedef struct _Device_cb
171 | {
172 | uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
173 | uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
174 | /* Control Endpoints*/
175 | uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
176 | uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev);
177 | uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev);
178 | /* Class Specific Endpoints*/
179 | uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
180 | uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
181 | uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev);
182 | uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
183 | uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
184 |
185 | uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
186 | uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
187 | uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
188 | uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
189 | #if (USBD_SUPPORT_USER_STRING_DESC == 1U)
190 | uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
191 | #endif
192 |
193 | } USBD_ClassTypeDef;
194 |
195 | /* Following USB Device Speed */
196 | typedef enum
197 | {
198 | USBD_SPEED_HIGH = 0U,
199 | USBD_SPEED_FULL = 1U,
200 | USBD_SPEED_LOW = 2U,
201 | } USBD_SpeedTypeDef;
202 |
203 | /* Following USB Device status */
204 | typedef enum
205 | {
206 | USBD_OK = 0U,
207 | USBD_BUSY,
208 | USBD_FAIL,
209 | } USBD_StatusTypeDef;
210 |
211 | /* USB Device descriptors structure */
212 | typedef struct
213 | {
214 | uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
215 | uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
216 | uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
217 | uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
218 | uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
219 | uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
220 | uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
221 | #if (USBD_LPM_ENABLED == 1U)
222 | uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
223 | #endif
224 | } USBD_DescriptorsTypeDef;
225 |
226 | /* USB Device handle structure */
227 | typedef struct
228 | {
229 | uint32_t status;
230 | uint32_t is_used;
231 | uint32_t total_length;
232 | uint32_t rem_length;
233 | uint32_t maxpacket;
234 | } USBD_EndpointTypeDef;
235 |
236 | /* USB Device handle structure */
237 | typedef struct _USBD_HandleTypeDef
238 | {
239 | uint8_t id;
240 | uint32_t dev_config;
241 | uint32_t dev_default_config;
242 | uint32_t dev_config_status;
243 | USBD_SpeedTypeDef dev_speed;
244 | USBD_EndpointTypeDef ep_in[16];
245 | USBD_EndpointTypeDef ep_out[16];
246 | uint32_t ep0_state;
247 | uint32_t ep0_data_len;
248 | uint8_t dev_state;
249 | uint8_t dev_old_state;
250 | uint8_t dev_address;
251 | uint8_t dev_connection_status;
252 | uint8_t dev_test_mode;
253 | uint32_t dev_remote_wakeup;
254 |
255 | USBD_SetupReqTypedef request;
256 | USBD_DescriptorsTypeDef *pDesc;
257 | USBD_ClassTypeDef *pClass;
258 | void *pClassData;
259 | void *pUserData;
260 | void *pData;
261 | } USBD_HandleTypeDef;
262 |
263 | /**
264 | * @}
265 | */
266 |
267 |
268 |
269 | /** @defgroup USBD_DEF_Exported_Macros
270 | * @{
271 | */
272 | #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
273 | (((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U))
274 |
275 | #define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
276 | #define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
277 | #define MIN(a, b) (((a) < (b)) ? (a) : (b))
278 | #define MAX(a, b) (((a) > (b)) ? (a) : (b))
279 |
280 |
281 | #if defined ( __GNUC__ )
282 | #ifndef __weak
283 | #define __weak __attribute__((weak))
284 | #endif /* __weak */
285 | #ifndef __packed
286 | #define __packed __attribute__((__packed__))
287 | #endif /* __packed */
288 | #endif /* __GNUC__ */
289 |
290 |
291 | /* In HS mode and when the DMA is used, all variables and data structures dealing
292 | with the DMA during the transaction process should be 4-bytes aligned */
293 |
294 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
295 | #ifndef __ALIGN_END
296 | #define __ALIGN_END __attribute__ ((aligned (4U)))
297 | #endif /* __ALIGN_END */
298 | #ifndef __ALIGN_BEGIN
299 | #define __ALIGN_BEGIN
300 | #endif /* __ALIGN_BEGIN */
301 | #else
302 | #ifndef __ALIGN_END
303 | #define __ALIGN_END
304 | #endif /* __ALIGN_END */
305 | #ifndef __ALIGN_BEGIN
306 | #if defined (__CC_ARM) /* ARM Compiler */
307 | #define __ALIGN_BEGIN __align(4U)
308 | #elif defined (__ICCARM__) /* IAR Compiler */
309 | #define __ALIGN_BEGIN
310 | #endif /* __CC_ARM */
311 | #endif /* __ALIGN_BEGIN */
312 | #endif /* __GNUC__ */
313 |
314 |
315 | /**
316 | * @}
317 | */
318 |
319 | /** @defgroup USBD_DEF_Exported_Variables
320 | * @{
321 | */
322 |
323 | /**
324 | * @}
325 | */
326 |
327 | /** @defgroup USBD_DEF_Exported_FunctionsPrototype
328 | * @{
329 | */
330 |
331 | /**
332 | * @}
333 | */
334 |
335 | #ifdef __cplusplus
336 | }
337 | #endif
338 |
339 | #endif /* __USBD_DEF_H */
340 |
341 | /**
342 | * @}
343 | */
344 |
345 | /**
346 | * @}
347 | */
348 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
349 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_ioreq.h
4 | * @author MCD Application Team
5 | * @brief Header file for the usbd_ioreq.c file
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USBD_IOREQ_H
22 | #define __USBD_IOREQ_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_def.h"
30 | #include "usbd_core.h"
31 |
32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
33 | * @{
34 | */
35 |
36 | /** @defgroup USBD_IOREQ
37 | * @brief header file for the usbd_ioreq.c file
38 | * @{
39 | */
40 |
41 | /** @defgroup USBD_IOREQ_Exported_Defines
42 | * @{
43 | */
44 | /**
45 | * @}
46 | */
47 |
48 |
49 | /** @defgroup USBD_IOREQ_Exported_Types
50 | * @{
51 | */
52 |
53 |
54 | /**
55 | * @}
56 | */
57 |
58 |
59 |
60 | /** @defgroup USBD_IOREQ_Exported_Macros
61 | * @{
62 | */
63 |
64 | /**
65 | * @}
66 | */
67 |
68 | /** @defgroup USBD_IOREQ_Exported_Variables
69 | * @{
70 | */
71 |
72 | /**
73 | * @}
74 | */
75 |
76 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype
77 | * @{
78 | */
79 |
80 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
81 | uint8_t *pbuf,
82 | uint16_t len);
83 |
84 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
85 | uint8_t *pbuf,
86 | uint16_t len);
87 |
88 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
89 | uint8_t *pbuf,
90 | uint16_t len);
91 |
92 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
93 | uint8_t *pbuf,
94 | uint16_t len);
95 |
96 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev);
97 |
98 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev);
99 |
100 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
101 |
102 | /**
103 | * @}
104 | */
105 |
106 | #ifdef __cplusplus
107 | }
108 | #endif
109 |
110 | #endif /* __USBD_IOREQ_H */
111 |
112 | /**
113 | * @}
114 | */
115 |
116 | /**
117 | * @}
118 | */
119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
120 |
--------------------------------------------------------------------------------
/app/dfu/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_ioreq.c
4 | * @author MCD Application Team
5 | * @brief This file provides the IO requests APIs for control endpoints.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Includes ------------------------------------------------------------------*/
21 | #include "usbd_ioreq.h"
22 |
23 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
24 | * @{
25 | */
26 |
27 |
28 | /** @defgroup USBD_IOREQ
29 | * @brief control I/O requests module
30 | * @{
31 | */
32 |
33 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions
34 | * @{
35 | */
36 | /**
37 | * @}
38 | */
39 |
40 |
41 | /** @defgroup USBD_IOREQ_Private_Defines
42 | * @{
43 | */
44 |
45 | /**
46 | * @}
47 | */
48 |
49 |
50 | /** @defgroup USBD_IOREQ_Private_Macros
51 | * @{
52 | */
53 | /**
54 | * @}
55 | */
56 |
57 |
58 | /** @defgroup USBD_IOREQ_Private_Variables
59 | * @{
60 | */
61 |
62 | /**
63 | * @}
64 | */
65 |
66 |
67 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes
68 | * @{
69 | */
70 | /**
71 | * @}
72 | */
73 |
74 |
75 | /** @defgroup USBD_IOREQ_Private_Functions
76 | * @{
77 | */
78 |
79 | /**
80 | * @brief USBD_CtlSendData
81 | * send data on the ctl pipe
82 | * @param pdev: device instance
83 | * @param buff: pointer to data buffer
84 | * @param len: length of data to be sent
85 | * @retval status
86 | */
87 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
88 | uint8_t *pbuf, uint16_t len)
89 | {
90 | /* Set EP0 State */
91 | pdev->ep0_state = USBD_EP0_DATA_IN;
92 | pdev->ep_in[0].total_length = len;
93 | pdev->ep_in[0].rem_length = len;
94 |
95 | /* Start the transfer */
96 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
97 |
98 | return USBD_OK;
99 | }
100 |
101 | /**
102 | * @brief USBD_CtlContinueSendData
103 | * continue sending data on the ctl pipe
104 | * @param pdev: device instance
105 | * @param buff: pointer to data buffer
106 | * @param len: length of data to be sent
107 | * @retval status
108 | */
109 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
110 | uint8_t *pbuf, uint16_t len)
111 | {
112 | /* Start the next transfer */
113 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
114 |
115 | return USBD_OK;
116 | }
117 |
118 | /**
119 | * @brief USBD_CtlPrepareRx
120 | * receive data on the ctl pipe
121 | * @param pdev: device instance
122 | * @param buff: pointer to data buffer
123 | * @param len: length of data to be received
124 | * @retval status
125 | */
126 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
127 | uint8_t *pbuf, uint16_t len)
128 | {
129 | /* Set EP0 State */
130 | pdev->ep0_state = USBD_EP0_DATA_OUT;
131 | pdev->ep_out[0].total_length = len;
132 | pdev->ep_out[0].rem_length = len;
133 |
134 | /* Start the transfer */
135 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
136 |
137 | return USBD_OK;
138 | }
139 |
140 | /**
141 | * @brief USBD_CtlContinueRx
142 | * continue receive data on the ctl pipe
143 | * @param pdev: device instance
144 | * @param buff: pointer to data buffer
145 | * @param len: length of data to be received
146 | * @retval status
147 | */
148 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
149 | uint8_t *pbuf, uint16_t len)
150 | {
151 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
152 |
153 | return USBD_OK;
154 | }
155 |
156 | /**
157 | * @brief USBD_CtlSendStatus
158 | * send zero lzngth packet on the ctl pipe
159 | * @param pdev: device instance
160 | * @retval status
161 | */
162 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev)
163 | {
164 | /* Set EP0 State */
165 | pdev->ep0_state = USBD_EP0_STATUS_IN;
166 |
167 | /* Start the transfer */
168 | USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
169 |
170 | return USBD_OK;
171 | }
172 |
173 | /**
174 | * @brief USBD_CtlReceiveStatus
175 | * receive zero lzngth packet on the ctl pipe
176 | * @param pdev: device instance
177 | * @retval status
178 | */
179 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev)
180 | {
181 | /* Set EP0 State */
182 | pdev->ep0_state = USBD_EP0_STATUS_OUT;
183 |
184 | /* Start the transfer */
185 | USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
186 |
187 | return USBD_OK;
188 | }
189 |
190 | /**
191 | * @brief USBD_GetRxCount
192 | * returns the received data length
193 | * @param pdev: device instance
194 | * @param ep_addr: endpoint address
195 | * @retval Rx Data blength
196 | */
197 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
198 | {
199 | return USBD_LL_GetRxDataSize(pdev, ep_addr);
200 | }
201 |
202 | /**
203 | * @}
204 | */
205 |
206 |
207 | /**
208 | * @}
209 | */
210 |
211 |
212 | /**
213 | * @}
214 | */
215 |
216 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
217 |
--------------------------------------------------------------------------------
/app/dfu/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file USB_Device/DFU_Standalone/CM7/Inc/usbd_conf.h
4 | * @author MCD Application Team
5 | * @brief General low level driver configuration
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2019 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USBD_CONF_H
22 | #define __USBD_CONF_H
23 |
24 | /* Includes ------------------------------------------------------------------*/
25 | #include "board.h"
26 | #include "stm32h7xx_hal.h"
27 | #include
28 | #include
29 | #include
30 |
31 | /* Exported types ------------------------------------------------------------*/
32 | /* Exported constants --------------------------------------------------------*/
33 | /* Common Config */
34 | #define USBD_MAX_NUM_INTERFACES 2
35 | #define USBD_MAX_NUM_CONFIGURATION 1
36 | #define USBD_MAX_STR_DESC_SIZ 0x100
37 | #define USBD_SUPPORT_USER_STRING_DESC 1
38 | #define USBD_SELF_POWERED 1
39 | #define USBD_DEBUG_LEVEL 0
40 |
41 | /* DFU Class Config */
42 | #define USBD_DFU_MAX_ITF_NUM 4
43 | #define USBD_DFU_XFER_SIZE 4096 /* Max DFU Packet Size = 4096 bytes */
44 | #define USBD_DFU_APP_DEFAULT_ADD BOARD_APP_DEFAULT_ADD /* The first sector (32 KB) is reserved for DFU code */
45 | #define USBD_DFU_MAX_NB_OF_SECTORS 16 /* Max number of sectors */
46 |
47 | #define CDC_CLASS_DESC_SIZE (8 + 58)
48 | #define ARDUINO_BL_CDC_INTERFACE CDC_CLASS_DESC_SIZE
49 |
50 | /* Exported macro ------------------------------------------------------------*/
51 | /* Memory management macros */
52 | #define USBD_malloc malloc
53 | #define USBD_free free
54 | #define USBD_memset memset
55 | #define USBD_memcpy memcpy
56 | #define USBD_Delay HAL_Delay
57 |
58 | /* DEBUG macros */
59 | #if (USBD_DEBUG_LEVEL > 0)
60 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\
61 | printf("\n");
62 | #else
63 | #define USBD_UsrLog(...)
64 | #endif
65 |
66 | #if (USBD_DEBUG_LEVEL > 1)
67 |
68 | #define USBD_ErrLog(...) printf("ERROR: ") ;\
69 | printf(__VA_ARGS__);\
70 | printf("\n");
71 | #else
72 | #define USBD_ErrLog(...)
73 | #endif
74 |
75 | #if (USBD_DEBUG_LEVEL > 2)
76 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\
77 | printf(__VA_ARGS__);\
78 | printf("\n");
79 | #else
80 | #define USBD_DbgLog(...)
81 | #endif
82 |
83 | /* Exported functions ------------------------------------------------------- */
84 | extern PCD_HandleTypeDef * HAL_PCD_GetHandle(void);
85 |
86 | #endif /* __USBD_CONF_H */
87 |
88 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
89 |
--------------------------------------------------------------------------------
/app/dfu/usbd_desc.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file USB_Device/DFU_Standalone/Src/usbd_desc.c
4 | * @author MCD Application Team
5 | * @brief This file provides the USBD descriptors and string formatting method.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2019 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | #if MCUBOOT_APPLICATION_HOOKS && MCUBOOT_APPLICATION_DFU
21 |
22 | /* Includes ------------------------------------------------------------------ */
23 | #include "board.h"
24 | #include "usbd_core.h"
25 | #include "usbd_desc.h"
26 | #include "usbd_conf.h"
27 |
28 | /* Private typedef ----------------------------------------------------------- */
29 | /* Private define ------------------------------------------------------------ */
30 | #define USBD_VID BOARD_USBD_VID
31 | #define USBD_PID BOARD_USBD_PID
32 | #define USBD_LANGID_STRING 0x409
33 | #define USBD_MANUFACTURER_STRING "Arduino SA"
34 | #define USBD_PRODUCT_HS_STRING BOARD_USBD_STRING
35 | #define USBD_PRODUCT_FS_STRING BOARD_USBD_STRING
36 | #define USBD_CONFIGURATION_HS_STRING "DFU Config"
37 | #define USBD_INTERFACE_HS_STRING "DFU Interface"
38 | #define USBD_CONFIGURATION_FS_STRING "DFU Config"
39 | #define USBD_INTERFACE_FS_STRING "DFU Interface"
40 |
41 | /* Private macro ------------------------------------------------------------- */
42 | /* Private function prototypes ----------------------------------------------- */
43 | uint8_t *USBD_DFU_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t * length);
44 | uint8_t *USBD_DFU_LangIDStrDescriptor(USBD_SpeedTypeDef speed,
45 | uint16_t * length);
46 | uint8_t *USBD_DFU_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed,
47 | uint16_t * length);
48 | uint8_t *USBD_DFU_ProductStrDescriptor(USBD_SpeedTypeDef speed,
49 | uint16_t * length);
50 | uint8_t *USBD_DFU_SerialStrDescriptor(USBD_SpeedTypeDef speed,
51 | uint16_t * length);
52 | uint8_t *USBD_DFU_ConfigStrDescriptor(USBD_SpeedTypeDef speed,
53 | uint16_t * length);
54 | uint8_t *USBD_DFU_InterfaceStrDescriptor(USBD_SpeedTypeDef speed,
55 | uint16_t * length);
56 |
57 | /* Private variables --------------------------------------------------------- */
58 | USBD_DescriptorsTypeDef DFU_Desc = {
59 | USBD_DFU_DeviceDescriptor,
60 | USBD_DFU_LangIDStrDescriptor,
61 | USBD_DFU_ManufacturerStrDescriptor,
62 | USBD_DFU_ProductStrDescriptor,
63 | USBD_DFU_SerialStrDescriptor,
64 | USBD_DFU_ConfigStrDescriptor,
65 | USBD_DFU_InterfaceStrDescriptor,
66 | };
67 |
68 | /* USB Standard Device Descriptor */
69 | #if defined ( __ICCARM__ ) /* !< IAR Compiler */
70 | #pragma data_alignment=4
71 | #endif
72 | __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
73 | 0x12, /* bLength */
74 | USB_DESC_TYPE_DEVICE, /* bDescriptorType */
75 | 0x00, /* bcdUSB */
76 | 0x02,
77 | 0x00, /* bDeviceClass */
78 | 0x00, /* bDeviceSubClass */
79 | 0x00, /* bDeviceProtocol */
80 | USB_MAX_EP0_SIZE, /* bMaxPacketSize */
81 | LOBYTE(USBD_VID), /* idVendor */
82 | HIBYTE(USBD_VID), /* idVendor */
83 | LOBYTE(USBD_PID), /* idVendor */
84 | HIBYTE(USBD_PID), /* idVendor */
85 | 0x00, /* bcdDevice rel. 2.00 */
86 | 0x02,
87 | USBD_IDX_MFC_STR, /* Index of manufacturer string */
88 | USBD_IDX_PRODUCT_STR, /* Index of product string */
89 | USBD_IDX_SERIAL_STR, /* Index of serial number string */
90 | USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
91 | }; /* USB_DeviceDescriptor */
92 |
93 | /* USB Standard Device Descriptor */
94 | #if defined ( __ICCARM__ ) /* !< IAR Compiler */
95 | #pragma data_alignment=4
96 | #endif
97 | __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
98 | USB_LEN_LANGID_STR_DESC,
99 | USB_DESC_TYPE_STRING,
100 | LOBYTE(USBD_LANGID_STRING),
101 | HIBYTE(USBD_LANGID_STRING),
102 | };
103 |
104 | #if defined ( __ICCARM__ ) /* !< IAR Compiler */
105 | #pragma data_alignment=4
106 | #endif
107 | __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = {
108 | USB_SIZ_STRING_SERIAL,
109 | USB_DESC_TYPE_STRING,
110 | };
111 |
112 | #if defined ( __ICCARM__ ) /* !< IAR Compiler */
113 | #pragma data_alignment=4
114 | #endif
115 | __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
116 |
117 | /* Private functions --------------------------------------------------------- */
118 | static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len);
119 | static void Get_SerialNum(void);
120 |
121 | /**
122 | * @brief Returns the device descriptor.
123 | * @param speed: Current device speed
124 | * @param length: Pointer to data length variable
125 | * @retval Pointer to descriptor buffer
126 | */
127 | uint8_t *USBD_DFU_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t * length)
128 | {
129 | *length = sizeof(USBD_DeviceDesc);
130 | return (uint8_t *) USBD_DeviceDesc;
131 | }
132 |
133 | /**
134 | * @brief Returns the LangID string descriptor.
135 | * @param speed: Current device speed
136 | * @param length: Pointer to data length variable
137 | * @retval Pointer to descriptor buffer
138 | */
139 | uint8_t *USBD_DFU_LangIDStrDescriptor(USBD_SpeedTypeDef speed,
140 | uint16_t * length)
141 | {
142 | *length = sizeof(USBD_LangIDDesc);
143 | return (uint8_t *) USBD_LangIDDesc;
144 | }
145 |
146 | /**
147 | * @brief Returns the product string descriptor.
148 | * @param speed: Current device speed
149 | * @param length: Pointer to data length variable
150 | * @retval Pointer to descriptor buffer
151 | */
152 | uint8_t *USBD_DFU_ProductStrDescriptor(USBD_SpeedTypeDef speed,
153 | uint16_t * length)
154 | {
155 | if (speed == USBD_SPEED_HIGH)
156 | {
157 | USBD_GetString((uint8_t *) USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
158 | }
159 | else
160 | {
161 | USBD_GetString((uint8_t *) USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
162 | }
163 | return USBD_StrDesc;
164 | }
165 |
166 | /**
167 | * @brief Returns the manufacturer string descriptor.
168 | * @param speed: Current device speed
169 | * @param length: Pointer to data length variable
170 | * @retval Pointer to descriptor buffer
171 | */
172 | uint8_t *USBD_DFU_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed,
173 | uint16_t * length)
174 | {
175 | USBD_GetString((uint8_t *) USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
176 | return USBD_StrDesc;
177 | }
178 |
179 | /**
180 | * @brief Returns the serial number string descriptor.
181 | * @param speed: Current device speed
182 | * @param length: Pointer to data length variable
183 | * @retval Pointer to descriptor buffer
184 | */
185 | uint8_t *USBD_DFU_SerialStrDescriptor(USBD_SpeedTypeDef speed,
186 | uint16_t * length)
187 | {
188 | *length = USB_SIZ_STRING_SERIAL;
189 |
190 | /* Update the serial number string descriptor with the data from the unique
191 | * ID */
192 | Get_SerialNum();
193 |
194 | return (uint8_t *) USBD_StringSerial;
195 | }
196 |
197 | /**
198 | * @brief Returns the configuration string descriptor.
199 | * @param speed: Current device speed
200 | * @param length: Pointer to data length variable
201 | * @retval Pointer to descriptor buffer
202 | */
203 | uint8_t *USBD_DFU_ConfigStrDescriptor(USBD_SpeedTypeDef speed,
204 | uint16_t * length)
205 | {
206 | if (speed == USBD_SPEED_HIGH)
207 | {
208 | USBD_GetString((uint8_t *) USBD_CONFIGURATION_HS_STRING, USBD_StrDesc,
209 | length);
210 | }
211 | else
212 | {
213 | USBD_GetString((uint8_t *) USBD_CONFIGURATION_FS_STRING, USBD_StrDesc,
214 | length);
215 | }
216 | return USBD_StrDesc;
217 | }
218 |
219 | /**
220 | * @brief Returns the interface string descriptor.
221 | * @param speed: Current device speed
222 | * @param length: Pointer to data length variable
223 | * @retval Pointer to descriptor buffer
224 | */
225 | uint8_t *USBD_DFU_InterfaceStrDescriptor(USBD_SpeedTypeDef speed,
226 | uint16_t * length)
227 | {
228 | if (speed == USBD_SPEED_HIGH)
229 | {
230 | USBD_GetString((uint8_t *) USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
231 | }
232 | else
233 | {
234 | USBD_GetString((uint8_t *) USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
235 | }
236 | return USBD_StrDesc;
237 | }
238 |
239 | static void utox8(uint32_t val, uint8_t* s) {
240 | for (int i = 0; i < 16; i=i+2) {
241 | int d = val & 0XF;
242 | val = (val >> 4);
243 |
244 | s[15 - i -1] = d > 9 ? 'A' + d - 10 : '0' + d;
245 | s[15 - i] = '\0';
246 | }
247 | }
248 |
249 | uint8_t getUniqueSerialNumber(uint8_t* name) {
250 | utox8(HAL_GetUIDw0(), &name[0]);
251 | utox8(HAL_GetUIDw1(), &name[16]);
252 | utox8(HAL_GetUIDw2(), &name[32]);
253 | return 48;
254 | }
255 |
256 | /**
257 | * @brief Create the serial number string descriptor
258 | * @param None
259 | * @retval None
260 | */
261 | static void Get_SerialNum(void)
262 | {
263 | getUniqueSerialNumber(&USBD_StringSerial[2]);
264 | }
265 |
266 | /**
267 | * @brief Convert Hex 32Bits value into char
268 | * @param value: value to convert
269 | * @param pbuf: pointer to the buffer
270 | * @param len: buffer length
271 | * @retval None
272 | */
273 | static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len)
274 | {
275 | uint8_t idx = 0;
276 |
277 | for (idx = 0; idx < len; idx++)
278 | {
279 | if (((value >> 28)) < 0xA)
280 | {
281 | pbuf[2 * idx] = (value >> 28) + '0';
282 | }
283 | else
284 | {
285 | pbuf[2 * idx] = (value >> 28) + 'A' - 10;
286 | }
287 |
288 | value = value << 4;
289 |
290 | pbuf[2 * idx + 1] = 0;
291 | }
292 | }
293 |
294 | #endif
295 |
296 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
297 |
--------------------------------------------------------------------------------
/app/dfu/usbd_desc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file USB_Device/DFU_Standalone/Inc/usbd_desc.h
4 | * @author MCD Application Team
5 | * @brief Header for usbd_desc.c module
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2019 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USBD_DESC_H
22 | #define __USBD_DESC_H
23 |
24 | /* Includes ------------------------------------------------------------------*/
25 | #include "usbd_def.h"
26 |
27 | /* Exported types ------------------------------------------------------------*/
28 | /* Exported constants --------------------------------------------------------*/
29 |
30 | #define USB_SIZ_STRING_SERIAL 48 + 2
31 | /* Exported macro ------------------------------------------------------------*/
32 | /* Exported functions ------------------------------------------------------- */
33 | extern USBD_DescriptorsTypeDef DFU_Desc;
34 |
35 | #endif /* __USBD_DESC_H */
36 |
37 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
38 |
--------------------------------------------------------------------------------
/app/dfu/usbd_dfu_flash.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file USB_Device/DFU_Standalone/Src/usbd_dfu_flash.c
4 | * @author MCD Application Team
5 | * @brief Memory management layer
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2019 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | #if MCUBOOT_APPLICATION_HOOKS && MCUBOOT_APPLICATION_DFU
21 |
22 | /* Includes ------------------------------------------------------------------ */
23 | #include "usbd_dfu_flash.h"
24 | //#include "option_bits.h"
25 | #include "mbed.h"
26 | #include "board.h"
27 | #include "BlockDevice.h"
28 | #include "FlashSimBlockDevice.h"
29 | #include "flash_map_backend/secondary_bd.h"
30 | #include "bootutil/bootutil.h"
31 |
32 | /* Private typedef ----------------------------------------------------------- */
33 | /* Private define ------------------------------------------------------------ */
34 | #define FLASH_DESC_STR "@Internal Flash 2MB /0x08000000/01*128Ka,15*128Kg"
35 | //#define BOOTLOADER_DESC_STR "@Option Bits /0x52002000/01*1Ka"
36 | #define QSPI_FLASH_DESC_STR "@Ext RAW Flash 16MB /0x90000000/4096*4Kg"
37 |
38 | #define FLASH_ERASE_TIME (uint16_t)0
39 | #define FLASH_PROGRAM_TIME (uint16_t)0
40 |
41 | /* Private macro ------------------------------------------------------------- */
42 | /* Private variables --------------------------------------------------------- */
43 | /* Private function prototypes ----------------------------------------------- */
44 | char BOOTLOADER_DESC_STR[48];
45 | char FILE_FLASH_DESC_STR[48] = "@Ext File Flash 16MB /0xA0000000/4096*4Kg";
46 |
47 |
48 | /* Extern function prototypes ------------------------------------------------ */
49 | uint16_t Flash_If_Init(void);
50 | uint16_t Flash_If_Erase(uint32_t Add);
51 | uint16_t Flash_If_Write(uint8_t * src, uint8_t * dest, uint32_t Len);
52 | uint8_t *Flash_If_Read(uint8_t * src, uint8_t * dest, uint32_t Len);
53 | uint16_t Flash_If_DeInit(void);
54 | uint16_t Flash_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t * buffer);
55 |
56 | extern FlashIAP flash;
57 | mbed::BlockDevice* qspi_flash = mbed::BlockDevice::get_default_instance();
58 | mbed::BlockDevice* dfu_secondary_bd = get_secondary_bd();
59 |
60 | const uint32_t QSPIFLASH_BASE_ADDRESS = 0x90000000;
61 | const uint32_t FILEBLOCK_BASE_ADDRESS = 0xA0000000;
62 |
63 | USBD_DFU_MediaTypeDef USBD_DFU_Flash_fops = {
64 | {
65 | (uint8_t *) FLASH_DESC_STR,
66 | (uint8_t *) QSPI_FLASH_DESC_STR,
67 | (uint8_t *) FILE_FLASH_DESC_STR,
68 | (uint8_t *) BOOTLOADER_DESC_STR
69 | },
70 | Flash_If_Init,
71 | Flash_If_DeInit,
72 | Flash_If_Erase,
73 | Flash_If_Write,
74 | Flash_If_Read,
75 | Flash_If_GetStatus,
76 | };
77 |
78 | bool Flash_If_Init_requested = false;
79 |
80 | void init_Memories() {
81 | flash.init();
82 | qspi_flash->init();
83 | if (dfu_secondary_bd != nullptr) {
84 | dfu_secondary_bd->init();
85 | snprintf(BOOTLOADER_DESC_STR, sizeof(BOOTLOADER_DESC_STR), "@MCUboot v.%02d /0x00000000/0*4Kg", BOOTLOADER_VERSION);
86 | } else {
87 | snprintf(BOOTLOADER_DESC_STR, sizeof(BOOTLOADER_DESC_STR), "@Arduino boot v.%02d /0x00000000/0*4Kg", BOOTLOADER_VERSION);
88 | snprintf(FILE_FLASH_DESC_STR, sizeof(FILE_FLASH_DESC_STR), "@Ext File Flash 0MB /0x00000000/0*4Kg");
89 | }
90 | }
91 |
92 | Thread writeThread(osPriorityHigh);
93 | EventQueue writeQueue;
94 |
95 | /**
96 | * @brief Initializes Memory.
97 | * @param None
98 | * @retval 0 if operation is successful, MAL_FAIL else.
99 | */
100 | uint16_t Flash_If_Init(void)
101 | {
102 | Flash_If_Init_requested = true;
103 | writeThread.start(callback(&writeQueue, &EventQueue::dispatch_forever));
104 | return 0;
105 | }
106 |
107 | /**
108 | * @brief De-Initializes Memory.
109 | * @param None
110 | * @retval 0 if operation is successful, MAL_FAIL else.
111 | */
112 | uint16_t Flash_If_DeInit(void)
113 | {
114 | flash.deinit();
115 | if (dfu_secondary_bd != nullptr) {
116 | dfu_secondary_bd->deinit();
117 | boot_set_pending(false);
118 | }
119 | return 0;
120 | }
121 |
122 | static bool isExternalFlash(uint32_t Add) {
123 | return (Add >= QSPIFLASH_BASE_ADDRESS);
124 | }
125 |
126 | static bool isFileBlockFlash(uint32_t Add) {
127 | return (Add >= FILEBLOCK_BASE_ADDRESS);
128 | }
129 |
130 | /**
131 | * @brief Erases sector.
132 | * @param Add: Address of sector to be erased.
133 | * @retval 0 if operation is successful, MAL_FAIL else.
134 | */
135 | uint16_t Flash_If_Erase(uint32_t Add)
136 | {
137 | if (isFileBlockFlash(Add) && dfu_secondary_bd == nullptr) {
138 | return -1;
139 | } else if (isFileBlockFlash(Add) && dfu_secondary_bd != nullptr) {
140 | Add -= FILEBLOCK_BASE_ADDRESS;
141 | return dfu_secondary_bd->erase(Add, dfu_secondary_bd->get_erase_size(Add));
142 | } else if (isExternalFlash(Add)) {
143 | Add -= QSPIFLASH_BASE_ADDRESS;
144 | return qspi_flash->erase(Add, qspi_flash->get_erase_size(Add));
145 | } else {
146 | return flash.erase(Add, flash.get_sector_size(Add));
147 | }
148 | }
149 |
150 | struct writeInfo {
151 | uint8_t* src;
152 | uint8_t* dest;
153 | uint32_t Len;
154 | };
155 |
156 | void delayed_write(struct writeInfo* info) {
157 | flash.program(info->src, (uint32_t)info->dest, info->Len);
158 | free(info->src);
159 | free(info);
160 | }
161 |
162 | /**
163 | * @brief Writes Data into Memory.
164 | * @param src: Pointer to the source buffer. Address to be written to.
165 | * @param dest: Pointer to the destination buffer.
166 | * @param Len: Number of data to be written (in bytes).
167 | * @retval 0 if operation is successful, MAL_FAIL else.
168 | */
169 | uint16_t Flash_If_Write(uint8_t * src, uint8_t * dest, uint32_t Len)
170 | {
171 | if (isFileBlockFlash((uint32_t)dest) && dfu_secondary_bd == nullptr) {
172 | return -1;
173 | } else if (isFileBlockFlash((uint32_t)dest) && dfu_secondary_bd != nullptr) {
174 | dest -= FILEBLOCK_BASE_ADDRESS;
175 | if (Len < dfu_secondary_bd->get_erase_size(0)) {
176 | uint8_t* srcCopy = (uint8_t*)malloc(dfu_secondary_bd->get_erase_size(0));
177 | memcpy(srcCopy, src, Len);
178 | memset(&srcCopy[Len], dfu_secondary_bd->get_erase_value(), dfu_secondary_bd->get_erase_size(0) - Len);
179 | return dfu_secondary_bd->program(&srcCopy[0],(uint32_t)dest, dfu_secondary_bd->get_erase_size(0));
180 | }
181 | return dfu_secondary_bd->program(src, (uint32_t)dest, Len);
182 | } else if (isExternalFlash((uint32_t)dest)) {
183 | dest -= QSPIFLASH_BASE_ADDRESS;
184 | if (Len < qspi_flash->get_erase_size(0)) {
185 | Len = qspi_flash->get_erase_size(0);
186 | }
187 | return qspi_flash->program(src, (uint32_t)dest, Len);
188 | } else {
189 | uint8_t* srcCopy = (uint8_t*)malloc(Len);
190 | memcpy(srcCopy, src, Len);
191 | struct writeInfo* info = (struct writeInfo*)malloc(sizeof(struct writeInfo));
192 | info->src = srcCopy;
193 | info->dest = dest;
194 | info->Len = Len;
195 | writeQueue.call(callback(&delayed_write, info));
196 | }
197 | return 0;
198 | }
199 |
200 | /**
201 | * @brief Reads Data into Memory.
202 | * @param src: Pointer to the source buffer. Address to be written to.
203 | * @param dest: Pointer to the destination buffer.
204 | * @param Len: Number of data to be read (in bytes).
205 | * @retval Pointer to the physical address where data should be read.
206 | */
207 | uint8_t *Flash_If_Read(uint8_t * src, uint8_t * dest, uint32_t Len)
208 | {
209 | uint32_t i = 0;
210 | uint8_t *psrc = src;
211 |
212 | if (isFileBlockFlash((uint32_t)src) && dfu_secondary_bd == nullptr) {
213 | Len = 0;
214 | } else if (isFileBlockFlash((uint32_t)src) && dfu_secondary_bd != nullptr) {
215 | src -= FILEBLOCK_BASE_ADDRESS;
216 | dfu_secondary_bd->read(dest, (uint32_t)src, Len);
217 | } else if (isExternalFlash((uint32_t)src)) {
218 | src -= QSPIFLASH_BASE_ADDRESS;
219 | qspi_flash->read(dest, (uint32_t)src, Len);
220 | } else {
221 | for (i = 0; i < Len; i++)
222 | {
223 | dest[i] = *psrc++;
224 | }
225 | }
226 |
227 | /* Return a valid address to avoid HardFault */
228 | return (uint8_t *) (dest);
229 | }
230 |
231 | /**
232 | * @brief Gets Memory Status.
233 | * @param Add: Address to be read from.
234 | * @param Cmd: Number of data to be read (in bytes).
235 | * @retval 0 if operation is successful
236 | */
237 | uint16_t Flash_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t * buffer)
238 | {
239 | switch (Cmd)
240 | {
241 | case DFU_MEDIA_PROGRAM:
242 | buffer[1] = (uint8_t) FLASH_PROGRAM_TIME;
243 | buffer[2] = (uint8_t) (FLASH_PROGRAM_TIME >> 8);
244 | buffer[3] = 0;
245 | break;
246 |
247 | case DFU_MEDIA_ERASE:
248 | default:
249 | buffer[1] = (uint8_t) FLASH_ERASE_TIME;
250 | buffer[2] = (uint8_t) (FLASH_ERASE_TIME >> 8);
251 | buffer[3] = 0;
252 | break;
253 | }
254 | return 0;
255 | }
256 |
257 | #endif
258 |
259 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
260 |
--------------------------------------------------------------------------------
/app/dfu/usbd_dfu_flash.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file USB_Device/DFU_Standalone/Inc/usbd_dfu_flash.h
4 | * @author MCD Application Team
5 | * @brief Header for usbd_dfu_flash.c file.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2019 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Ultimate Liberty license
13 | * SLA0044, the "License"; You may not use this file except in compliance with
14 | * the License. You may obtain a copy of the License at:
15 | * www.st.com/SLA0044
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USBD_DFU_FLASH_H_
22 | #define __USBD_DFU_FLASH_H_
23 |
24 | /* Includes ------------------------------------------------------------------*/
25 | #include "usbd_dfu.h"
26 |
27 | /* Exported types ------------------------------------------------------------*/
28 | /* Exported constants --------------------------------------------------------*/
29 |
30 | /* Base address of the Flash sectors Bank 1 */
31 | #define ADDR_FLASH_SECTOR_0_BANK1 ((uint32_t)0x08000000) /* Base @ of Sector 0, 128 Kbytes */
32 | #define ADDR_FLASH_SECTOR_1_BANK1 ((uint32_t)0x08020000) /* Base @ of Sector 1, 128 Kbytes */
33 | #define ADDR_FLASH_SECTOR_2_BANK1 ((uint32_t)0x08040000) /* Base @ of Sector 2, 128 Kbytes */
34 | #define ADDR_FLASH_SECTOR_3_BANK1 ((uint32_t)0x08060000) /* Base @ of Sector 3, 128 Kbytes */
35 | #define ADDR_FLASH_SECTOR_4_BANK1 ((uint32_t)0x08080000) /* Base @ of Sector 4, 128 Kbytes */
36 | #define ADDR_FLASH_SECTOR_5_BANK1 ((uint32_t)0x080A0000) /* Base @ of Sector 5, 128 Kbytes */
37 | #define ADDR_FLASH_SECTOR_6_BANK1 ((uint32_t)0x080C0000) /* Base @ of Sector 6, 128 Kbytes */
38 | #define ADDR_FLASH_SECTOR_7_BANK1 ((uint32_t)0x080E0000) /* Base @ of Sector 7, 128 Kbytes */
39 |
40 | /* Base address of the Flash sectors Bank 2 */
41 | #define ADDR_FLASH_SECTOR_0_BANK2 ((uint32_t)0x08100000) /* Base @ of Sector 0, 128 Kbytes */
42 | #define ADDR_FLASH_SECTOR_1_BANK2 ((uint32_t)0x08120000) /* Base @ of Sector 1, 128 Kbytes */
43 | #define ADDR_FLASH_SECTOR_2_BANK2 ((uint32_t)0x08140000) /* Base @ of Sector 2, 128 Kbytes */
44 | #define ADDR_FLASH_SECTOR_3_BANK2 ((uint32_t)0x08160000) /* Base @ of Sector 3, 128 Kbytes */
45 | #define ADDR_FLASH_SECTOR_4_BANK2 ((uint32_t)0x08180000) /* Base @ of Sector 4, 128 Kbytes */
46 | #define ADDR_FLASH_SECTOR_5_BANK2 ((uint32_t)0x081A0000) /* Base @ of Sector 5, 128 Kbytes */
47 | #define ADDR_FLASH_SECTOR_6_BANK2 ((uint32_t)0x081C0000) /* Base @ of Sector 6, 128 Kbytes */
48 | #define ADDR_FLASH_SECTOR_7_BANK2 ((uint32_t)0x081E0000) /* Base @ of Sector 7, 128 Kbytes */
49 |
50 | /* Exported macro ------------------------------------------------------------*/
51 | extern USBD_DFU_MediaTypeDef USBD_DFU_Flash_fops;
52 | #define FLASH_BASE_ADDR (uint32_t)(FLASH_BASE)
53 | #define FLASH_END_ADDR (uint32_t)(0x081FFFFF)
54 |
55 | /* Exported functions ------------------------------------------------------- */
56 | extern void init_Memories(void);
57 |
58 | #endif /* __USBD_DFU_FLASH_H_ */
59 |
60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
61 |
--------------------------------------------------------------------------------
/app/fileblockdevice/FileBlockDevice.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #include "FileBlockDevice.h"
20 | #include "platform/mbed_assert.h"
21 | #include "stddef.h"
22 | #include
23 |
24 | #ifndef MBED_CONF_MBED_TRACE_ENABLE
25 | #define MBED_CONF_MBED_TRACE_ENABLE 0
26 | #endif
27 |
28 | #include "mbed_trace.h"
29 | #define TRACE_GROUP "FILEBD"
30 |
31 | namespace mbed {
32 |
33 | FileBlockDevice::FileBlockDevice(const char *path, const char *flags, bd_size_t bd_size, bd_size_t r_size, bd_size_t w_size, bd_size_t e_size)
34 | :_path(path), _oflag(flags), _bd_size(bd_size), _r_size(r_size), _w_size(w_size), _e_size(e_size)
35 | {
36 |
37 | }
38 |
39 | int FileBlockDevice::init()
40 | {
41 | tr_debug("Opening file block device %s", _path);
42 |
43 | _file[0] = fopen(_path, _oflag);
44 | if (_file[0] == NULL) {
45 | printf("E-Cannot open file block device %s %s\n", _path, _oflag);
46 | return BD_ERROR_DEVICE_ERROR;
47 | }
48 |
49 | int err = fseek (_file[0] , 0 , SEEK_END);
50 | if (err) {
51 | printf("E-Init:fseek\n");
52 | return BD_ERROR_DEVICE_ERROR;
53 | }
54 |
55 | uint32_t f_size = ftell (_file[0]);
56 | if (f_size != _bd_size) {
57 | printf("W-File %s size (0x%zx) should be the same of underlying block device (0x%zx)\n", _path, f_size, _bd_size);
58 | }
59 |
60 | tr_debug("Opened file block device handle %d file size 0x%zx", _file[0], f_size);
61 |
62 | _is_initialized = true;
63 |
64 | return BD_ERROR_OK;
65 | }
66 |
67 | int FileBlockDevice::deinit()
68 | {
69 | tr_debug("Closing file block handle %d", _file[0]);
70 | fclose(_file[0]);
71 | return BD_ERROR_OK;
72 | }
73 |
74 | int FileBlockDevice::sync()
75 | {
76 | return BD_ERROR_OK;
77 | }
78 |
79 | int FileBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
80 | {
81 | if (_file[0] == NULL) {
82 | printf("E-Read:invalid handle\n");
83 | return BD_ERROR_DEVICE_ERROR;
84 | }
85 |
86 | tr_debug("reading addr 0x%x", (long)addr);
87 | tr_debug("reading size %d", (int)size);
88 | int err = fseek(_file[0], addr, SEEK_SET);
89 | if (err) {
90 | printf("E-Read:fseek\n");
91 | return BD_ERROR_DEVICE_ERROR;
92 | }
93 | size_t count = fread(buffer, 1u, size, _file[0]);
94 | tr_debug("reading count %d", (int)count);
95 | if (count != size) {
96 | printf("E-Read:handle %d count 0x%zx\n", _file[0], count);
97 | return BD_ERROR_DEVICE_ERROR;
98 | }
99 |
100 | return BD_ERROR_OK;
101 | }
102 |
103 | int FileBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
104 | {
105 | if (_file[0] == NULL) {
106 | printf("E-Program:invalid handle\n");
107 | return BD_ERROR_DEVICE_ERROR;
108 | }
109 |
110 | tr_debug("program addr 0x%x", (long)addr);
111 | tr_debug("program size %d", (int)size);
112 | int err = fseek(_file[0], addr, SEEK_SET);
113 | if (err) {
114 | printf("E-Program:fseek\n");
115 | return BD_ERROR_DEVICE_ERROR;
116 | }
117 |
118 | int count = fwrite(buffer, size, 1u, _file[0]);
119 | if (count != 1u) {
120 | printf("E-Program:handle %d count 0x%zx\n", _file[0], count);
121 | return BD_ERROR_DEVICE_ERROR;
122 | }
123 |
124 | err = fflush(_file[0]);
125 | if (err != 0u) {
126 | printf("E-Program:flush\n");
127 | return BD_ERROR_DEVICE_ERROR;
128 | }
129 |
130 | return BD_ERROR_OK;
131 | }
132 |
133 | int FileBlockDevice::erase(bd_addr_t addr, bd_size_t size)
134 | {
135 | if (_file[0] == NULL) {
136 | printf("E-Erase:invalid handle\n");
137 | return BD_ERROR_DEVICE_ERROR;
138 | }
139 |
140 | tr_debug("program addr 0x%x", (long)addr);
141 | tr_debug("program size %d", (int)size);
142 | bd_size_t len;
143 | for (len = 0; len < size; len++) {
144 | int err = fseek(_file[0], addr + len, SEEK_SET);
145 | if (err) {
146 | printf("E-Erase:fseek\n");
147 | return BD_ERROR_DEVICE_ERROR;
148 | }
149 | uint8_t erase_val = 0xFF;
150 | int count = fwrite(&erase_val, 1u, 1u, _file[0]);
151 | if (count != 1u) {
152 | printf("E-Erase:handle %d count 0x%zx\n", _file[0], count);
153 | return BD_ERROR_DEVICE_ERROR;
154 | }
155 | }
156 |
157 | int err = fflush(_file[0]);
158 | if (err != 0u) {
159 | printf("E-Erase:flush\n");
160 | return BD_ERROR_DEVICE_ERROR;
161 | }
162 |
163 | return BD_ERROR_OK;
164 | }
165 |
166 | bool FileBlockDevice::is_valid_read(bd_addr_t addr, bd_size_t size) const
167 | {
168 | return ((addr + size) <= _bd_size);
169 | }
170 |
171 | bool FileBlockDevice::is_valid_program(bd_addr_t addr, bd_size_t size) const
172 | {
173 | return ((addr + size) <= _bd_size);
174 | }
175 |
176 | bool FileBlockDevice::is_valid_erase(bd_addr_t addr, bd_size_t size) const
177 | {
178 | return ((addr + size) <= _bd_size);
179 | }
180 |
181 | bd_size_t FileBlockDevice::get_read_size() const
182 | {
183 | // Return minimum read size in bytes for the device
184 | return _r_size;
185 | }
186 |
187 | bd_size_t FileBlockDevice::get_program_size() const
188 | {
189 | // Return minimum program/write size in bytes for the device
190 | return _w_size;
191 | }
192 |
193 | bd_size_t FileBlockDevice::get_erase_size() const
194 | {
195 | // return minimal erase size supported by all regions (0 if none exists)
196 | return _e_size;
197 | }
198 |
199 | bd_size_t FileBlockDevice::get_erase_size(bd_addr_t addr) const
200 | {
201 | return _e_size;
202 | }
203 |
204 | int FileBlockDevice::get_erase_value() const
205 | {
206 | return 0xFF;
207 | }
208 |
209 | bd_size_t FileBlockDevice::size() const
210 | {
211 | return _bd_size;
212 | }
213 |
214 | const char *FileBlockDevice::get_type() const
215 | {
216 | return "FILEBD";
217 | }
218 |
219 | } // namespace mbed
220 |
--------------------------------------------------------------------------------
/app/fileblockdevice/FileBlockDevice.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | /** \addtogroup storage */
20 | /** @{*/
21 |
22 | #ifndef MBED_FILE_BLOCK_DEVICE_H
23 | #define MBED_FILE_BLOCK_DEVICE_H
24 |
25 | #include "mbed.h"
26 | #include "BlockDevice.h"
27 | #include "platform/mbed_assert.h"
28 | #include
29 |
30 | namespace mbed {
31 |
32 | /** BlockDevice for mapping a file into a Blockdevice
33 | *
34 | */
35 | class FileBlockDevice : public BlockDevice {
36 | public:
37 | /** Create FileBlockDevice - An SFDP based Flash Block Device over QSPI bus
38 | *
39 | */
40 | FileBlockDevice(const char *path, const char * flags, bd_size_t bd_size, bd_size_t r_size, bd_size_t w_size, bd_size_t e_size);
41 |
42 | /** Lifetime of a block device
43 | */
44 | ~FileBlockDevice() {};
45 |
46 | /** Initialize a block device
47 | *
48 | * @return QSPIF_BD_ERROR_OK(0) - success
49 | * QSPIF_BD_ERROR_DEVICE_ERROR - device driver transaction failed
50 | * QSPIF_BD_ERROR_READY_FAILED - Waiting for Memory ready failed or timedout
51 | * QSPIF_BD_ERROR_PARSING_FAILED - unexpected format or values in one of the SFDP tables
52 | */
53 | virtual int init();
54 |
55 | /** Deinitialize a block device
56 | *
57 | * @return QSPIF_BD_ERROR_OK(0) - success
58 | * QSPIF_BD_ERROR_DEVICE_ERROR - device driver transaction failed
59 | */
60 | virtual int deinit();
61 |
62 | /** Ensure data on storage is in sync with the driver
63 | *
64 | * @return 0 on success or a negative error code on failure
65 | */
66 | virtual int sync();
67 |
68 | /** Read blocks from a block device
69 | *
70 | * @param buffer Buffer to write blocks to
71 | * @param addr Address of block to begin reading from
72 | * @param size Size to read in bytes, must be a multiple of read block size
73 | * @return QSPIF_BD_ERROR_OK(0) - success
74 | * QSPIF_BD_ERROR_DEVICE_ERROR - device driver transaction failed
75 | */
76 | virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
77 |
78 | /** Program blocks to a block device
79 | *
80 | * The blocks must have been erased prior to being programmed
81 | *
82 | * @param buffer Buffer of data to write to blocks
83 | * @param addr Address of block to begin writing to
84 | * @param size Size to write in bytes, must be a multiple of program block size
85 | * @return QSPIF_BD_ERROR_OK(0) - success
86 | * QSPIF_BD_ERROR_DEVICE_ERROR - device driver transaction failed
87 | * QSPIF_BD_ERROR_READY_FAILED - Waiting for Memory ready failed or timed out
88 | * QSPIF_BD_ERROR_WREN_FAILED - Write Enable failed
89 | * QSPIF_BD_ERROR_PARSING_FAILED - unexpected format or values in one of the SFDP tables
90 | */
91 | virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
92 |
93 | /** Erase blocks on a block device
94 | *
95 | * The state of an erased block is undefined until it has been programmed
96 | *
97 | * @param addr Address of block to begin erasing
98 | * @param size Size to erase in bytes, must be a multiple of erase block size
99 | * @return QSPIF_BD_ERROR_OK(0) - success
100 | * QSPIF_BD_ERROR_DEVICE_ERROR - device driver transaction failed
101 | * QSPIF_BD_ERROR_READY_FAILED - Waiting for Memory ready failed or timed out
102 | * QSPIF_BD_ERROR_WREN_FAILED - Write Enable failed
103 | * QSPIF_BD_ERROR_PARSING_FAILED - unexpected format or values in one of the SFDP tables
104 | * QSPIF_BD_ERROR_INVALID_ERASE_PARAMS - Trying to erase unaligned address or size
105 | */
106 | virtual int erase(bd_addr_t addr, bd_size_t size);
107 |
108 | /** Get the size of a readable block
109 | *
110 | * @return Size of a readable block in bytes
111 | */
112 | virtual bd_size_t get_read_size() const;
113 |
114 | /** Get the size of a programable block
115 | *
116 | * @return Size of a program block size in bytes
117 | * @note Must be a multiple of the read size
118 | */
119 | virtual bd_size_t get_program_size() const;
120 |
121 | /** Get the size of a eraseable block
122 | *
123 | * @return Size of a minimal erase block, common to all regions, in bytes
124 | * @note Must be a multiple of the program size
125 | */
126 | virtual bd_size_t get_erase_size() const;
127 |
128 | /** Get the size of minimal eraseable sector size of given address
129 | *
130 | * @param addr Any address within block queried for erase sector size (can be any address within flash size offset)
131 | * @return Size of minimal erase sector size, in given address region, in bytes
132 | * @note Must be a multiple of the program size
133 | */
134 | virtual bd_size_t get_erase_size(bd_addr_t addr) const;
135 |
136 | /** Get the value of storage byte after it was erased
137 | *
138 | * If get_erase_value returns a non-negative byte value, the underlying
139 | * storage is set to that value when erased, and storage containing
140 | * that value can be programmed without another erase.
141 | *
142 | * @return The value of storage when erased, or -1 if you can't
143 | * rely on the value of erased storage
144 | */
145 | virtual int get_erase_value() const;
146 |
147 | /** Get the total size of the underlying device
148 | *
149 | * @return Size of the underlying device in bytes
150 | */
151 | virtual mbed::bd_size_t size() const;
152 |
153 | /** Get the BlockDevice class type.
154 | *
155 | * @return A string represent the BlockDevice class type.
156 | */
157 | virtual const char *get_type() const;
158 |
159 | /** Convenience function for checking block program validity
160 | *
161 | * @param addr Address of block to begin writing to
162 | * @param size Size to write in bytes
163 | * @return True if program is valid for underlying block device
164 | */
165 | virtual bool is_valid_program(bd_addr_t addr, bd_size_t size) const;
166 |
167 | /** Convenience function for checking block read validity
168 | *
169 | * @param addr Address of block to begin reading from
170 | * @param size Size to read in bytes
171 | * @return True if read is valid for underlying block device
172 | */
173 | virtual bool is_valid_read(bd_addr_t addr, bd_size_t size) const;
174 |
175 | /** Convenience function for checking block erase validity
176 | *
177 | * @param addr Address of block to begin erasing
178 | * @param size Size to erase in bytes
179 | * @return True if erase is valid for underlying block device
180 | */
181 | virtual bool is_valid_erase(bd_addr_t addr, bd_size_t size) const;
182 |
183 | private:
184 | FILE *_file[1];
185 | const char *_path;
186 | const char *_oflag;
187 | bd_size_t _bd_size;
188 | bd_size_t _r_size;
189 | bd_size_t _w_size;
190 | bd_size_t _e_size;
191 | bool _is_initialized;
192 | };
193 |
194 | } // namespace mbed
195 |
196 | // Added "using" for backwards compatibility
197 | #ifndef MBED_NO_GLOBAL_USING_DIRECTIVE
198 | using mbed::FileBlockDevice;
199 | #endif
200 |
201 | #endif
202 |
203 | /** @}*/
204 |
--------------------------------------------------------------------------------
/app/keys/ecdsa-p256-encrypt-key.c:
--------------------------------------------------------------------------------
1 | /* Autogenerated by imgtool.py, do not edit. */
2 | #if MCUBOOT_INCLUDE_KEYS
3 | const unsigned char enc_priv_key[256] __attribute__ ((section (".encrypt_key"), used)) = {
4 | 0x30, 0x81, 0x87, 0x02, 0x01, 0x00, 0x30, 0x13,
5 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
6 | 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
7 | 0x03, 0x01, 0x07, 0x04, 0x6d, 0x30, 0x6b, 0x02,
8 | 0x01, 0x01, 0x04, 0x20, 0x79, 0x72, 0xb6, 0xf3,
9 | 0x62, 0x91, 0x09, 0xbb, 0x35, 0x22, 0xb8, 0x54,
10 | 0x32, 0x3b, 0xfe, 0x1c, 0x9f, 0xa7, 0x10, 0x6f,
11 | 0xba, 0xaf, 0x73, 0x64, 0xd3, 0xf5, 0x31, 0xbc,
12 | 0x28, 0xe7, 0xc9, 0x72, 0xa1, 0x44, 0x03, 0x42,
13 | 0x00, 0x04, 0x6a, 0xc9, 0x20, 0x4c, 0x96, 0xd6,
14 | 0x89, 0xe8, 0xd1, 0x6e, 0x51, 0x04, 0x02, 0x86,
15 | 0xe8, 0x95, 0x0b, 0x22, 0xc4, 0xc9, 0x95, 0x06,
16 | 0x4f, 0xf5, 0x1b, 0xf6, 0xd0, 0xe3, 0x83, 0xd9,
17 | 0xd1, 0x81, 0x66, 0x6e, 0xf2, 0x07, 0x3b, 0x03,
18 | 0xdb, 0xe4, 0xd1, 0xde, 0x7c, 0x43, 0x70, 0x8d,
19 | 0xa2, 0x89, 0xeb, 0x1b, 0xfa, 0xbe, 0x02, 0x5e,
20 | 0x5c, 0xa0, 0x12, 0xdc, 0x23, 0x31, 0xc1, 0xe0,
21 | 0x37, 0xb0,
22 | };
23 | #else
24 | const unsigned char enc_priv_key[256] __attribute__ ((section (".encrypt_key"), used)) = {
25 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
26 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
27 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
28 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
30 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
31 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
32 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
33 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
34 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
35 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
36 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
37 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
38 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
39 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
40 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
41 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
42 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
43 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
44 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
45 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
46 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
47 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
48 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
49 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
50 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
51 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
52 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
53 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
54 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
55 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
56 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
57 | };
58 | #endif
59 | const unsigned int enc_priv_key_len = 138;
60 |
--------------------------------------------------------------------------------
/app/keys/ecdsa-p256-encrypt-key.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgeXK282KRCbs1IrhU
3 | Mjv+HJ+nEG+6r3Nk0/UxvCjnyXKhRANCAARqySBMltaJ6NFuUQQChuiVCyLEyZUG
4 | T/Ub9tDjg9nRgWZu8gc7A9vk0d58Q3CNoonrG/q+Al5coBLcIzHB4Dew
5 | -----END PRIVATE KEY-----
6 |
--------------------------------------------------------------------------------
/app/keys/ecdsa-p256-signing-key.c:
--------------------------------------------------------------------------------
1 | /* Autogenerated by imgtool.py, do not edit. */
2 | #if MCUBOOT_INCLUDE_KEYS
3 | const unsigned char ecdsa_pub_key[256] __attribute__ ((section (".signing_key"), used)) = {
4 | 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86,
5 | 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a,
6 | 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,
7 | 0x42, 0x00, 0x04, 0xd5, 0x16, 0x35, 0x26, 0xc3,
8 | 0x3b, 0xad, 0x4d, 0x67, 0x8e, 0x43, 0x24, 0xc4,
9 | 0x98, 0xe9, 0x6b, 0x2e, 0xbe, 0x0d, 0xa3, 0xf1,
10 | 0xf4, 0x97, 0x80, 0x7b, 0x31, 0x32, 0x07, 0xd9,
11 | 0x95, 0xa7, 0x17, 0x57, 0x69, 0x43, 0x7b, 0xe9,
12 | 0xc8, 0xaa, 0xd0, 0x0a, 0x0c, 0x86, 0x0b, 0xe3,
13 | 0x7f, 0x99, 0x88, 0x51, 0xc4, 0xf9, 0x22, 0x98,
14 | 0xbe, 0x5e, 0xaa, 0xfd, 0x90, 0x3c, 0xa2, 0x74,
15 | 0x18, 0x49, 0x05,
16 | };
17 | #else
18 | const unsigned char ecdsa_pub_key[256] __attribute__ ((section (".signing_key"), used)) = {
19 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
20 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
21 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
22 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
23 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
24 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
25 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
26 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
27 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
28 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
30 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
31 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
32 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
33 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
34 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
35 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
36 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
37 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
38 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
39 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
40 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
41 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
42 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
43 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
44 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
45 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
46 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
47 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
48 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
49 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
50 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
51 | };
52 | #endif
53 | const unsigned int ecdsa_pub_key_len = 91;
54 |
--------------------------------------------------------------------------------
/app/keys/ecdsa-p256-signing-key.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgx7NPA8ciVn4ZF6tp
3 | wW8dRJpfN3098/hTLmP1uVEEMr+hRANCAATVFjUmwzutTWeOQyTEmOlrLr4No/H0
4 | l4B7MTIH2ZWnF1dpQ3vpyKrQCgyGC+N/mYhRxPkimL5eqv2QPKJ0GEkF
5 | -----END PRIVATE KEY-----
6 |
--------------------------------------------------------------------------------
/app/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #if MCUBOOT_APPLICATION_HOOKS
20 |
21 | #include "mbed.h"
22 | #include "board.h"
23 | #include "ota.h"
24 | #include "rtc.h"
25 | #include "power.h"
26 | #include "bootutil/bootutil_extra.h"
27 | #include "bootutil/bootutil_log.h"
28 | #include "bootutil/bootutil.h"
29 | #include "bootutil/image.h"
30 | #include "mbedtls/platform.h"
31 |
32 | #if MCUBOOT_APPLICATION_DFU
33 | #include "usbd_desc.h"
34 | #include "usbd_dfu_flash.h"
35 | #endif
36 |
37 | /*
38 | * CLOCK_SOURCE is configured with "target.clock_source" in mbed_app.json file
39 | */
40 | #define USE_PLL_HSE_EXTC 0x8 // Use external clock (ST Link MCO)
41 | #define USE_PLL_HSE_XTAL 0x4 // Use external xtal (X3 on board - not provided by default)
42 | #define USE_PLL_HSI 0x2 // Use HSI internal clock
43 |
44 | #if ((CLOCK_SOURCE) & USE_PLL_HSI)
45 | extern "C" uint8_t SetSysClock_PLL_HSI(void);
46 | #elif ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC)
47 | extern "C" uint8_t SetSysClock_PLL_HSE(uint8_t bypass, bool lowspeed);
48 | #else
49 |
50 | #endif
51 |
52 | volatile const uint8_t bootloader_data[] __attribute__ ((section (".bootloader_version"), used)) = {
53 | BOOTLOADER_CONFIG_MAGIC,
54 | BOOTLOADER_VERSION,
55 | CLOCK_SOURCE,
56 | BOARD_USB_SPEED,
57 | BOARD_HAS_ETHERNET,
58 | BOARD_HAS_WIFI,
59 | BOARD_RAM_SIZE,
60 | BOARD_QSPI_SIZE,
61 | BOARD_HAS_VIDEO,
62 | BOARD_HAS_CRYPTO,
63 | BOARD_EXTCLOCK,
64 | };
65 |
66 | volatile const uint8_t bootloader_identifier[] __attribute__ ((section (".bootloader_identification"), used)) = "MCUboot Arduino";
67 |
68 | #if MCUBOOT_APPLICATION_DFU
69 | USBD_HandleTypeDef USBD_Device;
70 | #endif
71 |
72 | DigitalOut red(BOARD_RED_LED, BOARD_LED_OFF);
73 | DigitalOut green(BOARD_GREEN_LED, BOARD_LED_OFF);
74 | DigitalOut blue(BOARD_BLUE_LED, BOARD_LED_OFF);
75 |
76 | #if defined (BOARD_BOOT_SEL)
77 | DigitalIn boot_sel(BOARD_BOOT_SEL,PullDown);
78 | #else
79 | bool boot_sel = false;
80 | #endif
81 |
82 | Ticker swap_ticker;
83 | bool debug_enabled = false;
84 |
85 | static void led_swap_feedback_off(void) {
86 | swap_ticker.detach();
87 | red = BOARD_LED_OFF;
88 | green = BOARD_LED_OFF;
89 | blue = BOARD_LED_OFF;
90 | }
91 |
92 | static void led_swap_feedback() {
93 | blue = !blue;
94 | red = !red;
95 | }
96 |
97 | static void led_pulse(DigitalOut* led) {
98 | static uint8_t ledKeepValue = 0;
99 | static uint8_t ledTargetValue = 20;
100 | static int8_t ledDirection = 1;
101 | static int divisor = 0;
102 |
103 | if (divisor++ % 40) {
104 | return;
105 | }
106 |
107 | if (ledKeepValue == 0) {
108 | ledTargetValue += ledDirection;
109 | *led = !*led;
110 | }
111 | ledKeepValue ++;
112 |
113 | if (ledTargetValue > 250 || ledTargetValue < 10) {
114 | ledDirection = -ledDirection;
115 | ledTargetValue += ledDirection;
116 | }
117 |
118 | if (ledKeepValue == ledTargetValue) {
119 | *led = !*led;
120 | }
121 | }
122 |
123 | static bool valid_application() {
124 | /* Test if user code is programmed starting from USBD_DFU_APP_DEFAULT_ADD
125 | * address.
126 | */
127 | return (((*(__IO uint32_t *) 0x08040000) & 0xFF000000) == 0x20000000) \
128 | || (((*(__IO uint32_t *) 0x08040000) & 0xFF000000) == 0x24000000) \
129 | || (((*(__IO uint32_t *) 0x08040000) & 0xFF000000) == 0x30000000) \
130 | || (((*(__IO uint32_t *) 0x08040000) & 0xFF000000) == 0x38000000);
131 |
132 | }
133 |
134 | static int debug_init(void) {
135 | RTCInit();
136 | debug_enabled = ((RTCGetBKPRegister(RTC_BKP_DR7) & 0x00000001) || boot_sel);
137 | return 0;
138 | }
139 |
140 | static int start_dfu(void) {
141 | RTCSetBKPRegister(RTC_BKP_DR0, 0);
142 |
143 | #if ((CLOCK_SOURCE) & USE_PLL_HSI)
144 | SetSysClock_PLL_HSI();
145 | #elif ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC)
146 | SetSysClock_PLL_HSE(1, false);
147 | #else
148 |
149 | #endif
150 |
151 | SystemCoreClockUpdate();
152 |
153 | led_swap_feedback_off();
154 |
155 | //turnDownEthernet();
156 |
157 | #if MCUBOOT_APPLICATION_DFU
158 | init_Memories();
159 |
160 | /* Otherwise enters DFU mode to allow user programming his application */
161 | /* Init Device Library */
162 | USBD_Init(&USBD_Device, &DFU_Desc, 0);
163 |
164 | /* Add Supported Class */
165 | USBD_RegisterClass(&USBD_Device, USBD_DFU_CLASS);
166 |
167 | /* Add DFU Media interface */
168 | USBD_DFU_RegisterMedia(&USBD_Device, &USBD_DFU_Flash_fops);
169 |
170 | /* Start Device Process */
171 | USBD_Start(&USBD_Device);
172 |
173 | /* Set USBHS Interrupt to the lowest priority */
174 | // HAL_NVIC_SetPriority(OTG_HS_IRQn, 1, 0);
175 |
176 | /* Enable USBHS Interrupt */
177 | HAL_NVIC_DisableIRQ(OTG_HS_IRQn);
178 | HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
179 | #endif
180 |
181 | while(1) {
182 | #if MCUBOOT_APPLICATION_DFU
183 | #ifdef USE_USB_HS
184 | if (USB_OTG_HS->GINTSTS & USB_OTG_HS->GINTMSK) {
185 | #else // USE_USB_FS
186 | if (USB_OTG_FS->GINTSTS & USB_OTG_FS->GINTMSK) {
187 | #endif
188 | HAL_PCD_IRQHandler(HAL_PCD_GetHandle());
189 | }
190 | #endif
191 | led_pulse(&green);
192 | }
193 |
194 | return 0;
195 | }
196 |
197 | int start_secure_application(void) {
198 | int rc;
199 |
200 | BOOT_LOG_INF("Starting MCUboot");
201 |
202 | // Initialize mbedtls crypto for use by MCUboot
203 | mbedtls_platform_context unused_ctx;
204 | rc = mbedtls_platform_setup(&unused_ctx);
205 | if(rc != 0) {
206 | BOOT_LOG_ERR("Failed to setup Mbed TLS, error: %d", rc);
207 | return -1;
208 | }
209 |
210 | struct boot_rsp rsp;
211 | rc = boot_go(&rsp);
212 | if(rc != 0) {
213 | BOOT_LOG_ERR("Failed to locate firmware image, error: %d\n", rc);
214 | return -1;
215 | }
216 |
217 | led_swap_feedback_off();
218 |
219 | // Run the application in the primary slot
220 | // Add header size offset to calculate the actual start address of application
221 | uint32_t address = rsp.br_image_off + rsp.br_hdr->ih_hdr_size;
222 | BOOT_LOG_INF("Booting firmware image at 0x%x\n", address);
223 | mbed_start_application(address);
224 | }
225 |
226 | static int start_ota(void) {
227 | // DR1 contains the backing storage type, DR2 the offset in case of raw device / MBR
228 | storageType storage_type = (storageType)RTCGetBKPRegister(RTC_BKP_DR1);
229 | uint32_t offset = RTCGetBKPRegister(RTC_BKP_DR2);
230 | uint32_t update_size = RTCGetBKPRegister(RTC_BKP_DR3);
231 | BOOT_LOG_INF("Start OTA 0x%X 0x%X 0x%X", storage_type, offset, update_size);
232 | return tryOTA(storage_type, offset, update_size);
233 | }
234 |
235 | int main(void) {
236 | debug_init();
237 |
238 | BOOT_LOG_INF("Starting Arduino bootloader");
239 |
240 | int magic = RTCGetBKPRegister(RTC_BKP_DR0);
241 | int reset = ResetReason::get();
242 | RTCSetBKPRegister(RTC_BKP_DR8, reset);
243 |
244 | // in case we have been reset let's wait 500 ms to see if user is trying to stay in bootloader
245 | if (reset == RESET_REASON_PIN_RESET) {
246 | // now that we've been reset let's set magic. resetting with this set will
247 | // flag we need to stay in bootloader.
248 | RTCSetBKPRegister(RTC_BKP_DR0, 0xDF59);
249 | HAL_Delay(500);
250 | }
251 |
252 | #if defined (BOARD_USB_RESET)
253 | DigitalOut usb_reset(BOARD_USB_RESET, 0);
254 | #endif
255 |
256 | #if defined (BOARD_HAS_VIDEO) && (BOARD_HAS_VIDEO)
257 | DigitalOut video_enable(BOARD_VIDEO_ENABLE, 0);
258 | DigitalOut video_reset(BOARD_VIDEO_RESET, 0);
259 | #endif
260 |
261 | #if defined (BOARD_ETH_RESET)
262 | DigitalOut eth_reset(BOARD_ETH_RESET, 1);
263 | #endif
264 |
265 | HAL_FLASH_Unlock();
266 |
267 | power_init();
268 | HAL_Delay(10);
269 |
270 | #if defined (BOARD_USB_RESET)
271 | usb_reset = 1;
272 | HAL_Delay(10);
273 | usb_reset = 0;
274 | HAL_Delay(10);
275 | usb_reset = 1;
276 | HAL_Delay(10);
277 | #endif
278 |
279 | if (magic != 0xDF59) {
280 | if (boot_empty_keys()) {
281 | BOOT_LOG_INF("Secure keys not configured");
282 | if ( magic == 0x07AA ) {
283 | /* Start OTA */
284 | int ota_result = start_ota();
285 | if (ota_result == 0) {
286 | // clean reboot with success flag
287 | BOOT_LOG_INF("Sketch updated");
288 | RTCSetBKPRegister(RTC_BKP_DR0, 0);
289 | HAL_FLASH_Lock();
290 | // wait for external reboot (watchdog)
291 | while (1) {}
292 | } else {
293 | RTCSetBKPRegister(RTC_BKP_DR0, ota_result);
294 | }
295 | }
296 |
297 | if (valid_application()) {
298 | /* Boot Sketch */
299 | BOOT_LOG_INF("Booting sketch at 0x%x\n", BOARD_APP_DEFAULT_ADD);
300 | RTCSetBKPRegister(RTC_BKP_DR0, 0);
301 | mbed_start_application(BOARD_APP_DEFAULT_ADD);
302 | } else {
303 | BOOT_LOG_INF("No sketch found");
304 | }
305 |
306 | } else {
307 | /* MCUboot secure boot */
308 | swap_ticker.attach(&led_swap_feedback, 250ms);
309 | RTCSetBKPRegister(RTC_BKP_DR0, 0);
310 | start_secure_application();
311 | }
312 | }
313 | start_dfu();
314 |
315 | return 0;
316 | }
317 |
318 | #endif
319 |
--------------------------------------------------------------------------------
/app/ota/ota.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #include "mbed.h"
20 | #include "BlockDevice.h"
21 | #include "FlashIAPBlockDevice.h"
22 | #include "MBRBlockDevice.h"
23 | #include "SDMMCBlockDevice.h"
24 |
25 | #include "FATFileSystem.h"
26 | #include "LittleFileSystem.h"
27 |
28 | #include "ota.h"
29 | #include "bootutil/bootutil_log.h"
30 |
31 | BlockDevice* bd = NULL;
32 | mbed::FileSystem* fs = NULL;
33 |
34 | extern FlashIAP flash;
35 |
36 | const uint32_t M7_FLASH_BASE = 0x8040000;
37 | const uint32_t M4_FLASH_BASE = 0x8100000;
38 |
39 | uint32_t getOTABinaryBase(uint32_t firstWord) {
40 |
41 | BOOT_LOG_DBG("First OTA binary word: %lx", firstWord);
42 | if ((firstWord & 0xFF000000) == 0x20000000
43 | || (firstWord & 0xFF000000) == 0x24000000
44 | || (firstWord & 0xFF000000) == 0x30000000
45 | || (firstWord & 0xFF000000) == 0x38000000) {
46 | BOOT_LOG_DBG("Flashing on M7");
47 | return M7_FLASH_BASE;
48 | }
49 | if ((firstWord & 0xFF000000) == 0x10000000) {
50 | BOOT_LOG_DBG("Flashing on M4");
51 | return M4_FLASH_BASE;
52 | }
53 | return 0xFFFFFFFF;
54 | }
55 |
56 | static Timeout restart_timer;
57 |
58 | size_t getFilesize(const char* filename) {
59 | struct stat st;
60 | if(stat(filename, &st) != 0) {
61 | return 0;
62 | }
63 | return st.st_size;
64 | }
65 |
66 | int tryOTA(enum storageType storage_type, uint32_t data_offset, uint32_t update_size) {
67 | int err;
68 | flash.init();
69 | BOOT_LOG_DBG("Configuration: ");
70 | if (storage_type & INTERNAL_FLASH_FLAG) {
71 | BOOT_LOG_DBG(" INTERNAL_FLASH ");
72 | if (storage_type & (FATFS_FLAG | LITTLEFS_FLAG)) {
73 | // have a filesystem, use offset as partition start
74 | bd = new FlashIAPBlockDevice(0x8000000 + data_offset, 2 * 1024 * 1024 - data_offset);
75 | } else {
76 | // raw device, no offset
77 | bd = new FlashIAPBlockDevice(0x8000000, 2 * 1024 * 1024);
78 | }
79 | }
80 | if (storage_type & QSPI_FLASH_FLAG) {
81 | BOOT_LOG_DBG(" QSPI_FLASH ");
82 | bd = mbed::BlockDevice::get_default_instance();
83 | }
84 | if (storage_type & SDCARD_FLAG) {
85 | #if MCUBOOT_APPLICATION_SDCARD
86 | BOOT_LOG_DBG(" SD_FLASH ");
87 | bd = new SDMMCBlockDevice();
88 | #else
89 | BOOT_LOG_ERR(" SD NOT SUPPORTED");
90 | #endif
91 | }
92 | if (storage_type & MBR_FLAG) {
93 | BOOT_LOG_DBG(" MBR ");
94 | BlockDevice* physical_block_device = bd;
95 | bd = new mbed::MBRBlockDevice(physical_block_device, data_offset);
96 | }
97 | if (storage_type & LITTLEFS_FLAG) {
98 | BOOT_LOG_DBG(" LITTLEFS ");
99 | fs = new LittleFileSystem("fs");
100 | }
101 | if (storage_type & FATFS_FLAG) {
102 | BOOT_LOG_DBG(" FATFS ");
103 | fs = new FATFileSystem("fs");
104 | }
105 | if (fs != NULL) {
106 | err = fs->mount(bd);
107 | if (err) {
108 | BOOT_LOG_DBG("Mount failed");
109 | return MOUNT_FAILED;
110 | }
111 | FILE* update = fopen("/fs/UPDATE.BIN", "rb");
112 | if (update == NULL) {
113 | BOOT_LOG_DBG("No OTA file");
114 | return NO_OTA_FILE;
115 | }
116 | uint32_t temp[4];
117 | fread((uint8_t*)temp, 1, 4, update);
118 | fseek(update, 0, SEEK_SET);
119 | uint32_t base = getOTABinaryBase(temp[0]);
120 | if (base == 0xFFFFFFFF) {
121 | BOOT_LOG_DBG("Couldn't decide if M7 or M4");
122 | return WRONG_OTA_BINARY;
123 | }
124 | // Ignore update_size and use file size instead
125 | update_size = getFilesize("/fs/UPDATE.BIN");
126 | uint32_t sector_size = flash.get_sector_size(base);
127 | if (sector_size > 4096 * 4) {
128 | sector_size = 4096 * 4;
129 | }
130 | uint8_t* buf = (uint8_t*)malloc(sector_size);
131 | BOOT_LOG_DBG("Sector size: %d", sector_size);
132 | for (uint32_t i = 0; i < update_size; i+= sector_size) {
133 | fread(buf, 1, sector_size, update);
134 | // erase?
135 | if (((uint32_t)base + i) % flash.get_sector_size(base) == 0) {
136 | BOOT_LOG_DBG("Erasing: %x %x", (uint32_t)base + i, flash.get_sector_size(base));
137 | flash.erase((uint32_t)base + i, flash.get_sector_size(base));
138 | wait_us(10000);
139 | }
140 | flash.program(buf, (uint32_t)base + i, sector_size);
141 | wait_us(1000);
142 | }
143 | } else if (bd != NULL) {
144 | // read first chuck of the file to understand if we need to flash the M4 or the M7
145 | err = bd->init();
146 | if (err != 0) {
147 | BOOT_LOG_DBG("Init failed");
148 | return INIT_FAILED;
149 | }
150 | int sz = bd->get_program_size();
151 | if (sz < 16) {
152 | sz = 16;
153 | }
154 | uint32_t temp[sz];
155 | bd->read(temp, (uint32_t)data_offset, sz);
156 | uint32_t base = getOTABinaryBase(temp[0]);
157 | if (base == 0xFFFFFFFF) {
158 | BOOT_LOG_DBG("Couldn't decide if M7 or M4");
159 | return WRONG_OTA_BINARY;
160 | }
161 | uint32_t sector_size = flash.get_sector_size(base);
162 | if (sector_size > 4096 * 4) {
163 | sector_size = 4096 * 4;
164 | }
165 | uint8_t* buf = (uint8_t*)malloc(sector_size);
166 | for (uint32_t i = 0; i < update_size; i+= sector_size) {
167 | bd->read(buf, (uint32_t)data_offset + i, sector_size);
168 | // erase?
169 | if (((uint32_t)base + i) % flash.get_sector_size(base) == 0) {
170 | flash.erase((uint32_t)base + i, flash.get_sector_size(base));
171 | wait_us(10000);
172 | }
173 | flash.program(buf, (uint32_t)base + i, sector_size);
174 | wait_us(1000);
175 | }
176 | }
177 | flash.deinit();
178 | restart_timer.attach(NVIC_SystemReset, 0.2f);
179 | return 0;
180 | }
181 |
--------------------------------------------------------------------------------
/app/ota/ota.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef __OTA_H
20 | #define __OTA_H
21 |
22 | #include
23 | #include "BlockDevice.h"
24 | #include "FileSystem.h"
25 |
26 | #define INTERNAL_FLASH_FLAG (1 << 1)
27 | #define QSPI_FLASH_FLAG (1 << 2)
28 | #define SDCARD_FLAG (1 << 3)
29 | #define RAW_FLAG (1 << 4)
30 | #define FATFS_FLAG (1 << 5)
31 | #define LITTLEFS_FLAG (1 << 6)
32 | #define MBR_FLAG (1 << 7)
33 |
34 | enum storageType {
35 | INVALID = 0,
36 | INTERNAL_FLASH_OFFSET = INTERNAL_FLASH_FLAG | RAW_FLAG,
37 | INTERNAL_FLASH_FATFS = INTERNAL_FLASH_FLAG | FATFS_FLAG,
38 | INTERNAL_FLASH_LITTLEFS = INTERNAL_FLASH_FLAG | LITTLEFS_FLAG,
39 | QSPI_FLASH_OFFSET = QSPI_FLASH_FLAG | RAW_FLAG,
40 | QSPI_FLASH_FATFS = QSPI_FLASH_FLAG | FATFS_FLAG,
41 | QSPI_FLASH_LITTLEFS = QSPI_FLASH_FLAG | LITTLEFS_FLAG,
42 | QSPI_FLASH_FATFS_MBR = QSPI_FLASH_FLAG | FATFS_FLAG | MBR_FLAG,
43 | QSPI_FLASH_LITTLEFS_MBR = QSPI_FLASH_FLAG | LITTLEFS_FLAG | MBR_FLAG,
44 | SD_OFFSET = SDCARD_FLAG | RAW_FLAG,
45 | SD_FATFS = SDCARD_FLAG | FATFS_FLAG,
46 | SD_LITTLEFS = SDCARD_FLAG | LITTLEFS_FLAG,
47 | SD_FATFS_MBR = SDCARD_FLAG | FATFS_FLAG | MBR_FLAG,
48 | SD_LITTLEFS_MBR = SDCARD_FLAG | LITTLEFS_FLAG | MBR_FLAG,
49 | };
50 |
51 | enum OTABlockDevice {
52 | SECONDARY_BLOCK_DEVICE = 0,
53 | SCRATCH_BLOCK_DEVICE = 1
54 | };
55 |
56 | struct BlockTableData {
57 | uint32_t storage_type;
58 | uint8_t raw_type;
59 | bool raw_flag;
60 | bool mbr_flag;
61 | uint8_t fs_type;
62 | uint32_t data_offset;
63 | uint32_t update_size;
64 | mbed::BlockDevice* raw_bd;
65 | mbed::BlockDevice* log_bd;
66 | mbed::BlockDevice* file_bd;
67 | mbed::FileSystem* log_fs;
68 | };
69 |
70 | #define WRONG_OTA_BINARY (-1)
71 | #define MOUNT_FAILED (-2)
72 | #define NO_OTA_FILE (-3)
73 | #define INIT_FAILED (-4)
74 |
75 | int tryOTA(enum storageType storage_type, uint32_t data_offset, uint32_t update_size);
76 |
77 | #endif //__OTA_H
78 |
--------------------------------------------------------------------------------
/app/power/power.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #include "power.h"
20 | #include "board.h"
21 | #include "mbed.h"
22 |
23 | #if defined TARGET_PORTENTA_H7_M7
24 | static void portenta_power_init() {
25 | I2C i2c(BOARD_I2C_SDA, BOARD_I2C_SCL);
26 |
27 | char data[2];
28 |
29 | // LDO2 to 1.8V
30 | data[0]=0x4F;
31 | data[1]=0x0;
32 | i2c.write(8 << 1, data, sizeof(data));
33 | data[0]=0x50;
34 | data[1]=0xF;
35 | i2c.write(8 << 1, data, sizeof(data));
36 |
37 | // LDO1 to 1.0V
38 | data[0]=0x4c;
39 | data[1]=0x5;
40 | i2c.write(8 << 1, data, sizeof(data));
41 | data[0]=0x4d;
42 | data[1]=0x3;
43 | i2c.write(8 << 1, data, sizeof(data));
44 |
45 | // LDO3 to 1.2V
46 | data[0]=0x52;
47 | data[1]=0x9;
48 | i2c.write(8 << 1, data, sizeof(data));
49 | data[0]=0x53;
50 | data[1]=0xF;
51 | i2c.write(8 << 1, data, sizeof(data));
52 |
53 | HAL_Delay(10);
54 |
55 | data[0]=0x9C;
56 | data[1]=(1 << 7);
57 | i2c.write(8 << 1, data, sizeof(data));
58 |
59 | // Disable charger led
60 | data[0]=0x9E;
61 | data[1]=(1 << 5);
62 | i2c.write(8 << 1, data, sizeof(data));
63 |
64 | HAL_Delay(10);
65 |
66 | // SW3: set 2A as current limit
67 | // Helps keeping the rail up at wifi startup
68 | data[0]=0x42;
69 | data[1]=(2);
70 | i2c.write(8 << 1, data, sizeof(data));
71 |
72 | HAL_Delay(10);
73 |
74 | // Change VBUS INPUT CURRENT LIMIT to 1.5A
75 | data[0]=0x94;
76 | data[1]=(20 << 3);
77 | i2c.write(8 << 1, data, sizeof(data));
78 |
79 | // SW2 to 3.3V (SW2_VOLT)
80 | data[0]=0x3B;
81 | data[1]=0xF;
82 | i2c.write(8 << 1, data, sizeof(data));
83 |
84 | // SW1 to 3.0V (SW1_VOLT)
85 | data[0]=0x35;
86 | data[1]=0xF;
87 | i2c.write(8 << 1, data, sizeof(data));
88 | }
89 | #endif
90 |
91 | #if defined TARGET_NICLA_VISION
92 | static void nicla_vision_power_init() {
93 | I2C i2c(BOARD_I2C_SDA, BOARD_I2C_SCL);
94 |
95 | char data[2];
96 |
97 | data[0]=0x9C;
98 | data[1]=(1 << 7);
99 | i2c.write(8 << 1, data, sizeof(data));
100 |
101 | // Disable charger led
102 | data[0]=0x9E;
103 | data[1]=(1 << 5);
104 | i2c.write(8 << 1, data, sizeof(data));
105 |
106 | HAL_Delay(10);
107 |
108 | // SW3: set 2A as current limit
109 | // Helps keeping the rail up at wifi startup
110 | data[0]=0x42;
111 | data[1]=(2);
112 | i2c.write(8 << 1, data, sizeof(data));
113 |
114 | HAL_Delay(10);
115 |
116 | // Change VBUS INPUT CURRENT LIMIT to 1.5A
117 | data[0]=0x94;
118 | data[1]=(20 << 3);
119 | i2c.write(8 << 1, data, sizeof(data));
120 | }
121 | #endif
122 |
123 | void power_init() {
124 | #if defined TARGET_PORTENTA_H7_M7
125 | portenta_power_init();
126 | #elif defined TARGET_NICLA_VISION
127 | nicla_vision_power_init();
128 | #elif defined TARGET_GIGA
129 | //no power init function
130 | #else
131 |
132 | #endif
133 | }
134 |
--------------------------------------------------------------------------------
/app/power/power.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef __POWER_H
20 | #define __POWER_H
21 |
22 | void power_init();
23 |
24 | #endif //__POWER_H
25 |
--------------------------------------------------------------------------------
/app/rtc/rtc.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #if MCUBOOT_APPLICATION_HOOKS
20 |
21 | #include "rtc.h"
22 | #include "bootutil/bootutil_log.h"
23 |
24 | RTC_HandleTypeDef RtcHandle;
25 | static int rtc_initialized = 0;
26 |
27 | void RTC_Bkp_Init(void)
28 | {
29 | /*##-1- Configure the RTC peripheral #######################################*/
30 | /* Configure RTC prescaler and RTC data registers */
31 | /* RTC configured as follow:
32 | - Hour Format = Format 24
33 | - Asynch Prediv = Value according to source clock
34 | - Synch Prediv = Value according to source clock
35 | - OutPut = Output Disable
36 | - OutPutPolarity = High Polarity
37 | - OutPutType = Open Drain */
38 | RtcHandle.Instance = RTC;
39 | __HAL_RCC_PWR_CLK_ENABLE();
40 | HAL_PWR_EnableBkUpAccess();
41 | rtc_initialized = 1;
42 | }
43 |
44 | void RTCInit() {
45 | if(!rtc_initialized) {
46 | RTC_Bkp_Init();
47 | }
48 | }
49 |
50 | uint32_t RTCGetBKPRegister(uint32_t BackupRegister) {
51 | if(rtc_initialized) {
52 | return HAL_RTCEx_BKUPRead(&RtcHandle, BackupRegister);
53 | } else {
54 | BOOT_LOG_ERR("RTCGetBKPRegister");
55 | return -1;
56 | }
57 | }
58 |
59 | uint32_t RTCSetBKPRegister(uint32_t BackupRegister, uint32_t Data) {
60 | if(rtc_initialized) {
61 | HAL_RTCEx_BKUPWrite(&RtcHandle, BackupRegister, Data);
62 | return 0;
63 | } else {
64 | BOOT_LOG_ERR("RTCSetBKPRegister");
65 | return -1;
66 | }
67 | }
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/app/rtc/rtc.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022 Arduino SA. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef __RTC_H
20 | #define __RTC_H
21 |
22 | #include
23 | #include "rtc_api_hal.h"
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | void RTCInit();
30 | uint32_t RTCGetBKPRegister(uint32_t BackupRegister);
31 | uint32_t RTCSetBKPRegister(uint32_t BackupRegister, uint32_t Data);
32 |
33 | #ifdef __cplusplus
34 | }
35 | #endif
36 |
37 | #endif //__RTC_H
38 |
--------------------------------------------------------------------------------
/app/sdcard/BSP.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32h747i_discovery_sd.h
4 | * @author MCD Application Team
5 | * @brief This file contains the common defines and functions prototypes for
6 | * the stm32h747i_discovery_sd.c driver.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * © Copyright (c) 2019 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software component is licensed by ST under BSD 3-Clause license,
14 | * the "License"; You may not use this file except in compliance with the
15 | * License. You may obtain a copy of the License at:
16 | * opensource.org/licenses/BSD-3-Clause
17 | *
18 | ******************************************************************************
19 | */
20 |
21 | /* Define to prevent recursive inclusion -------------------------------------*/
22 | #ifndef __STM32H747I_DISCOVERY_SD_H
23 | #define __STM32H747I_DISCOVERY_SD_H
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | /* Includes ------------------------------------------------------------------*/
30 | #include "stm32h7xx_hal.h"
31 |
32 | /** @addtogroup BSP
33 | * @{
34 | */
35 |
36 | /** @addtogroup STM32H747I_DISCOVERY
37 | * @{
38 | */
39 |
40 | /** @addtogroup STM32H747I_DISCOVERY_SD
41 | * @{
42 | */
43 |
44 | /** @defgroup STM32H747I_DISCOVERY_SD_Exported_Types Exported Types
45 | * @{
46 | */
47 |
48 | /**
49 | * @brief SD Card information structure
50 | */
51 | #define BSP_SD_CardInfo HAL_SD_CardInfoTypeDef
52 | /**
53 | * @}
54 | */
55 |
56 | /** @defgroup STM32H747I_DISCOVERY_SD_ Exported_Constants Exported Constants
57 | * @{
58 | */
59 | /**
60 | * @brief SD status structure definition
61 | */
62 | #define MSD_OK ((uint8_t)0x00)
63 | #define MSD_ERROR ((uint8_t)0x01)
64 | #define MSD_ERROR_SD_NOT_PRESENT ((uint8_t)0x02)
65 |
66 | /**
67 | * @brief SD transfer state definition
68 | */
69 | #define SD_TRANSFER_OK ((uint8_t)0x00)
70 | #define SD_TRANSFER_BUSY ((uint8_t)0x01)
71 |
72 |
73 | #define SD_PRESENT ((uint8_t)0x01)
74 | #define SD_NOT_PRESENT ((uint8_t)0x00)
75 |
76 | #define SD_DATATIMEOUT ((uint32_t)100000000)
77 |
78 | /**
79 | * @}
80 | */
81 |
82 |
83 | /** @addtogroup STM32H747I_DISCOVERY_SD_Exported_Functions
84 | * @{
85 | */
86 | uint8_t BSP_SD_Init(void);
87 | uint8_t BSP_SD_DeInit(void);
88 | uint8_t BSP_SD_ITConfig(void);
89 |
90 | uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout);
91 | uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout);
92 | uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks);
93 | uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks);
94 | uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr);
95 | uint8_t BSP_SD_GetCardState(void);
96 | void BSP_SD_GetCardInfo(BSP_SD_CardInfo *CardInfo);
97 | uint8_t BSP_SD_IsDetected(void);
98 | void BSP_SD_IRQHandler(void);
99 |
100 | /* These functions can be modified in case the current settings (e.g. DMA stream)
101 | need to be changed for specific application needs */
102 | void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params);
103 | void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params);
104 | void BSP_SD_AbortCallback(void);
105 | void BSP_SD_WriteCpltCallback(void);
106 | void BSP_SD_ReadCpltCallback(void);
107 |
108 |
109 | /**
110 | * @}
111 | */
112 |
113 | /**
114 | * @}
115 | */
116 |
117 | /**
118 | * @}
119 | */
120 |
121 | /**
122 | * @}
123 | */
124 |
125 | #ifdef __cplusplus
126 | }
127 | #endif
128 |
129 | #endif /* __STM32H747I_DISCOVERY_SD_H */
130 |
131 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
132 |
--------------------------------------------------------------------------------
/app/sdcard/SDMMCBlockDevice.cpp:
--------------------------------------------------------------------------------
1 | /* SD/MMC Block device Library for MBED-OS
2 | * Copyright 2017 Roy Krikke
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | #if MCUBOOT_APPLICATION_HOOKS && MCUBOOT_APPLICATION_SDCARD
19 |
20 | #include "SDMMCBlockDevice.h"
21 | #include "mbed_debug.h"
22 |
23 | /* Required version: 5.5.0 and above */
24 | #if defined(MBED_MAJOR_VERSION) && MBED_MAJOR_VERSION >= 5
25 | #if (MBED_VERSION < MBED_ENCODE_VERSION(5,5,0))
26 | #error "Incompatible mbed-os version detected! Required 5.5.0 and above"
27 | #endif
28 | #else
29 | #warning "mbed-os version 5.5.0 or above required"
30 | #endif
31 |
32 | #define SD_DBG 0 /*!< 1 - Enable debugging */
33 |
34 | /** Enum of standard error codes
35 | *
36 | * @enum bd_sd_error
37 | */
38 | enum bd_sd_error {
39 | SD_BLOCK_DEVICE_OK = 0, /*!< no error */
40 | SD_BLOCK_DEVICE_ERROR = -5000, /*!< device specific error */
41 | //SD_BLOCK_DEVICE_ERROR_WOULD_BLOCK = -5001, /*!< operation would block */
42 | //SD_BLOCK_DEVICE_ERROR_UNSUPPORTED = -5002, /*!< unsupported operation */
43 | SD_BLOCK_DEVICE_ERROR_PARAMETER = -5003, /*!< invalid parameter */
44 | SD_BLOCK_DEVICE_ERROR_NO_INIT = -5004, /*!< uninitialized */
45 | SD_BLOCK_DEVICE_ERROR_NO_DEVICE = -5005, /*!< device is missing or not connected */
46 | //SD_BLOCK_DEVICE_ERROR_WRITE_PROTECTED = -5006, /*!< write protected */
47 | //SD_BLOCK_DEVICE_ERROR_UNUSABLE = -5007, /*!< unusable card */
48 | //SD_BLOCK_DEVICE_ERROR_NO_RESPONSE = -5008, /*!< No response from device */
49 | //SD_BLOCK_DEVICE_ERROR_CRC = -5009, /*!< CRC error */
50 | SD_BLOCK_DEVICE_ERROR_ERASE = -5010, /*!< Erase error */
51 | SD_BLOCK_DEVICE_ERROR_READ = -5011, /*!< Read error */
52 | SD_BLOCK_DEVICE_ERROR_PROGRAM = -5012, /*!< Program error */
53 | };
54 |
55 | #define BLOCK_SIZE_HC 512 /*!< Block size supported for SD card is 512 bytes */
56 |
57 | SDMMCBlockDevice::SDMMCBlockDevice() :
58 | _read_size (BLOCK_SIZE_HC), _program_size (BLOCK_SIZE_HC),
59 | _erase_size(BLOCK_SIZE_HC), _block_size (BLOCK_SIZE_HC),
60 | _capacity_in_blocks (0)
61 | {
62 | _timeout = 1000;
63 | }
64 |
65 | SDMMCBlockDevice::~SDMMCBlockDevice()
66 | {
67 | if(_is_initialized) {
68 | deinit ();
69 | }
70 | }
71 |
72 | int SDMMCBlockDevice::init()
73 | {
74 | lock();
75 | _sd_state = BSP_SD_Init();
76 |
77 | if(_sd_state != MSD_OK) {
78 | if(_sd_state == MSD_ERROR_SD_NOT_PRESENT) {
79 | debug_if(SD_DBG, "SD card is missing or not connected\n");
80 | unlock ();
81 | return SD_BLOCK_DEVICE_ERROR_NO_DEVICE;
82 | } else {
83 | debug_if(SD_DBG, "SD card initialization failed\n");
84 | unlock();
85 | return SD_BLOCK_DEVICE_ERROR_NO_INIT;
86 | }
87 | }
88 | BSP_SD_GetCardInfo(&_current_card_info);
89 |
90 | _card_type = _current_card_info.CardType;
91 | _read_size = _current_card_info.BlockSize;
92 | _program_size = _current_card_info.BlockSize;
93 | _erase_size = _current_card_info.BlockSize;
94 | _block_size = _current_card_info.BlockSize;
95 | _capacity_in_blocks = _current_card_info.BlockNbr;
96 |
97 | debug_if(SD_DBG, "Card Type: %i\n", _current_card_info.CardType);
98 | debug_if(SD_DBG, "Card Version: %i\n", _current_card_info.CardVersion);
99 | debug_if(SD_DBG, "Class: %i\n", _current_card_info.Class);
100 | debug_if(SD_DBG, "Relative Card Address: %x\n", _current_card_info.RelCardAdd);
101 | debug_if(SD_DBG, "Card Capacity in blocks: %i\n", _current_card_info.BlockNbr);
102 | debug_if(SD_DBG, "One block size in bytes: %i\n", _current_card_info.BlockSize);
103 | debug_if(SD_DBG, "Card logical Capacity in blocks: %i\n", _current_card_info.LogBlockNbr);
104 | debug_if(SD_DBG, "Logical block size in bytes: %i\n", _current_card_info.LogBlockSize);
105 | debug_if(SD_DBG, "Timeout: %i\n", _timeout);
106 |
107 | _is_initialized = true;
108 | unlock();
109 | return SD_BLOCK_DEVICE_OK;
110 | }
111 |
112 | int SDMMCBlockDevice::deinit()
113 | {
114 | lock();
115 | _sd_state = BSP_SD_DeInit ();
116 | if(_sd_state != MSD_OK) {
117 | debug_if (SD_DBG, "SD card deinitialization failed\n");
118 | return SD_BLOCK_DEVICE_ERROR;
119 | }
120 | _is_initialized = false;
121 | unlock();
122 | return BD_ERROR_OK;
123 | }
124 |
125 | int SDMMCBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
126 | {
127 | if(!is_valid_read (addr, size)) {
128 | return SD_BLOCK_DEVICE_ERROR_PARAMETER;
129 | }
130 |
131 | lock();
132 | if(!_is_initialized) {
133 | unlock();
134 | return SD_BLOCK_DEVICE_ERROR_NO_INIT;
135 | }
136 |
137 | uint32_t *buffer = static_cast (b);
138 | int status = SD_BLOCK_DEVICE_OK;
139 |
140 | // Get block address
141 | uint32_t block_addr = addr / _block_size;
142 | // Get block count
143 | uint32_t block_cnt = size / _block_size;
144 |
145 | debug_if(
146 | SD_DBG,
147 | "SDMMCBlockDevice::read addr: 0x%x, block_addr: %i size: %lu block count: %i\n",
148 | addr, block_addr, size, block_cnt);
149 |
150 | if(BSP_SD_ReadBlocks (buffer, block_addr, block_cnt, _timeout) != MSD_OK) {
151 | status = SD_BLOCK_DEVICE_ERROR_READ;
152 | }
153 |
154 | // Wait until SD card is ready to use for new operation
155 | while(BSP_SD_GetCardState() != SD_TRANSFER_OK) {
156 | }
157 |
158 | unlock ();
159 | return status;
160 | }
161 |
162 | int SDMMCBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
163 | {
164 | if(!is_valid_program (addr, size)) {
165 | return SD_BLOCK_DEVICE_ERROR_PARAMETER;
166 | }
167 |
168 | lock();
169 | if(!_is_initialized) {
170 | unlock ();
171 | return SD_BLOCK_DEVICE_ERROR_NO_INIT;
172 | }
173 |
174 | uint32_t* buffer =
175 | const_cast (reinterpret_cast (b));
176 | int status = SD_BLOCK_DEVICE_OK;
177 |
178 | // Get block address
179 | uint32_t block_addr = addr / _block_size;
180 | // Get block count
181 | uint32_t block_cnt = size / _block_size;
182 |
183 | debug_if (
184 | SD_DBG,
185 | "SDMMCBlockDevice::program addr: 0x%x, block_addr: %i size: %lu block count: %i\n",
186 | addr, block_addr, size, block_cnt);
187 |
188 | if(BSP_SD_WriteBlocks (buffer, block_addr, block_cnt, _timeout) != MSD_OK) {
189 | status = SD_BLOCK_DEVICE_ERROR_PROGRAM;
190 | }
191 |
192 | // Wait until SD card is ready to use for new operation
193 | while(BSP_SD_GetCardState() != SD_TRANSFER_OK) {
194 | }
195 |
196 | unlock();
197 | return status;
198 | }
199 |
200 | int SDMMCBlockDevice::erase(bd_addr_t addr, bd_size_t size)
201 | {
202 | if (!is_valid_erase(addr, size)) {
203 | return SD_BLOCK_DEVICE_ERROR_PARAMETER;
204 | }
205 |
206 | lock();
207 | if(!_is_initialized) {
208 | unlock();
209 | return SD_BLOCK_DEVICE_ERROR_NO_INIT;
210 | }
211 |
212 | size -= _block_size;
213 |
214 | int status = SD_BLOCK_DEVICE_OK;
215 | uint32_t start_addr = addr;
216 | uint32_t end_addr = start_addr + size;
217 |
218 | // Get block count
219 | uint32_t block_start_addr = start_addr / _block_size;
220 | // Get block address
221 | uint32_t block_end_addr = end_addr / _block_size;
222 |
223 | debug_if(
224 | SD_DBG,
225 | "SDMMCBlockDevice::erase start_addr: 0x%x, block_start_addr: %i | end_addr: 0x%x, block_end_addr: %i size: %lu\n",
226 | start_addr, block_start_addr, end_addr, block_end_addr, size);
227 |
228 | if(BSP_SD_Erase (block_start_addr, block_end_addr) != MSD_OK) {
229 | status = SD_BLOCK_DEVICE_ERROR_ERASE;
230 | }
231 |
232 | /* Wait until SD card is ready to use for new operation */
233 | while(BSP_SD_GetCardState() != SD_TRANSFER_OK) {
234 | }
235 |
236 | unlock();
237 | return status;
238 | }
239 |
240 | bd_size_t SDMMCBlockDevice::get_read_size() const
241 | {
242 | return _read_size;
243 | }
244 |
245 | bd_size_t SDMMCBlockDevice::get_program_size() const
246 | {
247 | return _program_size;
248 | }
249 |
250 | bd_size_t SDMMCBlockDevice::get_erase_size() const
251 | {
252 | return _erase_size;
253 | }
254 |
255 | bd_size_t SDMMCBlockDevice::size() const
256 | {
257 | return (_block_size * _capacity_in_blocks);
258 | }
259 |
260 | const char *SDMMCBlockDevice::get_type() const
261 | {
262 | return "SDCARD";
263 | }
264 |
265 | #endif
266 |
--------------------------------------------------------------------------------
/app/sdcard/SDMMCBlockDevice.h:
--------------------------------------------------------------------------------
1 | /* SD/MMC Block device Library for MBED-OS
2 | * Copyright 2017 Roy Krikke
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | #ifndef _SDMMC_BLOCKDEVICE_H_
19 | #define _SDMMC_BLOCKDEVICE_H_
20 |
21 | #include "mbed.h"
22 | #include "BlockDevice.h"
23 | #include "platform/PlatformMutex.h"
24 | #include "BSP.h"
25 |
26 | using namespace mbed;
27 |
28 | /**
29 | * SDMMCBlockDevice class.
30 | * Block device class for creating a block device to access a SD/MMC card via SD/MMC interface on ENVIE
31 | *
32 | * Example:
33 | * @code
34 | * #include "mbed.h"
35 | * #include "SDMMCBlockDevice.h"
36 | *
37 | * DigitalOut led (LED1);
38 | *
39 | * // Instantiate the Block Device for sd card on DISCO-F746NG
40 | * SDMMCBlockDevice bd;
41 | * uint8_t block[512] = "Hello World!\n";
42 | *
43 | * int
44 | * main () {
45 | * Serial pc(SERIAL_TX, SERIAL_RX);
46 | * pc.baud (115200);
47 | * printf("Start\n");
48 | *
49 | * // Call the SDMMCBlockDevice instance initialisation method.
50 | * printf("sd card init...\n");
51 | * if (0 != bd.init ()) {
52 | * printf("Init failed \n");
53 | * return -1;
54 | * }
55 | *
56 | * printf("sd size: %llu\n", bd.size ());
57 | * printf("sd read size: %llu\n", bd.get_read_size ());
58 | * printf("sd program size: %llu\n", bd.get_program_size ());
59 | * printf("sd erase size: %llu\n\n", bd.get_erase_size ());
60 | *
61 | * printf("sd erase...\n");
62 | * if (0 != bd.erase (0, bd.get_erase_size ())) {
63 | * printf ("Error Erasing block \n");
64 | * }
65 | *
66 | * // Write some the data block to the device
67 | * printf("sd write: %s\n", block);
68 | * if (0 == bd.program (block, 0, 512)) {
69 | * // read the data block from the device
70 | * printf ("sd read: ");
71 | * if (0 == bd.read (block, 0, 512)) {
72 | * // print the contents of the block
73 | * printf ("%s", block);
74 | * }
75 | * }
76 | *
77 | * // Call the SDMMCBlockDevice instance de-initialisation method.
78 | * printf("sd card deinit...\n");
79 | * if(0 != bd.deinit ()) {
80 | * printf ("Deinit failed \n");
81 | * return -1;
82 | * }
83 | *
84 | * // Blink led with 2 Hz
85 | * while(true) {
86 | * led = !led;
87 | * wait (0.5);
88 | * }
89 | * }
90 | * @endcode
91 | *
92 | */
93 | class SDMMCBlockDevice : public BlockDevice
94 | {
95 | public:
96 |
97 | /** Lifetime of the memory block device
98 | *
99 | * Only a block size of 512 bytes is supported
100 | *
101 | */
102 | SDMMCBlockDevice();
103 | virtual ~SDMMCBlockDevice();
104 |
105 | /** Initialize a block device
106 | *
107 | * @return 0 on success or a negative error code on failure
108 | */
109 | virtual int init();
110 |
111 | /** Deinitialize a block device
112 | *
113 | * @return 0 on success or a negative error code on failure
114 | */
115 | virtual int deinit();
116 |
117 | /** Read blocks from a block device
118 | *
119 | * @param buffer Buffer to read blocks into
120 | * @param addr Address of block to begin reading from
121 | * @param size Size to read in bytes, must be a multiple of read block size
122 | * @return 0 on success, negative error code on failure
123 | */
124 | virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
125 |
126 | /** Program blocks to a block device
127 | *
128 | * The blocks must have been erased prior to being programmed
129 | *
130 | * @param buffer Buffer of data to write to blocks
131 | * @param addr Address of block to begin writing to
132 | * @param size Size to write in bytes, must be a multiple of program block size
133 | * @return 0 on success, negative error code on failure
134 | */
135 | virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
136 |
137 | /** Erase blocks on a block device
138 | *
139 | * The state of an erased block is undefined until it has been programmed
140 | *
141 | * @param addr Address of block to begin erasing
142 | * @param size Size to erase in bytes, must be a multiple of erase block size
143 | * @return 0 on success, negative error code on failure
144 | */
145 | virtual int erase(bd_addr_t addr, bd_size_t size);
146 |
147 | /** Get the size of a readable block
148 | *
149 | * @return Size of a readable block in bytes
150 | */
151 | virtual bd_size_t get_read_size() const;
152 |
153 | /** Get the size of a programable block
154 | *
155 | * @return Size of a programable block in bytes
156 | */
157 | virtual bd_size_t get_program_size() const;
158 |
159 | /** Get the size of a eraseable block
160 | *
161 | * @return Size of a eraseable block in bytes
162 | */
163 | virtual bd_size_t get_erase_size() const;
164 |
165 | /** Get the total size of the underlying device
166 | *
167 | * @return Size of the underlying device in bytes
168 | */
169 | virtual bd_size_t size() const;
170 |
171 | virtual const char *get_type() const;
172 |
173 | private:
174 | uint8_t _card_type;
175 | bd_size_t _read_size;
176 | bd_size_t _program_size;
177 | bd_size_t _erase_size;
178 | bd_size_t _block_size;
179 | bd_size_t _capacity_in_blocks;
180 | BSP_SD_CardInfo _current_card_info;
181 | uint8_t _sd_state;
182 | uint32_t _timeout;
183 | PlatformMutex _mutex;
184 | bool _is_initialized;
185 |
186 | virtual void
187 | lock () {
188 | _mutex.lock();
189 | }
190 |
191 | virtual void
192 | unlock() {
193 | _mutex.unlock ();
194 | }
195 |
196 | };
197 |
198 | #endif /* _SDMMC_BLOCKDEVICE_H_ */
199 |
--------------------------------------------------------------------------------
/assets/current-layout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arduino/mcuboot-arduino-stm32h7/4fc1de04aa589957dfb654f9a81bd3981f810354/assets/current-layout.png
--------------------------------------------------------------------------------
/custom.json:
--------------------------------------------------------------------------------
1 | {
2 | "GCC_ARM": {
3 | "common": ["-Wall", "-Wextra",
4 | "-Wno-unused-parameter", "-Wno-missing-field-initializers",
5 | "-fmessage-length=0", "-fno-exceptions",
6 | "-ffunction-sections", "-fdata-sections", "-funsigned-char",
7 | "-MMD", "-flto",
8 | "-fomit-frame-pointer", "-Os", "-DNDEBUG", "-g"],
9 | "asm": ["-c", "-x", "assembler-with-cpp"],
10 | "c": ["-c", "-std=gnu11"],
11 | "cxx": ["-c", "-std=gnu++14", "-fno-rtti", "-Wvla"],
12 | "ld": ["-Wl,--gc-sections", "-Wl,--wrap,main", "-Wl,--wrap,_malloc_r",
13 | "-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r", "-Wl,--wrap,_memalign_r",
14 | "-Wl,--wrap,_calloc_r", "-Wl,--wrap,exit", "-Wl,--wrap,atexit",
15 | "-Wl,-n", "-u __wrap_printf", "-u main", "-u malloc", "-u __wrap_snprintf", "-u _malloc_r"]
16 | },
17 | "ARMC6": {
18 | "common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Oz",
19 | "-Wno-armcc-pragma-push-pop", "-Wno-armcc-pragma-anon-unions",
20 | "-Wno-reserved-user-defined-literal", "-Wno-deprecated-register",
21 | "-DMULADDC_CANNOT_USE_R7", "-fdata-sections",
22 | "-fno-exceptions", "-MMD", "-fshort-enums", "-fshort-wchar",
23 | "-DNDEBUG"],
24 | "asm": [],
25 | "c": ["-D__ASSERT_MSG", "-std=gnu11"],
26 | "cxx": ["-fno-rtti", "-std=gnu++14"],
27 | "ld": ["--show_full_path", "--legacyalign", "--any_contingency",
28 | "--keep=os_cb_sections"]
29 | },
30 | "ARM": {
31 | "common": ["-c", "--gnu", "-Ospace", "--split_sections",
32 | "--apcs=interwork", "--brief_diagnostics", "--restrict",
33 | "--multibyte_chars", "-O3", "-DNDEBUG"],
34 | "asm": [],
35 | "c": ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
36 | "cxx": ["--cpp11", "--no_rtti", "--no_vla"],
37 | "ld": ["--show_full_path", "--any_contingency", "--keep=os_cb_sections"]
38 | },
39 | "uARM": {
40 | "common": ["-c", "--gnu", "-Ospace", "--split_sections",
41 | "--apcs=interwork", "--brief_diagnostics", "--restrict",
42 | "--multibyte_chars", "-O3", "-D__MICROLIB",
43 | "--library_type=microlib", "-DMBED_RTOS_SINGLE_THREAD", "-DNDEBUG"],
44 | "asm": [],
45 | "c": ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
46 | "cxx": ["--cpp11", "--no_rtti", "--no_vla"],
47 | "ld": ["--library_type=microlib"]
48 | },
49 | "IAR": {
50 | "common": [
51 | "--no_wrap_diagnostics", "-e",
52 | "--diag_suppress=Pa050,Pa084,Pa093,Pa082,Pe540", "-Ohz", "-DNDEBUG", "--enable_restrict"],
53 | "asm": [],
54 | "c": ["--vla", "--diag_suppress=Pe546"],
55 | "cxx": ["--guard_calls", "--no_static_destruction"],
56 | "ld": ["--skip_dynamic_initialization", "--threaded_lib", "--inline"]
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/generate_rel.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | rm -rf release
3 | rm -rf BUILD
4 |
5 | mbed compile -c -m PORTENTA_H7_M7 -t GCC_ARM --app=mbed_app_bootutil.json
6 |
7 | set -e
8 |
9 | echo
10 | echo Generating bootutil library
11 | find ./BUILD/PORTENTA_H7_M7/GCC_ARM/ \( -name "FileBlockDevice.o" -o -name "BSP.o" -o -name "SDMMCBlockDevice.o" -o -name "rtc.o" -o -name "default_bd.o" -o -name "bootutil_extra.o" -o -name "flash_map_backend.o" -o -name "bootutil_public.o" \) | xargs arm-none-eabi-ar -csr libbootutil.a
12 | echo -n "Library: "
13 | find ./ -name "libbootutil.a"
14 |
15 | if [[ $1 == "portenta" ]] || [[ $1 == "all" ]]; then
16 | echo
17 | echo Generating binaries for PORTENTA H7
18 | mbed compile -c -m PORTENTA_H7_M7 -t GCC_ARM --app=mbed_app_portenta.json --profile=custom.json -N mcuboot_portenta_h7
19 | mkdir -p release/PORTENTA_H7
20 | cp ./libbootutil.a ./release/PORTENTA_H7
21 | cp ./BUILD/PORTENTA_H7_M7/GCC_ARM-CUSTOM/mcuboot_portenta_h7.bin ./release/PORTENTA_H7/mcuboot_portenta_h7.bin
22 | cp ./BUILD/PORTENTA_H7_M7/GCC_ARM-CUSTOM/mcuboot_portenta_h7_application.elf ./release/PORTENTA_H7/mcuboot_portenta_h7.elf
23 | xxd -i ./release/PORTENTA_H7/mcuboot_portenta_h7.bin > ./release/PORTENTA_H7/mcuboot_portenta_h7.h
24 | sed -i "s/unsigned char __release_PORTENTA_H7_mcuboot_portenta_h7_bin/const unsigned char mcuboot_portenta_h7_bin/" ./release/PORTENTA_H7/mcuboot_portenta_h7.h
25 | sed -i "s/__release_PORTENTA_H7_mcuboot_portenta_h7_bin_len/mcuboot_portenta_h7_bin_len/" ./release/PORTENTA_H7/mcuboot_portenta_h7.h
26 | tar -czvf ./release/PORTENTA_H7.tar.gz -C ./release/ PORTENTA_H7
27 | fi
28 |
29 | if [[ $1 == "lite" ]] || [[ $1 == "all" ]]; then
30 | echo
31 | echo Generating binaries for PORTENTA H7 Lite
32 | mbed compile -c -m PORTENTA_H7_M7 -t GCC_ARM --app=mbed_app_portenta_lite.json --profile=custom.json -N mcuboot_portenta_h7_lite
33 | mkdir -p release/PORTENTA_H7_Lite
34 | cp ./libbootutil.a ./release/PORTENTA_H7_Lite
35 | cp ./BUILD/PORTENTA_H7_M7/GCC_ARM-CUSTOM/mcuboot_portenta_h7_lite.bin ./release/PORTENTA_H7_Lite/mcuboot_portenta_h7_lite.bin
36 | cp ./BUILD/PORTENTA_H7_M7/GCC_ARM-CUSTOM/mcuboot_portenta_h7_lite_application.elf ./release/PORTENTA_H7_Lite/mcuboot_portenta_h7_lite.elf
37 | xxd -i ./release/PORTENTA_H7_Lite/mcuboot_portenta_h7_lite.bin > ./release/PORTENTA_H7_Lite/mcuboot_portenta_h7_lite.h
38 | sed -i "s/unsigned char __release_PORTENTA_H7_mcuboot_portenta_h7_lite_bin/const unsigned char mcuboot_portenta_h7_lite_bin/" ./release/PORTENTA_H7_Lite/mcuboot_portenta_h7_lite.h
39 | sed -i "s/__release_PORTENTA_H7_mcuboot_portenta_h7_lite_bin_len/mcuboot_portenta_h7_lite_bin_len/" ./release/PORTENTA_H7_Lite/mcuboot_portenta_h7_lite.h
40 | tar -czvf ./release/PORTENTA_H7_Lite.tar.gz -C ./release/ PORTENTA_H7_Lite
41 | fi
42 |
43 | if [[ $1 == "connected" ]] || [[ $1 == "all" ]]; then
44 | echo
45 | echo Generating binaries for PORTENTA H7 Lite Connected
46 | mbed compile -c -m PORTENTA_H7_M7 -t GCC_ARM --app=mbed_app_portenta_lite_connected.json --profile=custom.json -N mcuboot_portenta_h7_lite_connected
47 | mkdir -p release/PORTENTA_H7_Lite_Connected
48 | cp ./libbootutil.a ./release/PORTENTA_H7_Lite_Connected
49 | cp ./BUILD/PORTENTA_H7_M7/GCC_ARM-CUSTOM/mcuboot_portenta_h7_lite_connected.bin ./release/PORTENTA_H7_Lite_Connected/mcuboot_portenta_h7_lite_connected.bin
50 | cp ./BUILD/PORTENTA_H7_M7/GCC_ARM-CUSTOM/mcuboot_portenta_h7_lite_connected_application.elf ./release/PORTENTA_H7_Lite_Connected/mcuboot_portenta_h7_lite_connected.elf
51 | xxd -i ./release/PORTENTA_H7_Lite_Connected/mcuboot_portenta_h7_lite_connected.bin > ./release/PORTENTA_H7_Lite_Connected/mcuboot_portenta_h7_lite_connected.h
52 | sed -i "s/unsigned char __release_PORTENTA_H7_mcuboot_portenta_h7_lite_connected_bin/const unsigned char mcuboot_portenta_h7_lite_connected_bin/" ./release/PORTENTA_H7_Lite_Connected/mcuboot_portenta_h7_lite_connected.h
53 | sed -i "s/__release_PORTENTA_H7_mcuboot_portenta_h7_lite_connected_bin_len/mcuboot_portenta_h7_lite_connected_bin_len/" ./release/PORTENTA_H7_Lite_Connected/mcuboot_portenta_h7_lite_connected.h
54 | tar -czvf ./release/PORTENTA_H7_Lite_Connected.tar.gz -C ./release/ PORTENTA_H7_Lite_Connected
55 | fi
56 |
57 | if [[ $1 == "nicla" ]] || [[ $1 == "all" ]]; then
58 | echo
59 | echo Generating binaries for NICLA VISION
60 | mbed compile -c -m NICLA_VISION -t GCC_ARM --app=mbed_app_nicla_vision.json --profile=custom.json -N mcuboot_nicla_vision
61 | mkdir -p release/NICLA_VISION
62 | cp ./libbootutil.a ./release/NICLA_VISION
63 | cp ./BUILD/NICLA_VISION/GCC_ARM-CUSTOM/mcuboot_nicla_vision.bin ./release/NICLA_VISION/mcuboot_nicla_vision.bin
64 | cp ./BUILD/NICLA_VISION/GCC_ARM-CUSTOM/mcuboot_nicla_vision_application.elf ./release/NICLA_VISION/mcuboot_nicla_vision.elf
65 | xxd -i ./release/NICLA_VISION/mcuboot_nicla_vision.bin > ./release/NICLA_VISION/mcuboot_nicla_vision.h
66 | sed -i "s/unsigned char __release_NICLA_VISION_mcuboot_nicla_vision_bin/const unsigned char mcuboot_nicla_vision_bin/" ./release/NICLA_VISION/mcuboot_nicla_vision.h
67 | sed -i "s/__release_NICLA_VISION_mcuboot_nicla_vision_bin_len/mcuboot_nicla_vision_bin_len/" ./release/NICLA_VISION/mcuboot_nicla_vision.h
68 | tar -czvf ./release/NICLA_VISION.tar.gz -C ./release/ NICLA_VISION
69 | fi
70 |
71 | if [[ $1 == "opta" ]] || [[ $1 == "all" ]]; then
72 | echo
73 | echo Generating binaries for OPTA
74 | mbed compile -c -m OPTA -t GCC_ARM --app=mbed_app_opta.json --profile=custom.json -N mcuboot_opta
75 | mkdir -p release/OPTA
76 | cp ./libbootutil.a ./release/OPTA
77 | cp ./BUILD/OPTA/GCC_ARM-CUSTOM/mcuboot_opta.bin ./release/OPTA/mcuboot_opta.bin
78 | cp ./BUILD/OPTA/GCC_ARM-CUSTOM/mcuboot_opta_application.elf ./release/OPTA/mcuboot_opta.elf
79 | xxd -i ./release/OPTA/mcuboot_opta.bin > ./release/OPTA/mcuboot_opta.h
80 | sed -i "s/unsigned char __release_OPTA_mcuboot_opta_bin/const unsigned char mcuboot_opta_bin/" ./release/OPTA/mcuboot_opta.h
81 | sed -i "s/__release_OPTA_mcuboot_opta_bin_len/mcuboot_opta_bin_len/" ./release/OPTA/mcuboot_opta.h
82 | tar -czvf ./release/OPTA.tar.gz -C ./release/ OPTA
83 | fi
84 |
85 | if [[ $1 == "giga" ]] || [[ $1 == "all" ]]; then
86 | echo
87 | echo Generating binaries for GIGA
88 | mbed compile -c -m GIGA -t GCC_ARM --app=mbed_app_giga.json --profile=custom.json -N mcuboot_giga
89 | mkdir -p release/GIGA
90 | cp ./libbootutil.a ./release/GIGA
91 | cp ./BUILD/GIGA/GCC_ARM-CUSTOM/mcuboot_giga.bin ./release/GIGA/mcuboot_giga.bin
92 | cp ./BUILD/GIGA/GCC_ARM-CUSTOM/mcuboot_giga_application.elf ./release/GIGA/mcuboot_giga.elf
93 | xxd -i ./release/GIGA/mcuboot_giga.bin > ./release/GIGA/mcuboot_giga.h
94 | sed -i "s/unsigned char __release_GIGA_mcuboot_giga_bin/const unsigned char mcuboot_giga_bin/" ./release/GIGA/mcuboot_giga.h
95 | sed -i "s/__release_GIGA_mcuboot_opta_bin_len/mcuboot_giga_bin_len/" ./release/GIGA/mcuboot_giga.h
96 | tar -czvf ./release/GIGA.tar.gz -C ./release/ GIGA
97 | fi
98 |
99 | if [[ $1 == "gigaw" ]] || [[ $1 == "all" ]]; then
100 | echo
101 | echo Generating binaries for GIGA_WiFi
102 | mbed compile -c -m GIGA -t GCC_ARM --app=mbed_app_giga_wifi.json --profile=custom.json -N mcuboot_giga_wifi
103 | mkdir -p release/GIGA_WiFi
104 | mv ./libbootutil.a ./release/GIGA_WiFi
105 | cp ./BUILD/GIGA/GCC_ARM-CUSTOM/mcuboot_giga_wifi.bin ./release/GIGA_WiFi/mcuboot_giga_wifi.bin
106 | cp ./BUILD/GIGA/GCC_ARM-CUSTOM/mcuboot_giga_wifi_application.elf ./release/GIGA_WiFi/mcuboot_giga_wifi.elf
107 | xxd -i ./release/GIGA_WiFi/mcuboot_giga_wifi.bin > ./release/GIGA_WiFi/mcuboot_giga_wifi.h
108 | sed -i "s/unsigned char __release_GIGA_WiFi_mcuboot_giga_wifi_bin/const unsigned char mcuboot_giga_wifi_bin/" ./release/GIGA_WiFi/mcuboot_giga_wifi.h
109 | sed -i "s/__release_GIGA_WiFi_mcuboot_giga_wifi_bin_len/mcuboot_giga_wifi_bin_len/" ./release/GIGA_WiFi/mcuboot_giga_wifi.h
110 | tar -czvf ./release/GIGA_WiFi.tar.gz -C ./release/ GIGA_WiFi
111 | fi
112 |
--------------------------------------------------------------------------------
/mbed-os.lib:
--------------------------------------------------------------------------------
1 | https://github.com/arduino/mbed-os/#2e1da01300f14f12b39c24434fe7fe5488258353
2 |
--------------------------------------------------------------------------------
/mbed_app.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": [
3 | "bare-metal",
4 | "mbedtls",
5 | "mcuboot",
6 | "flashiap-block-device",
7 | "spif-driver",
8 | "qspif",
9 | "mbed-trace",
10 | "filesystem",
11 | "fat_chan",
12 | "littlefs",
13 | "rtos",
14 | "cmsis-cmsis5-rtos2",
15 | "events"
16 | ],
17 | "macros": [
18 | "MBED_FAULT_HANDLER_DISABLED",
19 | "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\""
20 | ],
21 | "config": {
22 | "serial-bootloader-enable": {
23 | "help": "Build bootloader with serial update support",
24 | "value": 0
25 | }
26 | },
27 | "target_overrides": {
28 | "*": {
29 | "target.restrict_size": "0x20000",
30 | "target.c_lib": "small",
31 | "target.printf_lib": "minimal-printf",
32 | "target.i2c_timing_value_algo": false,
33 | "target.extra_labels_remove" : ["CORDIO"],
34 | "target.features_remove" : ["BLE"],
35 | "target.device_has_remove": [
36 | "USBDEVICE",
37 | "EMAC",
38 | "CAN",
39 | "SPI_ASYNCH",
40 | "SPISLAVE",
41 | "SPI",
42 | "SERIAL_FC",
43 | "PWMOUT",
44 | "ANALOGIN",
45 | "ANALOGOUT",
46 | "I2CSLAVE",
47 | "I2C_ASYNC",
48 | "OSPI",
49 | "TRNG",
50 | "DAC",
51 | "CRC",
52 | "WATCHDOG",
53 | "RTC",
54 | "LPTICKER",
55 | "SLEEP"
56 | ],
57 | "platform.minimal-printf-enable-floating-point": false,
58 | "platform.minimal-printf-enable-64-bit": false,
59 | "platform.stdio-flush-at-exit": false,
60 | "platform.stdio-baud-rate": 115200,
61 | "fat_chan.ff_use_mkfs": 0,
62 | "fat_chan.ff_use_lfn": 0,
63 | "fat_chan.ff_fs_rpath": 0,
64 | "mcuboot.log-level": "MCUBOOT_LOG_LEVEL_INFO",
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-dfu": true,
75 | "mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
76 | "mcuboot.encrypt-ec256": true,
77 | "mcuboot.include-keys": null,
78 | "mcuboot.bootloader-build": false,
79 | "mcuboot.encrypt-scratch": true,
80 | "mcuboot.swap-buf-size": 131072,
81 | "mbed-trace.enable": false,
82 | "mbed-trace.fea-ipv6": false
83 | },
84 | "PORTENTA_H7_M7": {
85 | "target.clock_source": "USE_PLL_HSE_EXTC",
86 | "target.use-mpu": false,
87 | "target.macros_add": [
88 | "USE_USB_HS",
89 | "LOWSPEED=1"
90 | ],
91 | "target.components_remove" : [
92 | "WHD",
93 | "4343W_FS",
94 | "CYW43XXX"
95 | ],
96 | "mcuboot.application-sdcard": true
97 | },
98 | "NICLA_VISION": {
99 | "target.clock_source": "USE_PLL_HSE_EXTC",
100 | "target.use-mpu": false,
101 | "target.macros_add": [
102 | "USE_USB_HS",
103 | "LOWSPEED=1",
104 | "BOARD_HAS_VIDEO=0",
105 | "BOARD_HAS_ETHERNET=0"
106 | ],
107 | "target.components_remove" : [
108 | "WHD",
109 | "4343W_FS",
110 | "CYW43XXX",
111 | "SE050"
112 | ],
113 | "mcuboot.application-sdcard": null
114 | },
115 | "OPTA": {
116 | "target.clock_source": "USE_PLL_HSE_EXTC",
117 | "target.use-mpu": false,
118 | "target.macros_add": [
119 | "USE_USB_FS",
120 | "LOWSPEED=1",
121 | "BOARD_HAS_VIDEO=0",
122 | "BOARD_RAM_SIZE=0"
123 | ],
124 | "target.usb_speed": "USE_USB_OTG_FS",
125 | "target.components_remove" : [
126 | "WHD",
127 | "4343W_FS",
128 | "CYW43XXX"
129 | ],
130 | "mcuboot.application-sdcard": null
131 | },
132 | "GIGA": {
133 | "target.clock_source": "USE_PLL_HSI",
134 | "target.use-mpu": true,
135 | "target.macros_add": [
136 | "USE_USB_FS",
137 | "BOARD_HAS_VIDEO=0",
138 | "BOARD_HAS_ETHERNET=0",
139 | "BOARD_HAS_WIFI=0",
140 | "BOARD_EXTCLOCK=16"
141 | ],
142 | "target.components_remove" : [
143 | "WHD",
144 | "4343W_FS",
145 | "CYW43XXX"
146 | ],
147 | "mcuboot.application-sdcard": null
148 | }
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/mbed_app_bootutil.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": [
3 | "bare-metal",
4 | "mbedtls",
5 | "mcuboot",
6 | "flashiap-block-device",
7 | "spif-driver",
8 | "qspif",
9 | "mbed-trace",
10 | "filesystem",
11 | "fat_chan",
12 | "littlefs",
13 | "rtos",
14 | "cmsis-cmsis5-rtos2",
15 | "events"
16 | ],
17 | "macros": [
18 | "MBED_FAULT_HANDLER_DISABLED",
19 | "USE_USB_HS",
20 | "LOWSPEED=1",
21 | "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\"",
22 | "BOOTUTIL_LIBARY_BUILD=1"
23 | ],
24 | "config": {
25 | "serial-bootloader-enable": {
26 | "help": "Build bootloader with serial update support",
27 | "value": 0
28 | }
29 | },
30 | "target_overrides": {
31 | "*": {
32 | "target.restrict_size": "0x40000",
33 | "target.c_lib": "small",
34 | "target.printf_lib": "minimal-printf",
35 | "target.i2c_timing_value_algo": false,
36 | "target.extra_labels_remove" : ["CORDIO"],
37 | "target.features_remove" : ["BLE"],
38 | "target.device_has_remove": [
39 | "USBDEVICE",
40 | "EMAC",
41 | "CAN",
42 | "SPI_ASYNCH",
43 | "SPISLAVE",
44 | "SPI",
45 | "SERIAL_FC",
46 | "PWMOUT",
47 | "ANALOGIN",
48 | "ANALOGOUT",
49 | "I2CSLAVE",
50 | "I2C_ASYNC",
51 | "OSPI",
52 | "TRNG",
53 | "DAC",
54 | "CRC",
55 | "WATCHDOG",
56 | "RTC",
57 | "LPTICKER",
58 | "SLEEP"
59 | ],
60 | "target.clock_source": "USE_PLL_HSE_EXTC",
61 | "target.use-mpu": false,
62 | "target.components_remove" : [
63 | "WHD",
64 | "4343W_FS",
65 | "CYW43XXX"
66 | ],
67 | "platform.minimal-printf-enable-floating-point": false,
68 | "platform.minimal-printf-enable-64-bit": false,
69 | "platform.stdio-flush-at-exit": false,
70 | "platform.stdio-baud-rate": 115200,
71 | "fat_chan.ff_use_mkfs": 0,
72 | "fat_chan.ff_use_lfn": 0,
73 | "fat_chan.ff_fs_rpath": 0,
74 | "mcuboot.log-level": "MCUBOOT_LOG_LEVEL_OFF",
75 | "mcuboot.primary-slot-address": "0x8020000",
76 | "mcuboot.slot-size": "0x1E0000",
77 | "mcuboot.scratch-address": "0x9000000",
78 | "mcuboot.scratch-size": "0x20000",
79 | "mcuboot.max-img-sectors": "0x3C0",
80 | "mcuboot.max-align": 32,
81 | "mcuboot.bootstrap": true,
82 | "mcuboot.application-hooks": true,
83 | "mcuboot.application-littlefs": true,
84 | "mcuboot.application-sdcard": true,
85 | "mcuboot.application-dfu": null,
86 | "mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
87 | "mcuboot.encrypt-ec256": true,
88 | "mcuboot.include-keys": null,
89 | "mcuboot.bootloader-build": false,
90 | "mbed-trace.enable": false,
91 | "mbed-trace.fea-ipv6": false
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/mbed_app_giga.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": [
3 | "bare-metal",
4 | "mbedtls",
5 | "mcuboot",
6 | "flashiap-block-device",
7 | "spif-driver",
8 | "qspif",
9 | "mbed-trace",
10 | "filesystem",
11 | "fat_chan",
12 | "littlefs",
13 | "rtos",
14 | "cmsis-cmsis5-rtos2",
15 | "events"
16 | ],
17 | "macros": [
18 | "MBED_FAULT_HANDLER_DISABLED",
19 | "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\""
20 | ],
21 | "config": {
22 | "serial-bootloader-enable": {
23 | "help": "Build bootloader with serial update support",
24 | "value": 0
25 | }
26 | },
27 | "target_overrides": {
28 | "GIGA": {
29 | "target.restrict_size": "0x20000",
30 | "target.c_lib": "small",
31 | "target.printf_lib": "minimal-printf",
32 | "target.i2c_timing_value_algo": false,
33 | "target.extra_labels_remove" : ["CORDIO"],
34 | "target.features_remove" : ["BLE"],
35 | "target.device_has_remove": [
36 | "USBDEVICE",
37 | "EMAC",
38 | "CAN",
39 | "SPI_ASYNCH",
40 | "SPISLAVE",
41 | "SPI",
42 | "SERIAL_FC",
43 | "PWMOUT",
44 | "ANALOGIN",
45 | "ANALOGOUT",
46 | "I2CSLAVE",
47 | "I2C_ASYNC",
48 | "OSPI",
49 | "TRNG",
50 | "DAC",
51 | "CRC",
52 | "WATCHDOG",
53 | "RTC",
54 | "LPTICKER",
55 | "SLEEP"
56 | ],
57 | "target.clock_source": "USE_PLL_HSI",
58 | "target.use-mpu": true,
59 | "target.macros_add": [
60 | "USE_USB_FS",
61 | "BOARD_HAS_VIDEO=0",
62 | "BOARD_HAS_ETHERNET=0",
63 | "BOARD_HAS_WIFI=0",
64 | "BOARD_EXTCLOCK=16"
65 | ],
66 | "target.components_remove" : [
67 | "WHD",
68 | "4343W_FS",
69 | "CYW43XXX"
70 | ],
71 | "platform.minimal-printf-enable-floating-point": false,
72 | "platform.minimal-printf-enable-64-bit": false,
73 | "platform.stdio-flush-at-exit": false,
74 | "platform.stdio-baud-rate": 115200,
75 | "fat_chan.ff_use_mkfs": 0,
76 | "fat_chan.ff_use_lfn": 0,
77 | "fat_chan.ff_fs_rpath": 0,
78 | "mcuboot.log-level": "MCUBOOT_LOG_LEVEL_INFO",
79 | "mcuboot.primary-slot-address": "0x8020000",
80 | "mcuboot.slot-size": "0x1E0000",
81 | "mcuboot.scratch-address": "0x9000000",
82 | "mcuboot.scratch-size": "0x20000",
83 | "mcuboot.max-img-sectors": "0x3C0",
84 | "mcuboot.max-align": 32,
85 | "mcuboot.bootstrap": true,
86 | "mcuboot.application-hooks": true,
87 | "mcuboot.application-littlefs": true,
88 | "mcuboot.application-dfu": true,
89 | "mcuboot.application-sdcard": null,
90 | "mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
91 | "mcuboot.encrypt-ec256": true,
92 | "mcuboot.include-keys": null,
93 | "mcuboot.bootloader-build": false,
94 | "mcuboot.encrypt-scratch": true,
95 | "mcuboot.swap-buf-size": 131072,
96 | "mbed-trace.enable": false,
97 | "mbed-trace.fea-ipv6": false
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/mbed_app_giga_wifi.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": [
3 | "bare-metal",
4 | "mbedtls",
5 | "mcuboot",
6 | "flashiap-block-device",
7 | "spif-driver",
8 | "qspif",
9 | "mbed-trace",
10 | "filesystem",
11 | "fat_chan",
12 | "littlefs",
13 | "rtos",
14 | "cmsis-cmsis5-rtos2",
15 | "events"
16 | ],
17 | "macros": [
18 | "MBED_FAULT_HANDLER_DISABLED",
19 | "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\""
20 | ],
21 | "config": {
22 | "serial-bootloader-enable": {
23 | "help": "Build bootloader with serial update support",
24 | "value": 0
25 | }
26 | },
27 | "target_overrides": {
28 | "GIGA": {
29 | "target.restrict_size": "0x20000",
30 | "target.c_lib": "small",
31 | "target.printf_lib": "minimal-printf",
32 | "target.i2c_timing_value_algo": false,
33 | "target.extra_labels_remove" : ["CORDIO"],
34 | "target.features_remove" : ["BLE"],
35 | "target.device_has_remove": [
36 | "USBDEVICE",
37 | "EMAC",
38 | "CAN",
39 | "SPI_ASYNCH",
40 | "SPISLAVE",
41 | "SPI",
42 | "SERIAL_FC",
43 | "PWMOUT",
44 | "ANALOGIN",
45 | "ANALOGOUT",
46 | "I2CSLAVE",
47 | "I2C_ASYNC",
48 | "OSPI",
49 | "TRNG",
50 | "DAC",
51 | "CRC",
52 | "WATCHDOG",
53 | "RTC",
54 | "LPTICKER",
55 | "SLEEP"
56 | ],
57 | "target.clock_source": "USE_PLL_HSI",
58 | "target.use-mpu": true,
59 | "target.macros_add": [
60 | "USE_USB_FS",
61 | "BOARD_HAS_VIDEO=0",
62 | "BOARD_HAS_ETHERNET=0",
63 | "BOARD_EXTCLOCK=16"
64 | ],
65 | "target.components_remove" : [
66 | "WHD",
67 | "4343W_FS",
68 | "CYW43XXX"
69 | ],
70 | "platform.minimal-printf-enable-floating-point": false,
71 | "platform.minimal-printf-enable-64-bit": false,
72 | "platform.stdio-flush-at-exit": false,
73 | "platform.stdio-baud-rate": 115200,
74 | "fat_chan.ff_use_mkfs": 0,
75 | "fat_chan.ff_use_lfn": 0,
76 | "fat_chan.ff_fs_rpath": 0,
77 | "mcuboot.log-level": "MCUBOOT_LOG_LEVEL_INFO",
78 | "mcuboot.primary-slot-address": "0x8020000",
79 | "mcuboot.slot-size": "0x1E0000",
80 | "mcuboot.scratch-address": "0x9000000",
81 | "mcuboot.scratch-size": "0x20000",
82 | "mcuboot.max-img-sectors": "0x3C0",
83 | "mcuboot.max-align": 32,
84 | "mcuboot.bootstrap": true,
85 | "mcuboot.application-hooks": true,
86 | "mcuboot.application-littlefs": true,
87 | "mcuboot.application-dfu": true,
88 | "mcuboot.application-sdcard": null,
89 | "mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
90 | "mcuboot.encrypt-ec256": true,
91 | "mcuboot.include-keys": null,
92 | "mcuboot.bootloader-build": false,
93 | "mcuboot.encrypt-scratch": true,
94 | "mcuboot.swap-buf-size": 131072,
95 | "mbed-trace.enable": false,
96 | "mbed-trace.fea-ipv6": false
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/mbed_app_nicla_vision.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": [
3 | "bare-metal",
4 | "mbedtls",
5 | "mcuboot",
6 | "flashiap-block-device",
7 | "spif-driver",
8 | "qspif",
9 | "mbed-trace",
10 | "filesystem",
11 | "fat_chan",
12 | "littlefs",
13 | "rtos",
14 | "cmsis-cmsis5-rtos2",
15 | "events"
16 | ],
17 | "macros": [
18 | "MBED_FAULT_HANDLER_DISABLED",
19 | "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\""
20 | ],
21 | "config": {
22 | "serial-bootloader-enable": {
23 | "help": "Build bootloader with serial update support",
24 | "value": 0
25 | }
26 | },
27 | "target_overrides": {
28 | "NICLA_VISION": {
29 | "target.restrict_size": "0x20000",
30 | "target.c_lib": "small",
31 | "target.printf_lib": "minimal-printf",
32 | "target.i2c_timing_value_algo": false,
33 | "target.extra_labels_remove" : ["CORDIO"],
34 | "target.features_remove" : ["BLE"],
35 | "target.device_has_remove": [
36 | "USBDEVICE",
37 | "EMAC",
38 | "CAN",
39 | "SPI_ASYNCH",
40 | "SPISLAVE",
41 | "SPI",
42 | "SERIAL_FC",
43 | "PWMOUT",
44 | "ANALOGIN",
45 | "ANALOGOUT",
46 | "I2CSLAVE",
47 | "I2C_ASYNC",
48 | "OSPI",
49 | "TRNG",
50 | "DAC",
51 | "CRC",
52 | "WATCHDOG",
53 | "RTC",
54 | "LPTICKER",
55 | "SLEEP"
56 | ],
57 | "target.clock_source": "USE_PLL_HSE_EXTC",
58 | "target.use-mpu": false,
59 | "target.macros_add": [
60 | "USE_USB_HS",
61 | "LOWSPEED=1",
62 | "BOARD_HAS_VIDEO=0",
63 | "BOARD_HAS_ETHERNET=0",
64 | "BOARD_RAM_SIZE=0"
65 | ],
66 | "target.components_remove" : [
67 | "WHD",
68 | "4343W_FS",
69 | "CYW43XXX",
70 | "SE050"
71 | ],
72 | "platform.minimal-printf-enable-floating-point": false,
73 | "platform.minimal-printf-enable-64-bit": false,
74 | "platform.stdio-flush-at-exit": false,
75 | "platform.stdio-baud-rate": 115200,
76 | "fat_chan.ff_use_mkfs": 0,
77 | "fat_chan.ff_use_lfn": 0,
78 | "fat_chan.ff_fs_rpath": 0,
79 | "mcuboot.log-level": "MCUBOOT_LOG_LEVEL_INFO",
80 | "mcuboot.primary-slot-address": "0x8020000",
81 | "mcuboot.slot-size": "0x1E0000",
82 | "mcuboot.scratch-address": "0x9000000",
83 | "mcuboot.scratch-size": "0x20000",
84 | "mcuboot.max-img-sectors": "0x3C0",
85 | "mcuboot.max-align": 32,
86 | "mcuboot.bootstrap": true,
87 | "mcuboot.application-hooks": true,
88 | "mcuboot.application-littlefs": true,
89 | "mcuboot.application-dfu": true,
90 | "mcuboot.application-sdcard": null,
91 | "mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
92 | "mcuboot.encrypt-ec256": true,
93 | "mcuboot.include-keys": null,
94 | "mcuboot.bootloader-build": false,
95 | "mcuboot.encrypt-scratch": true,
96 | "mcuboot.swap-buf-size": 131072,
97 | "mbed-trace.enable": false,
98 | "mbed-trace.fea-ipv6": false
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/mbed_app_opta.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": [
3 | "bare-metal",
4 | "mbedtls",
5 | "mcuboot",
6 | "flashiap-block-device",
7 | "spif-driver",
8 | "qspif",
9 | "mbed-trace",
10 | "filesystem",
11 | "fat_chan",
12 | "littlefs",
13 | "rtos",
14 | "cmsis-cmsis5-rtos2",
15 | "events"
16 | ],
17 | "macros": [
18 | "MBED_FAULT_HANDLER_DISABLED",
19 | "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\""
20 | ],
21 | "config": {
22 | "serial-bootloader-enable": {
23 | "help": "Build bootloader with serial update support",
24 | "value": 0
25 | }
26 | },
27 | "target_overrides": {
28 | "OPTA": {
29 | "target.restrict_size": "0x20000",
30 | "target.c_lib": "small",
31 | "target.printf_lib": "minimal-printf",
32 | "target.i2c_timing_value_algo": false,
33 | "target.extra_labels_remove" : ["CORDIO"],
34 | "target.features_remove" : ["BLE"],
35 | "target.device_has_remove": [
36 | "USBDEVICE",
37 | "EMAC",
38 | "CAN",
39 | "SPI_ASYNCH",
40 | "SPISLAVE",
41 | "SPI",
42 | "SERIAL_FC",
43 | "PWMOUT",
44 | "ANALOGIN",
45 | "ANALOGOUT",
46 | "I2CSLAVE",
47 | "I2C_ASYNC",
48 | "OSPI",
49 | "TRNG",
50 | "DAC",
51 | "CRC",
52 | "WATCHDOG",
53 | "RTC",
54 | "LPTICKER",
55 | "SLEEP"
56 | ],
57 | "target.clock_source": "USE_PLL_HSE_EXTC",
58 | "target.use-mpu": false,
59 | "target.macros_add": [
60 | "USE_USB_FS",
61 | "LOWSPEED=1",
62 | "BOARD_HAS_VIDEO=0",
63 | "BOARD_RAM_SIZE=0"
64 | ],
65 | "target.usb_speed": "USE_USB_OTG_FS",
66 | "target.components_remove" : [
67 | "WHD",
68 | "4343W_FS",
69 | "CYW43XXX"
70 | ],
71 | "platform.minimal-printf-enable-floating-point": false,
72 | "platform.minimal-printf-enable-64-bit": false,
73 | "platform.stdio-flush-at-exit": false,
74 | "platform.stdio-baud-rate": 115200,
75 | "fat_chan.ff_use_mkfs": 0,
76 | "fat_chan.ff_use_lfn": 0,
77 | "fat_chan.ff_fs_rpath": 0,
78 | "mcuboot.log-level": "MCUBOOT_LOG_LEVEL_INFO",
79 | "mcuboot.primary-slot-address": "0x8020000",
80 | "mcuboot.slot-size": "0x1E0000",
81 | "mcuboot.scratch-address": "0x9000000",
82 | "mcuboot.scratch-size": "0x20000",
83 | "mcuboot.max-img-sectors": "0x3C0",
84 | "mcuboot.max-align": 32,
85 | "mcuboot.bootstrap": true,
86 | "mcuboot.application-hooks": true,
87 | "mcuboot.application-littlefs": true,
88 | "mcuboot.application-dfu": true,
89 | "mcuboot.application-sdcard": null,
90 | "mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
91 | "mcuboot.encrypt-ec256": true,
92 | "mcuboot.include-keys": null,
93 | "mcuboot.bootloader-build": false,
94 | "mcuboot.encrypt-scratch": true,
95 | "mcuboot.swap-buf-size": 131072,
96 | "mbed-trace.enable": false,
97 | "mbed-trace.fea-ipv6": false
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/mbed_app_portenta.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": [
3 | "bare-metal",
4 | "mbedtls",
5 | "mcuboot",
6 | "flashiap-block-device",
7 | "spif-driver",
8 | "qspif",
9 | "mbed-trace",
10 | "filesystem",
11 | "fat_chan",
12 | "littlefs",
13 | "rtos",
14 | "cmsis-cmsis5-rtos2",
15 | "events"
16 | ],
17 | "macros": [
18 | "MBED_FAULT_HANDLER_DISABLED",
19 | "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\""
20 | ],
21 | "config": {
22 | "serial-bootloader-enable": {
23 | "help": "Build bootloader with serial update support",
24 | "value": 0
25 | }
26 | },
27 | "target_overrides": {
28 | "PORTENTA_H7_M7": {
29 | "target.restrict_size": "0x20000",
30 | "target.c_lib": "small",
31 | "target.printf_lib": "minimal-printf",
32 | "target.i2c_timing_value_algo": false,
33 | "target.extra_labels_remove" : ["CORDIO"],
34 | "target.features_remove" : ["BLE"],
35 | "target.device_has_remove": [
36 | "USBDEVICE",
37 | "EMAC",
38 | "CAN",
39 | "SPI_ASYNCH",
40 | "SPISLAVE",
41 | "SPI",
42 | "SERIAL_FC",
43 | "PWMOUT",
44 | "ANALOGIN",
45 | "ANALOGOUT",
46 | "I2CSLAVE",
47 | "I2C_ASYNC",
48 | "OSPI",
49 | "TRNG",
50 | "DAC",
51 | "CRC",
52 | "WATCHDOG",
53 | "RTC",
54 | "LPTICKER",
55 | "SLEEP"
56 | ],
57 | "target.clock_source": "USE_PLL_HSE_EXTC",
58 | "target.use-mpu": false,
59 | "target.macros_add": [
60 | "USE_USB_HS",
61 | "LOWSPEED=1"
62 | ],
63 | "target.components_remove" : [
64 | "WHD",
65 | "4343W_FS",
66 | "CYW43XXX"
67 | ],
68 | "platform.minimal-printf-enable-floating-point": false,
69 | "platform.minimal-printf-enable-64-bit": false,
70 | "platform.stdio-flush-at-exit": false,
71 | "platform.stdio-baud-rate": 115200,
72 | "fat_chan.ff_use_mkfs": 0,
73 | "fat_chan.ff_use_lfn": 0,
74 | "fat_chan.ff_fs_rpath": 0,
75 | "mcuboot.log-level": "MCUBOOT_LOG_LEVEL_INFO",
76 | "mcuboot.primary-slot-address": "0x8020000",
77 | "mcuboot.slot-size": "0x1E0000",
78 | "mcuboot.scratch-address": "0x9000000",
79 | "mcuboot.scratch-size": "0x20000",
80 | "mcuboot.max-img-sectors": "0x3C0",
81 | "mcuboot.max-align": 32,
82 | "mcuboot.bootstrap": true,
83 | "mcuboot.application-hooks": true,
84 | "mcuboot.application-littlefs": true,
85 | "mcuboot.application-dfu": true,
86 | "mcuboot.application-sdcard": true,
87 | "mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
88 | "mcuboot.encrypt-ec256": true,
89 | "mcuboot.include-keys": null,
90 | "mcuboot.bootloader-build": false,
91 | "mcuboot.encrypt-scratch": true,
92 | "mcuboot.swap-buf-size": 131072,
93 | "mbed-trace.enable": false,
94 | "mbed-trace.fea-ipv6": false
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/mbed_app_portenta_lite.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": [
3 | "bare-metal",
4 | "mbedtls",
5 | "mcuboot",
6 | "flashiap-block-device",
7 | "spif-driver",
8 | "qspif",
9 | "mbed-trace",
10 | "filesystem",
11 | "fat_chan",
12 | "littlefs",
13 | "rtos",
14 | "cmsis-cmsis5-rtos2",
15 | "events"
16 | ],
17 | "macros": [
18 | "MBED_FAULT_HANDLER_DISABLED",
19 | "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\""
20 | ],
21 | "config": {
22 | "serial-bootloader-enable": {
23 | "help": "Build bootloader with serial update support",
24 | "value": 0
25 | }
26 | },
27 | "target_overrides": {
28 | "PORTENTA_H7_M7": {
29 | "target.restrict_size": "0x20000",
30 | "target.c_lib": "small",
31 | "target.printf_lib": "minimal-printf",
32 | "target.i2c_timing_value_algo": false,
33 | "target.extra_labels_remove" : ["CORDIO"],
34 | "target.features_remove" : ["BLE"],
35 | "target.device_has_remove": [
36 | "USBDEVICE",
37 | "EMAC",
38 | "CAN",
39 | "SPI_ASYNCH",
40 | "SPISLAVE",
41 | "SPI",
42 | "SERIAL_FC",
43 | "PWMOUT",
44 | "ANALOGIN",
45 | "ANALOGOUT",
46 | "I2CSLAVE",
47 | "I2C_ASYNC",
48 | "OSPI",
49 | "TRNG",
50 | "DAC",
51 | "CRC",
52 | "WATCHDOG",
53 | "RTC",
54 | "LPTICKER",
55 | "SLEEP"
56 | ],
57 | "target.clock_source": "USE_PLL_HSE_EXTC",
58 | "target.use-mpu": false,
59 | "target.macros_add": [
60 | "USE_USB_HS",
61 | "LOWSPEED=1",
62 | "BOARD_HAS_VIDEO=0",
63 | "BOARD_HAS_WIFI=0"
64 | ],
65 | "target.components_remove" : [
66 | "WHD",
67 | "4343W_FS",
68 | "CYW43XXX"
69 | ],
70 | "platform.minimal-printf-enable-floating-point": false,
71 | "platform.minimal-printf-enable-64-bit": false,
72 | "platform.stdio-flush-at-exit": false,
73 | "platform.stdio-baud-rate": 115200,
74 | "fat_chan.ff_use_mkfs": 0,
75 | "fat_chan.ff_use_lfn": 0,
76 | "fat_chan.ff_fs_rpath": 0,
77 | "mcuboot.log-level": "MCUBOOT_LOG_LEVEL_INFO",
78 | "mcuboot.primary-slot-address": "0x8020000",
79 | "mcuboot.slot-size": "0x1E0000",
80 | "mcuboot.scratch-address": "0x9000000",
81 | "mcuboot.scratch-size": "0x20000",
82 | "mcuboot.max-img-sectors": "0x3C0",
83 | "mcuboot.max-align": 32,
84 | "mcuboot.bootstrap": true,
85 | "mcuboot.application-hooks": true,
86 | "mcuboot.application-littlefs": true,
87 | "mcuboot.application-dfu": true,
88 | "mcuboot.application-sdcard": true,
89 | "mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
90 | "mcuboot.encrypt-ec256": true,
91 | "mcuboot.include-keys": null,
92 | "mcuboot.bootloader-build": false,
93 | "mcuboot.encrypt-scratch": true,
94 | "mcuboot.swap-buf-size": 131072,
95 | "mbed-trace.enable": false,
96 | "mbed-trace.fea-ipv6": false
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/mbed_app_portenta_lite_connected.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": [
3 | "bare-metal",
4 | "mbedtls",
5 | "mcuboot",
6 | "flashiap-block-device",
7 | "spif-driver",
8 | "qspif",
9 | "mbed-trace",
10 | "filesystem",
11 | "fat_chan",
12 | "littlefs",
13 | "rtos",
14 | "cmsis-cmsis5-rtos2",
15 | "events"
16 | ],
17 | "macros": [
18 | "MBED_FAULT_HANDLER_DISABLED",
19 | "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\""
20 | ],
21 | "config": {
22 | "serial-bootloader-enable": {
23 | "help": "Build bootloader with serial update support",
24 | "value": 0
25 | }
26 | },
27 | "target_overrides": {
28 | "PORTENTA_H7_M7": {
29 | "target.restrict_size": "0x20000",
30 | "target.c_lib": "small",
31 | "target.printf_lib": "minimal-printf",
32 | "target.i2c_timing_value_algo": false,
33 | "target.extra_labels_remove" : ["CORDIO"],
34 | "target.features_remove" : ["BLE"],
35 | "target.device_has_remove": [
36 | "USBDEVICE",
37 | "EMAC",
38 | "CAN",
39 | "SPI_ASYNCH",
40 | "SPISLAVE",
41 | "SPI",
42 | "SERIAL_FC",
43 | "PWMOUT",
44 | "ANALOGIN",
45 | "ANALOGOUT",
46 | "I2CSLAVE",
47 | "I2C_ASYNC",
48 | "OSPI",
49 | "TRNG",
50 | "DAC",
51 | "CRC",
52 | "WATCHDOG",
53 | "RTC",
54 | "LPTICKER",
55 | "SLEEP"
56 | ],
57 | "target.clock_source": "USE_PLL_HSE_EXTC",
58 | "target.use-mpu": false,
59 | "target.macros_add": [
60 | "USE_USB_HS",
61 | "LOWSPEED=1",
62 | "BOARD_HAS_VIDEO=0"
63 | ],
64 | "target.components_remove" : [
65 | "WHD",
66 | "4343W_FS",
67 | "CYW43XXX"
68 | ],
69 | "platform.minimal-printf-enable-floating-point": false,
70 | "platform.minimal-printf-enable-64-bit": false,
71 | "platform.stdio-flush-at-exit": false,
72 | "platform.stdio-baud-rate": 115200,
73 | "fat_chan.ff_use_mkfs": 0,
74 | "fat_chan.ff_use_lfn": 0,
75 | "fat_chan.ff_fs_rpath": 0,
76 | "mcuboot.log-level": "MCUBOOT_LOG_LEVEL_INFO",
77 | "mcuboot.primary-slot-address": "0x8020000",
78 | "mcuboot.slot-size": "0x1E0000",
79 | "mcuboot.scratch-address": "0x9000000",
80 | "mcuboot.scratch-size": "0x20000",
81 | "mcuboot.max-img-sectors": "0x3C0",
82 | "mcuboot.max-align": 32,
83 | "mcuboot.bootstrap": true,
84 | "mcuboot.application-hooks": true,
85 | "mcuboot.application-littlefs": true,
86 | "mcuboot.application-dfu": true,
87 | "mcuboot.application-sdcard": true,
88 | "mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
89 | "mcuboot.encrypt-ec256": true,
90 | "mcuboot.include-keys": null,
91 | "mcuboot.bootloader-build": false,
92 | "mcuboot.encrypt-scratch": true,
93 | "mcuboot.swap-buf-size": 131072,
94 | "mbed-trace.enable": false,
95 | "mbed-trace.fea-ipv6": false
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/mbedtls_config.h:
--------------------------------------------------------------------------------
1 | #if !defined(MBEDTLS_AES_C)
2 | #define MBEDTLS_AES_C
3 | #endif
4 |
5 | #if !defined(MBEDTLS_CIPHER_MODE_CTR)
6 | #define MBEDTLS_CIPHER_MODE_CTR
7 | #endif
8 |
9 | #if defined(MBEDTLS_SHA1_C)
10 | #undef MBEDTLS_SHA1_C
11 | #endif
12 |
13 | #if defined(MBEDTLS_SHA512_C)
14 | #undef MBEDTLS_SHA512_C
15 | #endif
16 |
17 | #if defined(MBEDTLS_AES_ROM_TABLES)
18 | #undef MBEDTLS_AES_ROM_TABLES
19 | #endif
20 |
21 | #if defined(MBEDTLS_RSA_C)
22 | #undef MBEDTLS_RSA_C
23 | #endif
24 |
25 | #if !defined(MBEDTLS_ECDH_C)
26 | #define MBEDTLS_ECDH_C
27 | #endif
28 |
--------------------------------------------------------------------------------
/mcuboot.lib:
--------------------------------------------------------------------------------
1 | https://github.com/arduino/mcuboot/#f53a4d0c7b866e0d98062d83b5a8a8e0dc20099c
--------------------------------------------------------------------------------