2 Commits

Author SHA1 Message Date
Eric Holland
b49f9c2227 [gpio] workaround for STM pulldown/pullup defines 2016-05-05 12:45:34 -07:00
Eric Holland
49eadd6b47 [target] Add target for NextCoinP0 2016-05-04 11:52:51 -07:00
19 changed files with 1315 additions and 3 deletions

View File

@@ -27,6 +27,13 @@
#include <platform/stm32.h>
#include <platform/gpio.h>
/**
* workaround for conflict in LK vs STM HAL defines for pullup and pulldown config
*/
#define STM_GPIO_PULLUP ((uint32_t)0x00000001) /*!< Pull-up activation */
#define STM_GPIO_PULLDOWN ((uint32_t)0x00000002) /*!< Pull-down activation */
#define STM_GPIO_NOPULL ((uint32_t)0x00000000) /*!< No Pull-up or Pull-down activation */
static GPIO_TypeDef *port_to_pointer(unsigned int port)
{
DEBUG_ASSERT(port <= GPIO_PORT_K);
@@ -136,11 +143,11 @@ int gpio_config(unsigned nr, unsigned flags)
}
if (flags & GPIO_PULLUP) {
init.Pull = GPIO_PULLUP;
init.Pull = STM_GPIO_PULLUP;
} else if (flags & GPIO_PULLDOWN) {
init.Pull = GPIO_PULLDOWN;
init.Pull = STM_GPIO_PULLDOWN;
} else {
init.Pull = GPIO_NOPULL;
init.Pull = STM_GPIO_NOPULL;
}
HAL_GPIO_Init(port_to_pointer(port), &init);

View File

@@ -0,0 +1,19 @@
include project/target/nextcoinP0.mk
include project/virtual/test.mk
# Console serial port is on pins PA9(TX) and PB7(RX)
include project/virtual/fs.mk
MODULES += \
target/nextcoinP0/projects/system
MODULE_DEPS += \
app/accelerometer \
MODULE_SRCS += \
$(LOCAL_DIR)/sensor_bus.c \
GLOBAL_DEFINES += \
ENABLE_SENSORBUS=1

View File

@@ -0,0 +1,3 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
TARGET := nextcoinP0

View File

