10.7-xiuos on board & other undo
This commit is contained in:
parent
1a6ee0234b
commit
d0e822c757
|
@ -114,8 +114,8 @@ InterruptVectors:
|
||||||
.word IsrEntry
|
.word IsrEntry
|
||||||
.word IsrEntry
|
.word IsrEntry
|
||||||
.word IsrEntry
|
.word IsrEntry
|
||||||
.word UartIsr1
|
.word IsrEntry //UartIsr1
|
||||||
.word IsrEntry //UartIsr2
|
.word UartIsr2 //UartIsr2
|
||||||
.word IsrEntry
|
.word IsrEntry
|
||||||
.word IsrEntry
|
.word IsrEntry
|
||||||
.word IsrEntry
|
.word IsrEntry
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
|
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
|
||||||
|
|
||||||
export CFLAGS := -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb
|
export CFLAGS := -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -Dgcc -Os -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb
|
||||||
export AFLAGS := -c -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2
|
export AFLAGS := -c -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2
|
||||||
export LFLAGS := -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-stm32f103-nano.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
|
export LFLAGS := -mcpu=cortex-m3 -specs=nano.specs -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-stm32f103-nano.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
|
||||||
export CXXFLAGS := -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g
|
export CXXFLAGS := -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -Dgcc -Os -gdwarf-2 -g
|
||||||
|
|
||||||
export APPLFLAGS := -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-app.map,-cref,-u, -T $(BSP_ROOT)/link_userspace.lds
|
export APPLFLAGS := -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-app.map,-cref,-u, -T $(BSP_ROOT)/link_userspace.lds
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
/* Program Entry, set to mark it as "used" and avoid gc */
|
/* Program Entry, set to mark it as "used" and avoid gc */
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
flash (rx) : ORIGIN = 0x08000000, LENGTH = 128k /* 128KB flash */
|
flash (rx) : ORIGIN = 0x08004000, LENGTH = 112k /* 128KB flash */
|
||||||
sram (rw) : ORIGIN = 0x20000000, LENGTH = 20k /* 20K sram */
|
sram (rw) : ORIGIN = 0x20000000, LENGTH = 20k /* 20K sram */
|
||||||
}
|
}
|
||||||
OUTPUT_ARCH(arm)
|
OUTPUT_ARCH(arm)
|
||||||
|
|
|
@ -2,6 +2,7 @@ SRC_DIR := libraries
|
||||||
|
|
||||||
ifeq ($(CONFIG_BSP_USING_UART),y)
|
ifeq ($(CONFIG_BSP_USING_UART),y)
|
||||||
SRC_DIR += uart
|
SRC_DIR += uart
|
||||||
|
SRC_DIR += common
|
||||||
endif
|
endif
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
menuconfig BSP_USING_CAN
|
||||||
|
bool "Enable UART1"
|
||||||
|
default y
|
||||||
|
if BSP_USING_UART1
|
||||||
|
config SERIAL_BUS_NAME_1
|
||||||
|
string "serial bus 1 name"
|
||||||
|
default "uart1"
|
||||||
|
config SERIAL_DRV_NAME_1
|
||||||
|
string "serial bus 1 driver name"
|
||||||
|
default "uart1_drv"
|
||||||
|
config SERIAL_1_DEVICE_NAME_0
|
||||||
|
string "serial bus 1 device name"
|
||||||
|
default "uart1_dev1"
|
||||||
|
endif
|
||||||
|
|
||||||
|
menuconfig BSP_USING_UART2
|
||||||
|
bool "Enable UART2"
|
||||||
|
default n
|
||||||
|
if BSP_USING_UART2
|
||||||
|
config SERIAL_BUS_NAME_2
|
||||||
|
string "serial bus 2 name"
|
||||||
|
default "uart2"
|
||||||
|
config SERIAL_DRV_NAME_2
|
||||||
|
string "serial bus 2 driver name"
|
||||||
|
default "uart2_drv"
|
||||||
|
config SERIAL_2_DEVICE_NAME_0
|
||||||
|
string "serial bus 2 device name"
|
||||||
|
default "uart2_dev2"
|
||||||
|
endif
|
||||||
|
|
|
@ -0,0 +1,438 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file connect_uart.c
|
||||||
|
* @brief support stm32f103_nano board uart function and register to bus framework
|
||||||
|
* @version 1.1
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2021-11-25
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <board.h>
|
||||||
|
#include <connect_uart.h>
|
||||||
|
|
||||||
|
#ifdef BSP_USING_UART1
|
||||||
|
static struct SerialBus serial_bus_1;
|
||||||
|
static struct SerialDriver serial_driver_1;
|
||||||
|
static struct SerialHardwareDevice serial_device_1;
|
||||||
|
#endif
|
||||||
|
#ifdef BSP_USING_UART2
|
||||||
|
static struct SerialBus serial_bus_2;
|
||||||
|
static struct SerialDriver serial_driver_2;
|
||||||
|
static struct SerialHardwareDevice serial_device_2;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void SerialCfgParamCheck(struct SerialCfgParam *serial_cfg_default, struct SerialCfgParam *serial_cfg_new)
|
||||||
|
{
|
||||||
|
struct SerialDataCfg *data_cfg_default = &serial_cfg_default->data_cfg;
|
||||||
|
struct SerialDataCfg *data_cfg_new = &serial_cfg_new->data_cfg;
|
||||||
|
|
||||||
|
if ((data_cfg_default->serial_baud_rate != data_cfg_new->serial_baud_rate) && (data_cfg_new->serial_baud_rate)) {
|
||||||
|
data_cfg_default->serial_baud_rate = data_cfg_new->serial_baud_rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((data_cfg_default->serial_bit_order != data_cfg_new->serial_bit_order) && (data_cfg_new->serial_bit_order)) {
|
||||||
|
data_cfg_default->serial_bit_order = data_cfg_new->serial_bit_order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((data_cfg_default->serial_buffer_size != data_cfg_new->serial_buffer_size) && (data_cfg_new->serial_buffer_size)) {
|
||||||
|
data_cfg_default->serial_buffer_size = data_cfg_new->serial_buffer_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((data_cfg_default->serial_data_bits != data_cfg_new->serial_data_bits) && (data_cfg_new->serial_data_bits)) {
|
||||||
|
data_cfg_default->serial_data_bits = data_cfg_new->serial_data_bits;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((data_cfg_default->serial_invert_mode != data_cfg_new->serial_invert_mode) && (data_cfg_new->serial_invert_mode)) {
|
||||||
|
data_cfg_default->serial_invert_mode = data_cfg_new->serial_invert_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((data_cfg_default->serial_parity_mode != data_cfg_new->serial_parity_mode) && (data_cfg_new->serial_parity_mode)) {
|
||||||
|
data_cfg_default->serial_parity_mode = data_cfg_new->serial_parity_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((data_cfg_default->serial_stop_bits != data_cfg_new->serial_stop_bits) && (data_cfg_new->serial_stop_bits)) {
|
||||||
|
data_cfg_default->serial_stop_bits = data_cfg_new->serial_stop_bits;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((data_cfg_default->serial_timeout != data_cfg_new->serial_timeout) && (data_cfg_new->serial_timeout)) {
|
||||||
|
data_cfg_default->serial_timeout = data_cfg_new->serial_timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UartHandler(struct SerialBus *serial_bus, struct SerialDriver *serial_drv)
|
||||||
|
{
|
||||||
|
struct SerialHardwareDevice *serial_dev = (struct SerialHardwareDevice *)serial_bus->bus.owner_haldev;
|
||||||
|
struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_drv->private_data;
|
||||||
|
struct Stm32UartHwCfg *serial_hw_cfg = (struct Stm32UartHwCfg *)serial_cfg->hw_cfg.private_data;
|
||||||
|
|
||||||
|
/* UART in mode Receiver -------------------------------------------------*/
|
||||||
|
if ((__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_RXNE) != RESET) &&
|
||||||
|
(__HAL_UART_GET_IT_SOURCE(&(serial_hw_cfg->uart_handle), UART_IT_RXNE) != RESET))
|
||||||
|
{
|
||||||
|
SerialSetIsr(serial_dev, SERIAL_EVENT_RX_IND);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_ORE) != RESET)
|
||||||
|
{
|
||||||
|
__HAL_UART_CLEAR_OREFLAG(&serial_hw_cfg->uart_handle);
|
||||||
|
}
|
||||||
|
if (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_NE) != RESET)
|
||||||
|
{
|
||||||
|
__HAL_UART_CLEAR_NEFLAG(&serial_hw_cfg->uart_handle);
|
||||||
|
}
|
||||||
|
if (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_FE) != RESET)
|
||||||
|
{
|
||||||
|
__HAL_UART_CLEAR_FEFLAG(&serial_hw_cfg->uart_handle);
|
||||||
|
}
|
||||||
|
if (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_PE) != RESET)
|
||||||
|
{
|
||||||
|
__HAL_UART_CLEAR_PEFLAG(&serial_hw_cfg->uart_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef BSP_USING_UART1
|
||||||
|
void UartIsr1(int vector, void *param)
|
||||||
|
{
|
||||||
|
/* get serial bus 1 */
|
||||||
|
UartHandler(&serial_bus_1, &serial_driver_1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BSP_USING_UART2
|
||||||
|
void UartIsr2(int vector, void *param)
|
||||||
|
{
|
||||||
|
/* get serial bus 2 */
|
||||||
|
UartHandler(&serial_bus_2, &serial_driver_2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static uint32 SerialInit(struct SerialDriver *serial_drv, struct BusConfigureInfo *configure_info)
|
||||||
|
{
|
||||||
|
NULL_PARAM_CHECK(serial_drv);
|
||||||
|
|
||||||
|
struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_drv->private_data;
|
||||||
|
struct Stm32UartHwCfg *serial_hw_cfg = (struct Stm32UartHwCfg *)serial_cfg->hw_cfg.private_data;
|
||||||
|
|
||||||
|
if (configure_info->private_data) {
|
||||||
|
struct SerialCfgParam *serial_cfg_new = (struct SerialCfgParam *)configure_info->private_data;
|
||||||
|
SerialCfgParamCheck(serial_cfg, serial_cfg_new);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SerialHardwareDevice *serial_dev = (struct SerialHardwareDevice *)serial_drv->driver.owner_bus->owner_haldev;
|
||||||
|
struct SerialDevParam *dev_param = (struct SerialDevParam *)serial_dev->haldev.private_data;
|
||||||
|
|
||||||
|
// config serial receive sem timeout
|
||||||
|
dev_param->serial_timeout = serial_cfg->data_cfg.serial_timeout;
|
||||||
|
|
||||||
|
serial_hw_cfg->uart_handle.Instance = serial_hw_cfg->uart_device;
|
||||||
|
serial_hw_cfg->uart_handle.Init.BaudRate = serial_cfg->data_cfg.serial_baud_rate;
|
||||||
|
serial_hw_cfg->uart_handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
|
serial_hw_cfg->uart_handle.Init.Mode = UART_MODE_TX_RX;
|
||||||
|
serial_hw_cfg->uart_handle.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
|
|
||||||
|
switch (serial_cfg->data_cfg.serial_data_bits)
|
||||||
|
{
|
||||||
|
case DATA_BITS_8:
|
||||||
|
if (serial_cfg->data_cfg.serial_parity_mode == PARITY_ODD || serial_cfg->data_cfg.serial_parity_mode == PARITY_EVEN)
|
||||||
|
serial_hw_cfg->uart_handle.Init.WordLength = UART_WORDLENGTH_9B;
|
||||||
|
else
|
||||||
|
serial_hw_cfg->uart_handle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
|
break;
|
||||||
|
case DATA_BITS_9:
|
||||||
|
serial_hw_cfg->uart_handle.Init.WordLength = UART_WORDLENGTH_9B;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
serial_hw_cfg->uart_handle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (serial_cfg->data_cfg.serial_stop_bits)
|
||||||
|
{
|
||||||
|
case STOP_BITS_1:
|
||||||
|
serial_hw_cfg->uart_handle.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
break;
|
||||||
|
case STOP_BITS_2:
|
||||||
|
serial_hw_cfg->uart_handle.Init.StopBits = UART_STOPBITS_2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
serial_hw_cfg->uart_handle.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (serial_cfg->data_cfg.serial_parity_mode)
|
||||||
|
{
|
||||||
|
case PARITY_NONE:
|
||||||
|
serial_hw_cfg->uart_handle.Init.Parity = UART_PARITY_NONE;
|
||||||
|
break;
|
||||||
|
case PARITY_ODD:
|
||||||
|
serial_hw_cfg->uart_handle.Init.Parity = UART_PARITY_ODD;
|
||||||
|
break;
|
||||||
|
case PARITY_EVEN:
|
||||||
|
serial_hw_cfg->uart_handle.Init.Parity = UART_PARITY_EVEN;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
serial_hw_cfg->uart_handle.Init.Parity = UART_PARITY_NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HAL_UART_Init(&serial_hw_cfg->uart_handle) != HAL_OK)
|
||||||
|
{
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32 SerialConfigure(struct SerialDriver *serial_drv, int serial_operation_cmd)
|
||||||
|
{
|
||||||
|
NULL_PARAM_CHECK(serial_drv);
|
||||||
|
|
||||||
|
struct SerialHardwareDevice *serial_dev = (struct SerialHardwareDevice *)serial_drv->driver.owner_bus->owner_haldev;
|
||||||
|
struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_drv->private_data;
|
||||||
|
struct Stm32UartHwCfg *serial_hw_cfg = (struct Stm32UartHwCfg *)serial_cfg->hw_cfg.private_data;
|
||||||
|
struct SerialDevParam *serial_dev_param = (struct SerialDevParam *)serial_dev->haldev.private_data;
|
||||||
|
|
||||||
|
if (OPER_CLR_INT == serial_operation_cmd) {
|
||||||
|
if (SIGN_OPER_INT_RX & serial_dev_param->serial_work_mode) {
|
||||||
|
/* disable rx irq */
|
||||||
|
NVIC_DisableIRQ(serial_hw_cfg->irq_type);
|
||||||
|
/* disable interrupt */
|
||||||
|
__HAL_UART_DISABLE_IT(&(serial_hw_cfg->uart_handle), UART_IT_RXNE);
|
||||||
|
}
|
||||||
|
} else if (OPER_SET_INT == serial_operation_cmd) {
|
||||||
|
/* enable rx irq */
|
||||||
|
HAL_NVIC_SetPriority(serial_hw_cfg->irq_type, 1, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(serial_hw_cfg->irq_type);
|
||||||
|
/* enable interrupt */
|
||||||
|
__HAL_UART_ENABLE_IT(&(serial_hw_cfg->uart_handle), UART_IT_RXNE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32 SerialDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
|
||||||
|
{
|
||||||
|
NULL_PARAM_CHECK(drv);
|
||||||
|
NULL_PARAM_CHECK(configure_info);
|
||||||
|
|
||||||
|
x_err_t ret = EOK;
|
||||||
|
int serial_operation_cmd;
|
||||||
|
struct SerialDriver *serial_drv = (struct SerialDriver *)drv;
|
||||||
|
|
||||||
|
switch (configure_info->configure_cmd)
|
||||||
|
{
|
||||||
|
case OPE_INT:
|
||||||
|
ret = SerialInit(serial_drv, configure_info);
|
||||||
|
break;
|
||||||
|
case OPE_CFG:
|
||||||
|
serial_operation_cmd = *(int *)configure_info->private_data;
|
||||||
|
ret = SerialConfigure(serial_drv, serial_operation_cmd);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int SerialPutChar(struct SerialHardwareDevice *serial_dev, char c)
|
||||||
|
{
|
||||||
|
struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_dev->private_data;
|
||||||
|
struct Stm32UartHwCfg *serial_hw_cfg = (struct Stm32UartHwCfg *)serial_cfg->hw_cfg.private_data;
|
||||||
|
|
||||||
|
UART_INSTANCE_CLEAR_FUNCTION(&(serial_hw_cfg->uart_handle), UART_FLAG_TC);
|
||||||
|
|
||||||
|
serial_hw_cfg->uart_handle.Instance->DR = c;
|
||||||
|
while (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_TC) == RESET);
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int SerialGetChar(struct SerialHardwareDevice *serial_dev)
|
||||||
|
{
|
||||||
|
struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_dev->private_data;
|
||||||
|
struct Stm32UartHwCfg *serial_hw_cfg = (struct Stm32UartHwCfg *)serial_cfg->hw_cfg.private_data;
|
||||||
|
|
||||||
|
int ch = -1;
|
||||||
|
if (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_RXNE) != RESET)
|
||||||
|
{
|
||||||
|
ch = serial_hw_cfg->uart_handle.Instance->DR & 0xff;
|
||||||
|
}
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct SerialDataCfg data_cfg_init =
|
||||||
|
{
|
||||||
|
.serial_baud_rate = BAUD_RATE_115200,
|
||||||
|
.serial_data_bits = DATA_BITS_8,
|
||||||
|
.serial_stop_bits = STOP_BITS_1,
|
||||||
|
.serial_parity_mode = PARITY_NONE,
|
||||||
|
.serial_bit_order = BIT_ORDER_LSB,
|
||||||
|
.serial_invert_mode = NRZ_NORMAL,
|
||||||
|
.serial_buffer_size = SERIAL_RB_BUFSZ,
|
||||||
|
.serial_timeout = WAITING_FOREVER,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*manage the serial device operations*/
|
||||||
|
static const struct SerialDrvDone drv_done =
|
||||||
|
{
|
||||||
|
.init = SerialInit,
|
||||||
|
.configure = SerialConfigure,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*manage the serial device hal operations*/
|
||||||
|
static struct SerialHwDevDone hwdev_done =
|
||||||
|
{
|
||||||
|
.put_char = SerialPutChar,
|
||||||
|
.get_char = SerialGetChar,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int BoardSerialBusInit(struct SerialBus *serial_bus, struct SerialDriver *serial_driver, const char *bus_name, const char *drv_name)
|
||||||
|
{
|
||||||
|
x_err_t ret = EOK;
|
||||||
|
|
||||||
|
/*Init the serial bus */
|
||||||
|
ret = SerialBusInit(serial_bus, bus_name);
|
||||||
|
if (EOK != ret) {
|
||||||
|
KPrintf("InitHwUart SerialBusInit error %d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Init the serial driver*/
|
||||||
|
ret = SerialDriverInit(serial_driver, drv_name);
|
||||||
|
if (EOK != ret) {
|
||||||
|
KPrintf("InitHwUart SerialDriverInit error %d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Attach the serial driver to the serial bus*/
|
||||||
|
ret = SerialDriverAttachToBus(drv_name, bus_name);
|
||||||
|
if (EOK != ret) {
|
||||||
|
KPrintf("InitHwUart SerialDriverAttachToBus error %d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Attach the serial device to the serial bus*/
|
||||||
|
static int BoardSerialDevBend(struct SerialHardwareDevice *serial_device, void *serial_param, const char *bus_name, const char *dev_name)
|
||||||
|
{
|
||||||
|
x_err_t ret = EOK;
|
||||||
|
|
||||||
|
ret = SerialDeviceRegister(serial_device, serial_param, dev_name);
|
||||||
|
if (EOK != ret) {
|
||||||
|
KPrintf("InitHwUart SerialDeviceInit device %s error %d\n", dev_name, ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = SerialDeviceAttachToBus(dev_name, bus_name);
|
||||||
|
if (EOK != ret) {
|
||||||
|
KPrintf("InitHwUart SerialDeviceAttachToBus device %s error %d\n", dev_name, ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int InitHwUart(void)
|
||||||
|
{
|
||||||
|
x_err_t ret = EOK;
|
||||||
|
|
||||||
|
#ifdef BSP_USING_UART1
|
||||||
|
memset(&serial_bus_1, 0, sizeof(struct SerialBus));
|
||||||
|
memset(&serial_driver_1, 0, sizeof(struct SerialDriver));
|
||||||
|
memset(&serial_device_1, 0, sizeof(struct SerialHardwareDevice));
|
||||||
|
|
||||||
|
static struct SerialCfgParam serial_cfg_1;
|
||||||
|
memset(&serial_cfg_1, 0, sizeof(struct SerialCfgParam));
|
||||||
|
|
||||||
|
static struct Stm32UartHwCfg serial_hw_cfg_1;
|
||||||
|
memset(&serial_hw_cfg_1, 0, sizeof(struct Stm32UartHwCfg));
|
||||||
|
|
||||||
|
static struct SerialDevParam serial_dev_param_1;
|
||||||
|
memset(&serial_dev_param_1, 0, sizeof(struct SerialDevParam));
|
||||||
|
|
||||||
|
serial_driver_1.drv_done = &drv_done;
|
||||||
|
serial_driver_1.configure = &SerialDrvConfigure;
|
||||||
|
serial_device_1.hwdev_done = &hwdev_done;
|
||||||
|
|
||||||
|
serial_cfg_1.data_cfg = data_cfg_init;
|
||||||
|
|
||||||
|
serial_cfg_1.hw_cfg.private_data = (void *)&serial_hw_cfg_1;
|
||||||
|
serial_hw_cfg_1.uart_device = USART1;
|
||||||
|
serial_hw_cfg_1.irq_type = USART1_IRQn;
|
||||||
|
serial_driver_1.private_data = (void *)&serial_cfg_1;
|
||||||
|
|
||||||
|
serial_dev_param_1.serial_work_mode = SIGN_OPER_INT_RX;
|
||||||
|
serial_device_1.haldev.private_data = (void *)&serial_dev_param_1;
|
||||||
|
|
||||||
|
ret = BoardSerialBusInit(&serial_bus_1, &serial_driver_1, SERIAL_BUS_NAME_1, SERIAL_DRV_NAME_1);
|
||||||
|
if (EOK != ret) {
|
||||||
|
KPrintf("InitHwUart uarths error ret %u\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = BoardSerialDevBend(&serial_device_1, (void *)&serial_cfg_1, SERIAL_BUS_NAME_1, SERIAL_1_DEVICE_NAME_0);
|
||||||
|
if (EOK != ret) {
|
||||||
|
KPrintf("InitHwUart uarths error ret %u\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BSP_USING_UART2
|
||||||
|
memset(&serial_bus_2, 0, sizeof(struct SerialBus));
|
||||||
|
memset(&serial_driver_2, 0, sizeof(struct SerialDriver));
|
||||||
|
memset(&serial_device_2, 0, sizeof(struct SerialHardwareDevice));
|
||||||
|
|
||||||
|
static struct SerialCfgParam serial_cfg_2;
|
||||||
|
memset(&serial_cfg_2, 0, sizeof(struct SerialCfgParam));
|
||||||
|
|
||||||
|
static struct Stm32UartHwCfg serial_hw_cfg_2;
|
||||||
|
memset(&serial_hw_cfg_2, 0, sizeof(struct Stm32UartHwCfg));
|
||||||
|
|
||||||
|
static struct SerialDevParam serial_dev_param_2;
|
||||||
|
memset(&serial_dev_param_2, 0, sizeof(struct SerialDevParam));
|
||||||
|
|
||||||
|
serial_driver_2.drv_done = &drv_done;
|
||||||
|
serial_driver_2.configure = &SerialDrvConfigure;
|
||||||
|
serial_device_2.hwdev_done = &hwdev_done;
|
||||||
|
|
||||||
|
serial_cfg_2.data_cfg = data_cfg_init;
|
||||||
|
|
||||||
|
serial_cfg_2.hw_cfg.private_data = (void *)&serial_hw_cfg_2;
|
||||||
|
serial_hw_cfg_2.uart_device = USART2;
|
||||||
|
serial_hw_cfg_2.irq_type = USART2_IRQn;
|
||||||
|
serial_driver_2.private_data = (void *)&serial_cfg_2;
|
||||||
|
|
||||||
|
serial_dev_param_2.serial_work_mode = SIGN_OPER_INT_RX;
|
||||||
|
serial_device_2.haldev.private_data = (void *)&serial_dev_param_2;
|
||||||
|
|
||||||
|
ret = BoardSerialBusInit(&serial_bus_2, &serial_driver_2, SERIAL_BUS_NAME_2, SERIAL_DRV_NAME_2);
|
||||||
|
if (EOK != ret) {
|
||||||
|
KPrintf("InitHwUart uarths error ret %u\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = BoardSerialDevBend(&serial_device_2, (void *)&serial_cfg_2, SERIAL_BUS_NAME_2, SERIAL_2_DEVICE_NAME_0);
|
||||||
|
if (EOK != ret) {
|
||||||
|
KPrintf("InitHwUart uarths error ret %u\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
menuconfig BSP_USING_YMODEM
|
||||||
|
bool "Enable ymodem"
|
||||||
|
default y
|
||||||
|
if BSP_USING_YMODEM
|
||||||
|
config YMODEM_BUS_NAME
|
||||||
|
string "serial bus 1 name"
|
||||||
|
default "uart1"
|
||||||
|
config YMODEM_DRV_NAME
|
||||||
|
string "serial bus 1 driver name"
|
||||||
|
default "uart1_drv"
|
||||||
|
config YMODEM_DEVICE_NAME
|
||||||
|
string "serial bus 1 device name"
|
||||||
|
default "uart1_dev1"
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
SRC_FILES := ymodem.c
|
||||||
|
|
||||||
|
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,365 @@
|
||||||
|
//#include <stdio.h>
|
||||||
|
//#include <string.h>
|
||||||
|
#include <ymodem.h>
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
|
|
||||||
|
#define Rx_Max 2048
|
||||||
|
|
||||||
|
|
||||||
|
// __STATIC_INLINE void Set_FAULTMASK(uint32_t faultMask)
|
||||||
|
// {
|
||||||
|
// register uint32_t __regFaultMask __ASM("faultmask");
|
||||||
|
// __regFaultMask = (faultMask & (uint32_t)1U);
|
||||||
|
// }
|
||||||
|
|
||||||
|
uint8_t Rx_Flag;
|
||||||
|
uint16_t Rx_Len;
|
||||||
|
uint8_t Rx_Buf[Rx_Max] ;
|
||||||
|
uint8_t flag_reset;
|
||||||
|
|
||||||
|
uint64_t NotUpgrade = {0xFFFFFFFFFFFFFFFF};
|
||||||
|
uint64_t Upgrade = {0xAAAAAAAAAAAAAAAA};
|
||||||
|
|
||||||
|
UART_HandleTypeDef huart1;
|
||||||
|
DMA_HandleTypeDef hdma_usart1_rx;
|
||||||
|
|
||||||
|
void ymodem_uart_init(void)
|
||||||
|
{
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
__HAL_RCC_USART1_CLK_ENABLE();
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_10;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
__HAL_AFIO_REMAP_USART1_ENABLE();
|
||||||
|
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(USART1_IRQn);
|
||||||
|
|
||||||
|
|
||||||
|
/* DMA controller clock enable */
|
||||||
|
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||||
|
/* DMA interrupt init */
|
||||||
|
/* DMA1_Channel5_IRQn interrupt configuration */
|
||||||
|
HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
|
||||||
|
|
||||||
|
// MX_USART2_UART_Init();
|
||||||
|
huart1.Instance = USART1;
|
||||||
|
huart1.Init.BaudRate = 115200;
|
||||||
|
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
|
huart1.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
huart1.Init.Parity = UART_PARITY_NONE;
|
||||||
|
huart1.Init.Mode = UART_MODE_TX_RX;
|
||||||
|
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
|
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
|
if (HAL_UART_Init(&huart1) != HAL_OK)
|
||||||
|
{
|
||||||
|
// Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
HAL_UART_Receive_DMA(&huart1, Rx_Buf, Rx_Max);
|
||||||
|
__HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 发送指令 */
|
||||||
|
void send_command(unsigned char command)
|
||||||
|
{
|
||||||
|
HAL_UART_Transmit(&huart1, (uint8_t *)&command,1 , 0xFFFF);
|
||||||
|
HAL_Delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @bieaf 擦除页
|
||||||
|
*
|
||||||
|
* @param pageaddr 页起始地址
|
||||||
|
* @param num 擦除的页数
|
||||||
|
* @return 1
|
||||||
|
*/
|
||||||
|
static int Erase_page(uint32_t pageaddr, uint32_t num)
|
||||||
|
{
|
||||||
|
HAL_FLASH_Unlock();
|
||||||
|
|
||||||
|
/* 擦除FLASH*/
|
||||||
|
FLASH_EraseInitTypeDef FlashSet;
|
||||||
|
FlashSet.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||||
|
FlashSet.PageAddress = pageaddr;
|
||||||
|
FlashSet.NbPages = num;
|
||||||
|
|
||||||
|
/*设置PageError,调用擦除函数*/
|
||||||
|
uint32_t PageError = 0;
|
||||||
|
if(HAL_FLASHEx_Erase(&FlashSet, &PageError) == HAL_OK){
|
||||||
|
KPrintf("erase APP2 success\r\n");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
KPrintf("erase APP2 failed\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
HAL_FLASH_Lock();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @bieaf 写若干个数据
|
||||||
|
*
|
||||||
|
* @param addr 写入的地址
|
||||||
|
* @param buff 写入数据的数组指针
|
||||||
|
* @param word_size 长度
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static void WriteFlash(uint32_t addr, uint32_t * buff, int word_size)
|
||||||
|
{
|
||||||
|
/* 1/4解锁FLASH*/
|
||||||
|
HAL_FLASH_Unlock();
|
||||||
|
for(int i = 0; i < word_size; i++)
|
||||||
|
{
|
||||||
|
/* 3/4对FLASH烧写*/
|
||||||
|
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, addr + 4 * i, buff[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 4/4锁住FLASH*/
|
||||||
|
HAL_FLASH_Lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*获取当前地址所在页*/
|
||||||
|
static uint32_t GetPage(uint32_t Addr)
|
||||||
|
{
|
||||||
|
return (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void InFlashWrite(uint32_t Address, uint64_t data)
|
||||||
|
{
|
||||||
|
HAL_FLASH_Unlock();//开锁
|
||||||
|
|
||||||
|
uint32_t FirstPage = 0, NbOfPages = 0;
|
||||||
|
uint32_t PageError = 0;
|
||||||
|
|
||||||
|
FLASH_EraseInitTypeDef EraseInitStruct;
|
||||||
|
|
||||||
|
FirstPage = GetPage(Address);//首页地址
|
||||||
|
KPrintf("FirstPage = %d\r\n", FirstPage);
|
||||||
|
|
||||||
|
NbOfPages = GetPage(Address+sizeof(data)) - FirstPage + 1;//页数
|
||||||
|
KPrintf("NbOfPages = %d\r\n", NbOfPages);
|
||||||
|
|
||||||
|
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||||
|
EraseInitStruct.PageAddress = Address;
|
||||||
|
EraseInitStruct.NbPages = NbOfPages;
|
||||||
|
|
||||||
|
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
|
||||||
|
{
|
||||||
|
KPrintf("ErasePageError\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, data) == HAL_OK)
|
||||||
|
{
|
||||||
|
KPrintf("Flash write success\r\n");
|
||||||
|
}
|
||||||
|
HAL_FLASH_Lock();//上锁
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 标记升级完成 */
|
||||||
|
void Set_Update_Down(void)
|
||||||
|
{
|
||||||
|
unsigned int update_flag = 0xAAAAAAAA; ///< 对应bootloader的启动步骤
|
||||||
|
WriteFlash((Application_2_Addr + Application_Size - 4), &update_flag,1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* 临时存储的buff */
|
||||||
|
unsigned char save_buf[128] = {0};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @bieaf CRC-16 校验
|
||||||
|
*
|
||||||
|
* @param addr 开始地址
|
||||||
|
* @param num 长度
|
||||||
|
* @param num CRC
|
||||||
|
* @return crc 返回CRC的值
|
||||||
|
*/
|
||||||
|
#define POLY 0x1021
|
||||||
|
uint16_t crc16(unsigned char *addr, int num, uint16_t crc)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (; num > 0; num--) /* Step through bytes in memory */
|
||||||
|
{
|
||||||
|
crc = crc ^ (*addr++ << 8); /* Fetch byte from memory, XOR into CRC top byte*/
|
||||||
|
for (i = 0; i < 8; i++) /* Prepare to rotate 8 bits */
|
||||||
|
{
|
||||||
|
if (crc & 0x8000) /* b15 is set... */
|
||||||
|
crc = (crc << 1) ^ POLY; /* rotate and XOR with polynomic */
|
||||||
|
else /* b15 is clear... */
|
||||||
|
crc <<= 1; /* just rotate */
|
||||||
|
} /* Loop for 8 bits */
|
||||||
|
crc &= 0xFFFF; /* Ensure CRC remains 16-bit value */
|
||||||
|
} /* Loop until num=0 */
|
||||||
|
return(crc); /* Return updated CRC */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @bieaf 获取数据包的类型, 顺便进行校验
|
||||||
|
*
|
||||||
|
* @param buf 开始地址
|
||||||
|
* @param len 长度
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
unsigned char Check_CRC(unsigned char* buf, int len)
|
||||||
|
{
|
||||||
|
unsigned short crc = 0;
|
||||||
|
|
||||||
|
/* 进行CRC校验 */
|
||||||
|
if((buf[0]==0x00)&&(len >= 133))
|
||||||
|
{
|
||||||
|
crc = crc16(buf+3, 128, crc);
|
||||||
|
if(crc != (buf[131]<<8|buf[132]))
|
||||||
|
{
|
||||||
|
return 0;///< 没通过校验
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 通过校验 */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* 设置升级的步骤 */
|
||||||
|
static enum UPDATE_STATE update_state = TO_START;
|
||||||
|
void Set_state(enum UPDATE_STATE state)
|
||||||
|
{
|
||||||
|
update_state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 查询升级的步骤 */
|
||||||
|
unsigned char Get_state(void)
|
||||||
|
{
|
||||||
|
return update_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char temp_buf[512] = {0};
|
||||||
|
uint16_t temp_len = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @bieaf YModem升级
|
||||||
|
*
|
||||||
|
* @param none
|
||||||
|
* @return none
|
||||||
|
*/
|
||||||
|
void ymodem_fun(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
KPrintf("in ymodem func\n");
|
||||||
|
ymodem_uart_init();
|
||||||
|
|
||||||
|
if(Get_state()==TO_START)
|
||||||
|
{
|
||||||
|
KPrintf("in ymodem wait\n");
|
||||||
|
send_command(CCC);
|
||||||
|
HAL_Delay(1000);
|
||||||
|
}
|
||||||
|
if(Rx_Flag) // Receive flag
|
||||||
|
{
|
||||||
|
Rx_Flag=0; // clean flag
|
||||||
|
|
||||||
|
/* 拷贝 */
|
||||||
|
temp_len = Rx_Len;
|
||||||
|
KPrintf("---Rx-len: %#x--------:\r\n", Rx_Len);
|
||||||
|
for(i = 0; i < temp_len; i++)
|
||||||
|
{
|
||||||
|
temp_buf[i] = Rx_Buf[i];
|
||||||
|
}
|
||||||
|
switch(temp_buf[0])
|
||||||
|
{
|
||||||
|
case SOH:///<数据包开始
|
||||||
|
{
|
||||||
|
static unsigned char data_state = 0;
|
||||||
|
static unsigned int app2_size = 0;
|
||||||
|
if(Check_CRC(temp_buf, temp_len)==1)///< 通过CRC16校验
|
||||||
|
{
|
||||||
|
if((Get_state()==TO_START)&&(temp_buf[1] == 0x00)&&(temp_buf[2] == (unsigned char)(~temp_buf[1])))///< 开始
|
||||||
|
{
|
||||||
|
KPrintf("> Receive start...\r\n");
|
||||||
|
Set_state(TO_RECEIVE_DATA);
|
||||||
|
data_state = 0x01;
|
||||||
|
send_command(ACK);
|
||||||
|
send_command(CCC);
|
||||||
|
KPrintf("1111111111\r\n");
|
||||||
|
|
||||||
|
/* 擦除App2 */
|
||||||
|
Erase_page(Application_2_Addr, Application_Size/1024); // 要擦除100页
|
||||||
|
KPrintf("2222222222\r\n");
|
||||||
|
}
|
||||||
|
else if((Get_state()==TO_RECEIVE_END)&&(temp_buf[1] == 0x00)&&(temp_buf[2] == (unsigned char)(~temp_buf[1])))///< 结束
|
||||||
|
{
|
||||||
|
KPrintf("> Receive end...\r\n");
|
||||||
|
InFlashWrite(UPGRADE_FLAG_ADDR, Upgrade); //将升级标志设置为升级
|
||||||
|
KPrintf("33333333333\r\n");
|
||||||
|
Set_state(TO_START);
|
||||||
|
KPrintf("44444444444\r\n");
|
||||||
|
send_command(ACK);
|
||||||
|
KPrintf("55555555555\r\n");
|
||||||
|
|
||||||
|
HAL_NVIC_SystemReset();
|
||||||
|
|
||||||
|
}
|
||||||
|
else if((Get_state()==TO_RECEIVE_DATA)&&(temp_buf[1] == data_state)&&(temp_buf[2] == (unsigned char)(~temp_buf[1])))///< 接收数据
|
||||||
|
{
|
||||||
|
KPrintf("> Receive data bag:%d byte\r\n",data_state * 128);
|
||||||
|
|
||||||
|
/* 烧录程序 */
|
||||||
|
WriteFlash((Application_2_Addr + (data_state-1) * 128), (uint32_t *)(&temp_buf[3]), 32);
|
||||||
|
data_state++;
|
||||||
|
|
||||||
|
send_command(ACK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
KPrintf("> Notpass crc\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}break;
|
||||||
|
case EOT://数据包开始
|
||||||
|
{
|
||||||
|
if(Get_state()==TO_RECEIVE_DATA)
|
||||||
|
{
|
||||||
|
KPrintf("> Receive EOT1...\r\n");
|
||||||
|
|
||||||
|
Set_state(TO_RECEIVE_EOT2);
|
||||||
|
send_command(NACK);
|
||||||
|
}
|
||||||
|
else if(Get_state()==TO_RECEIVE_EOT2)
|
||||||
|
{
|
||||||
|
KPrintf("> Receive EOT2...\r\n");
|
||||||
|
|
||||||
|
Set_state(TO_RECEIVE_END);
|
||||||
|
send_command(ACK);
|
||||||
|
send_command(CCC);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
KPrintf("> Receive EOT, But error...\r\n");
|
||||||
|
}
|
||||||
|
}break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,9 @@ struct Stm32UartHwCfg
|
||||||
IRQn_Type irq_type;
|
IRQn_Type irq_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define KERNEL_CONSOLE_BUS_NAME SERIAL_BUS_NAME_1
|
#define KERNEL_CONSOLE_BUS_NAME SERIAL_BUS_NAME_2
|
||||||
#define KERNEL_CONSOLE_DRV_NAME SERIAL_DRV_NAME_1
|
#define KERNEL_CONSOLE_DRV_NAME SERIAL_DRV_NAME_2
|
||||||
#define KERNEL_CONSOLE_DEVICE_NAME SERIAL_1_DEVICE_NAME_0
|
#define KERNEL_CONSOLE_DEVICE_NAME SERIAL_2_DEVICE_NAME_0
|
||||||
|
|
||||||
int InitHwUart(void);
|
int InitHwUart(void);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef YMODEM_H
|
||||||
|
#define YMODEM_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stm32f1xx_hal.h>
|
||||||
|
#include <stm32f1xx_hal_flash.h>
|
||||||
|
#include <stm32f1xx_hal_flash_ex.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*=====用户配置(根据自己的分区进行配置)=====*/
|
||||||
|
#define BootLoader_Size 0x4000U ///< BootLoader的大小 16K
|
||||||
|
#define Application_Size 0xc000U ///< 应用程序的大小 48K
|
||||||
|
|
||||||
|
#define Application_1_Addr 0x08004000U ///< 应用程序1的首地址
|
||||||
|
#define Application_2_Addr 0x08010000U ///< 应用程序2的首地址
|
||||||
|
/*==========================================*/
|
||||||
|
#define UPGRADE_FLAG_ADDR ((uint32_t)0x0801FD00)
|
||||||
|
|
||||||
|
|
||||||
|
#define SOH 0x01
|
||||||
|
#define STX 0x02
|
||||||
|
#define ACK 0x06
|
||||||
|
#define NACK 0x15
|
||||||
|
#define EOT 0x04
|
||||||
|
#define CCC 0x43
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* 升级的步骤 */
|
||||||
|
enum UPDATE_STATE
|
||||||
|
{
|
||||||
|
TO_START = 0x01,
|
||||||
|
TO_RECEIVE_DATA = 0x02,
|
||||||
|
TO_RECEIVE_EOT1 = 0x03,
|
||||||
|
TO_RECEIVE_EOT2 = 0x04,
|
||||||
|
TO_RECEIVE_END = 0x05
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ymodem_fun(void);
|
||||||
|
|
||||||
|
#endif /* YMODEM_H */
|
|
@ -1,3 +1,3 @@
|
||||||
SRC_FILES := stm32f1xx_hal.c stm32f1xx_hal_uart.c stm32f1xx_hal_usart.c stm32f1xx_hal_cortex.c stm32f1xx_hal_rcc.c stm32f1xx_hal_rcc_ex.c stm32f1xx_hal_gpio.c stm32f1xx_hal_msp.c
|
SRC_FILES := stm32f1xx_hal.c stm32f1xx_hal_uart.c stm32f1xx_hal_usart.c stm32f1xx_hal_cortex.c stm32f1xx_hal_rcc.c stm32f1xx_hal_rcc_ex.c stm32f1xx_hal_gpio.c stm32f1xx_hal_msp.c stm32f1xx_hal_flash.c stm32f1xx_hal_flash_ex.c stm32f1xx_hal_dma.c
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -0,0 +1,964 @@
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file stm32f1xx_hal_flash.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief FLASH HAL module driver.
|
||||||
|
* This file provides firmware functions to manage the following
|
||||||
|
* functionalities of the internal FLASH memory:
|
||||||
|
* + Program operations functions
|
||||||
|
* + Memory Control functions
|
||||||
|
* + Peripheral State functions
|
||||||
|
*
|
||||||
|
@verbatim
|
||||||
|
==============================================================================
|
||||||
|
##### FLASH peripheral features #####
|
||||||
|
==============================================================================
|
||||||
|
[..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses
|
||||||
|
to the Flash memory. It implements the erase and program Flash memory operations
|
||||||
|
and the read and write protection mechanisms.
|
||||||
|
|
||||||
|
[..] The Flash memory interface accelerates code execution with a system of instruction
|
||||||
|
prefetch.
|
||||||
|
|
||||||
|
[..] The FLASH main features are:
|
||||||
|
(+) Flash memory read operations
|
||||||
|
(+) Flash memory program/erase operations
|
||||||
|
(+) Read / write protections
|
||||||
|
(+) Prefetch on I-Code
|
||||||
|
(+) Option Bytes programming
|
||||||
|
|
||||||
|
|
||||||
|
##### How to use this driver #####
|
||||||
|
==============================================================================
|
||||||
|
[..]
|
||||||
|
This driver provides functions and macros to configure and program the FLASH
|
||||||
|
memory of all STM32F1xx devices.
|
||||||
|
|
||||||
|
(#) FLASH Memory I/O Programming functions: this group includes all needed
|
||||||
|
functions to erase and program the main memory:
|
||||||
|
(++) Lock and Unlock the FLASH interface
|
||||||
|
(++) Erase function: Erase page, erase all pages
|
||||||
|
(++) Program functions: half word, word and doubleword
|
||||||
|
(#) FLASH Option Bytes Programming functions: this group includes all needed
|
||||||
|
functions to manage the Option Bytes:
|
||||||
|
(++) Lock and Unlock the Option Bytes
|
||||||
|
(++) Set/Reset the write protection
|
||||||
|
(++) Set the Read protection Level
|
||||||
|
(++) Program the user Option Bytes
|
||||||
|
(++) Launch the Option Bytes loader
|
||||||
|
(++) Erase Option Bytes
|
||||||
|
(++) Program the data Option Bytes
|
||||||
|
(++) Get the Write protection.
|
||||||
|
(++) Get the user option bytes.
|
||||||
|
|
||||||
|
(#) Interrupts and flags management functions : this group
|
||||||
|
includes all needed functions to:
|
||||||
|
(++) Handle FLASH interrupts
|
||||||
|
(++) Wait for last FLASH operation according to its status
|
||||||
|
(++) Get error flag status
|
||||||
|
|
||||||
|
[..] In addition to these function, this driver includes a set of macros allowing
|
||||||
|
to handle the following operations:
|
||||||
|
|
||||||
|
(+) Set/Get the latency
|
||||||
|
(+) Enable/Disable the prefetch buffer
|
||||||
|
(+) Enable/Disable the half cycle access
|
||||||
|
(+) Enable/Disable the FLASH interrupts
|
||||||
|
(+) Monitor the FLASH flags status
|
||||||
|
|
||||||
|
@endverbatim
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file in
|
||||||
|
* the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32F1xx_HAL_Driver
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||||
|
|
||||||
|
/** @defgroup FLASH FLASH
|
||||||
|
* @brief FLASH HAL module driver
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/** @defgroup FLASH_Private_Constants FLASH Private Constants
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Private macro ---------------------------- ---------------------------------*/
|
||||||
|
/** @defgroup FLASH_Private_Macros FLASH Private Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
/** @defgroup FLASH_Private_Variables FLASH Private Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/* Variables used for Erase pages under interruption*/
|
||||||
|
FLASH_ProcessTypeDef pFlash;
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
/** @defgroup FLASH_Private_Functions FLASH Private Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data);
|
||||||
|
static void FLASH_SetErrorCode(void);
|
||||||
|
extern void FLASH_PageErase(uint32_t PageAddress);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported functions ---------------------------------------------------------*/
|
||||||
|
/** @defgroup FLASH_Exported_Functions FLASH Exported Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions
|
||||||
|
* @brief Programming operation functions
|
||||||
|
*
|
||||||
|
@verbatim
|
||||||
|
@endverbatim
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Program halfword, word or double word at a specified address
|
||||||
|
* @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
|
||||||
|
* The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
|
||||||
|
*
|
||||||
|
* @note If an erase and a program operations are requested simultaneously,
|
||||||
|
* the erase operation is performed before the program one.
|
||||||
|
*
|
||||||
|
* @note FLASH should be previously erased before new programmation (only exception to this
|
||||||
|
* is when 0x0000 is programmed)
|
||||||
|
*
|
||||||
|
* @param TypeProgram: Indicate the way to program at a specified address.
|
||||||
|
* This parameter can be a value of @ref FLASH_Type_Program
|
||||||
|
* @param Address: Specifies the address to be programmed.
|
||||||
|
* @param Data: Specifies the data to be programmed
|
||||||
|
*
|
||||||
|
* @retval HAL_StatusTypeDef HAL Status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef status = HAL_ERROR;
|
||||||
|
uint8_t index = 0;
|
||||||
|
uint8_t nbiterations = 0;
|
||||||
|
|
||||||
|
/* Process Locked */
|
||||||
|
__HAL_LOCK(&pFlash);
|
||||||
|
|
||||||
|
/* Check the parameters */
|
||||||
|
assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
|
||||||
|
assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
|
||||||
|
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
if(Address <= FLASH_BANK1_END)
|
||||||
|
{
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
/* Wait for last operation to be completed */
|
||||||
|
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Wait for last operation to be completed */
|
||||||
|
status = FLASH_WaitForLastOperationBank2(FLASH_TIMEOUT_VALUE);
|
||||||
|
}
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
|
if(status == HAL_OK)
|
||||||
|
{
|
||||||
|
if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
|
||||||
|
{
|
||||||
|
/* Program halfword (16-bit) at a specified address. */
|
||||||
|
nbiterations = 1U;
|
||||||
|
}
|
||||||
|
else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
|
||||||
|
{
|
||||||
|
/* Program word (32-bit = 2*16-bit) at a specified address. */
|
||||||
|
nbiterations = 2U;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Program double word (64-bit = 4*16-bit) at a specified address. */
|
||||||
|
nbiterations = 4U;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (index = 0U; index < nbiterations; index++)
|
||||||
|
{
|
||||||
|
FLASH_Program_HalfWord((Address + (2U*index)), (uint16_t)(Data >> (16U*index)));
|
||||||
|
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
if(Address <= FLASH_BANK1_END)
|
||||||
|
{
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
/* Wait for last operation to be completed */
|
||||||
|
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
||||||
|
|
||||||
|
/* If the program operation is completed, disable the PG Bit */
|
||||||
|
CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Wait for last operation to be completed */
|
||||||
|
status = FLASH_WaitForLastOperationBank2(FLASH_TIMEOUT_VALUE);
|
||||||
|
|
||||||
|
/* If the program operation is completed, disable the PG Bit */
|
||||||
|
CLEAR_BIT(FLASH->CR2, FLASH_CR2_PG);
|
||||||
|
}
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
/* In case of error, stop programation procedure */
|
||||||
|
if (status != HAL_OK)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process Unlocked */
|
||||||
|
__HAL_UNLOCK(&pFlash);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Program halfword, word or double word at a specified address with interrupt enabled.
|
||||||
|
* @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
|
||||||
|
* The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
|
||||||
|
*
|
||||||
|
* @note If an erase and a program operations are requested simultaneously,
|
||||||
|
* the erase operation is performed before the program one.
|
||||||
|
*
|
||||||
|
* @param TypeProgram: Indicate the way to program at a specified address.
|
||||||
|
* This parameter can be a value of @ref FLASH_Type_Program
|
||||||
|
* @param Address: Specifies the address to be programmed.
|
||||||
|
* @param Data: Specifies the data to be programmed
|
||||||
|
*
|
||||||
|
* @retval HAL_StatusTypeDef HAL Status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
|
/* Process Locked */
|
||||||
|
__HAL_LOCK(&pFlash);
|
||||||
|
|
||||||
|
/* Check the parameters */
|
||||||
|
assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
|
||||||
|
assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
|
||||||
|
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
/* If procedure already ongoing, reject the next one */
|
||||||
|
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
||||||
|
{
|
||||||
|
return HAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Address <= FLASH_BANK1_END)
|
||||||
|
{
|
||||||
|
/* Enable End of FLASH Operation and Error source interrupts */
|
||||||
|
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1);
|
||||||
|
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
/* Enable End of FLASH Operation and Error source interrupts */
|
||||||
|
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* Enable End of FLASH Operation and Error source interrupts */
|
||||||
|
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR);
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
|
pFlash.Address = Address;
|
||||||
|
pFlash.Data = Data;
|
||||||
|
|
||||||
|
if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
|
||||||
|
{
|
||||||
|
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMHALFWORD;
|
||||||
|
/* Program halfword (16-bit) at a specified address. */
|
||||||
|
pFlash.DataRemaining = 1U;
|
||||||
|
}
|
||||||
|
else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
|
||||||
|
{
|
||||||
|
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMWORD;
|
||||||
|
/* Program word (32-bit : 2*16-bit) at a specified address. */
|
||||||
|
pFlash.DataRemaining = 2U;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMDOUBLEWORD;
|
||||||
|
/* Program double word (64-bit : 4*16-bit) at a specified address. */
|
||||||
|
pFlash.DataRemaining = 4U;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Program halfword (16-bit) at a specified address. */
|
||||||
|
FLASH_Program_HalfWord(Address, (uint16_t)Data);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles FLASH interrupt request.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_FLASH_IRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t addresstmp = 0U;
|
||||||
|
|
||||||
|
/* Check FLASH operation error flags */
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK1) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK1) || \
|
||||||
|
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)))
|
||||||
|
#else
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
{
|
||||||
|
/* Return the faulty address */
|
||||||
|
addresstmp = pFlash.Address;
|
||||||
|
/* Reset address */
|
||||||
|
pFlash.Address = 0xFFFFFFFFU;
|
||||||
|
|
||||||
|
/* Save the Error code */
|
||||||
|
FLASH_SetErrorCode();
|
||||||
|
|
||||||
|
/* FLASH error interrupt user callback */
|
||||||
|
HAL_FLASH_OperationErrorCallback(addresstmp);
|
||||||
|
|
||||||
|
/* Stop the procedure ongoing */
|
||||||
|
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check FLASH End of Operation flag */
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK1))
|
||||||
|
{
|
||||||
|
/* Clear FLASH End of Operation pending bit */
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK1);
|
||||||
|
#else
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
|
||||||
|
{
|
||||||
|
/* Clear FLASH End of Operation pending bit */
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
|
/* Process can continue only if no error detected */
|
||||||
|
if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
||||||
|
{
|
||||||
|
if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
|
||||||
|
{
|
||||||
|
/* Nb of pages to erased can be decreased */
|
||||||
|
pFlash.DataRemaining--;
|
||||||
|
|
||||||
|
/* Check if there are still pages to erase */
|
||||||
|
if(pFlash.DataRemaining != 0U)
|
||||||
|
{
|
||||||
|
addresstmp = pFlash.Address;
|
||||||
|
/*Indicate user which sector has been erased */
|
||||||
|
HAL_FLASH_EndOfOperationCallback(addresstmp);
|
||||||
|
|
||||||
|
/*Increment sector number*/
|
||||||
|
addresstmp = pFlash.Address + FLASH_PAGE_SIZE;
|
||||||
|
pFlash.Address = addresstmp;
|
||||||
|
|
||||||
|
/* If the erase operation is completed, disable the PER Bit */
|
||||||
|
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
|
||||||
|
|
||||||
|
FLASH_PageErase(addresstmp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* No more pages to Erase, user callback can be called. */
|
||||||
|
/* Reset Sector and stop Erase pages procedure */
|
||||||
|
pFlash.Address = addresstmp = 0xFFFFFFFFU;
|
||||||
|
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||||
|
/* FLASH EOP interrupt user callback */
|
||||||
|
HAL_FLASH_EndOfOperationCallback(addresstmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
|
||||||
|
{
|
||||||
|
/* Operation is completed, disable the MER Bit */
|
||||||
|
CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
|
||||||
|
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
/* Stop Mass Erase procedure if no pending mass erase on other bank */
|
||||||
|
if (HAL_IS_BIT_CLR(FLASH->CR2, FLASH_CR2_MER))
|
||||||
|
{
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
/* MassErase ended. Return the selected bank */
|
||||||
|
/* FLASH EOP interrupt user callback */
|
||||||
|
HAL_FLASH_EndOfOperationCallback(0U);
|
||||||
|
|
||||||
|
/* Stop Mass Erase procedure*/
|
||||||
|
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||||
|
}
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
}
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Nb of 16-bit data to program can be decreased */
|
||||||
|
pFlash.DataRemaining--;
|
||||||
|
|
||||||
|
/* Check if there are still 16-bit data to program */
|
||||||
|
if(pFlash.DataRemaining != 0U)
|
||||||
|
{
|
||||||
|
/* Increment address to 16-bit */
|
||||||
|
pFlash.Address += 2U;
|
||||||
|
addresstmp = pFlash.Address;
|
||||||
|
|
||||||
|
/* Shift to have next 16-bit data */
|
||||||
|
pFlash.Data = (pFlash.Data >> 16U);
|
||||||
|
|
||||||
|
/* Operation is completed, disable the PG Bit */
|
||||||
|
CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
|
||||||
|
|
||||||
|
/*Program halfword (16-bit) at a specified address.*/
|
||||||
|
FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Program ended. Return the selected address */
|
||||||
|
/* FLASH EOP interrupt user callback */
|
||||||
|
if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
|
||||||
|
{
|
||||||
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||||
|
}
|
||||||
|
else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
|
||||||
|
{
|
||||||
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 2U);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 6U);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset Address and stop Program procedure */
|
||||||
|
pFlash.Address = 0xFFFFFFFFU;
|
||||||
|
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
/* Check FLASH End of Operation flag */
|
||||||
|
if(__HAL_FLASH_GET_FLAG( FLASH_FLAG_EOP_BANK2))
|
||||||
|
{
|
||||||
|
/* Clear FLASH End of Operation pending bit */
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
|
||||||
|
|
||||||
|
/* Process can continue only if no error detected */
|
||||||
|
if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
||||||
|
{
|
||||||
|
if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
|
||||||
|
{
|
||||||
|
/* Nb of pages to erased can be decreased */
|
||||||
|
pFlash.DataRemaining--;
|
||||||
|
|
||||||
|
/* Check if there are still pages to erase*/
|
||||||
|
if(pFlash.DataRemaining != 0U)
|
||||||
|
{
|
||||||
|
/* Indicate user which page address has been erased*/
|
||||||
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||||
|
|
||||||
|
/* Increment page address to next page */
|
||||||
|
pFlash.Address += FLASH_PAGE_SIZE;
|
||||||
|
addresstmp = pFlash.Address;
|
||||||
|
|
||||||
|
/* Operation is completed, disable the PER Bit */
|
||||||
|
CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER);
|
||||||
|
|
||||||
|
FLASH_PageErase(addresstmp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*No more pages to Erase*/
|
||||||
|
|
||||||
|
/*Reset Address and stop Erase pages procedure*/
|
||||||
|
pFlash.Address = 0xFFFFFFFFU;
|
||||||
|
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||||
|
|
||||||
|
/* FLASH EOP interrupt user callback */
|
||||||
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
|
||||||
|
{
|
||||||
|
/* Operation is completed, disable the MER Bit */
|
||||||
|
CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||||
|
|
||||||
|
if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_MER))
|
||||||
|
{
|
||||||
|
/* MassErase ended. Return the selected bank*/
|
||||||
|
/* FLASH EOP interrupt user callback */
|
||||||
|
HAL_FLASH_EndOfOperationCallback(0U);
|
||||||
|
|
||||||
|
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Nb of 16-bit data to program can be decreased */
|
||||||
|
pFlash.DataRemaining--;
|
||||||
|
|
||||||
|
/* Check if there are still 16-bit data to program */
|
||||||
|
if(pFlash.DataRemaining != 0U)
|
||||||
|
{
|
||||||
|
/* Increment address to 16-bit */
|
||||||
|
pFlash.Address += 2U;
|
||||||
|
addresstmp = pFlash.Address;
|
||||||
|
|
||||||
|
/* Shift to have next 16-bit data */
|
||||||
|
pFlash.Data = (pFlash.Data >> 16U);
|
||||||
|
|
||||||
|
/* Operation is completed, disable the PG Bit */
|
||||||
|
CLEAR_BIT(FLASH->CR2, FLASH_CR2_PG);
|
||||||
|
|
||||||
|
/*Program halfword (16-bit) at a specified address.*/
|
||||||
|
FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*Program ended. Return the selected address*/
|
||||||
|
/* FLASH EOP interrupt user callback */
|
||||||
|
if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
|
||||||
|
{
|
||||||
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||||
|
}
|
||||||
|
else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
|
||||||
|
{
|
||||||
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address-2U);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address-6U);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset Address and stop Program procedure*/
|
||||||
|
pFlash.Address = 0xFFFFFFFFU;
|
||||||
|
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE)
|
||||||
|
{
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
/* Operation is completed, disable the PG, PER and MER Bits for both bank */
|
||||||
|
CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER));
|
||||||
|
CLEAR_BIT(FLASH->CR2, (FLASH_CR2_PG | FLASH_CR2_PER | FLASH_CR2_MER));
|
||||||
|
|
||||||
|
/* Disable End of FLASH Operation and Error source interrupts for both banks */
|
||||||
|
__HAL_FLASH_DISABLE_IT(FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1 | FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
|
||||||
|
#else
|
||||||
|
/* Operation is completed, disable the PG, PER and MER Bits */
|
||||||
|
CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER));
|
||||||
|
|
||||||
|
/* Disable End of FLASH Operation and Error source interrupts */
|
||||||
|
__HAL_FLASH_DISABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR);
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
|
/* Process Unlocked */
|
||||||
|
__HAL_UNLOCK(&pFlash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief FLASH end of operation interrupt callback
|
||||||
|
* @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
|
||||||
|
* - Mass Erase: No return value expected
|
||||||
|
* - Pages Erase: Address of the page which has been erased
|
||||||
|
* (if 0xFFFFFFFF, it means that all the selected pages have been erased)
|
||||||
|
* - Program: Address which was selected for data program
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
|
||||||
|
{
|
||||||
|
/* Prevent unused argument(s) compilation warning */
|
||||||
|
UNUSED(ReturnValue);
|
||||||
|
|
||||||
|
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||||
|
the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief FLASH operation error interrupt callback
|
||||||
|
* @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
|
||||||
|
* - Mass Erase: No return value expected
|
||||||
|
* - Pages Erase: Address of the page which returned an error
|
||||||
|
* - Program: Address which was selected for data program
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
|
||||||
|
{
|
||||||
|
/* Prevent unused argument(s) compilation warning */
|
||||||
|
UNUSED(ReturnValue);
|
||||||
|
|
||||||
|
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||||
|
the HAL_FLASH_OperationErrorCallback could be implemented in the user file
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions
|
||||||
|
* @brief management functions
|
||||||
|
*
|
||||||
|
@verbatim
|
||||||
|
===============================================================================
|
||||||
|
##### Peripheral Control functions #####
|
||||||
|
===============================================================================
|
||||||
|
[..]
|
||||||
|
This subsection provides a set of functions allowing to control the FLASH
|
||||||
|
memory operations.
|
||||||
|
|
||||||
|
@endverbatim
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Unlock the FLASH control register access
|
||||||
|
* @retval HAL Status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_FLASH_Unlock(void)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
|
if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
|
||||||
|
{
|
||||||
|
/* Authorize the FLASH Registers access */
|
||||||
|
WRITE_REG(FLASH->KEYR, FLASH_KEY1);
|
||||||
|
WRITE_REG(FLASH->KEYR, FLASH_KEY2);
|
||||||
|
|
||||||
|
/* Verify Flash is unlocked */
|
||||||
|
if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
|
||||||
|
{
|
||||||
|
status = HAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
if(READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET)
|
||||||
|
{
|
||||||
|
/* Authorize the FLASH BANK2 Registers access */
|
||||||
|
WRITE_REG(FLASH->KEYR2, FLASH_KEY1);
|
||||||
|
WRITE_REG(FLASH->KEYR2, FLASH_KEY2);
|
||||||
|
|
||||||
|
/* Verify Flash BANK2 is unlocked */
|
||||||
|
if(READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET)
|
||||||
|
{
|
||||||
|
status = HAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Locks the FLASH control register access
|
||||||
|
* @retval HAL Status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_FLASH_Lock(void)
|
||||||
|
{
|
||||||
|
/* Set the LOCK Bit to lock the FLASH Registers access */
|
||||||
|
SET_BIT(FLASH->CR, FLASH_CR_LOCK);
|
||||||
|
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
/* Set the LOCK Bit to lock the FLASH BANK2 Registers access */
|
||||||
|
SET_BIT(FLASH->CR2, FLASH_CR2_LOCK);
|
||||||
|
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Unlock the FLASH Option Control Registers access.
|
||||||
|
* @retval HAL Status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
|
||||||
|
{
|
||||||
|
if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_OPTWRE))
|
||||||
|
{
|
||||||
|
/* Authorizes the Option Byte register programming */
|
||||||
|
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
|
||||||
|
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return HAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Lock the FLASH Option Control Registers access.
|
||||||
|
* @retval HAL Status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
|
||||||
|
{
|
||||||
|
/* Clear the OPTWRE Bit to lock the FLASH Option Byte Registers access */
|
||||||
|
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTWRE);
|
||||||
|
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Launch the option byte loading.
|
||||||
|
* @note This function will reset automatically the MCU.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_FLASH_OB_Launch(void)
|
||||||
|
{
|
||||||
|
/* Initiates a system reset request to launch the option byte loading */
|
||||||
|
HAL_NVIC_SystemReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FLASH_Exported_Functions_Group3 Peripheral errors functions
|
||||||
|
* @brief Peripheral errors functions
|
||||||
|
*
|
||||||
|
@verbatim
|
||||||
|
===============================================================================
|
||||||
|
##### Peripheral Errors functions #####
|
||||||
|
===============================================================================
|
||||||
|
[..]
|
||||||
|
This subsection permit to get in run-time errors of the FLASH peripheral.
|
||||||
|
|
||||||
|
@endverbatim
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the specific FLASH error flag.
|
||||||
|
* @retval FLASH_ErrorCode The returned value can be:
|
||||||
|
* @ref FLASH_Error_Codes
|
||||||
|
*/
|
||||||
|
uint32_t HAL_FLASH_GetError(void)
|
||||||
|
{
|
||||||
|
return pFlash.ErrorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup FLASH_Private_Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Program a half-word (16-bit) at a specified address.
|
||||||
|
* @param Address specify the address to be programmed.
|
||||||
|
* @param Data specify the data to be programmed.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data)
|
||||||
|
{
|
||||||
|
/* Clean the error context */
|
||||||
|
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||||
|
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
if(Address <= FLASH_BANK1_END)
|
||||||
|
{
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
/* Proceed to program the new data */
|
||||||
|
SET_BIT(FLASH->CR, FLASH_CR_PG);
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Proceed to program the new data */
|
||||||
|
SET_BIT(FLASH->CR2, FLASH_CR2_PG);
|
||||||
|
}
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
|
/* Write data in the address */
|
||||||
|
*(__IO uint16_t*)Address = Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Wait for a FLASH operation to complete.
|
||||||
|
* @param Timeout maximum flash operation timeout
|
||||||
|
* @retval HAL Status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
|
||||||
|
{
|
||||||
|
/* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
|
||||||
|
Even if the FLASH operation fails, the BUSY flag will be reset and an error
|
||||||
|
flag will be set */
|
||||||
|
|
||||||
|
uint32_t tickstart = HAL_GetTick();
|
||||||
|
|
||||||
|
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
|
||||||
|
{
|
||||||
|
if (Timeout != HAL_MAX_DELAY)
|
||||||
|
{
|
||||||
|
if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout))
|
||||||
|
{
|
||||||
|
return HAL_TIMEOUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check FLASH End of Operation flag */
|
||||||
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
|
||||||
|
{
|
||||||
|
/* Clear FLASH End of Operation pending bit */
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||
|
||||||
|
__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) ||
|
||||||
|
__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
|
||||||
|
{
|
||||||
|
/*Save the error code*/
|
||||||
|
FLASH_SetErrorCode();
|
||||||
|
return HAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* There is no error flag set */
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
/**
|
||||||
|
* @brief Wait for a FLASH BANK2 operation to complete.
|
||||||
|
* @param Timeout maximum flash operation timeout
|
||||||
|
* @retval HAL_StatusTypeDef HAL Status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout)
|
||||||
|
{
|
||||||
|
/* Wait for the FLASH BANK2 operation to complete by polling on BUSY flag to be reset.
|
||||||
|
Even if the FLASH BANK2 operation fails, the BUSY flag will be reset and an error
|
||||||
|
flag will be set */
|
||||||
|
|
||||||
|
uint32_t tickstart = HAL_GetTick();
|
||||||
|
|
||||||
|
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY_BANK2))
|
||||||
|
{
|
||||||
|
if (Timeout != HAL_MAX_DELAY)
|
||||||
|
{
|
||||||
|
if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout))
|
||||||
|
{
|
||||||
|
return HAL_TIMEOUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check FLASH End of Operation flag */
|
||||||
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK2))
|
||||||
|
{
|
||||||
|
/* Clear FLASH End of Operation pending bit */
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))
|
||||||
|
{
|
||||||
|
/*Save the error code*/
|
||||||
|
FLASH_SetErrorCode();
|
||||||
|
return HAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If there is an error flag set */
|
||||||
|
return HAL_OK;
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the specific FLASH error flag.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void FLASH_SetErrorCode(void)
|
||||||
|
{
|
||||||
|
uint32_t flags = 0U;
|
||||||
|
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2))
|
||||||
|
#else
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
{
|
||||||
|
pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
flags |= FLASH_FLAG_WRPERR | FLASH_FLAG_WRPERR_BANK2;
|
||||||
|
#else
|
||||||
|
flags |= FLASH_FLAG_WRPERR;
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
}
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))
|
||||||
|
#else
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
{
|
||||||
|
pFlash.ErrorCode |= HAL_FLASH_ERROR_PROG;
|
||||||
|
#if defined(FLASH_BANK2_END)
|
||||||
|
flags |= FLASH_FLAG_PGERR | FLASH_FLAG_PGERR_BANK2;
|
||||||
|
#else
|
||||||
|
flags |= FLASH_FLAG_PGERR;
|
||||||
|
#endif /* FLASH_BANK2_END */
|
||||||
|
}
|
||||||
|
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR))
|
||||||
|
{
|
||||||
|
pFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV;
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear FLASH error pending bits */
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(flags);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -446,6 +446,25 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
|
||||||
/* USER CODE BEGIN USART1_MspInit 1 */
|
/* USER CODE BEGIN USART1_MspInit 1 */
|
||||||
/* USER CODE END USART1_MspInit 1 */
|
/* USER CODE END USART1_MspInit 1 */
|
||||||
}
|
}
|
||||||
|
else if(huart->Instance==USART2)// yunji usart2 for console
|
||||||
|
{
|
||||||
|
__HAL_RCC_USART2_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
/**USART2 GPIO Configuration
|
||||||
|
PA2 ------> USART2_TX
|
||||||
|
PA3 ------> USART2_RX
|
||||||
|
*/
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_3;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
HAL_NVIC_SetPriority(USART2_IRQn, 5, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(USART2_IRQn);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,6 +496,12 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
|
||||||
/* USER CODE BEGIN USART1_MspDeInit 1 */
|
/* USER CODE BEGIN USART1_MspDeInit 1 */
|
||||||
/* USER CODE END USART1_MspDeInit 1 */
|
/* USER CODE END USART1_MspDeInit 1 */
|
||||||
}
|
}
|
||||||
|
else if(huart->Instance==USART2)
|
||||||
|
{
|
||||||
|
__HAL_RCC_USART1_CLK_DISABLE();
|
||||||
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
|
||||||
|
HAL_NVIC_DisableIRQ(USART2_IRQn);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ void ShowBanner(void)
|
||||||
KPrintf("A:::::A A:::::A i::::::i II:::::::::II II:::::::::II T:::::::::::::::TT \n");
|
KPrintf("A:::::A A:::::A i::::::i II:::::::::II II:::::::::II T:::::::::::::::TT \n");
|
||||||
KPrintf("AAAAAAA AAAAAAA iiiiiiii IIIIIIIII IIIIIIIII TTTTTTTTTTTTTTT \n");
|
KPrintf("AAAAAAA AAAAAAA iiiiiiii IIIIIIIII IIIIIIIII TTTTTTTTTTTTTTT \n");
|
||||||
KPrintf("*********************************************************************************************\n");
|
KPrintf("*********************************************************************************************\n");
|
||||||
KPrintf("*********************-----X Industrial Ubiquitous Operating System-----**********************\n");
|
KPrintf("*********************-----X Industrial Ubiquitous Operating System-APP-**********************\n");
|
||||||
KPrintf("***************************2021 Copyright AIIT Ubiquitous-OS Team****************************\n");
|
KPrintf("***************************2021 Copyright AIIT Ubiquitous-OS Team****************************\n");
|
||||||
KPrintf("*********************************************************************************************\n");
|
KPrintf("*********************************************************************************************\n");
|
||||||
}
|
}
|
|
@ -252,6 +252,7 @@ extern int InitUserspace(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
StartupOsAssign();
|
StartupOsAssign();
|
||||||
|
ymodem_fun();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,15 @@ static void ZombieKTaskEntry(void *parameter)
|
||||||
lock = CriticalAreaLock();
|
lock = CriticalAreaLock();
|
||||||
if (JudgeZombieKTaskIsNotEmpty()) {
|
if (JudgeZombieKTaskIsNotEmpty()) {
|
||||||
task = SYS_DOUBLE_LINKLIST_ENTRY(KTaskZombie.node_next, struct TaskDescriptor, task_dync_sched_member.sched_link);
|
task = SYS_DOUBLE_LINKLIST_ENTRY(KTaskZombie.node_next, struct TaskDescriptor, task_dync_sched_member.sched_link);
|
||||||
|
if(0 == strcmp("main", task->task_base_info.name))
|
||||||
|
{
|
||||||
|
// KPrintf("Zombie KTask Is main\n");
|
||||||
|
SuspendKTask(zombie_recycle);
|
||||||
|
CriticalAreaUnLock(lock);
|
||||||
|
DO_KTASK_ASSIGN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
DoubleLinkListRmNode(&(task->task_dync_sched_member.sched_link));
|
DoubleLinkListRmNode(&(task->task_dync_sched_member.sched_link));
|
||||||
CriticalAreaUnLock(lock);
|
CriticalAreaUnLock(lock);
|
||||||
#ifdef SEPARATE_COMPILE
|
#ifdef SEPARATE_COMPILE
|
||||||
|
@ -72,6 +81,7 @@ static void ZombieKTaskEntry(void *parameter)
|
||||||
KERNEL_FREE(task->task_dync_sched_member.delay);
|
KERNEL_FREE(task->task_dync_sched_member.delay);
|
||||||
}
|
}
|
||||||
KERNEL_FREE(task);
|
KERNEL_FREE(task);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
SuspendKTask(zombie_recycle);
|
SuspendKTask(zombie_recycle);
|
||||||
CriticalAreaUnLock(lock);
|
CriticalAreaUnLock(lock);
|
||||||
|
|
Loading…
Reference in New Issue