16 #include "sysconfig.h" 25 #define RCC_AHB1ENR (*(volatile unsigned long *)0x40023830) 26 #define RCC_AHB1LPENR (*(volatile unsigned long *)0x40023850) 27 #define RCC_AHB1_BIT_GPIOB (1UL<<1) 29 #define GPIOB_MODER (*(volatile unsigned long *)0x40020400) 30 #define GPIO_MODE_BIT_IN 0x00 // Input Mode 31 #define GPIO_MODE_BIT_OUT 0x01 // Output Mode 32 #define GPIO_MODE_BIT_AF 0x02 // Alternate functions Mode 33 #define GPIO_MODE_BIT_AN 0x03 // Analog Mode 34 #define GPIO_MODE_BIT_ALL 0x03 36 #define GPIOB_OTYPE (*(volatile unsigned long *)0x40020404) 37 #define GPIO_OTYPE_BIT_PP 0x00 // push-pull 38 #define GPIO_OTYPE_BIT_OD 0x01 // open-drain 40 #define GPIOB_OSPEEDR (*(volatile unsigned long *)0x40020408) 41 #define GPIO_OSPEED_BIT_ALL 0x03 42 #define GPIO_OSPEED_BIT_50MHz 0x02 43 #define GPIO_OSPEED_BIT_100MHz 0x03 45 #define GPIOB_PUPDR (*(volatile unsigned long *)0x4002040C) 46 #define GPIO_PUPDR_BIT_NOPULL 0x00 // No pull-up, pull-down 47 #define GPIO_PUPDR_BIT_PUP 0x01 // pull-up 48 #define GPIO_PUPDR_BIT_PDOWN 0x02 // pull-down 49 #define GPIO_PUPDR_BIT_ALL 0x03 51 #define GPIOB_IDR (*(volatile unsigned long *)0x40020410) 52 #define GPIOB_ODR (*(volatile unsigned long *)0x40020414) 53 #define GPIOB_BSRRL (*(volatile unsigned short *)0x40020418) 54 #define GPIOB_BSRRH (*(volatile unsigned short *)0x4002041A) 55 #define GPIOB_LCKR (*(volatile unsigned long *)0x4002041C) 56 #define GPIOB_AFRL (*(volatile unsigned long *)0x40020420) 57 #define GPIOB_AFRH (*(volatile unsigned long *)0x40020424) 59 static void init_pin(
int pos)
61 GPIOB_MODER &= ~(((
unsigned long)GPIO_MODE_BIT_ALL) << (2*pos));
62 GPIOB_MODER |= (((
unsigned long)GPIO_MODE_BIT_OUT) << (2*pos));
63 GPIOB_OSPEEDR &= ~(((
unsigned long)GPIO_OSPEED_BIT_ALL) << (2*pos));
64 GPIOB_OSPEEDR |= (((
unsigned long)GPIO_OSPEED_BIT_100MHz) << (2*pos));
65 GPIOB_OTYPE &= ~(((
unsigned long)1) << pos);
66 GPIOB_OTYPE |= (((
unsigned long)GPIO_OTYPE_BIT_PP) << pos);
67 GPIOB_PUPDR &= ~(((
unsigned long)GPIO_PUPDR_BIT_ALL) << (2*pos));
68 GPIOB_PUPDR |= (((
unsigned long)GPIO_PUPDR_BIT_NOPULL) << (2*pos));
71 #define CS_PIN 6 // GPIOB 6 73 static void cs_low(
void)
75 GPIOB_BSRRH = (1UL<<CS_PIN);
78 static void cs_high(
void)
80 GPIOB_BSRRL = (1UL<<CS_PIN);
86 static int mmc_register(
struct st_device *dev,
char *param)
90 SYSERR_PRINT(
"Cannot open device \"%s\"\n", param);
94 RCC_AHB1ENR |= RCC_AHB1_BIT_GPIOB;
101 static int mmc_getc(
struct st_device *dev,
unsigned char *rd)
112 static int mmc_read(
struct st_device *dev,
void *data,
unsigned int size)
123 static int mmc_putc(
struct st_device *dev,
unsigned char ch)
134 static int mmc_write(
struct st_device *dev,
const void *data,
unsigned int size)
145 static int mmc_ioctl(
struct st_device *dev,
unsigned int com,
unsigned int arg,
void *param)
166 static int mmc_suspend(
struct st_device *dev)
177 static int mmc_resume(
struct st_device *dev)
189 const struct st_device stm_mmc_device = {
191 .explan =
"STM32F4xx Nucleo SPI MMC",
192 .register_dev = mmc_register,
198 .suspend = mmc_suspend,
199 .resume = mmc_resume,
#define IOCMD_SPI_CS0NEGATE
CS0をネゲートする
struct st_device * open_device(char *name)
デバイスをオープンする
int write_device(struct st_device *dev, const void *buf, unsigned int count)
デバイスにデータを書き込む
int read_device(struct st_device *dev, void *buf, unsigned int count)
デバイスよりデータを読み出す
int resume_device(struct st_device *dev)
デバイスを活性化する
int getc_device(struct st_device *dev, unsigned char *data)
デバイスよりデータを1バイト読み出す
#define IOCMD_SPI_CS0ASSERT
CS0をアサートしたままにする
int putc_device(struct st_device *dev, unsigned char data)
デバイスにデータを1バイト書き込む
int suspend_device(struct st_device *dev)
デバイスを休止状態にする
int ioctl_device(struct st_device *dev, unsigned int com, unsigned int arg, void *param)
デバイスを制御する
char name[MAX_DEVNAMELRN]
デバイス名文字列