From 2764fc4ea27190dee1b0febbab14157abcf0e4ed Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 8 May 2018 17:35:13 +0900 Subject: [PATCH] Fix flash_protect for GD32F103. --- ChangeLog | 1 + NEWS | 11 +++++++---- mcu/sys-stm32f103.c | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index cbbf9de..b4d0b44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ * doc/chopstx.texi (Compile-time macro): Add chapter. * mcu/sys-stm32f103.c (usb_lld_sys_init): Use MHZ. + (flash_protect): Fix for GD32F103. 2018-04-26 NIIBE Yutaka diff --git a/NEWS b/NEWS index fd7bc26..ca1aadf 100644 --- a/NEWS +++ b/NEWS @@ -9,14 +9,17 @@ NEWS - Noteworthy changes GD32F103 is an alternative implementation of STM32F103 by Giga Device, which can run at 96MHz. -** Minor USB driver fix for STM32F103 -BTABLE setting should be done for initialization, not for USB RESET. +** Minor USB driver fix for STM32F103/GD32F103 +BTABLE setting should be done at initialization, not at USB RESET. + +** Minor SYS driver fix for GD32F103 +flash_protect should check FLASH_CR_OPTWRE. ** Minor ADC driver change for GD32F103 ADC on GD32F103 is another implementation and its behavior is somewhat different. It requires waits after enabling. So, we use continuous -samping. Still, we observe enough noise (> 4.7 bit/byte) for each ADC -sampling. +sampling, instead of start and stop for each sample. Still, we +observe enough noise (> 4.7 bit/byte) for each ADC sampling. * Major changes in Chopstx 1.8 diff --git a/mcu/sys-stm32f103.c b/mcu/sys-stm32f103.c index 129054b..f98913f 100644 --- a/mcu/sys-stm32f103.c +++ b/mcu/sys-stm32f103.c @@ -1,7 +1,7 @@ /* * sys-stm32f103.c - system routines for the initial page for STM32F103. * - * Copyright (C) 2013, 2014, 2015, 2016, 2017 + * Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018 * Flying Stone Technology * Author: NIIBE Yutaka * @@ -256,6 +256,9 @@ flash_protect (void) FLASH->OPTKEYR = FLASH_KEY1; FLASH->OPTKEYR = FLASH_KEY2; + while (!(FLASH->CR & FLASH_CR_OPTWRE)) + ; + FLASH->CR |= FLASH_CR_OPTER; FLASH->CR |= FLASH_CR_STRT;