fix the project

This commit is contained in:
supperthomas 2021-02-11 10:57:00 +08:00
parent abcac46fcf
commit 864d1dd703
6 changed files with 89 additions and 88 deletions

View File

@ -11,27 +11,22 @@
#include <rtthread.h>
#include <rtdevice.h>
#define DK_BOARD_LED_1 13
#define DK_BOARD_LED_2 14
#include "gpio.h"
const gpio_cfg_t led_pin[] = {
const gpio_cfg_t led_pin[] =
{
{PORT_0, PIN_13, GPIO_FUNC_OUT, GPIO_PAD_NONE},
};
int main(void)
{
int count = 1;
int count = 1;
GPIO_Config(&led_pin[0]);
//rt_pin_mode(DK_BOARD_LED_1, PIN_MODE_OUTPUT);
GPIO_OutSet(&led_pin[0]);
while (count++)
{
//rt_pin_write(DK_BOARD_LED_1, PIN_HIGH);
{
rt_thread_mdelay(500);
GPIO_OutToggle(&led_pin[0]);
//rt_pin_write(DK_BOARD_LED_1, PIN_LOW);
//rt_thread_mdelay(500);
}
return RT_EOK;
}
}

View File

@ -12,10 +12,6 @@
#include "uart.h"
#include "rtdevice.h"
#define BUFF_SIZE 10
uint8_t rxdata[BUFF_SIZE]={0};
#define UART0_CONFIG \
{ \
.name = "uart0", \
@ -23,7 +19,7 @@ uint8_t rxdata[BUFF_SIZE]={0};
.irq_type = MXC_UART_GET_IRQ(0), \
}
#define UART1_CONFIG \
{ \
.name = "uart1", \
@ -87,13 +83,13 @@ static struct mcu_uart uart_obj[sizeof(uart_config) / sizeof(uart_config[0])] =
void UART1_IRQHandler(void)
{
rt_interrupt_enter();
rt_hw_serial_isr(&(uart_obj[UART1_INDEX].serial), RT_SERIAL_EVENT_RX_IND);
/* leave interrupt */
uint32_t intst = 0;
intst = MXC_UART1->int_fl;
MXC_UART1->int_fl = intst;
rt_interrupt_leave();
}
#endif
@ -101,16 +97,16 @@ void UART1_IRQHandler(void)
#ifdef BSP_USING_UART0
void UART0_IRQHandler(void)
{
//UART_Handler(MXC_UART0);
/* enter interrupt */
rt_interrupt_enter();
rt_hw_serial_isr(&(uart_obj[UART0_INDEX].serial), RT_SERIAL_EVENT_RX_IND);
/* leave interrupt */
/* clear flags */
uint32_t intst = 0;
intst = MXC_UART0->int_fl;
MXC_UART0->int_fl = intst;
/* leave interrupt */
rt_interrupt_leave();
}
@ -119,11 +115,12 @@ void UART0_IRQHandler(void)
static rt_err_t mcu_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
{
int error, i;
int error;
struct mcu_uart *uart;
RT_ASSERT(serial != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
const sys_cfg_uart_t sys_uart_cfg = {
const sys_cfg_uart_t sys_uart_cfg =
{
MAP_A,
UART_FLOW_DISABLE,
};
@ -136,10 +133,12 @@ static rt_err_t mcu_configure(struct rt_serial_device *serial, struct serial_con
mcu_cfg.size = UART_DATA_SIZE_8_BITS;
mcu_cfg.flow = UART_FLOW_CTRL_EN;
mcu_cfg.pol = UART_FLOW_POL_EN;
error= UART_Init(uart->handle, &mcu_cfg, &sys_uart_cfg);
error = UART_Init(uart->handle, &mcu_cfg, &sys_uart_cfg);
if (error != E_NO_ERROR) {
rt_kprintf("Error initializing UART %d\n", error);
while(1) {}
}
return RT_EOK;
}
@ -155,7 +154,6 @@ static rt_err_t mcu_control(struct rt_serial_device *serial, int cmd, void *arg)
/* disable interrupt */
case RT_DEVICE_CTRL_CLR_INT:
/* disable rx irq */
// NVIC_DisableIRQ(uart->config->irq_type);
NVIC_ClearPendingIRQ(uart->config->irq_type);
NVIC_DisableIRQ(uart->config->irq_type);
/* disable interrupt */
@ -164,31 +162,23 @@ static rt_err_t mcu_control(struct rt_serial_device *serial, int cmd, void *arg)
/* enable interrupt */
case RT_DEVICE_CTRL_SET_INT:
/* enable rx irq */
NVIC_SetPriority(uart->config->irq_type, 1);
NVIC_EnableIRQ(uart->config->irq_type);
/* enable interrupt */
uart->handle->ctrl |= 0x05 << MXC_F_UART_CTRL_RX_TO_POS;
uart->handle->int_en |= MXC_F_UART_INT_EN_RX_FIFO_THRESH | MXC_F_UART_INT_EN_RX_TIMEOUT;
#define UART_ER_IE (MXC_F_UART_INT_EN_RX_FRAME_ERROR | \
MXC_F_UART_INT_EN_RX_PARITY_ERROR | \
MXC_F_UART_INT_EN_RX_OVERRUN )
uart->handle->int_en |= UART_ER_IE;
NVIC_SetPriority(uart->config->irq_type, 1);
NVIC_EnableIRQ(uart->config->irq_type);
/* enable interrupt */
uart->handle->ctrl |= 0x05 << MXC_F_UART_CTRL_RX_TO_POS;
uart->handle->int_en |= MXC_F_UART_INT_EN_RX_FIFO_THRESH | \
MXC_F_UART_INT_EN_RX_TIMEOUT;
uart->handle->thresh_ctrl=MXC_UART_FIFO_DEPTH<<
MXC_F_UART_THRESH_CTRL_RX_FIFO_THRESH_POS;
break;
uart->handle->int_en |= MXC_F_UART_INT_EN_RX_FRAME_ERROR | \
MXC_F_UART_INT_EN_RX_PARITY_ERROR | \
MXC_F_UART_INT_EN_RX_OVERRUN ;
#ifdef RT_SERIAL_USING_DMA
case RT_DEVICE_CTRL_CONFIG:
stm32_dma_config(serial, ctrl_arg);
uart->handle->thresh_ctrl = MXC_UART_FIFO_DEPTH <<
MXC_F_UART_THRESH_CTRL_RX_FIFO_THRESH_POS;
break;
#endif
case RT_DEVICE_CTRL_CLOSE:
// if (HAL_UART_DeInit(&(uart->handle)) != HAL_OK )
// {
// RT_ASSERT(0)
// }
UART_Shutdown(uart->handle);
break;
}
@ -214,18 +204,14 @@ static int mcu_getc(struct rt_serial_device *serial)
ch = -1;
if(UART_NumReadAvail(uart->handle))
if (UART_NumReadAvail(uart->handle))
{
ch = UART_ReadByte(uart->handle);
ch = UART_ReadByte(uart->handle);
}
return ch;
}
static const struct rt_uart_ops mcu_uart_ops =
{
.configure = mcu_configure,

View File

@ -5,11 +5,10 @@
*
* Change Logs:
* Date Author Notes
* 2018.10.30 SummerGift first version
* 2019.03.05 whj4674672 add stm32h7
* 2020-10-14 Dozingfiretruck Porting for stm32wbxx
* 2021-02-08 Supperthomas first version
*/
#ifndef __DRV_USART_H__
#define __DRV_USART_H__

View File

@ -32,49 +32,36 @@ void SysTick_Handler(void)
rt_interrupt_leave();
}
void SysTick_Configuration(void)
void rt_hw_systick_init(void)
{
uint32_t error;
error = SYS_SysTick_Config(SYS_SysTick_GetFreq()/RT_TICK_PER_SECOND, 1, MXC_TMR0);
error = SYS_SysTick_Config(SYS_SysTick_GetFreq() / RT_TICK_PER_SECOND, 1, MXC_TMR0);
if (error != E_NO_ERROR) {
if (error != E_NO_ERROR)
{
printf("ERROR: Ticks is not valid");
}
}
mxc_uart_regs_t *ConsoleUART = MXC_UART_GET_UART(1);
const sys_cfg_uart_t console_uart_sys_cfg = {
MAP_A,
UART_FLOW_DISABLE,
};
void rt_hw_board_init(void)
{
// rt_hw_interrupt_enable(0);
// sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
/* Activate deep sleep mode */
SysTick_Configuration();
rt_hw_systick_init();
#if defined(RT_USING_HEAP)
rt_system_heap_init((void *)(0x20000000+16*1024), (void *)(0x20000000+64*1024));
rt_system_heap_init((void *)(HEAP_BEGIN), (void *)(HEAP_END));
#endif
#ifdef RT_USING_SERIAL
rt_hw_usart_init();
#endif
#ifdef RT_USING_CONSOLE
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
}

View File

@ -4,10 +4,13 @@
#include <rtthread.h>
#include <rthw.h>
#define MCU_FLASH_SIZE MCU_FLASH_SIZE_KB*1024
#define MCU_FLASH_END_ADDRESS ((uint32_t)(MCU_FLASH_START_ADDRESS + MCU_FLASH_SIZE))
#define MCU_SRAM_SIZE MCU_SRAM_SIZE_KB*1024
#define MCU_SRAM_END_ADDRESS (MCU_SRAM_START_ADDRESS + MCU_SRAM_SIZE)
#define MCU_FLASH_START_ADRESS ((uint32_t)0x0)
#define MCU_FLASH_SIZE_KB (256)
#define MCU_FLASH_END_ADDRESS ((uint32_t)(MCU_FLASH_START_ADRESS + MCU_FLASH_SIZE*1024))
#define MCU_SRAM_SIZE_KB (96)
#define MCU_SRAM_START (0x20000000)
#define MCU_SRAM_END (MCU_SRAM_START + MCU_SRAM_SIZE_KB * 1024)
#if defined(__CC_ARM) || defined(__CLANG_ARM)
extern int Image$$RW_IRAM1$$ZI$$Limit;
@ -20,8 +23,7 @@ extern int __bss_end__;
#define HEAP_BEGIN ((void *)&__bss_end__)
#endif
#define HEAP_SIZE 16*1024
#define HEAP_END (HEAP_BEGIN + HEAP_SIZE)
#define HEAP_END MCU_SRAM_END
void rt_hw_board_init(void);

View File

@ -229,6 +229,38 @@
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>5</Number>
<Type>0</Type>
<LineNumber>209</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\applications\drv_uart.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>6</Number>
<Type>0</Type>
<LineNumber>220</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\applications\drv_uart.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
<Ww>
@ -562,7 +594,7 @@
<Group>
<GroupName>CPU</GroupName>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>