本文來源電子發燒友社區,作者:盧松濤, 帖子地址:https://bbs.elecfans.com/jishu_2310064_1_1.html
接上文|# 【開鴻智谷NiobeU4開發板免費試用體驗】Demo例程;|
感謝開鴻智谷研發人員依然小燁哥和?大佬們的支持指導。
想用開鴻智谷NiobeU4開發板資源 (GPIO02、GPIO27)輸出,(ADC1_CH0上有SW4和SW5兩個按鍵)模擬輸入,板(GPIO02控制雙色LED的紅色、GPIO27控制雙色LED的藍色)LED,板(ADC1_CH0上有SW4和SW5兩個按鍵)button,來通過光耦中間繼電器控制加熱設備。
開發自己的應用程序,
方法1:
- 需要在menuconfig中關閉 use openvalley niobeu4 application選項,然后在niobeu4_src/vendor/openvalley/niobeu4/demo/BUILD.gn文件中modules選項中填入自己的應用程序目錄名,目錄下內容可參考其它示例程序。
方法2:
- 拷貝一份demo 案例目錄重新命名新案例目錄名,
- 修改niobeu4_src/vendor/openvalley/niobeu4/demo/Kconfig.liteos_m.applications
- 修改新案例目錄名下.application_config
- 修改新案例目錄名下BUILD.gn
- 修改新案例目錄名下程序
準備采用 方法2。
控溫程序(1)
起動系統及MobaXterm,
1. 新案例目錄
拷貝一份niobeu4_src/vendor/openvalley/niobeu4/demo/002_system_los_thread
重新命名 niobeu4_src/vendor/openvalley/niobeu4/demo/301_user
2. 修改Kconfig.liteos_m.applications
在MobaXterm右側
在niobeu4_src/vendor/openvalley/niobeu4/demo/目錄
下打開Kconfig.liteos_m.applications文件,在最后的位置添加default "301_user" if NIOBEU4_APPLICATION_301:
# Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
config USE_OPENVALLEY_APPLICATION
bool "use openvalley niobeu4 application"
default n
help
This is a switch for use openvalley niobeu4 application.
If you want to write your application code, please close it.
choice
prompt "niobeu4 application choose"
depends on USE_OPENVALLEY_APPLICATION
default NIOBEU4_APPLICATION_001
help
This is a choose for application name
orsource "*/.application_config"
endchoice
config NIOBEU4_APPLICATION_NAME
string
depends on USE_OPENVALLEY_APPLICATION
default "001_quick_start" if NIOBEU4_APPLICATION_001
default "002_system_los_thread" if NIOBEU4_APPLICATION_002
default "003_system_los_timer" if NIOBEU4_APPLICATION_003
default "004_system_los_event" if NIOBEU4_APPLICATION_004
default "005_system_los_mutex" if NIOBEU4_APPLICATION_005
default "006_system_los_semp" if NIOBEU4_APPLICATION_006
default "007_system_los_message" if NIOBEU4_APPLICATION_007
default "101_hdf_adc" if NIOBEU4_APPLICATION_101
default "102_hdf_gpio" if NIOBEU4_APPLICATION_102
default "103_hdf_uart" if NIOBEU4_APPLICATION_103
default "104_hdf_watchdog" if NIOBEU4_APPLICATION_104
default "105_hdf_pwm" if NIOBEU4_APPLICATION_105
default "106_hdf_i2c" if NIOBEU4_APPLICATION_106
default "107_hdf_spi" if NIOBEU4_APPLICATION_107
default "201_bluetooth" if NIOBEU4_APPLICATION_201
default "202_wifi" if NIOBEU4_APPLICATION_202
default "301_user" if NIOBEU4_APPLICATION_301
3. 修改.application_config
在MobaXterm右側
在niobeu4_src/vendor/openvalley/niobeu4/demo/301_user目錄
下打開# .application_config文件,修改內容:
# Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
config NIOBEU4_APPLICATION_301
bool "301_user"
select DRIVERS
select DRIVERS_HDF
select DRIVERS_HDF_PLATFORM
select DRIVERS_HDF_CONFIG_MACRO
select DRIVERS_HDF_PLATFORM_GPIO
select DRIVERS_HDF_PLATFORM_ADC
4. 修改BUILD.gn
在MobaXterm右側
在niobeu4_src/vendor/openvalley/niobeu4/demo/301_user目錄
下打開BUILD.gn文件,修改內容:
# Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("http://kernel/liteos_m/liteos.gni")
assert(defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO), "Must Config LOSCFG_DRIVERS_HDF_CONFIG_MACRO in kernel/liteos_m menuconfig!")
assert(defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO), "Must Config LOSCFG_DRIVERS_HDF_PLATFORM_GPIO in kernel/liteos_m menuconfig!")
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"os_thread_example.c"
]
include_dirs = [
"http://kernel/liteos_m/kernel/include"
"http://drivers/hdf_core/framework/include/platform/",
"http://drivers/hdf_core/framework/include/utils/",
"http://drivers/hdf_core/framework/support/platform/include/gpio",
"http://drivers/hdf_core/adapter/khdf/liteos_m/osal/include/",
"http://drivers/hdf_core/framework/include/core/",
"http://drivers/hdf_core/framework/include/osal/",
"http://device/soc/esp/esp32/components/esp_adc_cal/include/",
"http://device/soc/esp/esp32/components/driver/esp32/include/"
]
}
5. 修改主程序
修改新案例目錄名下 主程序
在MobaXterm右側打
在niobeu4_src/vendor/openvalley/niobeu4/demo/301_user
下打開os_thread_example.c文件,修改內容:
/*
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include
#include
#include
#include "los_task.h"
#include "ohos_run.h"
#include "gpio_types.h"
#include "gpio_if.h"
#include "cmsis_os2.h"//cmsis 2.0 接口osThreadNew()
#include "hdf_log.h"
#include "ohos_run.h"
#include "esp_adc_cal.h"
UINT32 g_taskHiId;
UINT32 g_taskLoId;
#define TSK_PRIOR_HI 24
#define TSK_PRIOR_LO 25
#define SYS_DELAY_TICKS 200
#define TASK_STACK_SIZE 4096
#define TASK_PRIO 25
#define KEY_LED_OFF 0
#define KEY_LED_ON 1
//在hcs文件中對應具體的GPIO口
#define RED_LED_PIN_INDEX 0 // 紅色LED
#define BLUE_LED_PIN_INDEX 1 // 藍色LED
#define PWR_SW_PIN_INDEX 2 // VCC_3.3 電源使能
osThreadId_t g_taskID = NULL;
UINT32 button_o=0;
//key_led_test
UINT32 Example_TaskHi(UINT32 arg)
{
int raw;
GpioSetDir(PWR_SW_PIN_INDEX, GPIO_DIR_OUT); // 設置VCC_3.3電源使能
GpioWrite(PWR_SW_PIN_INDEX, KEY_LED_ON);
GpioSetDir(RED_LED_PIN_INDEX, GPIO_DIR_OUT); // 紅燈對應GPIO配置為輸出
GpioWrite(RED_LED_PIN_INDEX, KEY_LED_OFF);//默認紅燈為關
GpioSetDir(BLUE_LED_PIN_INDEX, GPIO_DIR_OUT); // 藍燈對應GPIO配置為輸出
GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_OFF);//默認藍燈為關
HDF_LOGE("[key_led] GPIO initn");
//因為niobeu4開發板ADC hdf代碼需要重新適配所以先是用esp32原生接口
adc1_config_width(ADC_WIDTH_12Bit); //設置采樣精度,2^12=4096
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11); //設置電壓采樣范圍
HDF_LOGE("[key_led] ADC initn");
while (1)
{
raw = adc1_get_raw(ADC1_CHANNEL_0); //獲取ADC1通道0的原始值
UINT32 button_s=0;
//HDF_LOGE("[key_led] raw: %dn", raw);
if (raw < 100)
{
LOS_Msleep(30);
raw = adc1_get_raw(ADC1_CHANNEL_0); //獲取ADC1通道0的原始值
if (raw < 100)
{
button_o=55;
button_s++;
HDF_LOGE("[key_led] sw4 pressed raw: %dn", raw);
while(adc1_get_raw(ADC1_CHANNEL_0)< 100){ LOS_Msleep(30);
button_s++;
if (button_s>34){
// HDF_LOGE("[key_led] sw4 pressed long: %dn", raw);
}
if (button_s>240){button_s=240;}
// GpioWrite(RED_LED_PIN_INDEX, KEY_LED_ON);
// GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_OFF);
}
button_s=0;
HDF_LOGE("[key_led] sw4 pressed up: %dn", raw);
// GpioWrite(RED_LED_PIN_INDEX, KEY_LED_ON);
// GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_OFF);
}
}
else if (raw >2000 && raw < 3000)
{
LOS_Msleep(30);
raw = adc1_get_raw(ADC1_CHANNEL_0); //獲取ADC1通道0的原始值
if (raw >2000 && raw < 3000)
{
button_o=66;
button_s++;
HDF_LOGE("[key_led] sw5 pressed raw: %dn", raw);
raw = adc1_get_raw(ADC1_CHANNEL_0); //獲取ADC1通道0的原始值
while(raw >2000 && raw < 3000){ LOS_Msleep(30);
button_s++;
if (button_s>34){
// HDF_LOGE("[key_led] sw5 pressed long: %dn", raw);
}
if (button_s>240){button_s=240;}
raw = adc1_get_raw(ADC1_CHANNEL_0);
// GpioWrite(RED_LED_PIN_INDEX, KEY_LED_ON);
// GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_OFF);
}
button_s=0;
HDF_LOGE("[key_led] sw5 pressed up: %dn", raw);
// GpioWrite(RED_LED_PIN_INDEX, KEY_LED_ON);
// GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_OFF);
}
// HDF_LOGE("[key_led] sw5 pressed raw: %dn", raw);
// GpioWrite(RED_LED_PIN_INDEX, KEY_LED_OFF);
// GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_ON);
}
LOS_Msleep(SYS_DELAY_TICKS);
}
}
/* 低優先級任務入口函數 */
UINT32 Example_TaskLo(UINT32 arg)
{uint16_t key_state = 0;
while(1){
LOS_Msleep(30);
if (button_o==55){
GpioRead(RED_LED_PIN_INDEX, &key_state);
button_o=0;
HDF_LOGE("[key_state] sw4 : %dn", key_state);
if (key_state){
GpioWrite(RED_LED_PIN_INDEX, KEY_LED_OFF);
HDF_LOGE("[RED_LED] sw4 : Offn");
}
else{
GpioWrite(RED_LED_PIN_INDEX, KEY_LED_ON);
HDF_LOGE("[RED_LED] sw4 : ONn");
}
}
// GpioWrite(RED_LED_PIN_INDEX, KEY_LED_ON);
// GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_OFF);
if (button_o==66){
GpioRead(BLUE_LED_PIN_INDEX, &key_state);
button_o=0;
HDF_LOGE("[key_state] sw5 : %dn", key_state);
if (key_state){GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_OFF);
HDF_LOGE("[RED_LED] sw5 : Offn");
}
else{
GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_ON);
HDF_LOGE("[RED_LED] sw5 : ONn");}
}
// UINT32 ret;
// printf("Enter TaskLo Handler.n");
// /* 延時100個Ticks,延時后該任務會掛起,執行剩余任務中最高優先級的任務 */
// ret = LOS_TaskDelay(100);
// if (ret != LOS_OK) {
// printf("Delay TaskLo Failed.n");
// return LOS_NOK;
// }
//
// printf("TaskHi LOS_TaskSuspend Success.n");
//
// /* 恢復被掛起的任務g_taskHiId */
// ret = LOS_TaskResume(g_taskHiId);
// if (ret != LOS_OK) {
// printf("Resume TaskHi Failed.n");
// return LOS_NOK;
// }
// return ret;
}
/* 任務測試入口函數,創建兩個不同優先級的任務 */
UINT32 Example_TskCaseEntry(VOID)
{
UINT32 ret;
TSK_INIT_PARAM_S initParam = {0};
/* 鎖任務調度,防止新創建的任務比本任務高而發生調度 */
LOS_TaskLock();
printf("LOS_TaskLock() Success!n");
UINT32 curTaskID = LOS_CurTaskIDGet();
TSK_INFO_S taskInfo;
ret = LOS_TaskInfoGet(curTaskID, &taskInfo);
if (ret == LOS_OK) {
printf("curTask prio = %dn", taskInfo.usTaskPrio);
}
initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_TaskHi;
initParam.usTaskPrio = TSK_PRIOR_HI;
initParam.pcName = "TaskHi";
initParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
initParam.uwResved = LOS_TASK_ATTR_JOINABLE; /* detach 屬性 允許使用LOS_TaskJoin */
/* 創建高優先級任務,由于鎖任務調度,任務創建成功后不會馬上執行 */
ret = LOS_TaskCreate(&g_taskHiId, &initParam);
if (ret != LOS_OK) {
LOS_TaskUnlock();
printf("Example_TaskHi create Failed!n");
return LOS_NOK;
}
printf("Example_TaskHi create Success!n");
initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_TaskLo;
initParam.usTaskPrio = TSK_PRIOR_LO;
initParam.pcName = "TaskLo";
initParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
/* 創建低優先級任務,由于鎖任務調度,任務創建成功后不會馬上執行 */
ret = LOS_TaskCreate(&g_taskLoId, &initParam);
if (ret != LOS_OK) {
LOS_TaskUnlock();
printf("Example_TaskLo create Failed!n");
return LOS_NOK;
}
printf("Example_TaskLo create Success!n");
/* 解鎖任務調度,此時會發生任務調度,執行就緒隊列中最高優先級任務 */
LOS_TaskUnlock();
// ret = LOS_TaskJoin(g_taskHiId, NULL);
// if (ret != LOS_OK) {
// printf("Join Example_TaskHi Failed!n");
// } else {
// printf("Join Example_TaskHi Success!n");
// }
return LOS_OK;
}
OHOS_APP_RUN(Example_TskCaseEntry);
構建源碼
- 進入源碼根目錄,執行hb set命令并選擇openvalley下的iotlink。
hb set
- 執行hb build –f腳本構建產生固件。
hb build –f
- 如圖所示,編譯成功,并查看生產的固件。
構建成功會提示類似如下信息。
[OHOS INFO] iotlink build success
[OHOS INFO] cost time: 0:03:28
- 查看生成的固件。
ls /home/lst/niobeu4_src/out/niobeu4/iotlink/bin/
| 固件名稱 | 用途 |
| ---------------- | ------------------------------- |
| OHOS_Image.bin | OpenHarmony內核及應用鏡像文件 |
| bootloader.bin | 啟動引導鏡像文件 |
| partitions.bin | 分區表鏡像文件 |
燒錄鏡像
- 通過MobaXterm軟件ssh登錄服務器,將生成的文件Download到Windows系統下,如圖所示。
Windows下可以使用Flash_Download_Tool
工具進行燒錄,點擊這里開始下載。
- 在windows下解壓flash_download_tool_3.9.2.rar。
- 雙擊解壓后得到的燒錄工具flash_download_tool_3.9.2.exe,chipType選擇 ESP32, workMode選擇 develop,進入主界面。
圖4Flash_Download_Tool
打開頁面圖
- 連接開發板的TypeC口到PC,查看設備管理器,確定串口端口號。
圖5設備管理器圖
- 進入下載頁面,填入需要燒錄的 bin 文件和對應的燒錄地址,并根據自己實際 需求填入 SPI SPEED、SPI MODE、COM 及 BAUD。
固件對應燒錄地址如下。
//out/niobeu4/iotlink/bin/bootloader.bin ----------> 0x1000
//out/niobeu4/iotlink/bin/partitions.bin ----------> 0x8000
//out/niobeu4/iotlink/OHOS_Image.bin ----------> 0x10000
圖6燒錄設置頁面圖
-
點擊 START 開始下載。下載過程中,下載工具會讀取 flash 的信息和芯片的 MAC 地址。我們可以通過勾選框選擇是否燒錄該文件,一般我們在首次燒錄時會全部燒錄,為了加快開發效率,調試時只需燒錄
OHOS_Image.bin
即可。下載完成后,可以看到如下提示。
圖7燒錄成功頁面圖
運行鏡像
燒錄完成后需要按下復位鍵復位設備,程序才會啟動。
達到預期狀態。
開發板體驗視頻,詳見作者原帖子文章。
-
開鴻智谷
+關注
關注
2文章
125瀏覽量
1150 -
NiobeU4
+關注
關注
3文章
31瀏覽量
505
發布評論請先 登錄
相關推薦
評論