@@ -0,0 +1,150 @@
/*
* Copyright (c) 2015 Eric Holland
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __SENSOR_BMI055_H
#define __SENSOR_BMI055_H
#include <sys/types.h>
#define BMI055_ADDRESS_READ(x) (x | 0x80)
#define BMI055_ADDERSS_WRITE(x) (x & 0x7F)
/**
* definitions for accelerometer IC
*/
#define BMI055_ACC_BGW_CHPID 0x00
#define BMI055_ACC_ACCD_X_LSB 0X02
#define BMI055_ACC_ACCD_X_MSB 0X03
#define BMI055_ACC_ACCD_Y_LSB 0X04
#define BMI055_ACC_ACCD_Y_MSB 0X05
#define BMI055_ACC_ACCD_Z_LSB 0X06
#define BMI055_ACC_ACCD_Z_MSB 0X07
#define BMI055_ACC_ACCD_TEMP 0X08
#define BMI055_ACC_INT_STATUS_0 0X09
#define BMI055_ACC_INT_STATUS_1 0X0a
#define BMI055_ACC_INT_STATUS_2 0x0b
#define BMI055_ACC_INT_STATUS_3 0x0c
#define BMI055_ACC_FIFO_STATUS 0x0e
#define BMI055_ACC_PMU_RANGE 0x0f
#define BMI055_ACC_PMU_BW 0x10
#define BMI055_ACC_PMU_LPW 0x11
#define BMI055_ACC_PMU_LOW_POWER 0x12
#define BMI055_ACC_ACCD_HBW 0x13
#define BMI055_ACC_BGW_SOFTRESET 0x14
#define BMI055_ACC_INT_EN_0 0x16
#define BMI055_ACC_INT_EN_1 0x17
#define BMI055_ACC_INT_EN_2 0x18
#define BMI055_ACC_INT_MAP_0 0x19
#define BMI055_ACC_INT_MAP_1 0x1A
#define BMI055_ACC_INT_MAP_2 0x1B
#define BMI055_ACC_INT_SRC 0x1E
#define BMI055_ACC_INT_OUT_CTRL 0x20
#define BMI055_ACC_INT_RST_LATCH 0x21
#define BMI055_ACC_INT_0 0x22
#define BMI055_ACC_INT_1 0x23
#define BMI055_ACC_INT_2 0x24
#define BMI055_ACC_INT_3 0x25
#define BMI055_ACC_INT_4 0x26
#define BMI055_ACC_INT_5 0x27
#define BMI055_ACC_INT_6 0x28
#define BMI055_ACC_INT_7 0x29
#define BMI055_ACC_INT_8 0x2a
#define BMI055_ACC_INT_9 0x2b
#define BMI055_ACC_INT_A 0x2c
#define BMI055_ACC_INT_B 0x2d
#define BMI055_ACC_INT_C 0x2e
#define BMI055_ACC_INT_D 0x2f
#define BMI055_ACC_FIFO_CONFIG_0 0x30
#define BMI055_ACC_PMU_SELF_TEST 0x32
#define BMI055_ACC_TRIM_NVM_CTRL 0x33
#define BMI055_ACC_BGW_SPI3_WDT 0x34
#define BMI055_ACC_OFC_CTRL 0x36
#define BMI055_ACC_OFC_SETTING 0x37
#define BMI055_ACC_OFC_OFFSET_X 0x38
#define BMI055_ACC_OFC_OFFSET_Y 0x39
#define BMI055_ACC_OFC_OFFSET_Z 0x3A
#define BMI055_ACC_TRIM_GP0 0x3B
#define BMI055_ACC_TRIM_GP1 0x3C
#define BMI055_ACC_FIFO_CONFIG_1 0x3E
#define BMI055_ACC_FIFO_DATA 0x3F
/**
* definitions for gyro IC
*/
#define BMI055_GYRO_CHIP_ID 0x00
#define BMI055_GYRO_RATE_X_LSB 0X02
#define BMI055_GYRO_RATE_X_MSB 0X03
#define BMI055_GYRO_RATE_Y_LSB 0X04
#define BMI055_GYRO_RATE_Y_MSB 0X05
#define BMI055_GYRO_RATE_Z_LSB 0X06
#define BMI055_GYRO_RATE_Z_MSB 0X07
#define BMI055_GYRO_INT_STATUS_0 0X09
#define BMI055_GYRO_INT_STATUS_1 0X0a
#define BMI055_GYRO_INT_STATUS_2 0x0b
#define BMI055_GYRO_INT_STATUS_3 0x0c
#define BMI055_GYRO_FIFO_STATUS 0x0e
#define BMI055_GYRO_RANGE 0x0f
#define BMI055_GYRO_BW 0x10
#define BMI055_GYRO_LPM1 0x11
#define BMI055_GYRO_LPM2 0x12
#define BMI055_GYRO_RATE_HBW 0x13
#define BMI055_GYRO_BGW_SOFTRESET 0x14
#define BMI055_GYRO_INT_EN_0 0x15
#define BMI055_GYRO_INT_EN_1 0x16
#define BMI055_GYRO_INT_MAP_0 0x17
#define BMI055_GYRO_INT_MAP_1 0x18
#define BMI055_GYRO_INT_MAP_2 0x19
#define BMI055_GYRO_0X1A 0x1A
#define BMI055_GYRO_0X1B 0x1B
#define BMI055_GYRO_0X1C 0x1C
#define BMI055_GYRO_0X1E 0x1E
#define BMI055_GYRO_INT_RST_LATCH 0x21
#define BMI055_GYRO_HIGH_TH_X 0x22
#define BMI055_GYRO_HIGH_DUR_X 0x23
#define BMI055_GYRO_HIGH_TH_Y 0x24
#define BMI055_GYRO_HIGH_DUR_Y 0x25
#define BMI055_GYRO_HIGH_TH_Z 0x26
#define BMI055_GYRO_HIGH_DUR_Z 0x27
#define BMI055_GYRO_SOC 0x31
#define BMI055_GYRO_A_FOC 0x32
#define BMI055_GYRO_TRIM_NVM_CTRL 0x33
#define BMI055_GYRO_BGW_SPI3_WDT 0x34
#define BMI055_GYRO_OFC1 0x36
#define BMI055_GYRO_OFC2 0x37
#define BMI055_GYRO_OFC3 0x38
#define BMI055_GYRO_OFC4 0x39
#define BMI055_GYRO_TRIM_GP0 0x3A
#define BMI055_GYRO_TRIM_GP1 0x3B
#define BMI055_GYRO_BIST 0x3C
#define BMI055_GYRO_FIFO_CONFIG_0 0x3D
#define BMI055_GYRO_FIFO_CONFIG_1 0x3E
#endif

