From ebb1b2458f5a96146112f2ee56c667cb4c19531e Mon Sep 17 00:00:00 2001 From: Rene Hopf Date: Wed, 18 Jan 2017 21:35:37 +0100 Subject: [PATCH] bootloader --- f3dfu/Inc/main.h | 7 ++---- f3dfu/Src/main.c | 13 ++++++++++- f3dfu/Src/usbd_dfu_if.c | 43 +++++++++++++++++------------------ stm32f303/src/comps/term.comp | 32 +++++++++++++------------- 4 files changed, 51 insertions(+), 44 deletions(-) diff --git a/f3dfu/Inc/main.h b/f3dfu/Inc/main.h index 4acaf8d5..0a46ada7 100644 --- a/f3dfu/Inc/main.h +++ b/f3dfu/Inc/main.h @@ -51,11 +51,8 @@ /* Private define ------------------------------------------------------------*/ -// #define LED_Pin GPIO_PIN_8 -// #define LED_GPIO_Port GPIOA -//discovery -#define LED_Pin GPIO_PIN_9 -#define LED_GPIO_Port GPIOE +#define LED_Pin GPIO_PIN_8 +#define LED_GPIO_Port GPIOA /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ diff --git a/f3dfu/Src/main.c b/f3dfu/Src/main.c index 0d4a451f..2b643c0c 100644 --- a/f3dfu/Src/main.c +++ b/f3dfu/Src/main.c @@ -108,6 +108,17 @@ int main(void) /* Configure the system clock */ SystemClock_Config(); + // __HAL_RCC_GPIOA_CLK_ENABLE(); + // GPIO_InitTypeDef GPIO_InitStruct; + // GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; + // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + // GPIO_InitStruct.Pull = GPIO_NOPULL; + // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET); + // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); + // HAL_Delay(500); + /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USB_DEVICE_Init(); @@ -127,6 +138,7 @@ int main(void) JumpToApplication(); while (1); } + RTC->BKP0R = 0x00000000; /* USER CODE END 2 */ /* Infinite loop */ @@ -255,7 +267,6 @@ static void MX_GPIO_Init(void) /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOE_CLK_ENABLE();//DISCOVERY LED /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET); diff --git a/f3dfu/Src/usbd_dfu_if.c b/f3dfu/Src/usbd_dfu_if.c index fcf72278..d15a6e4c 100644 --- a/f3dfu/Src/usbd_dfu_if.c +++ b/f3dfu/Src/usbd_dfu_if.c @@ -189,7 +189,7 @@ uint16_t MEM_If_Erase_FS(uint32_t Add) /* Variable contains Flash operation status */ HAL_StatusTypeDef status; FLASH_EraseInitTypeDef eraseinitstruct; - + //TODO: only erase APP pages /* Get the number of sector to erase from 1st sector*/ //NbOfPages = (USBD_DFU_APP_END_ADD - USBD_DFU_APP_DEFAULT_ADD) / FLASH_PAGE_SIZE; NbOfPages = 1; @@ -218,28 +218,27 @@ uint16_t MEM_If_Erase_FS(uint32_t Add) uint16_t MEM_If_Write_FS(uint8_t *src, uint8_t *dest, uint32_t Len) { /* USER CODE BEGIN 3 */ - uint32_t i = 0; + uint32_t i = 0; - for(i = 0; i < Len; i+=4) - { - /* Device voltage range supposed to be [2.7V to 3.6V], the operation will - be done by byte */ - if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, (uint32_t)(dest+i), *(uint32_t*)(src+i)) == HAL_OK) - { - /* Check the written value */ - if(*(uint32_t *)(src + i) != *(uint32_t*)(dest+i)) - { - /* Flash content doesn't match SRAM content */ - return 2; - } - } - else - { - /* Error occurred while writing data in Flash memory */ - return 1; - } - } - return 0; + for(i = 0; i < Len; i+=4) + { + /* Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by byte */ + if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, (uint32_t)(dest+i), *(uint32_t*)(src+i)) == HAL_OK) + { + /* Check the written value */ + if(*(uint32_t *)(src + i) != *(uint32_t*)(dest+i)) + { + /* Flash content doesn't match SRAM content */ + return 2; + } + } + else + { + /* Error occurred while writing data in Flash memory */ + return 1; + } + } + return 0; /* USER CODE END 3 */ } diff --git a/stm32f303/src/comps/term.comp b/stm32f303/src/comps/term.comp index ea8f2969..ac75513c 100644 --- a/stm32f303/src/comps/term.comp +++ b/stm32f303/src/comps/term.comp @@ -169,14 +169,14 @@ NRT( void cmd(char * s){ if(!strcmp(s, "bootloader")){//reset and jump to bootloader RTC->BKP0R = 0xDEADBEEF;//set bootloader trigger - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); - HAL_Delay(500); + // GPIO_InitTypeDef GPIO_InitStruct; + // GPIO_InitStruct.Pin = GPIO_PIN_12; + // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + // GPIO_InitStruct.Pull = GPIO_NOPULL; + // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); + // HAL_Delay(500); NVIC_SystemReset(); } else if(!strcmp(s, "start")){ @@ -199,14 +199,14 @@ NRT( sysinfo(); } else if(!strcmp(s, "reset")){ - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); - HAL_Delay(500); + // GPIO_InitTypeDef GPIO_InitStruct; + // GPIO_InitStruct.Pin = GPIO_PIN_12; + // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + // GPIO_InitStruct.Pull = GPIO_NOPULL; + // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); + // HAL_Delay(500); NVIC_SystemReset(); } else if(!strcmp(s, "list")){