Add the beginning of an STM32 CAN driver

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4209 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2011-12-21 15:50:06 +00:00
parent 2d1cd3ec84
commit b0bf66456c
17 changed files with 986 additions and 34 deletions
+2
View File
@@ -2286,5 +2286,7 @@
* drivers/mtd/mp25x.c: Add ability to use different SPI modes and different
manufacturers codes. Fix a error in the wait for not busy (submitted by
Mohammad Elwakeel.
* arch/arm/src/stm32/stm32_can.c. Add a low-level STM32 CAN driver. (Initial
check is incomplete).
+53 -7
View File
@@ -12,7 +12,7 @@
<h1><big><font color="#3c34ec">
<i>NuttX RTOS Porting Guide</i>
</font></big></h1>
<p>Last Updated: December 19, 2011</p>
<p>Last Updated: December 21, 2011</p>
</td>
</tr>
</table>
@@ -127,7 +127,8 @@
<a href="#usbhostdrivers">6.3.9 USB Host-Side Drivers</a><br>
<a href="#usbdevdrivers">6.3.10 USB Device-Side Drivers</a><br>
<a href="#analogdrivers">6.3.11 Analog (ADC/DAC) Drivers</a><br>
<a href="#pwmdrivers">6.3.12 PWM Drivers</a>
<a href="#pwmdrivers">6.3.12 PWM Drivers</a><br>
<a href="#candrivers">6.3.13 CAN Drivers</a>
</ul>
<a href="#pwrmgmt">6.4 Power Management</a>
<ul>
@@ -3212,23 +3213,55 @@ extern void up_ledoff(int led);
A &quot;lower half&quot;, platform-specific driver that implements the low-level timer controls to implement the PWM functionality.
</li>
</ol>
<p>
Files supporting PWM can be found in the following locations:
</p>
<ul>
<li>
<li><b>Interface Definition</b>.
The header file for the NuttX PWM driver reside at <code>include/nuttx/pwm.h</code>.
This header file includes both the application level interface to the PWM driver as well as the interface between the &quot;upper half&quot; and &quot;lower half&quot; drivers.
The PWM module uses a standard character driver framework.
However, since the PWM driver is a devices control interface and not a data transfer interface,
the majority of the functionality available to the application is implemented in driver ioctl calls.
</li>
<li>
<li><b>&quot;Upper Half&quot; Driver</b>.
The generic, &quot;upper half&quot; PWM driver resides at <code>drivers/pwm.c</code>.
</li>
<li>
Platform-specific PWM drivers reside in <code>arch/</code><i>&lt;architecture&gt;</i><code>/src/</code><i>&lt;chip&gt;</i> directory for the specific processor <i>&lt;architecture&gt;</i> and for the specific <i>&lt;chip&gt;</i> analog peripheral devices.
<li><b>&quot;Lower Half&quot; Drivers</b>.
Platform-specific PWM drivers reside in <code>arch/</code><i>&lt;architecture&gt;</i><code>/src/</code><i>&lt;chip&gt;</i> directory for the specific processor <i>&lt;architecture&gt;</i> and for the specific <i>&lt;chip&gt;</i> PWM peripheral devices.
</li>
</ul>
<h3><a name="candrivers">6.3.13 CAN Drivers</a></h3>
<p>
NuttX supports only a very low-level CAN driver.
This driver supports only the data exchange and does not include any high-level CAN protocol.
The NuttX CAN driver is split into two parts:
</p>
<ol>
<li>
An &quot;upper half&quot;, generic driver that provides the comman CAN interface to application level code, and
</li>
<li>
A &quot;lower half&quot;, platform-specific driver that implements the low-level timer controls to implement the CAN functionality.
</li>
</ol>
<p>
Files supporting CAN can be found in the following locations:
</p>
<ul>
<li><b>Interface Definition</b>.
The header file for the NuttX CAN driver reside at <code>include/nuttx/can.h</code>.
This header file includes both the application level interface to the CAN driver as well as the interface between the &quot;upper half&quot; and &quot;lower half&quot; drivers.
The CAN module uses a standard character driver framework.
</li>
<li><b>&quot;Upper Half&quot; Driver</b>.
The generic, &quot;upper half&quot; CAN driver resides at <code>drivers/can.c</code>.
</li>
<li><b>&quot;Lower Half&quot; Drivers</b>.
Platform-specific CAN drivers reside in <code>arch/</code><i>&lt;architecture&gt;</i><code>/src/</code><i>&lt;chip&gt;</i> directory for the specific processor <i>&lt;architecture&gt;</i> and for the specific <i>&lt;chip&gt;</i> CAN peripheral devices.
</li>
</ul>
<h2><a name="pwrmgmt">6.4 Power Management</a></h2>
@@ -4332,6 +4365,19 @@ build
</li>
</ul>
<h3>CAN driver</h3>
<ul>
<li>
<code>CONFIG_CAN</code>: Enables CAN support
</li>
<li>
<code>CONFIG_CAN_FIFOSIZE</code>: The size of the circular buffer of CAN messages. Default: 8
</li>
<li>
<code>CONFIG_CAN_NPENDINGRTR</code>: The size of the list of pending RTR requests. Default: 4
</li>
</ul>
<h3>SPI driver</h3>
<ul>
<li>
+8 -5
View File
@@ -2,7 +2,7 @@
# arch/arm/src/lpc17xx/Make.defs
#
# Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -57,10 +57,9 @@ endif
# Required LPC17xx files
CHIP_ASRCS =
CHIP_CSRCS = lpc17_allocateheap.c lpc17_can.c lpc17_clockconfig.c \
lpc17_clrpend.c lpc17_gpio.c lpc17_i2c.c lpc17_idle.c lpc17_irq.c \
lpc17_lowputc.c lpc17_serial.c lpc17_spi.c lpc17_ssp.c lpc17_start.c \
lpc17_timerisr.c
CHIP_CSRCS = lpc17_allocateheap.c lpc17_clockconfig.c lpc17_clrpend.c \
lpc17_gpio.c lpc17_i2c.c lpc17_idle.c lpc17_irq.c lpc17_lowputc.c \
lpc17_serial.c lpc17_spi.c lpc17_ssp.c lpc17_start.c lpc17_timerisr.c
# Configuration-dependent LPC17xx files
@@ -90,6 +89,10 @@ CHIP_CSRCS += lpc17_ethernet.c
endif
endif
ifeq ($(CONFIG_CAN),y)
CHIP_CSRCS += lpc17_can.c
endif
ifeq ($(CONFIG_LPC17_ADC),y)
CHIP_CSRCS += lpc17_adc.c
endif
+5 -1
View File
@@ -2,7 +2,7 @@
# arch/arm/src/stm32/Make.defs
#
# Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -87,6 +87,10 @@ ifeq ($(CONFIG_PWM),y)
CHIP_CSRCS += stm32_pwm.c
endif
ifeq ($(CONFIG_CAN),y)
CHIP_CSRCS += stm32_can.c
endif
ifeq ($(CONFIG_DEBUG),y)
CHIP_CSRCS += stm32_dumpgpio.c
endif
+761
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -2,7 +2,7 @@
* arch/arm/src/stm32/stm32_pwm.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
+9
View File
@@ -633,6 +633,15 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_RTC_ALARM - Enable if the RTC hardware supports setting of an
alarm. A callback function will be executed when the alarm goes off
CAN driver
CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
SPI driver
CONFIG_SPI_OWNBUS - Set if there is only one active device
+12 -2
View File
@@ -486,8 +486,18 @@ HY-Mini specific Configuration Options
4-bit transfer mode.
CONFIG_MMCSD_HAVECARDDETECT - Select if SDIO driver card detection
is 100% accurate (it is on the HY-MiniSTM32V)
HY-MiniSTM32V CAN Configuration
CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
CONFIG_CAN1_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN1 is defined.
CONFIG_CAN2_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN2 is defined.
HY-MiniSTM32V LCD Hardware Configuration (SSD1289 controler)
CONFIG_NX_LCDDRIVER - To be defined to include LCD driver
+11
View File
@@ -575,6 +575,17 @@ STM3210E-EVAL-specific Configuration Options
CONFIG_SDIO_WIDTH_D1_ONLY - Select 1-bit transfer mode. Default:
4-bit transfer mode.
STM3210E-EVAL CAN Configuration
CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
CONFIG_CAN1_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN1 is defined.
CONFIG_CAN2_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN2 is defined.
STM3210E-EVAL LCD Hardware Configuration
CONFIG_LCD_LANDSCAPE - Define for 320x240 display "landscape"
+11
View File
@@ -481,6 +481,17 @@ STM3240G-EVAL-specific Configuration Options
CONFIG_STM32_ETH_PTP - Precision Time Protocol (PTP). Not supported
but some hooks are indicated with this condition.
STM3240G-EVAL CAN Configuration
CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
CONFIG_CAN1_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN1 is defined.
CONFIG_CAN2_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN2 is defined.
STM3240G-EVAL LCD Hardware Configuration
Configurations
+18
View File
@@ -256,6 +256,24 @@ CONFIG_SSI1_DISABLE=y
CONFIG_SSI_POLLWAIT=y
#CONFIG_SSI_TXLIMIT=4
#
# STM32F40xxx specific CAN device driver settings
#
# CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or
# CONFIG_STM32_CAN2 must also be defined)
# CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
# Default: 8
# CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
# Default: 4
# CONFIG_CAN1_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN1 is defined.
# CONFIG_CAN2_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN2 is defined.
#
CONFIG_CAN=n
#CONFIG_CAN_FIFOSIZE
#CONFIG_CAN_NPENDINGRTR
CONFIG_CAN1_BAUD=115200
CONFIG_CAN2_BAUD=115200
#
# STM32F40xxx Ethernet device driver settings
#
+18
View File
@@ -256,6 +256,24 @@ CONFIG_SSI1_DISABLE=y
CONFIG_SSI_POLLWAIT=y
#CONFIG_SSI_TXLIMIT=4
#
# STM32F40xxx specific CAN device driver settings
#
# CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or
# CONFIG_STM32_CAN2 must also be defined)
# CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
# Default: 8
# CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
# Default: 4
# CONFIG_CAN1_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN1 is defined.
# CONFIG_CAN2_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN2 is defined.
#
CONFIG_CAN=n
#CONFIG_CAN_FIFOSIZE
#CONFIG_CAN_NPENDINGRTR
CONFIG_CAN1_BAUD=115200
CONFIG_CAN2_BAUD=115200
#
# STM32F40xxx Ethernet device driver settings
#
+18
View File
@@ -256,6 +256,24 @@ CONFIG_SSI1_DISABLE=y
CONFIG_SSI_POLLWAIT=y
#CONFIG_SSI_TXLIMIT=4
#
# STM32F40xxx specific CAN device driver settings
#
# CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or
# CONFIG_STM32_CAN2 must also be defined)
# CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
# Default: 8
# CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
# Default: 4
# CONFIG_CAN1_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN1 is defined.
# CONFIG_CAN2_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN2 is defined.
#
CONFIG_CAN=n
#CONFIG_CAN_FIFOSIZE
#CONFIG_CAN_NPENDINGRTR
CONFIG_CAN1_BAUD=115200
CONFIG_CAN2_BAUD=115200
#
# STM32F40xxx Ethernet device driver settings
#
+18
View File
@@ -256,6 +256,24 @@ CONFIG_SSI1_DISABLE=y
CONFIG_SSI_POLLWAIT=y
#CONFIG_SSI_TXLIMIT=4
#
# STM32F40xxx specific CAN device driver settings
#
# CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or
# CONFIG_STM32_CAN2 must also be defined)
# CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
# Default: 8
# CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
# Default: 4
# CONFIG_CAN1_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN1 is defined.
# CONFIG_CAN2_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN2 is defined.
#
CONFIG_CAN=n
#CONFIG_CAN_FIFOSIZE
#CONFIG_CAN_NPENDINGRTR
CONFIG_CAN1_BAUD=115200
CONFIG_CAN2_BAUD=115200
#
# STM32F40xxx Ethernet device driver settings
#
+5 -2
View File
@@ -2,7 +2,7 @@
# drivers/Makefile
#
# Copyright (C) 2007-2011 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -64,10 +64,13 @@ include usbhost/Make.defs
include wireless/Make.defs
ifneq ($(CONFIG_NFILE_DESCRIPTORS),0)
CSRCS += dev_null.c dev_zero.c loop.c can.c
CSRCS += dev_null.c dev_zero.c loop.c
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
CSRCS += ramdisk.c rwbuffer.c
endif
ifneq ($(CONFIG_CAN),y)
CSRCS += can.c
endif
ifeq ($(CONFIG_PWM),y)
CSRCS += pwm.c
endif
+22 -7
View File
@@ -1,8 +1,8 @@
/****************************************************************************
* drivers/can.c
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -33,10 +33,6 @@
*
****************************************************************************/
/****************************************************************************
* Compilation Switches
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
@@ -60,9 +56,27 @@
#include <arch/irq.h>
#ifdef CONFIG_CAN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Debug ********************************************************************/
/* Non-standard debug that may be enabled just for testing CAN */
#ifdef CONFIG_DEBUG_CAN
# define candbg dbg
# define canvdbg vdbg
# define canlldbg lldbg
# define canllvdbg llvdbg
#else
# define candbg(x...)
# define canvdbg(x...)
# define canlldbg(x...)
# define canllvdbg(x...)
#endif
/* Timing Definitions *******************************************************/
#define HALF_SECOND_MSEC 500
#define HALF_SECOND_USEC 500000L
@@ -619,7 +633,7 @@ int can_register(FAR const char *path, FAR struct can_dev_s *dev)
/* Register the CAN device */
dbg("Registering %s\n", path);
canvdbg("Registering %s\n", path);
return register_driver(path, &g_canops, 0666, dev);
}
@@ -768,3 +782,4 @@ int can_txdone(FAR struct can_dev_s *dev)
return ret;
}
#endif /* CONFIG_CAN */
+14 -9
View File
@@ -1,8 +1,8 @@
/************************************************************************************
* include/nuttx/can.h
*
* Copyright (C) 2008, 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Copyright (C) 2008, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -33,8 +33,8 @@
*
************************************************************************************/
#ifndef __NUTTX_CAN_H
#define __NUTTX_CAN_H
#ifndef _INCLUDE_NUTTX_CAN_H
#define _INCLUDE_NUTTX_CAN_H
/************************************************************************************
* Included Files
@@ -46,14 +46,18 @@
#include <stdint.h>
#include <stdbool.h>
#include <semaphore.h>
#include <nuttx/fs.h>
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/* Default configuration settings that may be overridden in the board configuration.
* file. The configured size is limited to 255 to fit into a uint8_t.
/* Default configuration settings that may be overridden in the NuttX configuration
* file or in the board configuration file. The configured size is limited to 255
* to fit into a uint8_t.
*/
#if !defined(CONFIG_CAN_FIFOSIZE)
@@ -165,8 +169,8 @@ struct can_ops_s
/* Configure the CAN. This method is called the first time that the CAN
* device is opened. This will occur when the port is first opened.
* This setup includes configuring and attaching CAN interrupts. Interrupts
* are all disabled upon return.
* This setup includes configuring and attaching CAN interrupts. All CAN
* interrupts are disabled upon return.
*/
CODE int (*co_setup)(FAR struct can_dev_s *dev);
@@ -305,4 +309,5 @@ EXTERN int can_txdone(FAR struct can_dev_s *dev);
}
#endif
#endif /* __NUTTX_CAN_H */
#endif /* CONFIG_CAN */
#endif /* _INCLUDE_NUTTX_CAN_H */