Skip to content

Commit

Permalink
feat: add barebone usb demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sakumisu committed May 16, 2024
1 parent 5362d68 commit 7f237b5
Show file tree
Hide file tree
Showing 14 changed files with 888 additions and 7 deletions.
3 changes: 3 additions & 0 deletions samples/hpm/barebone_uart/inc/csh_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@
/*!< enable macro export symbol table */
#define CONFIG_CSH_SYMTAB 1

/*!< print buffer size */
#define CONFIG_CSH_PRINT_BUFFER_SIZE 512

#endif
6 changes: 3 additions & 3 deletions samples/hpm/barebone_uart/src/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static chry_shell_t csh;
static UART_Type *shell_uart = NULL;
static bool login = false;
static chry_ringbuffer_t shell_rb;
static ATTR_PLACE_AT_NONCACHEABLE uint8_t mempool[256];
static uint8_t mempool[1024];

void shell_uart_isr(void)
{
Expand Down Expand Up @@ -105,8 +105,8 @@ int shell_init(UART_Type *uart, bool need_login)
csh_init.uid = 0;
csh_init.user[0] = "cherry";

/*!< The port hash function is required,
and the strcmp attribute is used weakly by default,
/*!< The port hash function is required,
and the strcmp attribute is used weakly by default,
int chry_shell_port_hash_strcmp(const char *hash, const char *str); */
csh_init.hash[0] = "12345678"; /*!< If there is no password, set to NULL */
csh_init.host = BOARD_NAME;
Expand Down
28 changes: 28 additions & 0 deletions samples/hpm/barebone_usb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2021 HPMicro
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required(VERSION 3.13)

set(CONFIG_CHERRYRB 1)
set(CONFIG_CHERRYUSB 1)
set(CONFIG_USB_DEVICE 1)
set(CONFIG_USB_DEVICE_CDC 1)

find_package(hpm-sdk REQUIRED HINTS $ENV{HPM_SDK_BASE})
project(cherryshell)

sdk_compile_options("-O2")

sdk_inc(inc)
sdk_inc(../../../)

sdk_app_src(
src/main.c
src/shell.c
../../../chry_shell.c
../../../builtin/help.c
../../../builtin/shsize.c
../../../builtin/login.c
)

generate_ses_project()
63 changes: 63 additions & 0 deletions samples/hpm/barebone_usb/README_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Cherry Shell Barebone USB

## Overview

The Cherry Shell Barebone example project demonstrates the basic usage of shell in bare-metal mode. In this project, you need to connect via USB PORT, and the shell requires a login. The default password is 12345678. After entering the password and pressing Enter, you will enter the shell. You can use the "help" command to view the available commands and variables.

Please refrain from using USB PORT assistants and consider downloading and using [MobaXterm](https://mobaxterm.mobatek.net/download.html)

## Board Setting

No special settings

## Running the example

- After the project runs successfully, the serial terminal will output the following information:

```console
login as: cherry
cherry@hpm5301evklite's password:
other task interval 5S
other task interval 5S
other task interval 5S
other task interval 5S
other task interval 5S

```

- If you manually enter the correct password "12345678" and press Enter, the terminal will output the following information:

```console
login as: cherry
cherry@hpm5301evklite's password:
other task interval 5S
other task interval 5S
other task interval 5S
other task interval 5S
other task interval 5S

welcome to cherry shell
cherry@hpm5301evklite:/$
```

- If you manually enter the command "help" and press Enter, the terminal will output the following information:

```console
cherry@hpm5301evklite:/$ help
total function 6
test -> /bin
toggle_led -> /bin
write_led -> /bin
exit -> /sbin
help -> /sbin
shsize -> /sbin

total variable 2
$PATH r- 11
$ZERO r- 1
cherry@hpm5301evklite:/$
```

- If you manually enter the command "toggle_led" and press Enter, the LED will toggle.
- If you manually enter the command "write_led 1" and press Enter, the LED will turn on.
- If you manually enter the command "write_led 0" and press Enter, the LED will turn off.
62 changes: 62 additions & 0 deletions samples/hpm/barebone_usb/README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Cherry Shell Barebone USB

## 概述

Cherry Shell Barebone示例工程展示了shell的裸机模式基本使用。在这个工程中,需要连接 USB,shell默认需要登陆,密码为12345678。输入密码后回车,进入shell,输入help可以查看命令和变量。
请勿使用串口助手,推荐下载使用 [MobaXterm](https://mobaxterm.mobatek.net/download.html)

## 硬件设置

无特殊设置

## 运行现象

- 当工程正确运行后,串口终端会输出如下信息:

```console
login as: cherry
cherry@hpm5301evklite's password:
other task interval 5S
other task interval 5S
other task interval 5S
other task interval 5S
other task interval 5S

```

- 如果此时通过键盘手动输入正确密码"12345678"并回车,终端会输出如下信息:

```console
login as: cherry
cherry@hpm5301evklite's password:
other task interval 5S
other task interval 5S
other task interval 5S
other task interval 5S
other task interval 5S

welcome to cherry shell
cherry@hpm5301evklite:/$
```

- 如果此时通过键盘手动输入命令"help"并回车,终端会输出如下信息:

```console
cherry@hpm5301evklite:/$ help
total function 6
test -> /bin
toggle_led -> /bin
write_led -> /bin
exit -> /sbin
help -> /sbin
shsize -> /sbin

total variable 2
$PATH r- 11
$ZERO r- 1
cherry@hpm5301evklite:/$
```

- 如果此时通过键盘手动输入命令"toggle_led"并回车,LED将会翻转
- 如果此时通过键盘手动输入命令"write_led 1"并回车,LED将会点亮
- 如果此时通过键盘手动输入命令"write_led 0"并回车,LED将会熄灭
91 changes: 91 additions & 0 deletions samples/hpm/barebone_usb/inc/csh_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2022, Egahp
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef CSH_CONFIG_H
#define CSH_CONFIG_H

/*!< argument check */
#define CONFIG_CSH_DEBUG 0

/*!< default row */
#define CONFIG_CSH_DFTROW 25

/*!< default column */
#define CONFIG_CSH_DFTCOL 80

/*!< history support <+550byte> */
#define CONFIG_CSH_HISTORY 1

/*!< completion support <+1100byte> */
#define CONFIG_CSH_COMPLETION 1

/*!< max completion item list count (use stack 4 x count byte) */
#define CONFIG_CSH_MAX_COMPLETION 40

/*!< prompt edit support <+1000byte> */
#define CONFIG_CSH_PROMPTEDIT 1

/*!< prompt segment count */
#define CONFIG_CSH_PROMPTSEG 7

/*!< xterm support */
#define CONFIG_CSH_XTERM 0

/*!< newline */
#define CONFIG_CSH_NEWLINE "\r\n"

/*!< tab space count */
#define CONFIG_CSH_SPACE 4

/*!< independent ctrl map */
#define CONFIG_CSH_CTRLMAP 0

/*!< independent alt map */
#define CONFIG_CSH_ALTMAP 0

/*!< refresh prompt */
#define CONFIG_CSH_REFRESH_PROMPT 1

/*!< no waiting for sget */
#define CONFIG_CSH_NOBLOCK 1

/*!< help information */
#define CONFIG_CSH_HELP ""

/*!< path length 0:const path, <=255:variable path */
#define CONFIG_CSH_MAXLEN_PATH 128

/*!< path segment count */
#define CONFIG_CSH_MAXSEG_PATH 16

/*!< user count */
#define CONFIG_CSH_MAX_USER 1

/*!< max argument count */
#define CONFIG_CSH_MAX_ARG 8

/*!< linebuffer static or on stack */
#define CONFIG_CSH_LNBUFF_STATIC 1

/*!< linebuffer size (valid only if lnbuff on stack) */
#define CONFIG_CSH_LNBUFF_SIZE 256

/*!< multi-thread mode */
#define CONFIG_CSH_MULTI_THREAD 0

/*!< independent signal handler (for multi instances) */
#define CONFIG_CSH_SIGNAL_HANDLER 0

/*!< Ctrl+c/d/q/s/z/\ F1-F12 UE <+120byte> */
#define CONFIG_CSH_USER_CALLBACK 1

/*!< enable macro export symbol table */
#define CONFIG_CSH_SYMTAB 1

/*!< print buffer size */
#define CONFIG_CSH_PRINT_BUFFER_SIZE 512

#endif
17 changes: 17 additions & 0 deletions samples/hpm/barebone_usb/inc/shell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2022, Egahp
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef SHELL_H
#define SHELL_H

#include "csh.h"

extern int shell_init(uint8_t busid, uint32_t regbase, bool need_login);
extern int shell_main(void);
extern void shell_lock(void);
extern void shell_unlock(void);

#endif
Loading

0 comments on commit 7f237b5

Please sign in to comment.