Skip to content

Add support for OPTA #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion app/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
#define BOARD_RED_LED PK_5
#define BOARD_BLUE_LED PK_7

#define BOARD_LED_OFF 1

#define BOARD_USB_RESET PJ_4
#define BOARD_ETH_RESET PJ_15
#define BOARD_BOOT_SEL PI_8
Expand Down Expand Up @@ -142,6 +144,8 @@
#define BOARD_RED_LED PE_3
#define BOARD_BLUE_LED PF_4

#define BOARD_LED_OFF 1

#define BOARD_USB_RESET PA_2

#define BOARD_I2C_SCL PF_1
Expand Down Expand Up @@ -204,8 +208,71 @@
#define BOARD_USB_OTG_HS_DIR_ALTERNATE (GPIO_AF10_OTG2_HS)
#define BOARD_USB_OTG_HS_DIR_GPIO (GPIOC)

#else
#elif defined TARGET_OPTA
#define BOARD_GREEN_LED PH_12
#define BOARD_RED_LED PH_11
#define BOARD_BLUE_LED PE_5

#define BOARD_LED_OFF 0

#define BOARD_ETH_RESET PJ_15

#define BOARD_USBD_VID 0x2341
#define BOARD_USBD_PID 0x0364

#define BOARD_USBD_STRING "Opta"

#define BOARD_QSPI_SO0 PD_11
#define BOARD_QSPI_SO1 PD_12
#define BOARD_QSPI_SO2 PE_2
#define BOARD_QSPI_SO3 PD_13
#define BOARD_QSPI_SCK PB_2
#define BOARD_QSPI_CS PG_6

#define BOARD_USB_OTG_FS_DM_DP_PIN (GPIO_PIN_11 | GPIO_PIN_12)
#define BOARD_USB_OTG_FS_DM_DP_MODE (GPIO_MODE_AF_PP)
#define BOARD_USB_OTG_FS_DM_DP_PULL (GPIO_PULLUP)
#define BOARD_USB_OTG_FS_DM_DP_SPEED (GPIO_SPEED_FREQ_VERY_HIGH)
#define BOARD_USB_OTG_FS_DM_DP_ALTERNATE (GPIO_AF10_OTG1_FS)
#define BOARD_USB_OTG_FS_DM_DP_GPIO (GPIOA)

#define BOARD_USB_OTG_HS_CLK_PIN (GPIO_PIN_5)
#define BOARD_USB_OTG_HS_CLK_MODE (GPIO_MODE_AF_PP)
#define BOARD_USB_OTG_HS_CLK_PULL (GPIO_NOPULL)
#define BOARD_USB_OTG_HS_CLK_SPEED (GPIO_SPEED_FREQ_VERY_HIGH)
#define BOARD_USB_OTG_HS_CLK_ALTERNATE (GPIO_AF10_OTG2_HS)
#define BOARD_USB_OTG_HS_CLK_GPIO (GPIOA)

#define BOARD_USB_OTG_HS_D0_PIN (GPIO_PIN_3)
#define BOARD_USB_OTG_HS_D0_MODE (GPIO_MODE_AF_PP)
#define BOARD_USB_OTG_HS_D0_PULL (GPIO_NOPULL)
#define BOARD_USB_OTG_HS_D0_SPEED (GPIO_SPEED_FREQ_VERY_HIGH)
#define BOARD_USB_OTG_HS_D0_ALTERNATE (GPIO_AF10_OTG2_HS)
#define BOARD_USB_OTG_HS_D0_GPIO (GPIOA)

#define BOARD_USB_OTG_HS_D1_D7_PIN (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13)
#define BOARD_USB_OTG_HS_D1_D7_MODE (GPIO_MODE_AF_PP)
#define BOARD_USB_OTG_HS_D1_D7_PULL (GPIO_NOPULL)
#define BOARD_USB_OTG_HS_D1_D7_ALTERNATE (GPIO_AF10_OTG2_HS)
#define BOARD_USB_OTG_HS_D1_D7_GPIO (GPIOB)

#define BOARD_USB_OTG_HS_STP_PIN (GPIO_PIN_0)
#define BOARD_USB_OTG_HS_STP_MODE (GPIO_MODE_AF_PP)
#define BOARD_USB_OTG_HS_STP_PULL (GPIO_NOPULL)
#define BOARD_USB_OTG_HS_STP_ALTERNATE (GPIO_AF10_OTG2_HS)
#define BOARD_USB_OTG_HS_STP_GPIO (GPIOC)

#define BOARD_USB_OTG_HS_NXT_PIN (GPIO_PIN_3)
#define BOARD_USB_OTG_HS_NXT_MODE (GPIO_MODE_AF_PP)
#define BOARD_USB_OTG_HS_NXT_PULL (GPIO_NOPULL)
#define BOARD_USB_OTG_HS_NXT_ALTERNATE (GPIO_AF10_OTG2_HS)
#define BOARD_USB_OTG_HS_NXT_GPIO (GPIOC)

