From 43b94a6ada83454c3404bda019ec114f97379c82 Mon Sep 17 00:00:00 2001 From: "Pavel V. Shatov" Date: Thu, 27 Aug 2015 00:01:24 +0400 Subject: Initial version of FMC driver for STM32. --- Src/main.c | 283 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 Src/main.c (limited to 'Src/main.c') diff --git a/Src/main.c b/Src/main.c new file mode 100644 index 0000000..705a04f --- /dev/null +++ b/Src/main.c @@ -0,0 +1,283 @@ +//------------------------------------------------------------------------------ +// main.c +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include "stm32f4xx_hal.h" +#include "stm-fmc.h" + + +//------------------------------------------------------------------------------ +// Defines +//------------------------------------------------------------------------------ +#define GPIO_PORT_LEDS GPIOJ + +#define GPIO_PIN_LED_RED GPIO_PIN_1 +#define GPIO_PIN_LED_YELLOW GPIO_PIN_2 +#define GPIO_PIN_LED_GREEN GPIO_PIN_3 +#define GPIO_PIN_LED_BLUE GPIO_PIN_4 + + +//------------------------------------------------------------------------------ +// Macros +//------------------------------------------------------------------------------ +#define led_on(pin) HAL_GPIO_WritePin(GPIO_PORT_LEDS,pin,GPIO_PIN_SET) +#define led_off(pin) HAL_GPIO_WritePin(GPIO_PORT_LEDS,pin,GPIO_PIN_RESET) +#define led_toggle(pin) HAL_GPIO_TogglePin(GPIO_PORT_LEDS,pin) + + +//------------------------------------------------------------------------------ +// Variables +//------------------------------------------------------------------------------ +RNG_HandleTypeDef rng_inst; + + + +//------------------------------------------------------------------------------ +// Prototypes +//------------------------------------------------------------------------------ +void SystemClock_Config(void); + +static void MX_RNG_Init(void); +static void MX_GPIO_Init(void); + +int test_fpga_data_bus(void); +int test_fpga_address_bus(void); + + +//------------------------------------------------------------------------------ +// Defines +//------------------------------------------------------------------------------ +#define TEST_NUM_ROUNDS 100000 + + +//------------------------------------------------------------------------------ +int main(void) +//------------------------------------------------------------------------------ +{ + // initialize hal + HAL_Init(); + + // configure system clock + SystemClock_Config(); + + // initialize gpio + MX_GPIO_Init(); + + // initialize rng + MX_RNG_Init(); + + // prepare fmc interface + fmc_init(); + + // turn on green led, turn off other leds + led_on(GPIO_PIN_LED_GREEN); + led_off(GPIO_PIN_LED_YELLOW); + led_off(GPIO_PIN_LED_RED); + led_off(GPIO_PIN_LED_BLUE); + + // vars + int test_ok; + + // main loop (test, until an error is detected) + while (1) + { + // test data bus + test_ok = test_fpga_data_bus(); + + // check for errors (abort testing in case of error) + if (test_ok < TEST_NUM_ROUNDS) /*break*/; + + + // test address bus + test_ok = test_fpga_address_bus(); + + // check for errors (abort testing in case of error) + if (test_ok < TEST_NUM_ROUNDS) /*break*/; + + // toggle yellow led to indicate, that we are alive + led_toggle(GPIO_PIN_LED_YELLOW); + } + + // error handler + while (1) + { + // turn on red led, turn off other leds + led_on(GPIO_PIN_LED_RED); + led_off(GPIO_PIN_LED_GREEN); + led_off(GPIO_PIN_LED_YELLOW); + led_off(GPIO_PIN_LED_BLUE); + } + + // should never reach this line +} + + +//------------------------------------------------------------------------------ +int test_fpga_data_bus(void) +//------------------------------------------------------------------------------ +{ + int c, ok; + uint32_t rnd, buf; + HAL_StatusTypeDef hal_result; + + // run some rounds of data bus test + for (c=0; c