View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) 2012 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __TARGET_DEBUGCONFIG_H
#define __TARGET_DEBUGCONFIG_H
#define DEBUG_UART 3
#endif

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016 Craig Stout <cstout@chromium.org>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// 1.28 Inch Monocromatic Sharp Memory LCD
#pragma once
#include <dev/display.h>
#define MLCD_WIDTH ((uint16_t)128)
#define MLCD_HEIGHT ((uint16_t)128)
// Ensure width corresponds to an integral number of bytes
STATIC_ASSERT((MLCD_WIDTH & 0x3) == 0);
// 1 bit per pixel divided by 8 bits per byte
#define MLCD_BYTES_LINE (MLCD_WIDTH / 8)
#define MLCD_FORMAT (DISPLAY_FORMAT_MONO_1)
uint8_t lcd_get_line(struct display_image *image, uint8_t idx, uint8_t *result);

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// 1.33 Inch 3-Bit RGB Sharp Color LCD
#pragma once
#include <dev/display.h>
#define MLCD_WIDTH ((uint16_t)128)
#define MLCD_HEIGHT ((uint16_t)128)
// Ensure width corresponds to an integral number of bytes
STATIC_ASSERT(((MLCD_WIDTH * 3) & 0x3) == 0);
// 3 bits per pixel (1 for each of RBG) divided by 8 bits per byte.
#define MLCD_BYTES_LINE ((MLCD_WIDTH * 3) / 8)
#define MLCD_FORMAT (DISPLAY_FORMAT_RGB_111)
uint8_t lcd_get_line(struct display_image *image, uint8_t idx, uint8_t *result);

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// 2.7 Inch Monocromatic Sharp Memory LCD
#pragma once
#include <dev/display.h>
#define MLCD_WIDTH ((uint16_t)400)
#define MLCD_HEIGHT ((uint16_t)240)
// Ensure width corresponds to an integral number of bytes
STATIC_ASSERT((MLCD_WIDTH & 0x3) == 0);
// 1 bit per pixel divided by 8 bits per byte
#define MLCD_BYTES_LINE (MLCD_WIDTH / 8)
#define MLCD_FORMAT (DISPLAY_FORMAT_MONO_1)
uint8_t lcd_get_line(struct display_image *image, uint8_t idx, uint8_t *result);