#define BOARD_USB_OTG_HS_DIR_PIN (GPIO_PIN_2)
#define BOARD_USB_OTG_HS_DIR_MODE (GPIO_MODE_AF_PP)
#define BOARD_USB_OTG_HS_DIR_PULL (GPIO_NOPULL)
#define BOARD_USB_OTG_HS_DIR_ALTERNATE (GPIO_AF10_OTG2_HS)
#define BOARD_USB_OTG_HS_DIR_GPIO (GPIOC)
#endif

#endif /* __BOARD_H */
41 changes: 29 additions & 12 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
#define USE_PLL_HSE_XTAL 0x4 // Use external xtal (X3 on board - not provided by default)
#define USE_PLL_HSI 0x2 // Use HSI internal clock

#if ((CLOCK_SOURCE) & USE_PLL_HSI)
extern "C" uint8_t SetSysClock_PLL_HSI(void);
#elif ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC)
extern "C" uint8_t SetSysClock_PLL_HSE(uint8_t bypass, bool lowspeed);
#else

#endif

volatile const uint8_t bootloader_data[] __attribute__ ((section (".bootloader_version"), used)) = {
BOOTLOADER_CONFIG_MAGIC,
Expand All @@ -63,23 +69,24 @@ volatile const uint8_t bootloader_identifier[] __attribute__ ((section (".bootlo
USBD_HandleTypeDef USBD_Device;
#endif

DigitalOut red(BOARD_RED_LED, 1);
DigitalOut green(BOARD_GREEN_LED, 1);
DigitalOut blue(BOARD_BLUE_LED, 1);
#if defined(TARGET_NICLA_VISION)
bool boot_sel = false;
#else
DigitalOut red(BOARD_RED_LED, BOARD_LED_OFF);
DigitalOut green(BOARD_GREEN_LED, BOARD_LED_OFF);
DigitalOut blue(BOARD_BLUE_LED, BOARD_LED_OFF);

#if defined (BOARD_BOOT_SEL)
DigitalIn boot_sel(BOARD_BOOT_SEL,PullDown);
#else
bool boot_sel = false;
#endif

Ticker swap_ticker;
bool debug_enabled = false;

static void led_swap_feedback_off(void) {
swap_ticker.detach();
red = 1;
green = 1;
blue = 1;
red = BOARD_LED_OFF;
green = BOARD_LED_OFF;
blue = BOARD_LED_OFF;
}

static void led_swap_feedback() {
Expand Down Expand Up @@ -133,7 +140,14 @@ static int debug_init(void) {
static int start_dfu(void) {
RTCSetBKPRegister(RTC_BKP_DR0, 0);

#if ((CLOCK_SOURCE) & USE_PLL_HSI)
SetSysClock_PLL_HSI();
#elif ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC)
SetSysClock_PLL_HSE(1, false);
#else

#endif

SystemCoreClockUpdate();

led_swap_feedback_off();
Expand Down Expand Up @@ -235,8 +249,11 @@ int main(void) {
HAL_Delay(500);
}

#if defined (BOARD_USB_RESET)
DigitalOut usb_reset(BOARD_USB_RESET, 0);
#if BOARD_HAS_VIDEO
#endif

#if defined (BOARD_HAS_VIDEO) && (BOARD_HAS_VIDEO)
DigitalOut video_enable(BOARD_VIDEO_ENABLE, 0);
DigitalOut video_reset(BOARD_VIDEO_RESET, 0);
#endif
Expand All @@ -248,16 +265,16 @@ int main(void) {
HAL_FLASH_Unlock();

power_init();

HAL_Delay(10);

#if defined (BOARD_USB_RESET)
usb_reset = 1;
HAL_Delay(10);
usb_reset = 0;
HAL_Delay(10);
usb_reset = 1;

HAL_Delay(10);
#endif

if (magic != 0xDF59) {
if (boot_empty_keys()) {
Expand Down
16 changes: 15 additions & 1 deletion generate_rel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,25 @@ echo
echo Generating binaries for NICLA VISION
mbed compile -c -m NICLA_VISION -t GCC_ARM --app=mbed_app_nicla_vision.json --profile=custom.json -N mcuboot_nicla_vision
mkdir -p release/NICLA_VISION
mv ./libbootutil.a ./release/NICLA_VISION
cp ./libbootutil.a ./release/NICLA_VISION
cp ./BUILD/NICLA_VISION/GCC_ARM-CUSTOM/mcuboot_nicla_vision.bin ./release/NICLA_VISION/mcuboot_nicla_vision.bin
cp ./BUILD/NICLA_VISION/GCC_ARM-CUSTOM/mcuboot_nicla_vision_application.elf ./release/NICLA_VISION/mcuboot_nicla_vision.elf
xxd -i ./release/NICLA_VISION/mcuboot_nicla_vision.bin > ./release/NICLA_VISION/mcuboot_nicla_vision.h
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
sed -i "s/__release_NICLA_VISION_mcuboot_nicla_vision_bin_len/mcuboot_nicla_vision_bin_len/" ./release/NICLA_VISION/mcuboot_nicla_vision.h
tar -czvf ./release/NICLA_VISION.tar.gz -C ./release/ NICLA_VISION
fi

if [[ $1 == "opta" ]] || [[ $1 == "all" ]]; then
echo
echo Generating binaries for OPTA
mbed compile -c -m OPTA -t GCC_ARM --app=mbed_app_opta.json --profile=custom.json -N mcuboot_opta
mkdir -p release/OPTA
mv ./libbootutil.a ./release/OPTA
cp ./BUILD/OPTA/GCC_ARM-CUSTOM/mcuboot_opta.bin ./release/OPTA/mcuboot_opta.bin
cp ./BUILD/OPTA/GCC_ARM-CUSTOM/mcuboot_opta_application.elf ./release/OPTA/mcuboot_opta.elf
xxd -i ./release/OPTA/mcuboot_opta.bin > ./release/OPTA/mcuboot_opta.h
sed -i "s/unsigned char __release_OPTA_mcuboot_opta_bin/const unsigned char mcuboot_opta_bin/" ./release/OPTA/mcuboot_opta.h
sed -i "s/__release_OPTA_mcuboot_opta_bin_len/mcuboot_opta_bin_len/" ./release/OPTA/mcuboot_opta.h
tar -czvf ./release/OPTA.tar.gz -C ./release/ OPTA
fi
17 changes: 17 additions & 0 deletions mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@
"SE050"
],
"mcuboot.application-sdcard": null
},
"OPTA": {
"target.clock_source": "USE_PLL_HSE_EXTC",
"target.use-mpu": false,
"target.macros_add": [
"USE_USB_FS",
"LOWSPEED=1",
"BOARD_HAS_VIDEO=0",
"BOARD_RAM_SIZE=0"
],
"target.usb_speed": "USE_USB_OTG_FS",
"target.components_remove" : [
"WHD",
"4343W_FS",
"CYW43XXX"
],
"mcuboot.application-sdcard": null
}
}
}
100 changes: 100 additions & 0 deletions mbed_app_opta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"requires": [
"bare-metal",
"mbedtls",
"mcuboot",
"flashiap-block-device",
"spif-driver",
"qspif",
"mbed-trace",
"filesystem",
"fat_chan",
"littlefs",
"rtos",
"cmsis-cmsis5-rtos2",
"events"
],
"macros": [
"MBED_FAULT_HANDLER_DISABLED",
"MBEDTLS_USER_CONFIG_FILE=\"mbedtls_config.h\""
],
"config": {
"serial-bootloader-enable": {
"help": "Build bootloader with serial update support",
"value": 0
}
},
"target_overrides": {
"OPTA": {
"target.restrict_size": "0x20000",
"target.c_lib": "small",
"target.printf_lib": "minimal-printf",
"target.i2c_timing_value_algo": false,
"target.extra_labels_remove" : ["CORDIO"],
"target.features_remove" : ["BLE"],
"target.device_has_remove": [
"USBDEVICE",
"EMAC",
"CAN",
"SPI_ASYNCH",
"SPISLAVE",
"SPI",
"SERIAL_FC",
"PWMOUT",
"ANALOGIN",
"ANALOGOUT",
"I2CSLAVE",
"I2C_ASYNC",
"OSPI",
"TRNG",
"DAC",
"CRC",
"WATCHDOG",
"RTC",
"LPTICKER",
"SLEEP"
],
"target.clock_source": "USE_PLL_HSE_EXTC",
"target.use-mpu": false,
"target.macros_add": [
"USE_USB_FS",
"LOWSPEED=1",
"BOARD_HAS_VIDEO=0",
"BOARD_RAM_SIZE=0"
],
"target.usb_speed": "USE_USB_OTG_FS",
"target.components_remove" : [
"WHD",
"4343W_FS",
"CYW43XXX"
],
"platform.minimal-printf-enable-floating-point": false,
"platform.minimal-printf-enable-64-bit": false,
"platform.stdio-flush-at-exit": false,
"platform.stdio-baud-rate": 115200,
"fat_chan.ff_use_mkfs": 0,
"fat_chan.ff_use_lfn": 0,
"fat_chan.ff_fs_rpath": 0,
"mcuboot.log-level": "MCUBOOT_LOG_LEVEL_INFO",
"mcuboot.primary-slot-address": "0x8020000",
"mcuboot.slot-size": "0x1E0000",
"mcuboot.scratch-address": "0x9000000",
"mcuboot.scratch-size": "0x20000",
"mcuboot.max-img-sectors": "0x3C0",
"mcuboot.max-align": 32,
"mcuboot.bootstrap": true,
"mcuboot.application-hooks": true,
"mcuboot.application-littlefs": true,
"mcuboot.application-dfu": true,
"mcuboot.application-sdcard": null,
"mcuboot.signature-algorithm": "SIGNATURE_TYPE_EC256",
"mcuboot.encrypt-ec256": true,
"mcuboot.include-keys": null,
"mcuboot.bootloader-build": false,
"mcuboot.encrypt-scratch": true,
"mcuboot.swap-buf-size": 131072,
"mbed-trace.enable": false,
"mbed-trace.fea-ipv6": false
}
}
}