[demo] Have ST send ACC data every 100 MS over SPI5

- Revert to HAL spi since there's still a timing bug in the new WIP driver
- Add nrf_sensors app to poll the ACC and send data every 100 ms
This commit is contained in:
Christopher Anderson
2016-05-12 11:18:50 -07:00
parent de971f8325
commit 425a9de687
4 changed files with 69 additions and 1 deletions

View File

@@ -0,0 +1,58 @@
#include <app.h>
#include <arch.h>
#include <assert.h>
#include <debug.h>
#include <err.h>
#include <kernel/event.h>
#include <lk/init.h>
#include <stdlib.h>
#include <trace.h>
#include <target/gpioconfig.h>
#include <stm32f7xx.h>
#include <stm32f7xx_hal_spi.h>
#include <dev/accelerometer.h>
/* This code reads from the accelerometer then sends the data over to the nRF chip
* every 100 milliseconds. */
static void nrf_sensors_init(const struct app_descriptor *app)
{
}
static void nrf_sensors_entry(const struct app_descriptor *app, void *args)
{
position_vector_t pos_vector;
SPI_HandleTypeDef spi_handle;
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;
gpio_config(GPIO_NRF_CS, GPIO_OUTPUT);
gpio_set(GPIO_NRF_CS, 1);
for (;;) {
acc_read_xyz(&pos_vector);
gpio_set(GPIO_NRF_CS, 0);
status_t ret = HAL_SPI_Transmit(&spi_handle, (uint8_t *)&pos_vector, sizeof(pos_vector), 5000);
if (ret != NO_ERROR) {
printf("error on spi_write for sensors: %d\n", ret);
}
gpio_set(GPIO_NRF_CS, 1);
thread_sleep(100);
}
}
APP_START(sbb)
.init = nrf_sensors_init,
.entry = nrf_sensors_entry,
APP_END

9
app/nrf_sensors/rules.mk Normal file
View File

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

View File

@@ -13,6 +13,7 @@ MODULES += \
MODULE_DEPS += \
app/accelerometer \
app/nrf_sensors \
MODULE_SRCS += \
$(LOCAL_DIR)/sensor_bus.c \

View File

@@ -86,7 +86,7 @@ status_t sensor_bus_init_early(void)
spi_handle.Init.NSS = SPI_NSS_SOFT;
spi_handle.Init.Mode = SPI_MODE_MASTER;
if (HAL_SPI_Init(&spi_handle) != HAL_OK) {
if (spi_init(&spi_handle) != HAL_OK) {
return ERR_GENERIC;
}
return NO_ERROR;