Skip to content
main.c 18.4 KiB
Newer Older
laurentc's avatar
laurentc committed
/**
  ******************************************************************************
  * File Name          : main.c
  * Description        : Main program body
  ******************************************************************************
  *
  * COPYRIGHT(c) 2017 STMicroelectronics
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "stm32f3xx_hal.h"

/* USER CODE BEGIN Includes */
#include "globals.h"
#include <string.h>
#include <math.h>
#include "led_driver.h"
#include "image_generator.h"
#include "image_filter.h"
#include "commands.h"

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;

TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim6;
TIM_HandleTypeDef htim7;
DMA_HandleTypeDef hdma_tim2_ch1;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_TIM6_Init(void);
static void MX_TIM7_Init(void);
static void MX_TIM2_Init(void);
static void MX_ADC1_Init(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */
	uint8_t raw[RAW_SIZE];
	uint8_t raw_out[RAW_SIZE];
	uint8_t rxWifi_raw[RAW_SIZE];

	uint8_t myColor[3];
	uint16_t t0,t1,t2;
	float frameRate;
	
#pragma pack(4)
  uint8_t portamem_flip[NB_DMA_WRITES];
  uint8_t portamem_flop[NB_DMA_WRITES];
	uint8_t *portamem_ff[2];
	uint8_t *portamem;

	float offsetX;
	float goffsetX;
  int ioffsetX;
	
	uint32_t currentMode;
	uint8_t dynamicGenerator;
	uint8_t intensity;	


// AUTO MODE 
// On startup or In absence of remote commands for 10 minutes, 

const uint8_t modTable[]={10, 1,10,19,10, 2,10,20,10, 3,10, 5,10, 4,10,12,10, 1,10,13,10, 2,10,14,10,16,10,15,10,17,10,18};
uint32_t durationTable[]={ 1,10, 2,10, 2,10, 1,10, 1,10, 2,10, 2,10, 1,10, 1,10, 2,10, 2,10, 1,10, 1,10, 2,10, 2,10, 1,10};

int findInTable(uint32_t timeSec)
{
	int i;
	for (i=0;i<sizeof(modTable);i++)
	{
		if (timeSec<durationTable[i])
			return i;
	}
	return 10; // scurit
}
 
float speeded_time;

void cycler(float time, uint8_t receivedCommand)
{
	static uint8_t initialized = 0;
	static uint8_t neverReceivedACommand = 1;
	static int lastMode;
	static float lastTimereceivedCommand = 0;
	uint32_t dt,modTime;
	static uint32_t modulo;
	int i;
	uint32_t total;
	
	if (!initialized)
	{
		total = 0;
		for (i=0;i<sizeof(modTable);i++)
		{
			total+=durationTable[i]*60; // interprets table expressed in minutes
			durationTable[i] = total; // duration table becomes a startup time table
		}
		modulo = total;
		lastMode = -1;
		initialized = 1;
	}
	
	if (receivedCommand)
	{
		lastTimereceivedCommand = time;
		neverReceivedACommand = 0;
		return;
	}
	
	dt = time-lastTimereceivedCommand;
	
	if ((dt>3600)|(neverReceivedACommand))
	{
		// which mode ???
		modTime = dt % modulo;
		intensity = 64;

    currentMode = modTable[findInTable(modTime)];	
		
	  switch(currentMode)
		{
			case 10 : setSpeedRPS(0.025f,speeded_time); break;
			default : setSpeedRPS(0,speeded_time); setOffsetX(0); break;
		}		
		if (currentMode!=lastMode) // detects the cycler wants to change mode
		{
			if (lastMode!=20) 
			{
			  currentMode = 20; // one frame black for cleanup, just one frame
			}
		  dynamicGenerator = 1;
		}
		lastMode = currentMode;
	}
	 
}


void dmaQuickBlack(void)
{
	initLedResetCodeInMemoryForDMA2(portamem_flip);
	dmaLedDrive2(portamem_flip);
	HAL_DMA_PollForTransfer(&hdma_tim2_ch1, HAL_DMA_FULL_TRANSFER, 20);
	dmaPostLedDrive();
}
/* USER CODE END 0 */


int main(void)
{

  /* USER CODE BEGIN 1 */
  int firstPass;
	int flip_flop;
	int cmd_id;
	uint8_t receivedCommand;
	float time, last_time, time_speed_coeff;

	portamem_ff[0] = portamem_flip;
	portamem_ff[1] = portamem_flop;
	
	// on veut tre sr que lorsque les pin RST et EN WIFI passent en sortie, elles sont bien  0.
	// Pour qu'il ne se mette pas  dmarrer sans notre contrle.
	GPIOA->ODR =  0;
	// tant que la clock n'est pas active, ne sera pas latch (pas vrifi si c'est vraiment latch)
laurentc's avatar
laurentc committed
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_TIM6_Init();
  MX_TIM7_Init();
  MX_TIM2_Init();
  MX_ADC1_Init();

  /* USER CODE BEGIN 2 */

//	HAL_TIM_Base_Start(&htim2);

  GPIOA->ODR = 0;

__HAL_DBGMCU_FREEZE_TIM2();
__HAL_DBGMCU_FREEZE_TIM6();
__HAL_DBGMCU_FREEZE_TIM7();


	HAL_TIM_Base_Start(&htim6); // pour la base de temps principale. Avec une it par seconde. Secondes et 0.1ms step
	HAL_TIM_Base_Start(&htim7); // TIM7  la micro seconde

// on a besoin de TIM7 pour les dlais power up sequence

	clig();

//rose 0x80, 0x40, 0x40
	myColor[0] = 0xFF;
	myColor[1] = 0xFF;
	myColor[2] = 0xFF;
	myColor[0] = 0x80;
	myColor[1] = 0x40;
	myColor[2] = 0x40;

	generateUniformColor(raw,myColor);
//	generateBlack(raw);
//	generate3RGBSpaceInvaders(raw);
	
	

	HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn);
	HAL_NVIC_SetPriority(TIM6_DAC_IRQn,2,2); // just below LED driver DMA
	TIM6->SR = 0; // Clear IT Flag
	HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
	TIM6->DIER |= TIM_DIER_UIE; // enable interrupt
	
	firstPass = 1;
	flip_flop = 0;
	
	// init DMA memory flip and flop
	initLedResetCodeInMemoryForDMA2(portamem_ff[0]);
	initLedResetCodeInMemoryForDMA2(portamem_ff[1]);

	currentMode = 1;
	dynamicGenerator = 1;
	intensity = 50;
	time_speed_coeff = 1;
	time = speeded_time = getTime(); // to have the current time from the start
	
  setSpeedRPS(0.0f,0); 
	setOffsetX(0.0f);
	
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

//		setOffsetX(cos(time)); // for play
		receivedCommand = 0;
		
		while (commandRx(&cmd_id,rxWifi_raw, time))
		{
			receivedCommand = 1;
			switch(cmd_id)
			{
				case CMD_POS : setOffsetX(*((float*)(rxWifi_raw))); RunLedToggle(); break;
//				case CMD_SPD : setSpeedRPS(*((float*)(rxWifi_raw)),speeded_time); RunLedToggle(); break;
				case CMD_SPD : time_speed_coeff = 1+9*(*((float*)(rxWifi_raw))); RunLedToggle(); break;
				case CMD_MOD : 	currentMode = *((uint32_t*)(rxWifi_raw)); 
												setOffsetX(0); 
												if (currentMode==10)
													setSpeedRPS(0.1f,speeded_time); 
												else
													setSpeedRPS(0,speeded_time); 
												dynamicGenerator = 1; 
												RunLedToggle(); break;
				case CMD_RAW : memcpy(raw,rxWifi_raw,RAW_SIZE); 
											 currentMode = 0; 
				#ifdef POWER_LIMITER
											 powerLimiter(raw,POWER_LIMIT);
				#endif
											 RunLedToggle(); 
											 break; // double copie,  viter
				case CMD_INT : intensity = (uint8_t) *((uint32_t*)(rxWifi_raw)); dynamicGenerator = 1; RunLedToggle(); break;
				case CMD_OFF : dmaWait();	// sweet stop	
											 dmaQuickBlack();	// pour viter la rmanence image
laurentc's avatar
laurentc committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
												break;
			}
		}

//		memcpy(raw,rxWifi_raw,RAW_SIZE+16);checkUpdateFlash(raw);
//		readImageFromFlash(raw,2);
		
		// get current offset to apply. Need it to compute the partial offset on gaussian
		// also gets the time
		last_time = time;
		time = getTime();
		speeded_time += (time-last_time)*time_speed_coeff;

		offsetX = updateOffsetX(speeded_time); // garanties 0<=offsetX<NB_COLUMNS
		
		    
		// invoque auto image generator (takes control on startup and after 60 minutes of inactivity (no commands received))
		// user has priority
		cycler(time,receivedCommand);


		// the offset must be expressed as the sum of an integer in [0;NB_COLUMN-1] and an offset in ]-0.5;0.5]
		// offsetX = ioffsetX+goffsetX;
		// values between NB_COLUMN-0.5<values<NB_COLUMN are reached by ioffset = 0 and -0.5<goffset<0

		ioffsetX = offsetX; //integer part in [0;NB_COLUMNS-1]
		goffsetX = offsetX - ioffsetX; // float part in [0;1[
		
		if (goffsetX>0.5f)
		{
			goffsetX = goffsetX - 1.0f; // float part in ]-0.5;0.5]
			ioffsetX++; //integer part in [1;NB_COLUMNS]
			if (ioffsetX == NB_COLUMNS)
				ioffsetX = 0; //integer part in [0;NB_COLUMNS-1]
		}
				
		// Generate Image into raw
		if (currentMode!=0)
		{
			if (dynamicGenerator)
			{
				dynamicGenerator = imageGenerator(currentMode,raw,speeded_time,intensity);
			}
		}
		
		// Process Image
		// Requires -0.5<=goffsetX<=0.5
		// needs the updated goffsetX
		filtreGaussienX(0.7f,NB_COLUMNS,NB_LINES, raw, raw_out,-goffsetX);

		// Format Data for DMA
		// requires  0 <= ioffset < NB_COLUMNS
		portamem = portamem_ff[flip_flop];
		formatMemoryForDMA2(raw_out,portamem,ioffsetX);

		
		// Wait for end of previous image DMA transfer before restarting a DMA transfer
		if (!firstPass)
		{
			dmaWait();
			t2 = TIM7->CNT;  // 1787s. OK ! Mesur 1.7ms  l'oscillo.
		}

// Position importante, cela assure que le DMA ne tourne plus au moment du power down.		
		// Si PWM tlcommande pas dtecte, STOP sans Wifi
		#ifdef REMOTE_MANAGER
			remoteManager();
		#endif

// Position importante, cela assure que le DMA ne tourne plus au moment du power down.
		// go to sleep anyway after 10 hours, with Wifi
		if (time>60*60*10)
		{
//			powerDownListeningWifi();
		}		

		// Start Send Image by DMA
		dmaLedDrive2(portamem); // Ne prend que 2s YES !!

		do
		{
			t1 = TIM7->CNT;
		}			
		while(t1<10000);
		
		TIM7->CNT = 0;	
		frameRate = 1e6/t1;
		
		firstPass = 0;
		flip_flop = 1 - flip_flop;

  }		
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  /* USER CODE END 3 */

}

