Browse Source

add lib/spi.*

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 6 years ago
parent
commit
8f97f1aab0
  1. 3
      Makefile
  2. 1
      lib/lib.mk
  3. 25
      lib/spi.c
  4. 22
      lib/spi.h
  5. 2
      targets/spectrum/flash.ld
  6. 7
      targets/spectrum/main.c
  7. 121
      targets/spectrum/retarget.c
  8. 43
      targets/spectrum/target.h

3
Makefile

@ -50,7 +50,8 @@ COMM_CFLAGS += -mlittle-endian -mthumb -fno-common -Wall -ffunction-sections -fd
include $(lib_dir)/lib.mk
target ?= vocoder
#target ?= vocoder
target ?= spectrum
target_dir := $(top_dir)/targets/$(target)

1
lib/lib.mk

@ -19,6 +19,7 @@ lib_srcs += \
$(lib_dir)/iic.c \
$(lib_dir)/i2c.c \
$(lib_dir)/iis.c \
$(lib_dir)/spi.c \
$(lib_dir)/at24c256_i2c.c \
$(lib_dir)/at24c256_iic.c \
$(lib_dir)/eeprom.c \

25
lib/spi.c

@ -0,0 +1,25 @@
#include "stm32f4xx.h"
#include "gpio.h"
#include "spi.h"
struct spi_descr {
SPI_TypeDef *base;
uint32_t rcc;
SPI_InitTypeDef conf;
void (*setup)(struct spi_descr *);
uint32_t cs;
};
int spi_setup(spi_t spi, uint32_t cs, int mode)
{
spi->cs = cs;
gpio_init(cs, GPIO_OUTPUT);
if (spi->setup)
spi->setup(spi);
return 0;
}

22
lib/spi.h

@ -0,0 +1,22 @@
#ifndef __SPI_H____
#define __SPI_H____
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "config.h"
typedef struct spi_descr *spi_t;
#define SPI_MODE_0 (0)
#define SPI_MODE_1 (1)
#define SPI_MODE_2 (2)
#define SPI_MODE_3 (2)
int spi_setup(spi_t, uint32_t cs, int mode);
#ifdef __cplusplus
}
#endif
#endif

2
targets/spectrum/flash.ld

@ -6,7 +6,7 @@ MEMORY {
ram2 (xrw) : org = 0x2001c000, len = 16K
ram3 (xrw) : org = 0x20020000, len = 64K
ccmram (rw): org = 0x10000000, len = 64K
sdram (rw): org = 0xc0000000, len = 32M
sdram (rw): org = 0xd0000000, len = 4M
}
SECTIONS {
.isr_vector : {

7
targets/spectrum/main.c

@ -4,13 +4,6 @@
int main()
{
bkp_sram_init();
cmd_init();
/* debug console */
serial_setup(&serial0, CONSOLE_BAUDRATE, 8, SERIAL_STOPBITS_1);
printf("build: %s (%s)\r\n", __DATE__, __TIME__);
bkp_sram_write(MAGIC_POS, MAGIC_APP);

121
targets/spectrum/retarget.c

@ -1,5 +1,11 @@
#include <stdlib.h>
#include "eeprom.h"
#include "stm32f4xx.h"
#include "serial.h"
#include "cmd.h"
#include "gpio.h"
#include "dwt.h"
#include "tick.h"
int console_read(void *ptr, int len)
{
@ -9,17 +15,36 @@ int console_read(void *ptr, int len)
int console_write(const void *_ptr, int len)
{
const uint8_t *ptr = _ptr;
#if 0
int n = len, x = len;
while (len > 0) {
n = serial_send_buffered(&serial0, ptr, len);
len -= n;
ptr += n;
}
return (x);
#else
return serial_send_blocking(&serial0, ptr, len);
#endif
}
static void init_board(void)
{
bkp_sram_init();
eeprom_init_with_io(PB8, PB9, 0x50, 0);
cmd_init();
/* debug console */
serial_setup(&serial0, CONSOLE_BAUDRATE, 8, SERIAL_STOPBITS_1);
gpio_init(WDI, GPIO_OUTPUT);
gpio_init(JPB1_VCC18_EN, GPIO_OUTPUT);
gpio_init(JPB1_VCC13_PG, GPIO_INPUT | GPIO_FLAG_PP | GPIO_FLAG_PU);
gpio_init(NAND_WP, GPIO_OUTPUT);
/* disable nand write protected */
gpio_set(NAND_WP);
gpio_init(CLK_MUX_OE, GPIO_OUTPUT);
gpio_set(CLK_MUX_OE);
gpio_init(CLK_MUX_PD, GPIO_OUTPUT);
gpio_set(CLK_MUX_PD);
gpio_init(SC18IS602_RST, GPIO_OUTPUT);
ticks_init(TICKS_PERIOD);
}
#ifdef BOOT_FROM_APP
@ -28,6 +53,82 @@ void lowlevel_init(void)
NVIC_SetVectorTable(NVIC_VectTab_FLASH, (APP_ADDRESS - NVIC_VectTab_FLASH));
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
__enable_irq();
init_board();
}
#else
void lowlevel_init(void)
{
init_board();
}
#endif
void target_uart4_setup()
{
GPIO_InitTypeDef gpio_conf;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_StructInit(&gpio_conf);
gpio_conf.GPIO_Pin = GPIO_Pin_10;
gpio_conf.GPIO_OType = GPIO_OType_PP;
gpio_conf.GPIO_Mode = GPIO_Mode_AF;
gpio_conf.GPIO_Speed = GPIO_Speed_50MHz;
gpio_conf.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &gpio_conf);
gpio_conf.GPIO_Pin = GPIO_Pin_11;
gpio_conf.GPIO_OType = GPIO_OType_OD;
gpio_conf.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &gpio_conf);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);
}
static int do_eer(cmd_tbl_t s, int argc, char *argv[])
{
uint16_t addr;
uint8_t val;
if (argc >= 2) {
addr = strtoul(argv[1], NULL, 0);
val = eeprom_read(addr);
printf("%04x: %02x\r\n", addr, val);
}
return 0;
}
CON_CMD(eer, 2, "read from eeprom", do_eer);
static int do_eew(cmd_tbl_t s, int argc, char *argv[])
{
uint16_t addr;
uint8_t val;
if (argc >= 3) {
addr = strtoul(argv[1], NULL, 0);
val = strtoul(argv[2], NULL, 0);
eeprom_write(addr, val);
}
return 0;
}
CON_CMD(eew, 3, "write to eeprom", do_eew);
static int do_vcc13(cmd_tbl_t s, int argc, char *argv[])
{
int r = gpio_read(JPB1_VCC13_PG);
printf("vcc1.3_pwr_good: %d %s\n", r, r ? "fault" : "good");
return 0;
}
CON_CMD(vcc13, 1, "vcc 1.3v power good", do_vcc13);
static int do_sc18is_rst(cmd_tbl_t s, int argc, char *argv[])
{
gpio_clear(SC18IS602_RST);
delay(20);
gpio_set(SC18IS602_RST);
return 0;
}
CON_CMD(sc18is_rst, 1, "reset sc18is602", do_sc18is_rst);

