- 2022-05-24
-
回复了主题帖:
测试开发岗位的薪资待遇比开发还要高?
版主大大,开个培训班呀,我第一个报名学习!
-
回复了主题帖:
【兆易GD32F310测评】+RTC的使用
RTC时钟,很实用的,谢谢分享,职业测评专家呀。
- 2022-05-23
-
回复了主题帖:
【RT-Thread读书笔记】第二部分(1)移植,运行及线程管理
RT—Thread 国产的选手之一,希望可以发扬光大。感谢分享。
-
回复了主题帖:
6月14日有奖直播|TI 带您领略互联、高效的智能家居方案
题目很好,就是不知道到时还记得到么,奖品还是有点没有吸引力。给你顶起来!
-
回复了主题帖:
物联网项目 集锦 1: 看看你想动手做哪个?
大佬这是要有大活动吗?我物联网资产管理有想法,不过现在的传感器应该不便宜吧。
-
回复了主题帖:
【BK7231N】涂鸦开发板评测1-系统开发环境搭建
谢谢分享,这个开发板可以玩很多东西,期待有精彩的作品呈现!
-
回复了主题帖:
什么是谐振与共振?它们都有哪些危害?
科普知识,期待大家给你的精彩点评!
-
回复了主题帖:
智能家居有哪些不足?如何解决这些问题呢?
还是现在的技术没有达到一定的高度吧,我的第一感觉就是个性化定制才有用,但是消费者不一定能买单!
-
回复了主题帖:
【平头哥RVB2601创意应用开发】四 从SGP30环境传感器都取eCO2和TVOC
作品很精彩,感谢分享!
-
回复了主题帖:
瑞萨CPK-RA6M4 开发板测评+DAC输出正弦波
示波器不错呀,看来楼主是大佬,作品很精彩!
-
回复了主题帖:
自动驾驶技术资料合集,免积分 下载从速!
车联网,很前卫的世界。
-
回复了主题帖:
【AT-START-F425测评】+获取MCU96位唯一ID、FLASH大小
这几天测试的频率很高呀,还有什么精彩作品呀。
-
发表了日志:
【GD32F310G-START】移植RT_Thread
-
发表了主题帖:
【GD32F310G-START】移植RT_Thread
【前言】移植RT_Thread是我的评测项目之一,具体RT_Thread的好处在这里不细说,这里详细讲述如何实现移植。
【移植】
1、将官方提供的例程GPIO_Ruing_LED文件夹复制一份备用,然后重命名01_GPIO_Runing_LED_RT
2、打开例程,然后导出为MDK5.0的工程:
3、再次打开例程,单击图示的地方,配置RTT
4、钩选kernel、shell两个选项,如下图所示: 5、点击OK后,项目自动加入RTOS目录:
6、编辑 board.c,修改 rt_hw_board_init 函数,新增 systick_config()。
修改为:
void rt_hw_board_init(void)
{
#include "systick.h"
systick_config();
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif
}
7、修改 board.c 中的堆栈大小,避免链接时报错。原来的是:#define RT_HEAP_SIZE (15*1024),现在修改为:#define RT_HEAP_SIZE (4*1024)
8、在 board.c 中新增 SysTick_Handler()
9、注释 gd32f3x0_it.c 中的 HardFault_Handler、PendSV_Handler 和 SysTick_Handler。
10、修改 rtconfig.h,取消#include"finsh_config.h"前的注释
11、修改finish_port.c中的uart0的功能函数:
具体代码下如:
#include <rthw.h>
#include <rtconfig.h>
#include "gd32f3x0.h"
#ifndef RT_USING_FINSH
#error Please uncomment the line <#include "finsh_config.h"> in the rtconfig.h
#endif
#ifdef RT_USING_FINSH
RT_WEAK char rt_hw_console_getchar(void)
{
/* Note: the initial value of ch must < 0 */
int ch = -1;
if(RESET != usart_flag_get(USART0, USART_FLAG_TC) && RESET != usart_flag_get(USART0, USART_FLAG_RBNE))
ch = usart_data_receive(USART0);
return ch;
}
#endif /* RT_USING_FINSH */
12、在rtconfig.h中打开RT串口打印
13、修改 board.c,新增 UART0的初始、发送函数、以及prinf的函数重定向:增加gd32f3x0.h以及stdio.h的头文件引用:
修改后代board.c代码如下:
/*
* Copyright (c) 2006-2019, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-05-24 the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include "gd32f3x0.h"
#include <stdio.h>
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
/*
* Please modify RT_HEAP_SIZE if you enable RT_USING_HEAP
* the RT_HEAP_SIZE max value = (sram size - ZI size), 1024 means 1024 bytes
*/
#define RT_HEAP_SIZE (4*1024)
static rt_uint8_t rt_heap[RT_HEAP_SIZE];
RT_WEAK void *rt_heap_begin_get(void)
{
return rt_heap;
}
RT_WEAK void *rt_heap_end_get(void)
{
return rt_heap + RT_HEAP_SIZE;
}
#endif
void rt_os_tick_callback(void)
{
rt_interrupt_enter();
rt_tick_increase();
rt_interrupt_leave();
}
void SysTick_Handler()
{
rt_os_tick_callback();
}
/**
* This function will initial your board.
*/
void rt_hw_board_init(void)
{
#include "systick.h"
systick_config();
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif
}
#ifdef RT_USING_CONSOLE
void usart0_gpio_config(void)
{
/* enable COM GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* connect port to USARTx_Tx */
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_9);
/* connect port to USARTx_Rx */
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_10);
/* configure USART Tx as alternate function push-pull */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_9);
/* configure USART Rx as alternate function push-pull */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);
}
/*!
\brief configure the USART0
\param[in] none
\param[out] none
\retval none
*/
void usart0_config(void)
{
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART0);
/* USART configure */
usart_deinit(USART0);
usart_word_length_set(USART0, USART_WL_8BIT);
usart_stop_bit_set(USART0, USART_STB_1BIT);
usart_parity_config(USART0, USART_PM_NONE);
usart_baudrate_set(USART0, 115200U);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
usart_enable(USART0);
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(USART0, (uint8_t) ch);
while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
return ch;
}
static int uart_init(void)
{
usart0_gpio_config();
usart0_config();
return 0;
}
INIT_BOARD_EXPORT(uart_init);
void rt_hw_console_output(const char *str)
{
printf("%s",str);
}
#endif
14、到这里基本代码修改完毕,编译通过:
15、在main函数引用“rtthread.h"
将delay_1ms替换成rt_thread_mdelay:
16、编译后下载,led闪烁,串口打印如下:
输入free:
到此,RT_Treade移植成功。
-
回复了主题帖:
听说一个搞单片机同学毕业4年已经年薪43万了,这是什么水平
其实吧,想要收入高,一是自己能力的提升,二是要有机遇遇到好老板,天时、地利、人和。
-
回复了主题帖:
物联网小项目-智能农业灌溉系统
挺好的,希望看到你的产品落地。我也准备给家乡的大棚做一个这样的系统。
- 2022-05-22
-
发表了主题帖:
【创龙TL570x-EVM】按键控制LED灯
本帖最后由 lugl4313820 于 2022-5-23 07:07 编辑
【前言】例程给了Python控制LED闪烁、检测按键的程序,结合两个案例学习综合一个按键控制例子。
【分析】LED闪灯,是循环检测是否退出的标志来维护的,我这里加入thread线程来开启。按键程序是even来检测的,如果再加入线程就会出现不能退出的现象。
【实现思路】按测键检来判断按键是否按下,然后更新延时秒数来控制LED灯闪烁的快慢。
1、初始化LED:
def __init__(self):
self.led_path = "/sys/class/leds/" # Led path
self.leds = [] # Save the led found
self.enumerate_led()
self.led_time = 0.1
self.key_sta = 1
""" enumerate all led """
def enumerate_led(self):
led_name = "user-led"
""" find led """
for filename in os.listdir(self.led_path):
if led_name in filename:
self.leds.append(os.path.join(self.led_path, filename))
if len(self.leds) == 0:
return False
"""
led sort, e.g.
/sys/class/leds/user-led0
/sys/class/leds/user-led1
/sys/class/leds/user-led2
"""
self.leds.sort()
print "find leds:"
for led in self.leds:
print led
return True
2、LED闪烁程序:
""" control led flash """
def flash_led(self):
led_num = len(self.leds)
while not KeyDevice.quit_flag:
""" Turn on leds """
for i in range(led_num):
""" Set the led brightness value to 1 to turn on the led """
ret = os.system("echo 1 > %s/brightness" % (self.leds))
if ret != 0:
print "Error: Failed to turn on %s" % self.leds
""" Keep the leds on for 500 ms """
time.sleep(self.led_time*self.key_sta)
for i in range(led_num):
""" Set the led brightness value to 0 to turn off the LED """
os.system("echo 0 > %s/brightness" % (self.leds))
""" Keep the leds off for 500 ms """
time.sleep(self.led_time*self.key_sta)
3、按键检测程序:
def open_device(self, key_dev):
try:
""" open key device, if success, return True"""
self.key_dev = evdev.InputDevice(key_dev)
return True
except Exception as e:
print e
return False
def listen_key_pressed(self):
try:
print "Please press the key to test.\n"
"""
Listen for the button to be pressed
event.value: 1: pressed; 0: released
"""
for event in self.key_dev.read_loop():
if event.type == evdev.ecodes.EV_KEY:
if event.code == evdev.ecodes.KEY_PROG1 and event.value == 1:
print "User key0 pressed!\n"
self.key_sta = 1
elif event.code == evdev.ecodes.KEY_PROG2 and event.value == 1:
print "User key1 pressed!\n"
self.key_sta = self.key_sta + 1
if self.key_sta >20:
self.key_sta = 1
except Exception as e:
if not KeyDevice.quit_flag:
print e
4、CTRL+C退出程序:
@classmethod
def stop(cls):
print "ctrl + c ..."
cls.quit_flag = True
sys.exit()
5、CTRL+C信号:
def sig_handle(signum, frame):
print "ctrl + c ..."
KeyDevice.stop()
sys.exit()
6、启动:
if __name__ == '__main__':
key_dev = "/dev/input/event0" # key deivce path
try:
""" Ctrl+c handler """
signal.signal(signal.SIGINT, sig_handle)
key_device = KeyDevice()
""" open key device """
res = key_device.open_device(key_dev)
if not res:
print "open %s failed!" % key_dev
exit(3)
t1 = threading.Thread(target=key_device.flash_led)
t1.start()
""" Listen for the button to be pressed """
key_device.listen_key_pressed()
except Exception, exc:
print exc
【实验现象】程序启动后,三个灯快速闪烁,按下按键4,灯闪得慢下来,慢到2秒一次时,再按一下又回到原来的闪烁频率。
本次实验主要学习了python 检测GPIO的输入输出控制。
【总结】python编程还是相对容易的,但是遗憾的就是event只在python2.7中支持,现象已经用习惯了python3,突然回到python2还有点不习惯,python中pip也不支持安装包,所以发挥不出来。希望官方出个如何添加包的教程。
-
发表了日志:
【创龙TL570x-EVM】按键控制LED灯
-
回复了主题帖:
【GD32F310G-START】ADC获取片内温度并显示
javnson 发表于 2022-5-22 20:35
赞!私以为加一个EOIC标志位的判定更加合理,但是实际上,对于此处温度测量已经能够实现效果了!
问了兆易的,说这个温度只能反映片内温度,测量外界的温度没有实际意义。
-
回复了主题帖:
【先楫HPM6750测评】CoreMark跑分测试
这芯片很强大呀,我跑CH32V307才380分。