/** System Clock Configuration
*/
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

/* ADC1 init function */
static void MX_ADC1_Init(void)
{

  ADC_ChannelConfTypeDef sConfig;

    /**Common config 
    */
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc1.Init.ContinuousConvMode = DISABLE;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion = 2;
  hadc1.Init.DMAContinuousRequests = DISABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc1.Init.LowPowerAutoWait = ENABLE;
  hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }

    /**Configure Regular Channel 
    */
  sConfig.Channel = ADC_CHANNEL_11;
  sConfig.Rank = 1;
  sConfig.SingleDiff = ADC_SINGLE_ENDED;
  sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
  sConfig.OffsetNumber = ADC_OFFSET_NONE;
  sConfig.Offset = 0;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }

    /**Configure Regular Channel 
    */
  sConfig.Channel = ADC_CHANNEL_12;
  sConfig.Rank = 2;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }

}

/* TIM2 init function */
static void MX_TIM2_Init(void)
{

  TIM_ClockConfigTypeDef sClockSourceConfig;
  TIM_MasterConfigTypeDef sMasterConfig;
  TIM_OC_InitTypeDef sConfigOC;

  htim2.Instance = TIM2;
  htim2.Init.Prescaler = 0;
  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim2.Init.Period = 25;
  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  {
    Error_Handler();
  }

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }

  if (HAL_TIM_OC_Init(&htim2) != HAL_OK)
  {
    Error_Handler();
  }

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }

  sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
  sConfigOC.Pulse = 10;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  if (HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  {
    Error_Handler();
  }

}

