-1

I'm Trying to enable DMA1 with USART1 in stm32f103c8 but it does not work . i enabled the usart to work as transmitter . and then enabled the DMA1 and make this configuration to it 1-enable the DMA1 clock from RCC. 2-disabled the DMA1 Channel . 3-set the DMA1 channel periority as very high periority. 4-make the direction of DMA1 channel from memory to peripheral. 5-make the memory size and peripheral size as byte. 6-enable memory increment and disable peripheral increment. 7-disable circular mode. 8-set the DMA interrupt for transfer complete. 7-set the memory address buffer and set the peripheral address as usart1 data register. 8-set the number of times to dma transfer as 6 . 9-enable the DMA1 channel interrupt in the NVIC. 10-enable the DMAT in the usart1 to make the usart work with the DMA1 11-enable the DMA1 to Start work.

after all this configuration the DMA does not work but the usart work successfully . in the main code i make intialize the usart1 and then intialize the DMA1 as me said up and then empty while(1) . the terminal did not receive the string in the memory and the DMA did not go to the handler that mean the DMA does not work never why ?

u8 Buffer[6] = "hesham";
int main(void){
    /*--------------------------------------------------------------------------------------------*/
    RCC_VidInit();
    RCC_VidEnablePeripheralClock( APB2_BUS , IOPA_EN   );    //Enable PORTA  Clock
    RCC_VidEnablePeripheralClock( APB2_BUS , USART1_EN );    //Enable USART1 Clock
    RCC_VidEnablePeripheralClock( AHB_BUS  , DMA1_EN   );    //Enable DMA1   Clock
    /*--------------------------------------------------------------------------------------------*/
    NVIC_VidEnableIRQ( 14 );                                 //Enable The DMA1Channel4 Interrupt Inside The NVIC
    /*-------------------------------GPIO Configuration Of Tx And Rx------------------------------*/
    CLR_BIT( GPIOA->CRH , 4 ); SET_BIT( GPIOA->CRH , 5 );    //PIN9 (TX) Output With 2MHZ Speed
    CLR_BIT( GPIOA->CRH , 6 ); SET_BIT( GPIOA->CRH , 7 );    //Make Pin9 Alternative Func PushPull

    CLR_BIT( GPIOA->CRH , 8  ); CLR_BIT( GPIOA->CRH , 9  );  //Pin10 (RX) Input
    SET_BIT( GPIOA->CRH , 10 ); CLR_BIT( GPIOA->CRH , 11 );  //Make Pin10 Floating Input
    /*-----------------------------------------------USART1 Configuration--------- ---------------*/
    //Using The Deafult M Size = 8 bit And 1 Stop bit
    USART1->BRR = 0x341 ;                                     //Set The BaudRate = 9600 Of External Oscillator = 8MHZ
    SET_BIT( USART1->CR3 , 7 );                               //Enable Usart To Work With DMA As Transmitter (DMAT bit)
    SET_BIT( USART1->CR1 , 3 ); SET_BIT( USART1->CR1 , 13 );  //Enable The Transmitter (TE Bit) and Enable The USART (UE bit)
    /*-----------------------------------------------DMA1 Channel 4 Configuration-----------------*/
    CLR_BIT( DMA1_CHANNEL4->CCR , 0 );                        //Disable The DMA To Access The Registers
    SET_BIT( DMA1_CHANNEL4->CCR , 1 );                        //Enable The Trnasmit Complete Interrupt (TCIE)
    SET_BIT( DMA1_CHANNEL4->CCR , 4 );                        //DMA Direction Is From Memory To Peripheral
    CLR_BIT( DMA1_CHANNEL4->CCR , 5 );                        //Disable Circular
    CLR_BIT( DMA1_CHANNEL4->CCR , 6 );                        //Disable Peripheral Increment
    SET_BIT( DMA1_CHANNEL4->CCR , 7 );                        //Enable Memory Increment
    CLR_BIT( DMA1_CHANNEL4->CCR , 8  ); CLR_BIT( DMA1_CHANNEL4->CCR , 9  );  //Peripheral Size = BYTE
    CLR_BIT( DMA1_CHANNEL4->CCR , 10 ); CLR_BIT( DMA1_CHANNEL4->CCR , 11 );  //Memory Size = BYTE
    SET_BIT( DMA1_CHANNEL4->CCR , 12 ); SET_BIT( DMA1_CHANNEL4->CCR , 13 );  //Channel Priority = Very High
    CLR_BIT( DMA1_CHANNEL4->CCR , 14 );                                      //Disable Memory To Memory Mode
    DMA1_CHANNEL4->CPAR = (u32)USART1->DR ;                   //The Address Of Peripheral is Usart Data Reg
    DMA1_CHANNEL4->CMAR = Buffer ;                            //The Address Of Memory is Buffer
    DMA1_CHANNEL4->CNDTR = 6 ;                                //The Number Of Transfer Item Is = The Size Of Buffer = 6
    //Clear The DMA1 Flags Of Channel 4
    SET_BIT( DMA1->IFCR , 12 );SET_BIT( DMA1->IFCR , 13 );SET_BIT( DMA1->IFCR , 14 );SET_BIT( DMA1->IFCR , 15 );
    SET_BIT( DMA1_CHANNEL4->CCR , 0 );                        //Enable The DMA To Work
    /*--------------------------------------------------------------------------------------------*/
    while(1);

    return 0;
}

