/* Includes ------------------------------------------------------------------*/ #include "stm32f3xx_hal.h" #include "globals.h" /* USER CODE BEGIN Includes */ #include "led_driver.h" /* USER CODE END Includes */ // Format Image data so that it can be pushed as is by DMA toward the GPIO // Starting from image in raw format RGB. // lines from left to right and top to bottom // NUCLEO 64 avec 446 // to be put in port B0..10,12..15 // and PC0..PC4 // Sequence de pilotage des leds // 8 bits G7..0, 8 bits R7..0, 8 bits B7..0 // Encodage des bits // Bit 0 : 100 // Bit 1 : 110 // To be called just once // This is actually supposed to be done at the end, but that's ok this way void initLedResetCodeInMemoryForDMA2(uint8_t *portamem) { uint32_t i; // pre fill never changing parts for (i=0;i> 1; // Bit 7 à Bit 0. } for (line=0;lineODR = 0; HAL_DMA_Start(&hdma_tim2_ch1, (uint32_t) portamem, (uint32_t) &GPIOA->ODR, NB_DMA_WRITES); // pourrait s'avérer nécessaire d'interrompre les interrupions entre ces deux instructions pour éviter un déphasage. // pas de problème, rien ne se passe avant que le timer 8 ne soit démarré. __HAL_TIM_ENABLE_DMA(&htim2, TIM_DMA_CC1); // Appelle pas ces fonction, pour ne pas démarrer le timer avant la fin de la config // HAL_TIM_OC_Start(&htim8,TIM_CHANNEL_1); //Démarre aussi le Timer 8 // HAL_TIM_OC_Start(&htim8,TIM_CHANNEL_3); // Ici on n'a qu'un seul channel, alors, c'est OK aussi TIM_CCxChannelCmd(TIM2, TIM_CHANNEL_1, TIM_CCx_ENABLE); if(IS_TIM_BREAK_INSTANCE(TIM2) != RESET) { /* Enable the main output */ __HAL_TIM_MOE_ENABLE(&htim2); } /* Enable the Peripheral */ __HAL_TIM_ENABLE(&htim2); } void dmaPostLedDrive(void) { // Il faut désactiver le CC0 avant le timer lui même. Sinon, __HAL_TIM_DISABLE est non fonctionnel. TIM_CCxChannelCmd(TIM2, TIM_CHANNEL_1, TIM_CCx_DISABLE); __HAL_TIM_MOE_DISABLE(&htim2); __HAL_TIM_DISABLE(&htim2); __HAL_TIM_DISABLE_DMA(&htim2, TIM_DMA_CC1); } void dmaWait(void) { HAL_StatusTypeDef dma_state; dma_state = HAL_DMA_PollForTransfer(&hdma_tim2_ch1, HAL_DMA_FULL_TRANSFER, 20); if (dma_state == HAL_OK) { dmaPostLedDrive(); // 1µs ou moins } else crash(CC_DMA_TIM2_CH1_FAILED); } // Only one case : in case of loss of power void dmaUrgentStop(void) { __HAL_DMA_DISABLE(&hdma_tim2_ch1); HAL_DMA_Abort(&hdma_tim2_ch1); // dmaPostLedDrive(); }