Share E-Book
Scan to open this page

Scan with your phone to open this page

Author李志明, 檀永, 徐石明

No description

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# STM32嵌入式系统开发实战指南:FreeRTOS与LwIP联合移植 ## 【One-Line Pitch】 A hands-on engineering guide for embedded developers who want to build a complete STM32F107 system by porting FreeRTOS and the LwIP TCP/IP stack together, covering everything from hardware selection to final network debugging. Read this if you are moving from bare-metal MCU coding to RTOS-based connected embedded systems. ## 【Book Arc】 - **Opening (~0%–14%)**: Introduces embedded system fundamentals, distinguishes microprocessors from microcontrollers, and walks through ARM architecture families (Cortex-M3, ARM7, SecurCore, StrongARM). Justifies the chip selection process—why STM32F107VCT6 with Cortex-M3, DMA-capable Ethernet, and CAN interfaces meets the project requirements. - **Early (~14%–29%)**: Covers hardware design concerns: Ethernet PHY interface (SMI, DMA-to-MAC data flow), RS485 bus termination and bias resistors, signal integrity basics for high-speed PCB layout, and power decoupling. Then shifts to toolchain setup—installing IAR EWARM 6.3 and MDK-ARM, configuring JTAG debuggers, and creating a project directory structure. - **Early (~29%–43%)**: Presents coding standards and firmware library conventions: ST's 24 fixed variable types, naming rules (prefixes like l for local, g for global), header file comment requirements, structure layout optimization, and defensive programming practices. Emphasizes avoiding random cohesion in functions and designing test hooks before writing code. - **Middle (~43%–57%)**: Dives into FreeRTOS fundamentals: task states and the scheduler as the only entity that switches tasks, priority-based preemptive scheduling with practical experiments (same-priority round-robin vs. different-priority preemption), task deletion and idle task cleanup, queue creation with xQueueCreate() and blocking send/receive semantics, and binary/counting semaphores with P()/V() equivalents. - **Middle (~57%–71%)**: Continues FreeRTOS with interrupt-safe API usage, mutexes for mutual exclusion, the daemon task pattern for centralized output, and a dedicated section on common pitfalls—especially stack overflow detection and the stack-efficient printf-stdarg.c replacement for sprintf(). Covers architecture-specific porting macros: configUSE_16_BIT_TICKS, portSTACK_GROWTH (Cortex-M3 grows downward, so -1), and portTICK_RATE_MS. - **Late (~71%–86%)**: Introduces TCP/IP networking theory relevant to LwIP: data link layer protocols (SDLC, HDLC, PPP), network layer routing and congestion control, ARP packet format and cache updates, FTP operation over control/data connections. Then examines LwIP internals—memory pool management via memp_memory, UDP control blocks (udp_pcb) with callback-based recv functions, and TCP control block fields (unsent/unacked/ooseq queues, keepalive timers, persist timers). - **Late (~86%–100%)**: Explains LwIP's dual API approach: the low-level callback-based Raw API vs. the BSD Socket compatibility layer, and why LwIP avoids data copying between app and stack. Walks through the actual porting steps: ethernetif_input() for reading frames from the NIC, GPIO pin muxing for MII signals (e.g., PA2 as MDO), low_level_input/output functions, and sys_arch_protect/unprotect for critical sections. Ends with a HelloWorld Raw API example and a serial/UDP loopback test using a PC client. ## 【Key Takeaways】 - **Chip selection must be requirement-driven** (Early): The book demonstrates a systematic filter—Cortex-M3 core for performance without MMU, DMA-capable Ethernet + CAN interfaces, main frequency above 60MHz—narrowing to STM32F107VCT6. This is a reusable methodology for any embedded project. - **Hardware design and software porting are inseparable** (Early): RS485 termination resistors (120Ω), bias resistors for idle bus states, and Ethernet decoupling capacitor loop areas directly affect whether the later LwIP stack works reliably. Skim this if you use a dev board, but deep-read if you design custom PCBs. - **Coding standards prevent debugging hell** (Early): The book's rules—no single-character variable names (except loop counters), consistent naming prefixes (l/g + type + v/c), structured header comments, avoiding random cohesion—are practical guardrails that pay off immediately in team projects. - **FreeRTOS scheduling is priority-driven preemption** (Middle): The scheduler always picks the highest-priority ready task; equal-priority tasks time-slice. The priority experiments (task1 at priority 1, task2 at priority 2) make this concrete—when task2 deletes itself, task1 resumes, then the idle task reclaims freed memory. - **Queues and semaphores are the core inter-task communication** (Middle): xQueueCreate() allocates from the heap and returns NULL on failure; xQueueSendToBack/Front with blocking timeouts handle full/empty conditions. Counting semaphores track available resources (count decrements on take, increments on give), initialized to the total resource count. - **Stack overflow is the #1 FreeRTOS beginner problem** (Late): The book dedicates the most space here—use the stack-efficient printf-stdarg.c instead of standard sprintf(), and configure configUSE_16_BIT_TICKS correctly (0 for 32-bit, 1 for 16-bit). Porting macros like portSTACK_GROWTH=-1 for Cortex-M3 must match the hardware. - **LwIP's Raw API avoids data copying but is harder to use** (Late): The callback-based interface (register a recv function per connection) saves embedded resources compared to BSD sockets, which copy data between app and stack buffers. LwIP keeps a BSD compatibility layer for familiarity, but the Raw API is the efficient choice for STM32-class devices. - **Porting LwIP to FreeRTOS touches only a few files** (Ending): The OS simulation layer (sys_arch_protect/unprotect for critical sections) and the Ethernet interface layer (ethernetif_input, low_level_input/output) are the only parts needing modification. The HelloWorld example shows the full path: signal from Ethernet RX interrupt → ethernetif_input task → LwIP stack → app callback. ## 【Reading Tips】 - **Skim Chapters 1–2** if you already know ARM basics and use a pre-built board; the chip selection logic and signal-integrity warnings are worth a quick scan, but the detailed PHY/RS485 layout rules matter mainly for custom hardware. - **Deep-read the FreeRTOS chapters (7)**: The priority experiments, queue/semaphore examples, and the common-errors section (especially stack overflow) are the highest-value content. Recreate the experiments yourself—the book's code listings are meant to be typed and run. - **The LwIP chapters (9–11) are code-heavy**: Don't try to memorize every struct field. Focus on the data flow—how a frame arrives (ethernetif_input → ethernet_input → etharp/ip/tcp/udp) and how the Raw API callbacks work. The TCP control block fields (unsent/unacked/ooseq) are useful for debugging, not for first read. -
Excerpt 1
书名: STM32嵌入式系统开发实战指南:FreeRTOS与LwIP联合移植 (单片机与嵌入式) (李志明;檀永;徐石明)(Z-Library) 作者: 李志明;檀永;徐石明 软件固化性以及应用专用性等方面,具有更加鲜明的特点。目前,嵌 入式系统的主流趋势是32位嵌入式微处理器或微控制器与实时多任务 操作系统的结...
View in text
Excerpt 2
、需求4)及工程应用需求,芯片必须带有DMA控制的 以太网接口和CAN总线接口,而且芯片主频必须达到60MHz以上。在 NXP、Atmel、ST公司生产的芯片中,具备此两种接口的有:NXP公司的 LPC系列、Atmel公司的SAM3系列和ST公司的STM32FX07系列。 根据需求4)~7),综合考虑选型因素,由...
View in text
Excerpt 3
下几方面考虑:针对模块或 系统某部分代码的调测;针对模块或系统某功能的调测;出于某种其 他目的,如对性能、容量等的测试。这样做便于软件功能的调测,并 且便于模块的单元测试、系统联调等。 ❑编写防错程序,然后在处理错误之后可用断言宣布发生错误。 示例:假如某模块收到通信链路上的消息,则应对消息的合法性 进行检查,若...
View in text
Excerpt 4
行时,以优先级2创建任务2。 因此现在任务2具有最高优先级,所以会立即得到执行。main()函数的 代码参见程序清单7.26,任务1的实现代码参见程序清单7.27。 ❑任务2仅是通过自己的任务句柄删除自身。当然,也可以通过传 递NULL值以vTaskDelete()来删除自身。任务2的实现代码见程序清单 7.28...
View in text
Excerpt 5
中输入正 确的用户名和密码即可登录FTP服务器。 3)通过使用Windows的命令行工具实现访问FTP服务器。在命令行 上输入:ftp主机名或IP地址,同样在输入正确的用户名和密码后,即 可登录FTP服务器。 表9.3列出了FTP协议一些常用的命令。 让我们通过对部分代码的分析,探讨一下LwIP是如何实现一大块内...
View in text
Excerpt 6
D套接字应用程序接口易于理解,并 且很多应用程序为它而写,所以LwIP保留了一个BSD Socket兼容层。 11.1.3 ethernetif_input函数 该函数用于从底层物理网卡读取报文,并将该报文向上传递给 LwIP协议栈函数ethernet_input进行处理。ethernetif_input的源代...
View in text
Tags
AI categories
Technology
ISBN: 711141716X
Language: English
File Format: PDF
File Size: 8.3 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…