add usart0, printf support for GD32VF103C_START board

This commit is contained in:
acevest
2019-10-01 17:18:54 +08:00
parent 25f2aeef9e
commit bd407ece98
8 changed files with 139 additions and 59 deletions

View 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

View 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

View 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);
}

View 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);
}

View File

@@ -144,6 +144,8 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/hello_world/TencentOS_tiny/arch/risc-v/bumblebee}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/hello_world/TencentOS_tiny/kernel/evtdrv/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/hello_world/Application/Inc}&quot;"/>
</option>

View File

@@ -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>

View File

@@ -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 &quot;${INPUTS}&quot;" 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 &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>

View File

@@ -1,58 +1,66 @@
#include "gd32vf103.h"
#include "tos.h"
#define TASK_SIZE 512
k_task_t k_task_task1;
k_task_t k_task_task2;
uint8_t k_task1_stk[TASK_SIZE];
uint8_t k_task2_stk[TASK_SIZE];
int share = 0xCBA7F9;
k_sem_t sem;
void task1(void *pdata)
{
int task_cnt1 = 0;
while (1) {
task_cnt1++;
tos_sem_pend(&sem, ~0U);
gpio_bit_write(GPIOA, GPIO_PIN_7, share % 2);
}
}
void task2(void *pdata)
{
int task_cnt2 = 0;
while (1) {
task_cnt2--;
share++;
tos_task_delay(1000);
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);
tos_knl_init();
tos_task_create(&k_task_task1, "task1", task1, NULL, 3, k_task1_stk, TASK_SIZE, 0);
tos_task_create(&k_task_task2, "task2", task2, NULL, 3, k_task2_stk, TASK_SIZE, 0);
k_err_t err = tos_sem_create(&sem, 1);
if (err != K_ERR_NONE) {
goto die;
}
tos_knl_start();
die:
while (1) {
asm("wfi;");
}
}
#include "mcu_init.h"
#include "tos.h"
#define TASK_SIZE 1024
k_task_t k_task_task1;
k_task_t k_task_task2;
uint8_t k_task1_stk[TASK_SIZE];
uint8_t k_task2_stk[TASK_SIZE];
int share = 0xCBA7F9;
k_sem_t sem;
void task1(void *pdata)
{
int task_cnt1 = 0;
while (1) {
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);
}
}
void task2(void *pdata)
{
int task_cnt2 = 0;
while (1) {
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) {
board_init();
tos_knl_init();
tos_task_create(&k_task_task1, "task1", task1, NULL, 3, k_task1_stk, TASK_SIZE, 0);
tos_task_create(&k_task_task2, "task2", task2, NULL, 3, k_task2_stk, TASK_SIZE, 0);
k_err_t err = tos_sem_create(&sem, 1);
if (err != K_ERR_NONE) {
goto die;
}
tos_knl_start();
die:
while (1) {
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;
}