RT-Thread 软件包-PikaScript用户手册-PIKA派WIRELESS开发板①

本文介绍了PIKA派-WIRELESS开发板,它是PikaPython官方的嵌入式开发平台,包含ESP32S3芯片,详细阐述了开发环境搭建、PikaScript编程示例、以及如何在RT-Thread上使用和下载固件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

RT-Thread 软件包-PikaScript用户手册-PIKA派WIRELESS开发板①

在这里插入图片描述

🚀 【新品上架】PIKA 派 - WIRELESS 开发板!PikaPython官方力作! 🚀

我们骄傲地推出PIKA 派 - WIRELESS开发板,这是PikaPython官方首次推出的全流程、手把手教程的开发板。

在这个信息爆炸的新时代,嵌入式编程与Python结合,创造出了前所未有的应用可能性。而PikaPython,作为嵌入式Python的领军力量,成为了许多创新项目的核心动力。

为了培养与帮助下一代的开发者掌握这一创新技术,我们荣誉推出专为技术爱好者与新世代研发者设计的“PIKA 派 - WIRELESS”开发学习板。

“PIKA 派 - WIRELESS”的核心采用了业界知名、学习友好的ESP32S3。该芯片性能卓越、功能多样,绝对能满足您对嵌入式Python的所有探索与实验需求。这块开发板集成了大量的硬件资源(8M的Flash、WIFI与4G通信、众多传感器),并且提供了许多扩展接口,为您在各种项目中展翅翱翔创造了条件。配合此开发学习板,您将得以深度体验PikaPython的魅力,锻炼自己的编程能力,并为未来的技术挑战做好万全的准备。
在这里插入图片描述

🛠 技术参数一览:

  • 主控:ESP32S3
  • 存储:FLASH 8M, PSRAM 8M, nand FLASH 128MB
  • 通信:WIFI、4G、RS485 接口
  • 显示:LCD 屏幕
  • 传感器:板载温湿度传感器、光敏电阻
  • 其他:蜂鸣器、继电器、12V供电、WS2812

此款开发板完整覆盖了内核移植、驱动适配、模块开发、事件驱动、应用开发到最佳实践的全流程。它旨在帮助开发者快速并深入地学习PikaPython在项目实战中的各种技术,并迅速掌握实战开发能力。

📚 课程亮点:

  1. PikaPython基础移植与脚本启动模式深入讲解

  2. ESP32实战系列,包括驱动适配、事件驱动等核心技术

  3. 深入嵌入式驱动框架设计与应用

  4. 嵌入式编程思想与最佳实践

    在这里插入图片描述

我们精心准备的课程不仅确保您能在此开发板上掌握PikaPython的核心技能,还设计了许多案例和实战,确保您可以举一反三,轻松拓展到任何新的平台上。

探索、学习,然后再创新。这不仅是我们的信念,更是我们希望与大家共同实现的目标。期待与您共同探索PikaPython的无限可能!💡

RT-Thread软件包-PikaScript用户手册:PIKA派WIRELESS开发板

一、简介

PikaScript是一款基于RT-Thread实时操作系统的脚本语言,它可以让开发者使用类似于Python的语法来编写RT-Thread应用。而PIKA派WIRELESS开发板则是一款基于RT-Thread的物联网开发板,具有无线连接功能,适用于各种物联网应用。

二、开发环境搭建

  1. 安装RT-Thread Studio:RT-Thread Studio是一款基于Eclipse的集成开发环境(IDE),专为RT-Thread设计。可以从RT-Thread官网下载并安装。
  2. 创建工程:在RT-Thread Studio中创建一个新的RT-Thread工程,选择PIKA派WIRELESS开发板作为目标硬件。
  3. 安装PikaScript软件包:在RT-Thread Studio的工程设置中,找到“Packages”选项,搜索并安装PikaScript软件包。
  4. 安装硬件支持包:在RT-Thread Studio的工程设置中,找到“Board Support Packages”选项,安装与PIKA派WIRELESS开发板相关的硬件支持包。

