start practical work N°2
just add the event and measure the time of it
This commit is contained in:
135
RTE/Hesso_pack/ext_26pin.c
Normal file
135
RTE/Hesso_pack/ext_26pin.c
Normal file
@ -0,0 +1,135 @@
|
||||
|
||||
#include "stm32f7xx_hal.h"
|
||||
#include "ext_26pin.h"
|
||||
|
||||
SPI_HandleTypeDef hspi2;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
int32_t Ext_Debug_Init (void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
|
||||
/* Configure GPIO pin: PF9 (GPIO_DEBUG) */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
||||
|
||||
return 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
int32_t Ext_FreqGen_Init (void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOI_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin : nCS_FREQ_GEN_Pin */
|
||||
GPIO_InitStruct.Pin = nCS_FREQ_GEN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(nCS_FREQ_GEN_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
|
||||
__HAL_RCC_SPI2_CLK_ENABLE();
|
||||
|
||||
/**SPI2 GPIO Configuration
|
||||
PI1 ------> SPI2_SCK
|
||||
PB15 ------> SPI2_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
|
||||
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
|
||||
/* SPI2 parameter configuration*/
|
||||
hspi2.Instance = SPI2;
|
||||
hspi2.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
||||
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi2.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
|
||||
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi2.Init.CRCPolynomial = 7;
|
||||
hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
|
||||
hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
|
||||
if (HAL_SPI_Init(&hspi2) != HAL_OK)
|
||||
return -1;
|
||||
Ext_FreqGen_Set(20,SQUARE);
|
||||
Ext_FreqGen_Set(20,SQUARE);
|
||||
return 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
void Ext_FreqGen_Set(uint32_t frequency,f_mode mode)
|
||||
{
|
||||
uint8_t data[2];
|
||||
float calcDivisor;
|
||||
uint32_t divisorInt;
|
||||
calcDivisor = ((float)frequency * 268435456L) / 16000000L;
|
||||
divisorInt = (uint32_t)calcDivisor + 1;
|
||||
//----------------------------------------------------------------------------
|
||||
// reset generator
|
||||
data[0] = 0x21;
|
||||
data[1] = 0x00;
|
||||
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_RESET);
|
||||
HAL_SPI_Transmit(&hspi2,data,2,10);
|
||||
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_SET);
|
||||
//----------------------------------------------------------------------------
|
||||
// set frequency LSB (14 bits)
|
||||
data[0] = ((divisorInt & 0x3FFF) | 0x4000) >> 8;
|
||||
data[1] = ((divisorInt & 0x3FFF) | 0x4000) >> 0;
|
||||
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_RESET);
|
||||
HAL_SPI_Transmit(&hspi2,data,2,10);
|
||||
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_SET);
|
||||
//----------------------------------------------------------------------------
|
||||
// set frequency MSB (14 bits)
|
||||
data[0] = (((divisorInt>>14) & 0x3FFF) | 0x4000) >> 8;
|
||||
data[1] = (((divisorInt>>14) & 0x3FFF) | 0x4000) >> 0;
|
||||
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_RESET);
|
||||
HAL_SPI_Transmit(&hspi2,data,2,10);
|
||||
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_SET);
|
||||
//----------------------------------------------------------------------------
|
||||
// set output signal
|
||||
data[0] = 0x20; // unreset
|
||||
switch(mode)
|
||||
{
|
||||
case SINUS:
|
||||
data[1] = 0x00;
|
||||
break;
|
||||
case TRIANGLE:
|
||||
data[1] = 0x02;
|
||||
break;
|
||||
case SQUARE:
|
||||
data[1] = 0x28;
|
||||
break;
|
||||
}
|
||||
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_RESET);
|
||||
HAL_SPI_Transmit(&hspi2,data,2,10);
|
||||
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_SET);
|
||||
}
|
47
RTE/Hesso_pack/ext_26pin.h
Normal file
47
RTE/Hesso_pack/ext_26pin.h
Normal file
@ -0,0 +1,47 @@
|
||||
/************************************************************************//**
|
||||
* \file ext_keyboard.h
|
||||
* \brief Function to use the extension keyboard
|
||||
* \author pascal (dot) sartoretti (at) hevs (dot) ch
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef __EXT_26PIN_H
|
||||
#define __EXT_26PIN_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "stm32f7xx_hal.h"
|
||||
|
||||
#define nCS_FREQ_GEN_Pin GPIO_PIN_6
|
||||
#define nCS_FREQ_GEN_GPIO_Port GPIOF
|
||||
typedef enum
|
||||
{
|
||||
SINUS,
|
||||
TRIANGLE,
|
||||
SQUARE
|
||||
}f_mode;
|
||||
/************************************************************************//**
|
||||
* \brief Inits the Sparkfun frequency generator connected to SPI
|
||||
* port on the 26 pin connector pins below:
|
||||
* SCK = pin 3
|
||||
* MOSI = pin 2
|
||||
* nCS = pin 4
|
||||
***************************************************************************/
|
||||
int32_t Ext_FreqGen_Init (void);
|
||||
/************************************************************************//**
|
||||
* \brief Sets a frequency on Sparfun generator output
|
||||
* \param frequency The frequency in hertz (below 20 Hz signal is bad)
|
||||
* \param mode The signal mode (SINUS,TRIANGLE,SQUARE)
|
||||
*
|
||||
* The signal is centered at about 1.61 volt +/- 0.53 volts
|
||||
***************************************************************************/
|
||||
void Ext_FreqGen_Set(uint32_t frequency,f_mode mode);
|
||||
|
||||
/************************************************************************//**
|
||||
* \brief Inits the debug pin PF9
|
||||
***************************************************************************/
|
||||
int32_t Ext_Debug_Init(void);
|
||||
|
||||
|
||||
|
||||
#endif /* __BOARD_LED_H */
|
||||
|
58
RTE/Hesso_pack/ext_buttons.c
Normal file
58
RTE/Hesso_pack/ext_buttons.c
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
#include "stm32f7xx_hal.h"
|
||||
#include "ext_buttons.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
int32_t Ext_Buttons_Init (void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOI_CLK_ENABLE();
|
||||
|
||||
/* Configure GPIO pin: PI2 (BTN_0) */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
|
||||
/* Configure GPIO pin: PI3 (BTN_1) */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_3;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
|
||||
/* Configure GPIO pin: PG7 (BTN_2) */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
||||
/* Configure GPIO pin: PG6 (BTN_3) */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
uint32_t Ext_Buttons_GetState (void) {
|
||||
uint32_t val = 0;
|
||||
|
||||
if (HAL_GPIO_ReadPin(GPIOI, GPIO_PIN_2) == GPIO_PIN_RESET) {
|
||||
val |= 1;
|
||||
}
|
||||
if (HAL_GPIO_ReadPin(GPIOI, GPIO_PIN_3) == GPIO_PIN_RESET) {
|
||||
val |= 2;
|
||||
}
|
||||
if (HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_7) == GPIO_PIN_RESET) {
|
||||
val |= 4;
|
||||
}
|
||||
if (HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_6) == GPIO_PIN_RESET) {
|
||||
val |= 8;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
23
RTE/Hesso_pack/ext_buttons.h
Normal file
23
RTE/Hesso_pack/ext_buttons.h
Normal file
@ -0,0 +1,23 @@
|
||||
/************************************************************************//**
|
||||
* \file ext_buttons.h
|
||||
* \brief Function to use the extension uart
|
||||
* \author pascal (dot) sartoretti (at) hevs (dot) ch
|
||||
***************************************************************************/
|
||||
#ifndef __EXT_BUTTONS_H
|
||||
#define __EXT_BUTTONS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/************************************************************************//**
|
||||
* \brief Inits the external buttons usage.
|
||||
* \return Always #0
|
||||
***************************************************************************/
|
||||
extern int32_t Ext_Buttons_Init(void);
|
||||
|
||||
/************************************************************************//**
|
||||
* \brief Reads the buttons status
|
||||
* \return The binary state of the buttons (example 4 for button 2 pressed).
|
||||
***************************************************************************/
|
||||
extern uint32_t Ext_Buttons_GetState(void);
|
||||
|
||||
#endif /* __BOARD_BUTTONS_H */
|
@ -20,6 +20,9 @@
|
||||
#define RTE_CMSIS_RTOS2 /* CMSIS-RTOS2 */
|
||||
#define RTE_CMSIS_RTOS2_RTX5 /* CMSIS-RTOS2 Keil RTX5 */
|
||||
#define RTE_CMSIS_RTOS2_RTX5_SOURCE /* CMSIS-RTOS2 Keil RTX5 Source */
|
||||
/* Keil.ARM Compiler::Compiler:Event Recorder:DAP:1.5.1 */
|
||||
#define RTE_Compiler_EventRecorder
|
||||
#define RTE_Compiler_EventRecorder_DAP
|
||||
/* Keil.ARM Compiler::Compiler:I/O:STDOUT:ITM:1.2.0 */
|
||||
#define RTE_Compiler_IO_STDOUT /* Compiler I/O: STDOUT */
|
||||
#define RTE_Compiler_IO_STDOUT_ITM /* Compiler I/O: STDOUT ITM */
|
||||
@ -33,12 +36,16 @@
|
||||
#define RTE_DEVICE_HAL_CORTEX
|
||||
/* Keil::Device:STM32Cube HAL:DMA:1.2.7 */
|
||||
#define RTE_DEVICE_HAL_DMA
|
||||
/* Keil::Device:STM32Cube HAL:EXTI:1.2.7 */
|
||||
#define RTE_DEVICE_HAL_EXTI
|
||||
/* Keil::Device:STM32Cube HAL:GPIO:1.2.7 */
|
||||
#define RTE_DEVICE_HAL_GPIO
|
||||
/* Keil::Device:STM32Cube HAL:PWR:1.2.7 */
|
||||
#define RTE_DEVICE_HAL_PWR
|
||||
/* Keil::Device:STM32Cube HAL:RCC:1.2.7 */
|
||||
#define RTE_DEVICE_HAL_RCC
|
||||
/* Keil::Device:STM32Cube HAL:SPI:1.2.7 */
|
||||
#define RTE_DEVICE_HAL_SPI
|
||||
/* Keil::Device:STM32Cube HAL:UART:1.2.7 */
|
||||
#define RTE_DEVICE_HAL_UART
|
||||
/* Keil::Device:Startup:1.2.4 */
|
||||
|
Reference in New Issue
Block a user