cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 programming

Moamen Ayman
Associate III
Posted on October 22, 2016 at 15:17

Hello, I'm trying to program STM32F407vgt6 chip using IAR and the code works fine but when I disconnect the power and connect it again the chip doesn't work like if the code in the flash memory was deleted and it need to be reprogrammed again to work. I connected Boot0 pin to the ground through 10kOhm resistor and configuring the clock to work at 168MHz from PLL sourced by HSI. could someone tell me what the problem may in?

and thanks in advance.

#clive1 #clive1
4 REPLIES 4
Posted on October 22, 2016 at 16:01

Use the ST-LINK Utilities to confirm if the memory is empty, or still contains exactly what you wrote there.

Identify all the while() loops your code, and that in the library/startup, might end up in and have those output to a GPIO pin, LED, or USART so you can identify where and how far into your code the system has made it.

BOOT0 Low should be sufficient to get your code to execute, you'd want to examine BOOT1, and the NRST pin.

I'd assume that the flash isn't getting erased, and there is some other issue with clocks or code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Moamen Ayman
Associate III
Posted on October 22, 2016 at 17:58

yes the problem was in the 10KOhm resistor because it results 1.4V on the BOOT0 pin, when I replaced it with zero ohm resistor it works fine.

Thanks a lot

kakaducsy
Associate II
Posted on October 23, 2016 at 10:56

Hi clive 1,

I am communicating with the ps2 using spi dma, but it did not work setup DMA

void
DMA_SPI()
{
//TX
DMA_Init_SPI.DMA_Channel = DMA_Channel_3;
DMA_Init_SPI.DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR);
DMA_Init_SPI.DMA_Memory0BaseAddr = (uint32_t)SPI_Out;
DMA_Init_SPI.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_Init_SPI.DMA_BufferSize = 9;
DMA_Init_SPI.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_Init_SPI.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_Init_SPI.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_Init_SPI.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_Init_SPI.DMA_Mode = DMA_Mode_Normal;
DMA_Init_SPI.DMA_Priority = DMA_Priority_Medium;
DMA_Init_SPI.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_Init_SPI.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
DMA_Init_SPI.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_Init_SPI.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream3, &DMA_Init_SPI);
NVIC_EnableIRQ(DMA2_Stream3_IRQn);
DMA_ITConfig(DMA2_Stream3, DMA_IT_TC, ENABLE);
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE);
//RX
DMA_Init_SPI.DMA_Channel = DMA_Channel_3;
DMA_Init_SPI.DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR);
DMA_Init_SPI.DMA_Memory0BaseAddr = (uint32_t)SPI_In;
DMA_Init_SPI.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_Init_SPI.DMA_BufferSize = 9;
DMA_Init_SPI.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_Init_SPI.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_Init_SPI.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_Init_SPI.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_Init_SPI.DMA_Mode = DMA_Mode_Normal;
DMA_Init_SPI.DMA_Priority = DMA_Priority_Medium;
DMA_Init_SPI.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_Init_SPI.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
DMA_Init_SPI.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_Init_SPI.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_Init_SPI);
NVIC_EnableIRQ(DMA2_Stream0_IRQn);
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Rx, ENABLE);
}

set up SPI

void
SPI_config()
{
SPI_I2S_DeInit(SPI1);
//configure the SPI
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; 
//8MHz/64 = 125000kHz
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; 
//sample on second edge (falling) of clock
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; 
//clock high when idle
SPI_InitStructure.SPI_CRCPolynomial = 0;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; 
//send 8 bits at a time
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; 
//full duplex communication
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB; 
//least significant bit first
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
}

interrupt

//RX
void
DMA2_Stream0_IRQHandler(
void
)
{
if
(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0) == SET)
{
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
delay_us(20);
GPIO_SetBits(GPIOA, GPIO_Pin_4); 
SPI_work=0;
i++;
}
}
//-----------------------------------------------------------------
//TX
void
DMA2_Stream3_IRQHandler(
void
)
{
if
(DMA_GetITStatus(DMA2_Stream3, DMA_IT_TCIF3) == SET)
{
DMA_ClearITPendingBit(DMA2_Stream3, DMA_IT_TCIF3);
j++;
}
}

start spi

void
StartSPI(uint8_t number)
{
DMA_SetCurrDataCounter(DMA2_Stream0,number);
DMA_SetCurrDataCounter(DMA2_Stream3,number);
SPI_work=1;
GPIO_ResetBits(GPIOA, GPIO_Pin_4); 
DMA_Cmd(DMA2_Stream0,ENABLE);
DMA_Cmd(DMA2_Stream3,ENABLE);
}

wait and recieve data

void
SPIwait(
void
)
{
while
(SPI_work){}
}
void
SetSPI_Out(uint8_t Adr,uint8_t Data)
{
if
(Adr<9)
{
SPI_Out[Adr]=Data;
}
}
uint8_t GetSPI_In(uint8_t Adr)
{
return
SPI_In[Adr];
}

in main

int
main(
void
)
{
PeriphClk_config();
GPIO_config();
Timer3_config();
SPI_config();
DMA_SPI();
//PS2_Send_Recive(PS2,Data, 9);
SetSPI_Out(0,0x01);
SetSPI_Out(1,0x42);
SetSPI_Out(2,0x00);
SetSPI_Out(3,0x00);
SetSPI_Out(4,0x00);
SetSPI_Out(5,0x00);
SetSPI_Out(6,0x00);
SetSPI_Out(7,0x00);
SetSPI_Out(8,0x00);
StartSPI(9);
SPIwait();
while
(1){}

when i read data SPI_In i see all value =255,incorrect the value correct is : i send 0x01 : recieve 255 ;0x42--155;0x00--90;0x00--255 help me
Posted on October 23, 2016 at 14:51

This seems off-topic, start a new thread when it is appropriate. There is a ''New'' button in the left corner of the thread list.

Code doesn't look unreasonable, but is incomplete, you could have just pasted a complete working example. Suggest you get a scope or analyzer and review the signal on the pins. Not clear what you are communicating with, but would suggest you try without DMA first and prove that works/responds as expected.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..