43
targets/spectrum/target.h

@ -6,50 +6,33 @@
#define TARGET_VROM_SECT_CNT 1
#define APP_ADDRESS (0x08008000)
#define LED_D3 (PI13)
#define LED_D4 (PK5)
#define LED_D5 (PK6)
#define LED_D6 (PK7)
#define TICKS_PERIOD (2) /* mill seconds */
#define CONSOLE_BAUDRATE (115200)
#define TARGET_MAGIC_DBG (0x01000001)
#define TARGET_MAGIC_UART4 (0x04000004)
#define TARGET_MAGIC_UART6 (0x06000006)
#define TARGET_HEAP_SIZE (8192)
#define TARGET_HAS_USART1 1
#define TARGET_HAS_USART2 0
#define TARGET_USART2_RX_BUFFER_SIZE (2048)
#define TARGET_USART2_TX_BUFFER_SIZE (2048)
#define TARGET_HAS_USART3 0
#define TARGET_HAS_USART3 1
#define TARGET_USART3_RX_BUFFER_SIZE (2048)
#define TARGET_USART3_TX_BUFFER_SIZE (2048)
#define TARGET_HAS_USART4 0
#define TARGET_HAS_USART4 1
#define TARGET_USART4_RX_BUFFER_SIZE (2048)
#define TARGET_USART4_TX_BUFFER_SIZE (2048)
#define TARGET_HAS_USART5 0
#define TARGET_USART5_RX_BUFFER_SIZE (2048)
#define TARGET_USART5_TX_BUFFER_SIZE (2048)
#define TARGET_HAS_USART6 0
#define TARGET_USART6_RX_BUFFER_SIZE (2048)
#define TARGET_USART6_TX_BUFFER_SIZE (2048)
#define TARGET_HAS_USART7 0
#define TARGET_HAS_USART7 1
#define TARGET_USART7_RX_BUFFER_SIZE (2048)
#define TARGET_USART7_TX_BUFFER_SIZE (2048)
#define TARGET_HAS_TIM1 0
#define TARGET_HAS_TIM3 1
#define TARGET_HAS_I2C1 1
#define TARGET_HEAP_SIZE (8192)
#define WDI (PA1)
#define JPB1_VCC18_EN (PC13)
#define JPB1_VCC13_PG (PA8)
#define NAND_WP (PC5)
#define CLK_MUX_OE (PF9)
#define CLK_MUX_PD (PF10)
#define SC18IS602_RST (PB0)
#endif

Loading…
Cancel
Save