First, build the compilation environment
1. Download virtual machines VMware and Ubuntu20.0.14
Download VMware Workstation Pro | CN
https://www.vmware.com/en/products/workstation-pro/workstation-pro-evaluation.html
Ubuntu System Downloads | Ubuntu
https://cn.ubuntu.com/download
2. After installing the vm, open the vm and click to create a new virtual machine
3. Select Typical and click Next, select the downloaded Ubuntu, and click Next. After the creation is completed, the virtual machine will automatically install Ubuntu
4. To obtain the OpenHarmony source code after installation, please refer to https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/get-code/sourcecode-acquire.md/
5. Install the compilation tool (1) Install Node.js Open the Ubuntu terminal and enter the command to install:
sudo apt-get install nodejs
sudo apt-get install npm
node --version //查看nodejs版本
npm --version //查看npm版本
(2) Install the Python compilation environment
sudo apt-get install python3.8
sudo apt-get install python3-pip
sudo pip3 install setuptools
sudo pip3 install kconfiglib
sudo pip3 install pycryptodome
sudo pip3 install six --upgrade --ignore-installed six
sudo pip3 install ecdsa
(3) Install SCons
python3 -m pip install scons
scons -v //查看版本
As shown in the figure:
(4) Install hb tool code test
python3 -m pip install --user ohos-build
vim ~/.bashrc //设置环境变量
export PATH=~/.local/bin:$PATH //将以下命令拷贝到.bashrc文件的最后一行,保存并退出
source ~/.bashrc //更新环境变量
Execute "hb -h", if the following information is printed, the installation is successful.
(5) Install gcc_riscv32
Download the gcc_riscv32 image
https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fharmonyos%2Fcompiler%2Fgcc_riscv32%2F7.3.0%2Flinux%2Fgcc_riscv32-linux-7.3.0.tar.gz
Set the environment variable to extract the archive to the root directory
tar -xvf gcc_riscv32-linux-7.3.0.tar.gz -C ~ //文件名需要与下载的文件相匹配
设置环境变量。
vim ~/.bashrc //设置环境变量
export PATH=~/gcc_riscv32/bin:$PATH //将以下命令拷贝到.bashrc文件的最后一行,保存并退出
source ~/.bashrc //更新环境变量
riscv32-unknown-elf-gcc -v //显示版本号,则安装成功
6. Modify the usr_config.mk file <br>file in the OpenHarmony source directory
device/hisilicon/hispark_pegasus/sdk_liteos/build/config/usr_config.mk
CONFIG_I2C_SUPPORT=y
CONFIG_PWM_SUPPORT=y
7. Modify the wifiservice folder <br> file in the OpenHarmony source directory
device/hisilicon/hispark_pegasus/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_hotspot.c
EnableHotspot函数中屏蔽如下字段
//if (SetHotspotIpConfig() != WIFI_SUCCESS) {
// return ERROR_WIFI_UNKNOWN;
//}
地址:device/hisilicon/hispark_pegasus/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device.c
DispatchConnectEvent函数下 屏蔽StaSetWifiNetConfig相关代码行
//StaSetWifiNetConfig(HI_WIFI_EVT_CONNECTED);
//StaSetWifiNetConfig(HI_WIFI_EVT_DISCONNECTED);
2. Create a project folder
1. Create a project demo in OpenHarmony 1.01 version
Create smart_demo in vendor/team_x in the source directory
Add the code we wrote in scr:
2. Initialize the uart serial port <br>First we need to create a program to initialize the uart serial port to initialize GPIO0 as the tx side and GPIO1 as the rx side
void UartInit(void){
RaiseLog(LOG_LEVEL_INFO,"[2022012x01] entry into UartInit");
IoTGpioInit(HAL_WIFI_IOT_IO_NAME_GPIO_0);
HalIoSetFunc(HAL_WIFI_IOT_IO_NAME_GPIO_0, WIFI_IOT_IO_FUNC_GPIO_0_UART1_TXD);
IoTGpioInit(HAL_WIFI_IOT_IO_NAME_GPIO_1);
HalIoSetFunc(HAL_WIFI_IOT_IO_NAME_GPIO_1, WIFI_IOT_IO_FUNC_GPIO_1_UART1_RXD);
hi_uart_attribute uart_attr = {
.baud_rate = UART_BAUD_RATE, /* baud_rate: 9600 */
.data_bits = UART_DATA_BITS, /* data_bits: 8bits */
.stop_bits = UART_STOP_BITS,
.parity = 0,
}
RaiseLog(LOG_LEVEL_INFO,"[2022012x01] uart_init success");
/* Initialize uart driver */
hi_u32 ret = hi_uart_init(HI_UART_IDX_1, &uart_attr, HI_NULL);
if (ret != HI_ERR_SUCCESS)
{
printf("[Dustbin_tes3]Failed to init uart! Err code = %d\n", ret);
return;
}
}
3. Create a thread task
static void *uart_demo_task(void)
{
static uint16_t countSendTimes = 0;
static uint8_t countReceiveTimes = 0;
uartController.isReadBusy = false;
printf("[Initialize uart successfully\n");
UartInit();
while (1)
{
osDelay(50);
UartReceiveMessage();//Collecting Serial Port Data
hi_sleep(SMART_BIN_SLEEP_2500MS);
}
return 0;
}
static void IotMainEntry(void)
{
osThreadAttr_t attr;
RaiseLog(LOG_LEVEL_INFO, "DATA:%s Time:%s \r\n", __FUNCTION__, __DATE__, __TIME__);
// Create the IoT Main task
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL
attr.stack_size = CONFIG_TASK_MAIN_STACKSIZE;
attr.priority = CONFIG_TASK_MAIN_PRIOR;
attr.name = "IoTMain";
(void) osThreadNew((osThreadFunc_t)uart_demo_task, NULL, (const osThreadAttr_t *)&attr);
return;
}
APP_FEATURE_INIT(IotMainEntry);
4. Receive serial data
static void UartReceiveMessage(void)
{
char *recData;
printf("----Listening----\n");
RaiseLog(LOG_LEVEL_INFO,"Start Listening serial port");
if (UartIsBufEmpty())
{
return;
}
if (uartController.isReadBusy)
{
return;
}
uartController.isReadBusy = true;
g_ReceivedDatalen = hi_uart_read(UART_NUM, g_uart_buff, UART_BUFF_SIZE);
if (g_ReceivedDatalen > 0)
{
printf("handleUartReceiveMessage rcvData len:%d,msg:%s.\n", g_ReceivedDatalen, g_uart_buff);
setVoiceCommand();//Setting voice Commands
memset(g_uart_buff, 0, sizeof(g_uart_buff));
g_ReceivedDatalen = 0;
}
uartController.isReadBusy = false;
}
When the hi3861 development board receives the data transmitted by other development boards, it can be printed out through the serial port. For this, a parsing command can be written to execute the corresponding command on the sent string.
Note: When wiring, connect tx to rx of another development board, because in the UART serial port protocol, data transmission and reception are carried out through TX (transmit pin) and RX (receive pin), and the TX transmit pin needs to be connected. The pin is connected to the RX receiving pin of another development board, so it needs to be cross-connected to ensure the normal communication between the two development boards.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。