三、PikaScript编程

  1. 编写脚本:使用PikaScript语法编写应用脚本。例如,可以创建一个LED闪烁的脚本:
from rtthread import *
from machine import Pin
import time

led = Pin('PA0', Pin.OUT)  # 初始化LED引脚
while True:
    led.value(1)  # 点亮LED
    time.sleep(1)  # 延时1秒
    led.value(0)  # 熄灭LED
    time.sleep(1)  # 延时1秒
  1. 保存脚本:将编写的脚本保存为.py文件,例如led_blink.py
  2. 配置入口:在工程的main.c文件中,配置PikaScript的解释器入口。例如:
#include <rtthread.h>
#include <pikascript/pikascript.h>

int main(void)
{
    pikascript_init();  // 初始化PikaScript解释器
    pikascript_execute_file("led_blink.py");  // 执行脚本文件
    return RT_EOK;
}

示例代码:

#include <rthw.h>
#include <rtthread.h>

#define RT_MEM_STATS

#if defined (RT_USING_HEAP) && defined (RT_USING_SLAB)
/* some statistical variable */
#ifdef RT_MEM_STATS
static rt_size_t used_mem, max_mem;
#endif

#ifdef RT_USING_HOOK
static void (*rt_malloc_hook)(void *ptr, rt_size_t size);
static void (*rt_free_hook)(void *ptr);

/**
 * @addtogroup Hook
 */

/**@{*/

/**
 * This function will set a hook function, which will be invoked when a memory
 * block is allocated from heap memory.
 *
 * @param hook the hook function
 */
void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size))
{
    rt_malloc_hook = hook;
}
RTM_EXPORT(rt_malloc_sethook);

/**
 * This function will set a hook function, which will be invoked when a memory
 * block is released to heap memory.
 *
 * @param hook the hook function
 */
void rt_free_sethook(void (*hook)(void *ptr))
{
    rt_free_hook = hook;
}
RTM_EXPORT(rt_free_sethook);

/**@}*/

#endif

/*
 * slab allocator implementation
 *
 * A slab allocator reserves a ZONE for each chunk size, then lays the
 * chunks out in an array within the zone.  Allocation and deallocation
 * is nearly instantanious, and fragmentation/overhead losses are limited
 * to a fixed worst-case amount.
 *
 * The downside of this slab implementation is in the chunk size
 * multiplied by the number of zones.  ~80 zones * 128K = 10MB of VM per cpu.
 * In a kernel implementation all this memory will be physical so
 * the zone size is adjusted downward on machines with less physical
 * memory.  The upside is that overhead is bounded... this is the *worst*
 * case overhead.
 *
 * Slab management is done on a per-cpu basis and no locking or mutexes
 * are required, only a critical section.  When one cpu frees memory
 * belonging to another cpu's slab manager an asynchronous IPI message
 * will be queued to execute the operation.   In addition, both the
 * high level slab allocator and the low level zone allocator optimize
 * M_ZERO requests, and the slab allocator does not have to pre initialize
 * the linked list of chunks.
 *
 * XXX Balancing is needed between cpus.  Balance will be handled through
 * asynchronous IPIs primarily by reassigning the z_Cpu ownership of chunks.
 *
 * XXX If we have to allocate a new zone and M_USE_RESERVE is set, use of
 * the new zone should be restricted to M_USE_RESERVE requests only.
 *
 *  Alloc Size  Chunking        Number of zones
 *  0-127       8               16
 *  128-255     16              8
 *  256-511     32              8
 *  512-1023    64              8
 *  1024-2047   128             8
 *  2048-4095   256             8
 *  4096-8191   512             8
 *  8192-16383  1024            8
 *  16384-32767 2048            8
 *  (if RT_MM_PAGE_SIZE is 4K the maximum zone allocation is 16383)
 *
 *  Allocations >= zone_limit go directly to kmem.
 *
 *          API REQUIREMENTS AND SIDE EFFECTS
 *
 *    To operate as a drop-in replacement to the FreeBSD-4.x malloc() we
 *    have remained compatible with the following API requirements:
 *
 *    + small power-of-2 sized allocations are power-of-2 aligned (kern_tty)
 *    + all power-of-2 sized allocations are power-of-2 aligned (twe)
 *    + malloc(0) is allowed and returns non-RT_NULL (ahc driver)
 *    + ability to allocate arbitrarily large chunks of memory
 */

