Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
fix the critical problem; fix bootloader sp check error
Browse files Browse the repository at this point in the history
  • Loading branch information
talpachen committed Oct 19, 2020
1 parent 78e5389 commit 812c2d1
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 42 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define symbol __ICFEDIT_region_ROM_end__ = 0x0800FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000004;
define symbol __ICFEDIT_region_RAM_end__ = 0x20001FFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_cstack__ = 0x3E0;
define symbol __ICFEDIT_size_heap__ = 0x0;
/**** End of ICF editor section. ###ICF###*/

Expand Down
4 changes: 2 additions & 2 deletions source/project_vllink_lite/vllink_lite/EWARM/project.ewp
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@
</option>
<option>
<name>IExtraOptionsCheck</name>
<state>1</state>
<state>0</state>
</option>
<option>
<name>IExtraOptions</name>
<state>--no_unaligned_access</state>
<state></state>
</option>
<option>
<name>CCLangConformance</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define GPIOE_ENABLE 0

#define USART_STREAM_ENABLE 1
#define USART_STREAM_EDA_PRIORITY vsf_prio_1 // same as VSF_USBD_CFG_EDA_PRIORITY
#define USART_BUFF_SIZE 64
#define USART0_ENABLE 1
# define USART0_DMA_ENABLE 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define GPIOF_ENABLE 0

