赞
踩
要想使用shell,必须是要使用uart1,对于我的这个板子。
注意这个不要勾!!!
加塞一个关于main.c文件的问题。(或者不需要它去修改的文件)
因为每次使用WorkBench生成新的文件的话会覆盖自己的源码文件,所以我建议把main.c文件不要用它自己生成的。
好,继续。。。
- //在board.c文件最后粘贴以下代码
-
- #ifdef RT_USING_CONSOLE
-
- static int uart_init(void)
- {
- // #error "TODO 2: Enable the hardware uart and config baudrate."
- return 0;
- }
- INIT_BOARD_EXPORT(uart_init);
-
- void rt_hw_console_output(const char *str)
- {
- // #error "TODO 3: Output the string 'str' through the uart."
- rt_enter_critical();
-
- /*进入临界区*/
- while (*str != '\0')
- {
- if (*str == '\n')
- {
- usart_data_transmit(USART1, '\r');
- while (usart_flag_get(USART1, USART_TDC_FLAG) == RESET)
- ;
- }
- usart_data_transmit(USART1, *str++);
- while (usart_flag_get(USART1, USART_TDC_FLAG) == RESET)
- ;
- }
-
- /* 退出临界区*/
- rt_exit_critical();
- }
-
- #endif
F7:构建 F8:下载。。。。
信息出来了。
扩展:
上一篇文章,我闪灯了,我这次要看一下延时时间是不是500ms。
- /* add user code begin Header */
- /**
- **************************************************************************
- * @file main.c
- * @brief main program
- **************************************************************************
- * Copyright notice & Disclaimer
- *
- * The software Board Support Package (BSP) that is made available to
- * download from Artery official website is the copyrighted work of Artery.
- * Artery authorizes customers to use, copy, and distribute the BSP
- * software and its related documentation for the purpose of design and
- * development in conjunction with Artery microcontrollers. Use of the
- * software is governed by this copyright notice and the following disclaimer.
- *
- * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
- * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
- * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
- * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
- * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
- *
- **************************************************************************
- */
- /* add user code end Header */
-
- /* Includes ------------------------------------------------------------------*/
- #include "at32f423_wk_config.h"
-
- /* private includes ----------------------------------------------------------*/
- /* add user code begin private includes */
- #include "rtthread.h"
- /* add user code end private includes */
-
- /* private typedef -----------------------------------------------------------*/
- /* add user code begin private typedef */
-
- /* add user code end private typedef */
-
- /* private define ------------------------------------------------------------*/
- /* add user code begin private define */
-
- /* add user code end private define */
-
- /* private macro -------------------------------------------------------------*/
- /* add user code begin private macro */
-
- /* add user code end private macro */
-
- /* private variables ---------------------------------------------------------*/
- /* add user code begin private variables */
-
- /* add user code end private variables */
-
- /* private function prototypes --------------------------------------------*/
- /* add user code begin function prototypes */
-
- /* add user code end function prototypes */
-
- /* private user code ---------------------------------------------------------*/
- /* add user code begin 0 */
-
- /* add user code end 0 */
-
-
- /**
- * @brief take some delay for waiting power stable, delay is about 60ms with frequency 8MHz.
- * @param none
- * @retval none
- */
- static void wk_wait_for_power_stable(void)
- {
- volatile uint32_t delay = 0;
- for(delay = 0; delay < 50000; delay++);
- }
-
- /**
- * @brief main function.
- * @param none
- * @retval none
- */
- int main(void)
- {
- /* add user code begin 1 */
-
- /* add user code end 1 */
-
- /* add a necessary delay to ensure that Vdd is higher than the operating
- voltage of battery powered domain (2.57V) when the battery powered
- domain is powered on for the first time and being operated. */
- //wk_wait_for_power_stable();
-
- ///* system clock config. */
- //wk_system_clock_config();
-
- ///* config periph clock. */
- //wk_periph_clock_config();
-
- ///* nvic config. */
- //wk_nvic_config();
-
- ///* init usart1 function. */
- //wk_usart1_init();
-
- ///* init gpio function. */
- //wk_gpio_config();
-
- /* add user code begin 2 */
-
- /* add user code end 2 */
-
- while(1)
- {
- /* add user code begin 3 */
- rt_thread_mdelay(500);
- rt_kprintf("ON\r\n");//打印
- gpio_bits_reset(RUNLED_GPIO_PORT,RUNLED_PIN);
- rt_thread_mdelay(500);
- rt_kprintf("OFF\r\n");//打印
- gpio_bits_set(RUNLED_GPIO_PORT,RUNLED_PIN);
- /* add user code end 3 */
- }
- }
这次实现了shell的显示,那么rtthread还有个比较不错的功能就是finsh,下一篇,我介绍以下RT_DEBUG和finsh的移植。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。