/*
 * Chunk structure for free elements
 */
typedef struct slab_chunk
{
    struct slab_chunk *c_next;
} slab_chunk;

/*
 * The IN-BAND zone header is placed at the beginning of each zone.
 */
typedef struct slab_zone
{
    rt_int32_t  z_magic;        /* magic number for sanity check */
    rt_int32_t  z_nfree;        /* total free chunks / ualloc space in zone */
    rt_int32_t  z_nmax;         /* maximum free chunks */

    struct slab_zone *z_next;   /* zoneary[] link if z_nfree non-zero */
    rt_uint8_t  *z_baseptr;     /* pointer to start of chunk array */

    rt_int32_t  z_uindex;       /* current initial allocation index */
    rt_int32_t  z_chunksize;    /* chunk size for validation */

    rt_int32_t  z_zoneindex;    /* zone index */
    slab_chunk  *z_freechunk;   /* free chunk list */
} slab_zone;

#define ZALLOC_SLAB_MAGIC       0x51ab51ab
#define ZALLOC_ZONE_LIMIT       (16 * 1024)     /* max slab-managed alloc */
#define ZALLOC_MIN_ZONE_SIZE    (32 * 1024)     /* minimum zone size */
#define ZALLOC_MAX_ZONE_SIZE    (128 * 1024)    /* maximum zone size */
#define NZONES                  72              /* number of zones */
#define ZONE_RELEASE_THRESH     2               /* threshold number of zones */

static slab_zone *zone_array[NZONES];   /* linked list of zones NFree > 0 */
static slab_zone *zone_free;            /* whole zones that have become free */

static int zone_free_cnt;
static int zone_size;
static int zone_limit;
static int zone_page_cnt;

/*
 * Misc constants.  Note that allocations that are exact multiples of
 * RT_MM_PAGE_SIZE, or exceed the zone limit, fall through to the kmem module.
 */
#define MIN_CHUNK_SIZE      8       /* in bytes */
#define MIN_CHUNK_MASK      (MIN_CHUNK_SIZE - 1)

/*
 * Array of descriptors that describe the contents of each page
 */
#define PAGE_TYPE_FREE      0x00
#define PAGE_TYPE_SMALL     0x01
#define PAGE_TYPE_LARGE     0x02
struct memusage
{
    rt_uint32_t type: 2 ;       /* page type */
    rt_uint32_t size: 30;       /* pages allocated or offset from zone */
};
static struct memusage *memusage = RT_NULL;
#define btokup(addr)    \
    (&memusage[((rt_ubase_t)(addr) - heap_start) >> RT_MM_PAGE_BITS])

static rt_ubase_t heap_start, heap_end;

/* page allocator */
struct rt_page_head
{
    struct rt_page_head *next;      /* next valid page */
    rt_size_t page;                 /* number of page  */

    /* dummy */
    char dummy[RT_MM_PAGE_SIZE - (sizeof(struct rt_page_head *) + sizeof(rt_size_t))];
};
static struct rt_page_head *rt_page_list;
static struct rt_semaphore heap_sem;

四、编译与下载

  1. 编译工程:在RT-Thread Studio中,右键点击工程并选择“Build Project”进行编译。
  2. 下载固件:连接PIKA派WIRELESS开发板到电脑,并使用适合的下载工具将编译生成的固件下载到开发板中。例如,可以使用ST-Link或J-Link等调试器进行下载。
  3. 运行应用:断开开发板与电脑的连接,给开发板上电,观察LED的闪烁效果。如果LED按照脚本设定的频率进行闪烁,说明PikaScript应用成功运行在PIKA派WIRELESS开发板上。

维护人:

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

华为奋斗者精神

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值