configs/nucleo-l432kc: Added support for AT45DB Serial Flash

This commit is contained in:
Daniel P. Carvalho 2018-10-25 16:12:59 -06:00 committed by Gregory Nutt
parent bde9b10b1d
commit 578114a74f
6 changed files with 134 additions and 10 deletions

View File

@ -108,7 +108,7 @@
#define NR_IRQS 48 #define NR_IRQS 48
/* Common register save structgure created by up_saveusercontext() and by /* Common register save structure created by up_saveusercontext() and by
* ISR/IRQ interrupt processing. * ISR/IRQ interrupt processing.
*/ */

View File

@ -52,6 +52,7 @@ Contents
- USARTs and Serial Consoles - USARTs and Serial Consoles
- QFN32 - QFN32
- mbed - mbed
- SPI Flash support
- Configurations - Configurations
Nucleo-32 Boards Nucleo-32 Boards
@ -441,6 +442,61 @@ Serial Consoles
As shipped, SB62 and SB63 are open and SB13 and SB14 closed, so the As shipped, SB62 and SB63 are open and SB13 and SB14 closed, so the
virtual COM port is enabled. virtual COM port is enabled.
SPI Flash support:
=====================
We can use an external SPI Serial Flash with nucleo-l432kc board. In this
case we tested with AT45DB081D (8Mbit = 1MiB).
You can connect the AT45DB081D memory in the nucleo-l432kc board this way:
--------------------------------
| Memory nucleo-l432kc |
|------------------------------|
| SI ---> D11 (PB5) |
| SCK ---> D13 (PB3) |
| /RESET ---> 3V3 |
| /CS ---> D10 (PA11) |
| /WP ---> 3V3 |
| VCC ---> 3V3 |
| GND ---> GND |
| SO ---> D12 (PB4) |
--------------------------------
You can start with default "nucleo-l432kc/nsh" configuration option and
enable/disable these options using "make menuconfig" :
System Type --->
STM32L4 Peripheral Support --->
[*] SPI1
Device Drivers --->
-*- Memory Technology Device (MTD) Support --->
-*- SPI-based AT45DB flash
(1000000) AT45DB Frequency
File Systems --->
[*] NXFFS file system
Then after compiling and flashing the file nuttx.bin you can test the flash
this way:
nsh> ls /mnt
/mnt:
at45db/
nsh> echo "Testing" > /mnt/at45db/file.txt
nsh> ls /mnt/at45db
/mnt/at45db:
file.txt
nsh> cat /mnt/at45db/file.txt
Testing
nsh>
Configurations Configurations
============== ==============

View File

@ -56,6 +56,10 @@ ifeq ($(CONFIG_DAC7571),y)
CSRCS += stm32_dac7571.c CSRCS += stm32_dac7571.c
endif endif
ifeq ($(CONFIG_MTD_AT45DB),y)
CSRCS += stm32_at45db.c
endif
ifeq ($(CONFIG_SENSORS_QENCODER),y) ifeq ($(CONFIG_SENSORS_QENCODER),y)
CSRCS += stm32_qencoder.c CSRCS += stm32_qencoder.c
endif endif

View File

