May 2014 DocID16236 Rev 2 1/50
AN3055
Application note
Getting started with STM8A LIN package (STSW-STM8A-LIN)
Introduction
This document explains how to get started with the STM8A LIN package (STSW-STM8A-
LIN).
The STM8A LIN package is a software package containing an implementation of a software
driver compliant with the LIN (Local Interconnect Network) standard specifications LIN 1.3,
LIN 2.0 and LIN 2.1. This driver implementation is targeted to the STM8A microcontrollers.
www.st.com
Contents AN3055
2/50 DocID16236 Rev 2
Contents
1 Purpose and scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Brief introduction to the LIN bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1 Frame header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Frame response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3 LIN frame slots and schedule tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 LIN driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.1 LIN package structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2 LIN driver configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
3.2.1 lin_def.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.2 lin_def.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.2.3 lin_def_stm8.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4 LIN driver integration into a user application . . . . . . . . . . . . . . . . . . . . 37
4.1 LIN driver integration process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.1.1 LIN package installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.1.2 Creating files for the lingen tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.1.3 Creating LIN driver configuration files . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.1.4 Setting-up LIN driver time base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.1.5 Setting up interrupts, GPIOs, LIN interface enabling . . . . . . . . . . . . . . . 42
4.1.6 Lingen process, compiling and linking . . . . . . . . . . . . . . . . . . . . . . . . . . 42
5 LIN versions compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.1 LIN 2.0 node compatibility with LIN 1.3 nodes . . . . . . . . . . . . . . . . . . . . . 45
5.2 LIN 2.1 node compatibility with LIN 1.3 nodes . . . . . . . . . . . . . . . . . . . . . 45
5.3 LIN 2.1 node compatibility with LIN 2.0 nodes . . . . . . . . . . . . . . . . . . . . . 46
6 Reference documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49