and this is the handler of the DMA

void DMA1_Channel4_IRQHandler(void){

    if( (GET_BIT( DMA1->ISR , 13 )) == 1 ){ //Checking About Transfer Complete Flag Of DMA
        //Clear The DMA1 Flags Of Channel 4
        SET_BIT( DMA1->IFCR , 12 );SET_BIT( DMA1->IFCR , 13 );SET_BIT( DMA1->IFCR , 14 );SET_BIT( DMA1->IFCR , 15 );
    }
}

can someone help me please ?

  • show the code [mcve] – 0___________ Dec 02 '19 at 22:22
  • P__J__ my code is done by me i mean that i have been accessed the registers and make my drivers and someone tell me before that here no one can see my code if i have been did it by my self they need me to use the HALL function – Hesham Adel Dec 02 '19 at 23:32
  • P__J__ can i upload my own code here ? to see it or you need a hall code ? – Hesham Adel Dec 03 '19 at 04:25
  • 1
    If `no one can see my code` then `no one can answer your question` – 0___________ Dec 03 '19 at 09:26
  • Your if( (GET_BIT( DMA1->ISR , 13 )) == 1 ) should be if( (GET_BIT( DMA1->ISR , 13 )) != 0 ). Also, you should use the DEFINE instead of value hardcoded. I work with STM32F0 and F103. In my case, the DMA CCR does not have any flag 13 What do you mean with SET_BIT( DMA1_CHANNEL4->CCR , 4 ); Is it SET_BIT( DMA1_CHANNEL4->CCR , DMA_CCR_DIR ); – YvonBlais Dec 04 '19 at 04:19
  • In the ISR register of the DMA the bit number 13 is the TCIF flag – Hesham Adel Dec 04 '19 at 04:29
  • yes the SET_BIT( DMA1_CHANNEL4->CCR , 4 ); Is the SET_BIT( DMA1_CHANNEL4->CCR , DMA_CCR_DIR ); – Hesham Adel Dec 04 '19 at 04:30
  • my if mean if the TCIF has been set go inside the if but it does not matter because the handler of the DMA does not come – Hesham Adel Dec 04 '19 at 04:31
  • Are you sure that the Interrupts are active NVIC_SetPriority_(DMAn_Channely_IRQn, 0); NVIC_EnableIRQ(DMAn_Channely_IRQn); – YvonBlais Dec 05 '19 at 00:42
  • Yes YvonBlais im sure . – Hesham Adel Dec 05 '19 at 00:57

1 Answers1

0

i have been solved my problem it was an error in the configuration . the error was when i'm passing the address of the data register i'm not passing the address already but i'm passing the value of the data register address