View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2012 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __TARGET_GPIOCONFIG_H
#define __TARGET_GPIOCONFIG_H
#include <platform/gpio.h>
#include <platform/stm32.h>
#define GPIO_LED_ON GPIO_PIN_RESET
#define GPIO_LED_OFF GPIO_PIN_SET
#define GPIO_USART3_TX GPIO(GPIO_PORT_B, 10)
#define GPIO_USART3_RX GPIO(GPIO_PORT_B, 11)
#define GPIO_LED108 GPIO(GPIO_PORT_E, 3)
#define GPIO_LED109 GPIO(GPIO_PORT_E, 4)
#define GPIO_LED110 GPIO(GPIO_PORT_E, 5)
#define GPIO_LED111 GPIO(GPIO_PORT_E, 6)
#define GPIO_LED112 GPIO(GPIO_PORT_D, 6)
#define GPIO_LED113 GPIO(GPIO_PORT_D, 7)
#define GPIO_LED114 GPIO(GPIO_PORT_J, 10)
#define GPIO_LED115 GPIO(GPIO_PORT_J, 11)
#define GPIO_SHIELD_D0 GPIO(GPIO_PORT_B, 11)
#define GPIO_SHIELD_D1 GPIO(GPIO_PORT_B, 10)
#define GPIO_SHIELD_D2 GPIO(GPIO_PORT_E, 3)
#define GPIO_SHIELD_D3 GPIO(GPIO_PORT_E, 4)
#define GPIO_SHIELD_D4 GPIO(GPIO_PORT_E, 5)
#define GPIO_SHIELD_D5 GPIO(GPIO_PORT_E, 6)
#define GPIO_SHIELD_D6 GPIO(GPIO_PORT_D, 6)
#define GPIO_SHIELD_D7 GPIO(GPIO_PORT_D, 7)
#define GPIO_SHIELD_D8 GPIO(GPIO_PORT_J, 10)
#define GPIO_SHIELD_D9 GPIO(GPIO_PORT_J, 11)
#define GPIO_SHIELD_D10 GPIO(GPIO_PORT_J, 12)
#define GPIO_SHIELD_D11 GPIO(GPIO_PORT_J, 13)
#define GPIO_SHIELD_D12 GPIO(GPIO_PORT_J, 14)
#define GPIO_SHIELD_D13 GPIO(GPIO_PORT_J, 15)
#define GPIO_SHIELD_ADC0 GPIO(GPIO_PORT_F, 6)
#define GPIO_SHIELD_ADC1 GPIO(GPIO_PORT_F, 10)
#define GPIO_SHIELD_ADC2 GPIO(GPIO_PORT_A, 3)
#define GPIO_SHIELD_ADC3 GPIO(GPIO_PORT_A, 5)
#define GPIO_SHIELD_ADC4 GPIO(GPIO_PORT_A, 6)
#define GPIO_SHIELD_ADC5 GPIO(GPIO_PORT_B, 0)
#define GPIO_SW100 GPIO(GPIO_PORT_J, 12)
#define GPIO_SW101 GPIO(GPIO_PORT_J, 13)
#define GPIO_SW102 GPIO(GPIO_PORT_J, 14)
#define GPIO_SW103 GPIO(GPIO_PORT_J, 15)
/**
* Definitions for sensor bus signals. Includes
* nrf51, accelerometer, and gyroscope
*/
#define __HAL_SENSOR_BUS_GPIO_CLK_ENABLE() \
__HAL_RCC_GPIOK_CLK_ENABLE(); \
__HAL_RCC_GPIOF_CLK_ENABLE()
#define GPIO_NRF_CS GPIO(GPIO_PORT_K, 0)
#define GPIO_NRF_INT GPIO(GPIO_PORT_K, 1)
#define GPIO_GYRO_nCS GPIO(GPIO_PORT_K, 4)
#define GPIO_GYRO_INT GPIO(GPIO_PORT_K, 5)
#define GPIO_ACC_nCS GPIO(GPIO_PORT_K, 2)
#define GPIO_ACC_INT GPIO(GPIO_PORT_K, 3)
#define GPIO_SPI5_SCK GPIO(GPIO_PORT_F, 7)
#define GPIO_SPI5_MISO GPIO(GPIO_PORT_F, 8)
#define GPIO_SPI5_MOSI GPIO(GPIO_PORT_F, 9)
#endif

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __TARGET_DARTUINOP0_MEMORY_LCD_H_
#define __TARGET_DARTUINOP0_MEMORY_LCD_H_
#include <stm32f7xx.h>
// Initialize the QSPI Flash device.
status_t memory_lcd_init(void);
#endif // __TARGET_DARTUINOP0_MEMORY_LCD_H_

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2015 Eric Holland
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __SENSOR_BUS_H
#define __SENSOR_BUS_H
#include <sys/types.h>
#include <dev/accelerometer.h>
status_t sensor_bus_init_early(void);
void sensor_bus_init(void);
status_t acc_read(uint8_t address, uint8_t *data);
status_t acc_flush(uint8_t *tbuff, uint8_t *rbuff, uint8_t numbytes);
#endif

462
target/nextcoinP0/init.c Normal file
View File

