add usart0, printf support for GD32VF103C_START board
This commit is contained in:
9
board/GD32VF103C_START/BSP/Inc/mcu_init.h
Normal file
9
board/GD32VF103C_START/BSP/Inc/mcu_init.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef __MCU_INIT_H
|
||||
#define __MCU_INIT_H
|
||||
|
||||
#include "gd32vf103.h"
|
||||
#include "usart.h"
|
||||
|
||||
void board_init();
|
||||
|
||||
#endif //__MCU_INIT_H
|
10
board/GD32VF103C_START/BSP/Inc/usart.h
Normal file
10
board/GD32VF103C_START/BSP/Inc/usart.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __USART_H
|
||||
#define __USART_H
|
||||
|
||||
#define USART0_GPIO_TX_PIN GPIO_PIN_9
|
||||
#define USART0_GPIO_RX_PIN GPIO_PIN_10
|
||||
#define USART0_GPIO_PORT GPIOA
|
||||
|
||||
void usart0_init(int baud);
|
||||
|
||||
#endif // __USART_H
|
11
board/GD32VF103C_START/BSP/Src/mcu_init.c
Normal file
11
board/GD32VF103C_START/BSP/Src/mcu_init.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "mcu_init.h"
|
||||
|
||||
void board_init() {
|
||||
rcu_periph_clock_enable(RCU_GPIOA);
|
||||
|
||||
gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
|
||||
|
||||
gpio_bit_reset(GPIOA, GPIO_PIN_7);
|
||||
|
||||
usart0_init(115200);
|
||||
}
|
30
board/GD32VF103C_START/BSP/Src/usart.c
Normal file
30
board/GD32VF103C_START/BSP/Src/usart.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "gd32vf103.h"
|
||||
#include "usart.h"
|
||||
void usart0_init(int baud)
|
||||
{
|
||||
uint32_t com = USART0;
|
||||
|
||||
/* enable GPIO clock */
|
||||
rcu_periph_clock_enable(RCU_GPIOA);
|
||||
|
||||
/* enable USART clock */
|
||||
rcu_periph_clock_enable(RCU_USART0);
|
||||
|
||||
/* connect port to USARTx_Tx */
|
||||
gpio_init(USART0_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART0_GPIO_TX_PIN);
|
||||
|
||||
/* connect port to USARTx_Rx */
|
||||
gpio_init(USART0_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART0_GPIO_RX_PIN);
|
||||
|
||||
/* USART configure */
|
||||
usart_deinit(com);
|
||||
usart_baudrate_set(com, baud);
|
||||
usart_word_length_set(com, USART_WL_8BIT);
|
||||
usart_stop_bit_set(com, USART_STB_1BIT);
|
||||
usart_parity_config(com, USART_PM_NONE);
|
||||
usart_hardware_flow_rts_config(com, USART_RTS_DISABLE);
|
||||
usart_hardware_flow_cts_config(com, USART_CTS_DISABLE);
|
||||
usart_receive_config(com, USART_RECEIVE_ENABLE);
|
||||
usart_transmit_config(com, USART_TRANSMIT_ENABLE);
|
||||
usart_enable(com);
|
||||
}
|
@@ -145,6 +145,8 @@
|
||||
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/hello_world/TencentOS_tiny/kernel/evtdrv/include}""/>
|
||||
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/hello_world/Application/Inc}""/>
|
||||
|
||||
</option>
|
||||
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs.1188292994" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols">
|
||||
|
@@ -39,6 +39,16 @@
|
||||
<type>2</type>
|
||||
<locationURI>virtual:/virtual</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Application/Inc</name>
|
||||
<type>2</type>
|
||||
<locationURI>TOP_DIR/board/GD32VF103C_START/BSP/Inc</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Application/Src</name>
|
||||
<type>2</type>
|
||||
<locationURI>TOP_DIR/board/GD32VF103C_START/BSP/Src</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Application/tos_config.h</name>
|
||||
<type>1</type>
|
||||
|
@@ -11,7 +11,7 @@
|
||||
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1367083006174630109" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1310167466484573552" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "gd32vf103.h"
|
||||
#include "mcu_init.h"
|
||||
#include "tos.h"
|
||||
|
||||
#define TASK_SIZE 512
|
||||
#define TASK_SIZE 1024
|
||||
k_task_t k_task_task1;
|
||||
k_task_t k_task_task2;
|
||||
uint8_t k_task1_stk[TASK_SIZE];
|
||||
@@ -14,7 +14,7 @@ void task1(void *pdata)
|
||||
{
|
||||
int task_cnt1 = 0;
|
||||
while (1) {
|
||||
task_cnt1++;
|
||||
printf("hello world from %s cnt: %d\n", __func__, task_cnt1++);
|
||||
tos_sem_pend(&sem, ~0U);
|
||||
gpio_bit_write(GPIOA, GPIO_PIN_7, share % 2);
|
||||
}
|
||||
@@ -24,20 +24,18 @@ void task2(void *pdata)
|
||||
{
|
||||
int task_cnt2 = 0;
|
||||
while (1) {
|
||||
task_cnt2--;
|
||||
share++;
|
||||
tos_task_delay(1000);
|
||||
share++;
|
||||
for(int i=0; i<5; i++) {
|
||||
printf("hello world from %s cnt: %08x\n", __func__, task_cnt2--);
|
||||
tos_task_delay(200);
|
||||
}
|
||||
tos_sem_post(&sem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void main(void) {
|
||||
rcu_periph_clock_enable(RCU_GPIOA);
|
||||
|
||||
gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
|
||||
|
||||
gpio_bit_reset(GPIOA, GPIO_PIN_7);
|
||||
board_init();
|
||||
|
||||
tos_knl_init();
|
||||
|
||||
@@ -56,3 +54,13 @@ die:
|
||||
asm("wfi;");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int _put_char(int ch)
|
||||
{
|
||||
usart_data_transmit(USART0, (uint8_t) ch );
|
||||
while (usart_flag_get(USART0, USART_FLAG_TBE)== RESET){
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
Reference in New Issue
Block a user