#define USART_STREAM_ENABLE 1
#define USART_STREAM_EDA_PRIORITY vsf_prio_1 // same as VSF_USBD_CFG_EDA_PRIORITY
#define USART_BUFF_SIZE 64
#define USART0_ENABLE 1
# define USART0_DMA_ENABLE 1
Expand Down
4 changes: 2 additions & 2 deletions source/project_vllink_lite/vllink_lite/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static void usrapp_config_usart(enum usart_idx_t idx, uint32_t *mode, uint32_t *
vsfhal_usart_config(PERIPHERAL_UART_EXT_IDX, usrapp.usart_ext_baud, usrapp.usart_ext_mode);
if (baudrate)
*baudrate = usrapp.usart_ext_baud;
vsfhal_usart_stream_init(PERIPHERAL_UART_EXT_IDX, PERIPHERAL_UART_EXT_PRIORITY, tx, rx);
vsfhal_usart_stream_init(PERIPHERAL_UART_EXT_IDX, USART_STREAM_EDA_PRIORITY, PERIPHERAL_UART_EXT_PRIORITY, tx, rx);
} else if (baudrate && *baudrate != usrapp.usart_ext_baud) {
usrapp.usart_ext_baud = *baudrate;
if (return_actual_baud)
Expand All @@ -162,7 +162,7 @@ static void usrapp_config_usart(enum usart_idx_t idx, uint32_t *mode, uint32_t *
vsfhal_usart_config(PERIPHERAL_UART_SWO_IDX, usrapp.usart_swo_baud, usrapp.usart_swo_mode);
if (baudrate)
*baudrate = usrapp.usart_swo_baud;
vsfhal_usart_stream_init(PERIPHERAL_UART_SWO_IDX, PERIPHERAL_UART_EXT_PRIORITY, tx, rx);
vsfhal_usart_stream_init(PERIPHERAL_UART_SWO_IDX, USART_STREAM_EDA_PRIORITY, PERIPHERAL_UART_EXT_PRIORITY, tx, rx);
} else if (baudrate && *baudrate != usrapp.usart_swo_baud) {
usrapp.usart_swo_baud = *baudrate;
if (return_actual_baud)
Expand Down
2 changes: 1 addition & 1 deletion source/project_vllink_lite/vllink_lite_bootloader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(void)
uint32_t sp_addr = *(uint32_t *)(FIRMWARE_AREA_ADDR);

if ((app_main_addr >= FIRMWARE_AREA_ADDR) && (app_main_addr < (FIRMWARE_AREA_ADDR + FIRMWARE_AREA_SIZE_MAX)) &&
(sp_addr >= FIRMWARE_SP_ADDR) && (sp_addr < (FIRMWARE_SP_ADDR + FIRMWARE_SP_SIZE_MAX))) {
(sp_addr >= FIRMWARE_SP_ADDR) && (sp_addr <= (FIRMWARE_SP_ADDR + FIRMWARE_SP_SIZE_MAX))) {
uint32_t (*app_main)(void) = (uint32_t(*)(void))app_main_addr;
__set_MSP(sp_addr);
app_main();
Expand Down
14 changes: 8 additions & 6 deletions source/vsf/component/usb/driver/otg/dwcotg/vsf_dwcotg_dcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,10 @@ vsf_err_t vk_dwcotg_dcd_ep_transaction_read_buffer(vk_dwcotg_dcd_t *dwcotg_dcd,
vsf_err_t vk_dwcotg_dcd_ep_transaction_enable_out(vk_dwcotg_dcd_t *dwcotg_dcd, uint_fast8_t ep, uint8_t *buffer)
{
VSF_USB_ASSERT(!(ep & 0x80));
VSF_USB_ASSERT(ep < dwcotg_dcd->ep_num);


uint_fast8_t ep_idx = ep;
VSF_USB_ASSERT(ep_idx < dwcotg_dcd->ep_num);

uint_fast16_t ep_size = vk_dwcotg_dcd_ep_get_size(dwcotg_dcd, ep);
struct dwcotg_dev_out_ep_regs_t *out_regs = &dwcotg_dcd->reg.dev.ep.out_regs[ep_idx];

Expand All @@ -485,7 +486,7 @@ vsf_err_t vk_dwcotg_dcd_ep_transaction_set_data_size(vk_dwcotg_dcd_t *dwcotg_dcd
VSF_USB_ASSERT(ep & 0x80);

uint_fast8_t ep_idx = ep & 0x0F;
VSF_USB_ASSERT(ep < dwcotg_dcd->ep_num);
VSF_USB_ASSERT(ep_idx < dwcotg_dcd->ep_num);

struct dwcotg_dev_in_ep_regs_t *in_regs = &dwcotg_dcd->reg.dev.ep.in_regs[ep_idx];

Expand All @@ -503,7 +504,7 @@ vsf_err_t vk_dwcotg_dcd_ep_transaction_write_buffer(vk_dwcotg_dcd_t *dwcotg_dcd,

uint32_t data;
uint_fast8_t ep_idx = ep & 0x0F;
VSF_USB_ASSERT(ep < dwcotg_dcd->ep_num);
VSF_USB_ASSERT(ep_idx < dwcotg_dcd->ep_num);

struct dwcotg_dev_in_ep_regs_t *in_regs = &dwcotg_dcd->reg.dev.ep.in_regs[ep_idx];

Expand All @@ -524,9 +525,10 @@ vsf_err_t vk_dwcotg_dcd_ep_transaction_write_buffer(vk_dwcotg_dcd_t *dwcotg_dcd,
uint_fast32_t vk_dwcotg_dcd_ep_get_data_size(vk_dwcotg_dcd_t *dwcotg_dcd, uint_fast8_t ep)
{
VSF_USB_ASSERT(!(ep & 0x80));
VSF_USB_ASSERT(ep < dwcotg_dcd->ep_num);

uint_fast8_t ep_idx = ep;
VSF_USB_ASSERT(ep_idx < dwcotg_dcd->ep_num);

return dwcotg_dcd->out_size[ep_idx];
}

Expand Down Expand Up @@ -757,7 +759,7 @@ void vk_dwcotg_dcd_irq(vk_dwcotg_dcd_t *dwcotg_dcd)
//case RXSTAT_GOUT_NAK:
//case RXSTAT_SETUP_COMP:
default:
VSF_HAL_ASSERT(false);
//VSF_HAL_ASSERT(false);
break;
}

Expand Down
85 changes: 71 additions & 14 deletions source/vsf_private/hal/driver/GigaDevice/GD32E10X/common/usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "io.h"
#include "dma.h"

#if USART_STREAM_ENABLE
# include "vsf.h" // use eda
#endif

/*============================ MACROS ========================================*/

#ifndef USART_BUFF_SIZE
Expand All @@ -19,6 +23,7 @@ typedef struct usart_control_t {
#if USART_STREAM_ENABLE
vsf_stream_t *tx;
vsf_stream_t *rx;
vsf_eda_t eda;
#endif
void (*ontx)(void *);
void (*onrx)(void *);
Expand Down Expand Up @@ -549,11 +554,10 @@ ROOT void TIMER6_IRQHandler(void)
#endif // USART3_ENABLE || USART4_ENABLE

#if USART_STREAM_ENABLE
static void stream_ontx(void *param)

static void stream_dotx(usart_control_t *ctrl, vsf_stream_t *stream)
{
uint32_t size;
usart_control_t *ctrl = param;
vsf_stream_t *stream = ctrl->tx;
enum usart_idx_t idx = ((uint32_t)ctrl - (uint32_t)usart_control) / sizeof(usart_control_t);

size = vsfhal_usart_tx_get_free_size(idx);
Expand All @@ -575,11 +579,9 @@ static void stream_ontx(void *param)
}
}

static void stream_onrx(void *param)
static void stream_dorx(usart_control_t *ctrl, vsf_stream_t *stream)
{
uint32_t size;
usart_control_t *ctrl = param;
vsf_stream_t *stream = ctrl->rx;
enum usart_idx_t idx = ((uint32_t)ctrl - (uint32_t)usart_control) / sizeof(usart_control_t);

if (stream->op == &vsf_fifo_stream_op) {
Expand All @@ -604,20 +606,69 @@ static void stream_onrx(void *param)
}
}

enum {
VSF_EVT_TX_STREAM_ONRX = VSF_EVT_USER + 0,
VSF_EVT_TX_STREAM_ONTX = VSF_EVT_USER + 1,
VSF_EVT_RX_STREAM_ONRX = VSF_EVT_USER + 2,
VSF_EVT_RX_STREAM_ONTX = VSF_EVT_USER + 3,
};

static void usart_stream_evthandler(vsf_eda_t *eda, vsf_evt_t evt)
{
usart_control_t *ctrl = container_of(eda, usart_control_t, eda);
vsf_stream_t *tx_stream = ctrl->tx;
vsf_stream_t *rx_stream = ctrl->rx;

switch (evt) {
case VSF_EVT_INIT:
break;
case VSF_EVT_TX_STREAM_ONRX:
case VSF_EVT_TX_STREAM_ONTX:
if (VSF_STREAM_GET_DATA_SIZE(tx_stream)) {
stream_dotx(ctrl, tx_stream);
}
break;
case VSF_EVT_RX_STREAM_ONRX:
stream_dorx(ctrl, rx_stream);
break;
case VSF_EVT_RX_STREAM_ONTX:
if (VSF_STREAM_GET_DATA_SIZE(rx_stream)) {
// used to call __vsf_stream_on_write
vsf_stream_set_rx_threshold(rx_stream, rx_stream->rx.threshold);
}
break;
}
}

static void tx_stream_rx_evthandler(void *param, vsf_stream_evt_t evt)
{
usart_control_t *ctrl = param;
vsf_stream_t *stream = ctrl->tx;

if (evt == VSF_STREAM_ON_RX) {
if (VSF_STREAM_GET_DATA_SIZE(stream)) {
stream_ontx(ctrl);
}
vsf_eda_post_evt(&ctrl->eda, VSF_EVT_TX_STREAM_ONRX);
}
}

static void rx_stream_tx_evthandler(void *param, vsf_stream_evt_t evt)
{
usart_control_t *ctrl = param;

if (evt == VSF_STREAM_ON_TX) {
vsf_eda_post_evt(&ctrl->eda, VSF_EVT_RX_STREAM_ONTX);
}
}

//static void rx_stream_tx_evthandler(void *param, vsf_stream_evt_t evt) {}
static void stream_ontx(void *param)
{
usart_control_t *ctrl = param;
vsf_eda_post_evt(&ctrl->eda, VSF_EVT_TX_STREAM_ONTX);
}

static void stream_onrx(void *param)
{
usart_control_t *ctrl = param;
vsf_eda_post_evt(&ctrl->eda, VSF_EVT_RX_STREAM_ONRX);
}

static void vsfhal_usart_stream_fini(enum usart_idx_t idx)
{
Expand All @@ -635,13 +686,19 @@ static void vsfhal_usart_stream_fini(enum usart_idx_t idx)
}
}

void vsfhal_usart_stream_init(enum usart_idx_t idx, int32_t int_priority, vsf_stream_t *tx, vsf_stream_t *rx)
void vsfhal_usart_stream_init(enum usart_idx_t idx, int32_t eda_priority, int32_t int_priority, vsf_stream_t *tx, vsf_stream_t *rx)
{
vsfhal_usart_stream_fini(idx);

if (!tx && !rx)
return;

const vsf_eda_cfg_t cfg = {
.fn.evthandler = usart_stream_evthandler,
.priority = eda_priority,
};
vsf_eda_init_ex(&usart_control[idx].eda, (vsf_eda_cfg_t *)&cfg);

usart_control[idx].tx = tx;
usart_control[idx].rx = rx;
vsfhal_usart_config_cb(idx, int_priority, &usart_control[idx], stream_ontx, stream_onrx);
Expand All @@ -652,8 +709,8 @@ void vsfhal_usart_stream_init(enum usart_idx_t idx, int32_t int_priority, vsf_st
VSF_STREAM_CONNECT_RX(tx);
}
if (rx) {
//rx->tx.evthandler = rx_stream_tx_evthandler;
//rx->tx.param = &usart_control[idx];
rx->tx.evthandler = rx_stream_tx_evthandler;
rx->tx.param = &usart_control[idx];
VSF_STREAM_CONNECT_TX(rx);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ uint16_t vsfhal_usart_tx_get_free_size(enum usart_idx_t idx);
uint16_t vsfhal_usart_rx_bytes(enum usart_idx_t idx, uint8_t *data, uint16_t size);
uint16_t vsfhal_usart_rx_get_data_size(enum usart_idx_t idx);
#if USART_STREAM_ENABLE
void vsfhal_usart_stream_init(enum usart_idx_t idx, int32_t int_priority, vsf_stream_t *tx, vsf_stream_t *rx);
void vsfhal_usart_stream_init(enum usart_idx_t idx, int32_t eda_priority, int32_t int_priority, vsf_stream_t *tx, vsf_stream_t *rx);
#endif
#endif

Expand Down
Loading

0 comments on commit 812c2d1

Please sign in to comment.