@@ -0,0 +1,462 @@
/*
* Copyright (c) 2015 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <err.h>
#include <stdlib.h>
#include <debug.h>
#include <trace.h>
#include <target.h>
#include <compiler.h>
#include <dev/gpio.h>
#include <dev/usb.h>
#include <dev/accelerometer.h>
#include <platform/stm32.h>
#include <platform/sdram.h>
#include <platform/gpio.h>
#include <platform/eth.h>
#include <platform/qspi.h>
#include <platform/n25q128a.h>
#include <target/bmi055.h>
#include <target/debugconfig.h>
#include <target/gpioconfig.h>
#include <reg.h>
#if ENABLE_LCD
#include <target/memory_lcd.h>
#endif
#if ENABLE_SENSORBUS
#include <target/sensor_bus.h>
#endif
#if WITH_LIB_MINIP
#include <lib/minip.h>
#endif
#if WITH_LIB_FS_SPIFS
#include <lib/fs.h>
#include <lib/fs/spifs.h>
#define SPIFS_TARGET_DEVICE "qspi-flash"
#endif
extern void target_usb_setup(void);
const sdram_config_t target_sdram_config = {
.bus_width = SDRAM_BUS_WIDTH_16,
.cas_latency = SDRAM_CAS_LATENCY_2,
.col_bits_num = SDRAM_COLUMN_BITS_8
};
void target_early_init(void)
{
GPIO_InitTypeDef gpio_init;
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOJ_CLK_ENABLE();
#if DEBUG_UART == 3
// configure usart 3 pins.
gpio_config(GPIO_USART3_TX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART3) | GPIO_PULLUP);
gpio_config(GPIO_USART3_RX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART3) | GPIO_PULLUP);
#else
#error need to configure gpio pins for debug uart
#endif
gpio_init.Mode = GPIO_MODE_OUTPUT_PP;
gpio_init.Pull = GPIO_NOPULL;
gpio_init.Speed = GPIO_SPEED_LOW;
gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED108) | GPIO_TO_PIN_MASK(GPIO_LED109) |
GPIO_TO_PIN_MASK(GPIO_LED110) | GPIO_TO_PIN_MASK(GPIO_LED111);
HAL_GPIO_Init(GPIOE, &gpio_init);
gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED112) | GPIO_TO_PIN_MASK(GPIO_LED113);
HAL_GPIO_Init(GPIOD, &gpio_init);
gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED114) | GPIO_TO_PIN_MASK(GPIO_LED115);
HAL_GPIO_Init(GPIOJ, &gpio_init);
// Initialize the switches GPIOs for interrupt on raising edge. In order
// to use stm32_EXTI15_10_IRQ() handler needs to be provided and EXTI15_10_IRQn
// needs to be enabled.
gpio_init.Mode = GPIO_MODE_INPUT;
gpio_init.Pull = GPIO_NOPULL;
gpio_init.Speed = GPIO_SPEED_FAST;
gpio_init.Mode = GPIO_MODE_IT_RISING;
gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_SW100) | GPIO_TO_PIN_MASK(GPIO_SW101) |
GPIO_TO_PIN_MASK(GPIO_SW102) | GPIO_TO_PIN_MASK(GPIO_SW103);
HAL_GPIO_Init(GPIOJ, &gpio_init);
#if ENABLE_SENSORBUS
// Initialize Sensor bus (accelerometer / gyroscope / nrf51 spi bus
sensor_bus_init_early();
#endif
// now that the uart gpios are configured, enable the debug uart.
stm32_debug_early_init();
// default all the debug leds to off
}
void target_init(void)
{
stm32_debug_init();
qspi_flash_init(N25Q128A_FLASH_SIZE);
#if ENABLE_LCD
memory_lcd_init();
#endif
#if WITH_LIB_MINIP
uint8_t mac_addr[6];
gen_random_mac_address(mac_addr);
eth_init(mac_addr, PHY_KSZ8721);
/* start minip */
minip_set_macaddr(mac_addr);
uint32_t ip_addr = IPV4(192, 168, 0, 98);
uint32_t ip_mask = IPV4(255, 255, 255, 0);
uint32_t ip_gateway = IPV4_NONE;
minip_init(stm32_eth_send_minip_pkt, NULL, ip_addr, ip_mask, ip_gateway);
#endif
#if WITH_LIB_FS_SPIFS
status_t mount_success = fs_mount(DEAULT_SPIFS_MOUNT_POINT,
DEAULT_SPIFS_NAME, SPIFS_TARGET_DEVICE);
if (mount_success != NO_ERROR) {
printf("failed to mount '%s' at path '%s' on '%s'."
" Make sure that device is formatted\n",
DEAULT_SPIFS_NAME, DEAULT_SPIFS_MOUNT_POINT,
SPIFS_TARGET_DEVICE);
}
#endif
// start usb
target_usb_setup();
#if ENABLE_SENSORBUS
sensor_bus_init();
#endif
}
void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{
GPIO_InitTypeDef GPIO_InitStruct;
if (hspi->Instance == SPI2) {
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* Enable GPIO TX/RX clock */
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOK_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/* Enable SPI clock */
__HAL_RCC_SPI2_CLK_ENABLE();
/*##-2- Configure peripheral GPIO ##########################################*/
/* SPI SCK GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* SPI MOSI GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_15;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
/* LCD_ON Pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_6;
HAL_GPIO_Init(GPIOK, &GPIO_InitStruct);
/* LCD_CS Pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_12;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*##-3- Configure the NVIC for SPI #########################################*/
/* NVIC for SPI */
HAL_NVIC_EnableIRQ(SPI2_IRQn);
}
}
/**
* @brief Initializes SDRAM GPIO.
* called back from stm32_sdram_init
*/
void stm_sdram_GPIO_init(void)
{
GPIO_InitTypeDef gpio_init_structure;
/* Enable GPIOs clock */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
/* Common GPIO configuration */
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_FAST;
gpio_init_structure.Alternate = GPIO_AF12_FMC;
/* GPIOC configuration */
gpio_init_structure.Pin = GPIO_PIN_3;
HAL_GPIO_Init(GPIOC, &gpio_init_structure);
/* GPIOD configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_8| GPIO_PIN_9 | GPIO_PIN_10 |\
GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
/* GPIOE configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_7| GPIO_PIN_8 | GPIO_PIN_9 |\
GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
GPIO_PIN_15;
HAL_GPIO_Init(GPIOE, &gpio_init_structure);
/* GPIOF configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
GPIO_PIN_15;
HAL_GPIO_Init(GPIOF, &gpio_init_structure);
/* GPIOG configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4| GPIO_PIN_5 | GPIO_PIN_8 |\
GPIO_PIN_15;
HAL_GPIO_Init(GPIOG, &gpio_init_structure);
/* GPIOH configuration */
gpio_init_structure.Pin = GPIO_PIN_3 | GPIO_PIN_5;
HAL_GPIO_Init(GPIOH, &gpio_init_structure);
}
/**
* @brief Initializes the ETH MSP.
* @param heth: ETH handle
* @retval None
*/
/* called back from the HAL_ETH_Init routine */
void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOs clocks */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
/* Ethernet pins configuration ************************************************/
/*
RMII_REF_CLK ----------------------> PA1
RMII_MDIO -------------------------> PA2
RMII_MDC --------------------------> PC1
RMII_MII_CRS_DV -------------------> PA7
RMII_MII_RXD0 ---------------------> PC4
RMII_MII_RXD1 ---------------------> PC5
RMII_MII_TX_EN --------------------> PG11
RMII_MII_TXD0 ---------------------> PG13
RMII_MII_TXD1 ---------------------> PG14
*/
/* Configure PA1, PA2 and PA7 */
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure PC1, PC4 and PC5 */
GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure PG2, PG11, PG13 and PG14 */
GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13 | GPIO_PIN_14;
HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
}
void HAL_QSPI_MspInit(QSPI_HandleTypeDef *hqspi)
{
GPIO_InitTypeDef GPIO_InitStruct;
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* Enable GPIO clocks */
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
/*##-2- Configure peripheral GPIO ##########################################*/
/* QSPI CS GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* QSPI CLK GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* QSPI D0 GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* QSPI D1 GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* QSPI D2 GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/* QSPI D3 GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}
/**
* @brief Initializes the PCD MSP.
* @param hpcd: PCD handle
* @retval None
*/
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
{
GPIO_InitTypeDef GPIO_InitStruct;
if (hpcd->Instance == USB_OTG_FS) {
/* Configure USB FS GPIOs */
__HAL_RCC_GPIOA_CLK_ENABLE();
/* Configure DM DP Pins */
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Enable USB FS Clock */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
/* Set USBFS Interrupt priority */
HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0);
/* Enable USBFS Interrupt */
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
if (hpcd->Init.low_power_enable == 1) {
/* Enable EXTI Line 18 for USB wakeup*/
__HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG();
__HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE();
__HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT();
/* Set EXTI Wakeup Interrupt priority*/
HAL_NVIC_SetPriority(OTG_FS_WKUP_IRQn, 0, 0);
/* Enable EXTI Interrupt */
HAL_NVIC_EnableIRQ(OTG_FS_WKUP_IRQn);
}
} else if (hpcd->Instance == USB_OTG_HS) {
/* Configure USB FS GPIOs */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
/* CLK */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* D0 */
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* D1 D2 D3 D4 D5 D6 D7 */
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 |\
GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* STP */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* NXT */
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
/* DIR */
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
__HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE();
/* Enable USB HS Clocks */
__HAL_RCC_USB_OTG_HS_CLK_ENABLE();
/* Set USBHS Interrupt to the lowest priority */
HAL_NVIC_SetPriority(OTG_HS_IRQn, 5, 0);
/* Enable USBHS Interrupt */
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
* Author: gkalsi@google.com (Gurjant Kalsi)
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
static char bootloader_primary_flash_name[] = "flash0";
static char bootloader_secondary_flash_name[] = "qspi-flash";
static char bootloader_mount_point[] = "/spifs";
#include <lib/fs.h>
#include <err.h>
#include <app/moot/stubs.h>
#include <stdio.h>
#define BOOTLOADER_SIZE_KB (64)
#define SYSTEM_FLASH_SIZE_KB (1024)
status_t moot_mount_default_fs(char **mount_path, char **device_name)
{
*mount_path = bootloader_mount_point;
*device_name = bootloader_secondary_flash_name;
return NO_ERROR;
}
const moot_sysinfo_t moot_system_info = {
.sys_base_addr = 0x00210000,
.btldr_offset = 0x0,
.bootloader_len = 1024 * BOOTLOADER_SIZE_KB,
.system_offset = 1024 * BOOTLOADER_SIZE_KB,
.system_len = (1024 * (SYSTEM_FLASH_SIZE_KB - BOOTLOADER_SIZE_KB)),
.system_flash_name = bootloader_primary_flash_name,
};

View File

@@ -0,0 +1,12 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
MODULE := $(LOCAL_DIR)
MODULE_SRCS += \
$(LOCAL_DIR)/bootloader_stubs.c
MODULE_DEPS += \
lib/fs
include make/module.mk

View File

@@ -0,0 +1,8 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
MODULE := $(LOCAL_DIR)
MODULE_SRCS += \
$(LOCAL_DIR)/system_stubs.c \
include make/module.mk

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
* Author: gkalsi@google.com (Gurjant Kalsi)
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <lib/ndebug/ndebug.h>
void append_usb_interfaces(void)
{
ndebug_init();
}

View File

@@ -0,0 +1,31 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
MODULE := $(LOCAL_DIR)
STM32_CHIP := stm32f756
PLATFORM := stm32f7xx
GLOBAL_DEFINES += \
ENABLE_UART3=1 \
PLL_M_VALUE=8 \
PLL_N_VALUE=336 \
PLL_P_VALUE=2 \
\
PKTBUF_POOL_SIZE=16 \
\
GLOBAL_INCLUDES += $(LOCAL_DIR)/include
MODULE_SRCS += \
$(LOCAL_DIR)/init.c \
$(LOCAL_DIR)/sensor_bus.c \
$(LOCAL_DIR)/usb.c \
MODULE_DEPS += \
dev/usb \
lib/ndebug
include make/module.mk

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 2015 Eric Holland
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <err.h>
#include <kernel/mutex.h>
#include <platform/gpio.h>
#include <target/gpioconfig.h>
#include <target/bmi055.h>
#include <target/sensor_bus.h>
#include <dev/accelerometer.h>
static mutex_t sensorbus_mutex;
static SPI_HandleTypeDef spi_handle;
static uint8_t tx_buff[16];
static uint8_t rx_buff[16];
status_t acc_read_xyz(position_vector_t *pos_vector_p)
{
tx_buff[0] = BMI055_ADDRESS_READ( BMI055_ACC_ACCD_X_LSB );
if ( acc_flush(tx_buff, rx_buff, 7) == NO_ERROR ) {
pos_vector_p->x = 0.001*(((int8_t)rx_buff[2] << 4) | ( (rx_buff[1] >> 4) & 0x0F));
pos_vector_p->y = 0.001*(((int8_t)rx_buff[4] << 4) | ( (rx_buff[3] >> 4) & 0x0F));
pos_vector_p->z = 0.001*(((int8_t)rx_buff[6] << 4) | ( (rx_buff[5] >> 4) & 0x0F));
return NO_ERROR;
} else {
return ERR_GENERIC;
}
}
status_t acc_flush(uint8_t *tbuff, uint8_t *rbuff, uint8_t numbytes)
{
status_t ret_status;
mutex_acquire(&sensorbus_mutex);
gpio_set(GPIO_ACC_nCS,GPIO_PIN_RESET);
ret_status = HAL_SPI_TransmitReceive(&spi_handle, tbuff, rbuff, numbytes, 5000);
gpio_set(GPIO_ACC_nCS,GPIO_PIN_SET);
mutex_release(&sensorbus_mutex);
return ret_status;
}
/**
* @brief Initiale SPI5 module and IO for control of spi bus linking nrf51, accelerometer, and gyroscope.
*
*/
status_t sensor_bus_init_early(void)
{
__HAL_SENSOR_BUS_GPIO_CLK_ENABLE();
__HAL_RCC_SPI5_CLK_ENABLE();
gpio_config(GPIO_SPI5_SCK, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF5_SPI5) | GPIO_PULLUP);
gpio_config(GPIO_SPI5_MISO, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF5_SPI5) | GPIO_PULLUP);
gpio_config(GPIO_SPI5_MOSI, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF5_SPI5) | GPIO_PULLUP);
gpio_config(GPIO_NRF_CS, GPIO_OUTPUT );
gpio_config(GPIO_NRF_INT, GPIO_INPUT | GPIO_PULLUP);
gpio_config(GPIO_GYRO_nCS, GPIO_OUTPUT );
gpio_config(GPIO_GYRO_INT, GPIO_INPUT | GPIO_PULLUP);
gpio_config(GPIO_ACC_nCS, GPIO_OUTPUT );
gpio_config(GPIO_ACC_INT, GPIO_INPUT | GPIO_PULLUP);
gpio_set(GPIO_NRF_CS, GPIO_PIN_RESET);
gpio_set(GPIO_GYRO_nCS, GPIO_PIN_SET);
gpio_set(GPIO_ACC_nCS, GPIO_PIN_SET);
spi_handle.Instance = SPI5;
spi_handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
spi_handle.Init.Direction = SPI_DIRECTION_2LINES;
spi_handle.Init.CLKPhase = SPI_PHASE_1EDGE;
spi_handle.Init.CLKPolarity = SPI_POLARITY_LOW;
spi_handle.Init.DataSize = SPI_DATASIZE_8BIT;
spi_handle.Init.FirstBit = SPI_FIRSTBIT_MSB;
spi_handle.Init.TIMode = SPI_TIMODE_DISABLE;
spi_handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
spi_handle.Init.CRCPolynomial = 7;
spi_handle.Init.NSS = SPI_NSS_SOFT;
spi_handle.Init.Mode = SPI_MODE_MASTER;
if (HAL_SPI_Init(&spi_handle) != HAL_OK) {
return ERR_GENERIC;
}
return NO_ERROR;
}
void sensor_bus_init(void)
{
mutex_init(&sensorbus_mutex);
}

