mirror of
https://github.com/rene-dev/stmbl.git
synced 2026-02-05 18:01:21 +08:00
bootloader
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user