@ -54,6 +54,7 @@
#define HAVE_PROC 1 #define HAVE_PROC 1
#define HAVE_RTC_DRIVER 1 #define HAVE_RTC_DRIVER 1
#define HAVE_AT45DB 1
#if !defined(CONFIG_FS_PROCFS) #if !defined(CONFIG_FS_PROCFS)
# undef HAVE_PROC # undef HAVE_PROC
@ -70,6 +71,12 @@
# undef HAVE_RTC_DRIVER # undef HAVE_RTC_DRIVER
#endif #endif
/* Check if we can support AT45DB FLASH file system */
#if !defined(CONFIG_STM32L4_SPI1) || !defined(CONFIG_MTD_AT45DB)
# undef HAVE_AT45DB
#endif
/* LED. User LD3: the green LED is a user LED connected to Arduino signal D13 /* LED. User LD3: the green LED is a user LED connected to Arduino signal D13
* corresponding to MCU I/O PB3 (pin 26) * corresponding to MCU I/O PB3 (pin 26)
* target. * target.
@ -83,6 +90,14 @@
GPIO_SPEED_50MHz) GPIO_SPEED_50MHz)
#define LED_DRIVER_PATH "/dev/userleds" #define LED_DRIVER_PATH "/dev/userleds"
/* SPI chip selects */
#ifdef CONFIG_MTD_AT45DB
# define AT45DB_SPI1_CS \
(GPIO_PORTA | GPIO_PIN11 | GPIO_OUTPUT_SET | GPIO_OUTPUT | GPIO_PUSHPULL | \
GPIO_SPEED_50MHz)
#endif
/************************************************************************************ /************************************************************************************
* Public Data * Public Data
************************************************************************************/ ************************************************************************************/
@ -156,6 +171,18 @@ int stm32l4_adc_setup(void);
int stm32_dac7571initialize(FAR const char *devpath); int stm32_dac7571initialize(FAR const char *devpath);
#endif #endif
/************************************************************************************
* Name: stm32_at45dbinitialize
*
* Description:
* Initialize and register the AT45DB driver.
*
************************************************************************************/
#ifdef CONFIG_MTD_AT45DB
int stm32_at45dbinitialize(int minor);
#endif
/**************************************************************************** /****************************************************************************
* Name: board_timer_driver_initialize * Name: board_timer_driver_initialize
* *

View File

@ -170,6 +170,18 @@ int board_app_initialize(uintptr_t arg)
} }
#endif #endif
#ifdef HAVE_AT45DB
/* Initialize and register the ATDB FLASH file system. */
ret = stm32_at45dbinitialize(0);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize AT45DB minor %d: %d\n",
0, ret);
return ret;
}
#endif
#ifdef CONFIG_PWM #ifdef CONFIG_PWM
/* Initialize PWM and register the PWM device. */ /* Initialize PWM and register the PWM device. */

View File

@ -82,20 +82,39 @@ struct spi_dev_s *g_spi2;
void stm32l4_spiinitialize(void) void stm32l4_spiinitialize(void)
{ {
#ifdef CONFIG_STM32L4_SPI1 #ifdef CONFIG_STM32L4_SPI1
/* Configure SPI1-based devices */
g_spi1 = stm32l4_spibus_initialize(1); g_spi1 = stm32l4_spibus_initialize(1);
if (!g_spi1)
spiinfo("SPI1 initialized\n"); {
#endif spierr("ERROR: FAILED to initialize SPI port 1\n");
}
#ifdef CONFIG_STM32L4_SPI2 else
/* Configure SPI-based devices */ {
spiinfo("INFO: SPI port 1 initialized\n");
g_spi2 = stm32l4_spibus_initialize(2); }
/* Setup CS, EN & IRQ line IOs */ /* Setup CS, EN & IRQ line IOs */
spiinfo("SPI2 initialized\n"); #ifdef CONFIG_MTD_AT45DB
(void)stm32l4_configgpio(AT45DB_SPI1_CS); /* FLASH chip select */
#endif
#endif
#ifdef CONFIG_STM32L4_SPI2
/* Configure SPI2-based devices */
g_spi2 = stm32l4_spibus_initialize(2);
if (!g_spi2)
{
spierr("ERROR: FAILED to initialize SPI port 2\n");
}
else
{
spiinfo("INFO: SPI port 2 initialized\n");
}
/* Setup CS, EN & IRQ line IOs */
#endif #endif
} }
@ -129,6 +148,12 @@ void stm32l4_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected
{ {
spiinfo("devid: %08X CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); spiinfo("devid: %08X CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
#ifdef CONFIG_MTD_AT45DB
if (devid == SPIDEV_FLASH(0))
{
stm32l4_gpiowrite(AT45DB_SPI1_CS, !selected);
}
#endif
} }
uint8_t stm32l4_spi1status(FAR struct spi_dev_s *dev, uint32_t devid) uint8_t stm32l4_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)