/* TIM6 init function */
static void MX_TIM6_Init(void)
{

  TIM_MasterConfigTypeDef sMasterConfig;

  htim6.Instance = TIM6;
  htim6.Init.Prescaler = 6400;
  htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim6.Init.Period = 9999;
  if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
  {
    Error_Handler();
  }

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }

}

/* TIM7 init function */
static void MX_TIM7_Init(void)
{

  TIM_MasterConfigTypeDef sMasterConfig;

  htim7.Instance = TIM7;
  htim7.Init.Prescaler = 64;
  htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim7.Init.Period = 0xFFFF;
  if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
  {
    Error_Handler();
  }

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }

}

/** 
  * Enable DMA controller clock
  */
static void MX_DMA_Init(void) 
{
  /* DMA controller clock enable */
  __HAL_RCC_DMA1_CLK_ENABLE();

  /* DMA interrupt init */
  /* DMA1_Channel5_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);

}

/** Configure pins as 
        * Analog 
        * Input 
        * Output
        * EVENT_OUT
        * EXTI
*/
static void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : PA0 */
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : LD3_Pin */
  GPIO_InitStruct.Pin = LD3_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LD3_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : BOUTON_POUSSOIR_Pin */
  GPIO_InitStruct.Pin = BOUTON_POUSSOIR_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(BOUTON_POUSSOIR_GPIO_Port, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @param  None
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler */
  /* User can add his own implementation to report the HAL error return state */
  while(1) 
  {
  }
  /* USER CODE END Error_Handler */ 
}

#ifdef USE_FULL_ASSERT

/**
   * @brief Reports the name of the source file and the source line number
   * where the assert_param error has occurred.
   * @param file: pointer to the source file name
   * @param line: assert_param error line source number
   * @retval None
   */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */

}

#endif

/**
  * @}
  */ 

/**
  * @}
*/ 

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/