110
target/nextcoinP0/usb.c Normal file
View File

@@ -0,0 +1,110 @@
/*
* Copyright (c) 2013-2015 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <compiler.h>
#include <debug.h>
#include <dev/usb.h>
#include <dev/usbc.h>
#include <err.h>
#include <hw/usb.h>
#include <lk/init.h>
#include <stdio.h>
#include <target.h>
#include <trace.h>
#define LOCAL_TRACE 0
#define W(w) (w & 0xff), (w >> 8)
#define W3(w) (w & 0xff), ((w >> 8) & 0xff), ((w >> 16) & 0xff)
extern void append_usb_interfaces(void);
/* top level device descriptor */
static const uint8_t dev_descr[] = {
0x12, /* descriptor length */
DEVICE, /* Device Descriptor type */
W(0x0200), /* USB Version */
0xff, /* class */
0xff, /* subclass */
0xff, /* protocol */
64, /* max packet size, ept0 */
W(0x18D1), /* vendor */
W(0xA010), /* product */
W(0x9999), /* release */
0x2, /* manufacturer string */
0x1, /* product string */
0x0, /* serialno string */
0x1, /* num configs */
};
/* high/low speed device qualifier */
static const uint8_t devqual_descr[] = {
0x0a, /* len */
DEVICE_QUALIFIER, /* Device Qualifier type */
W(0x0200), /* USB version */
0x00, /* class */
0x00, /* subclass */
0x00, /* protocol */
64, /* max packet size, ept0 */
0x01, /* num configs */
0x00 /* reserved */
};
static const uint8_t cfg_descr[] = {
0x09, /* Length of Cfg Descr */
CONFIGURATION, /* Type of Cfg Descr */
W(0x09), /* Total Length (incl ifc, ept) */
0x00, /* # Interfaces */
0x01, /* Cfg Value */
0x00, /* Cfg String */
0xc0, /* Attributes -- self powered */
250, /* Power Consumption - 500mA */
};
static const uchar langid[] = { 0x04, 0x03, 0x09, 0x04 };
usb_config config = {
.lowspeed = {
.device = USB_DESC_STATIC(dev_descr),
.device_qual = USB_DESC_STATIC(devqual_descr),
.config = USB_DESC_STATIC(cfg_descr),
},
.highspeed = {
.device = USB_DESC_STATIC(dev_descr),
.device_qual = USB_DESC_STATIC(devqual_descr),
.config = USB_DESC_STATIC(cfg_descr),
},
.langid = USB_DESC_STATIC(langid),
};
void target_usb_setup(void)
{
usb_setup(&config);
append_usb_interfaces();
usb_add_string("LK", 1);
usb_add_string("LK Industries", 2);
usb_start();
}