STM32F429I (STM32-DISCO) & CoIDE? Getting started... - Page 1
Forum section: electronics / general

author: QrackM
author_rank: Contributor
timestamp: August 06, 2014, 08:57:27 pm
content: First, being new to community I'd like to politely excause for my newbien-nessHope I didn't do anything wrong starting this topic here or something...But, let's stick to the topic:Just got my brand new STM32F4 eval board (exactlyhttp://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF259090). Trying to quick-start with it failed due to lack of experience. When I was ordering I was thinking about CooCox IDE, but it appears it doesn't support this exact ARM. To sum up, problems which I face are:Where can I get demo project files from (to be able to revert it any time and take a peek into code maybe?)Can I get CoIDE to work (blink a LED, handle button, use I2C is all I need at the moment)?if answer to above is not, what IDE and compiler would you recommend? Read about emblocks and gcc, but your opinion would be very worthyWhere can I get libraries from? (I mean, I suppose st.com, but for me, their website is a mess, can't find a thing and be sure that is exactly what I wanted! really!)Obviously, I'm in a bit of rush with that, as it usually is...

author: Dongulus
author_rank: Regular Contributor
timestamp: August 06, 2014, 09:08:52 pm
content: I took a day course about getting started with the STM32F429 offered by STMicroelectonics. For the course, we used the free, code-limited version of IAR. They gave us some example program source code on a USB. The same files are available on the product websitelisted under "Related Tools and Software".

author: andyturk
author_rank: Frequent Contributor
timestamp: August 06, 2014, 09:45:12 pm
content: I've never used CoIDE, but I'd be shocked if it didn't support STM32F4xx. The web page seems to suggest support was added for that product line in2012:QuoteEven if the whiz-bang stuff that's unique to the '429 isn't supported, the other peripherals (I2C in particular) should be essentially the same as what you get with the rest of the F4 family.Also,ChibiOS/RT(which is an RTOS with excellent STM32 support) has a '429demo.

author: QrackM
author_rank: Contributor
timestamp: August 07, 2014, 04:17:53 pm
content: @andyturk:QuoteYea, but seems this exact model (STM32F429) is not yet supported anyway. List of supported models fromhttp://www.coocox.org/CooCox_CoIDE.htm:QuotePlus, this claim is suported by CooCox forum discussions:Thisandthat.Using CoIDE was important for me, as group I work in uses it... but well, I'll wait for 1.8 or try to use it anyway as you suggestedI'll share my experience (if only my memory doesn't fail me)

author: dannyf
author_rank: Super Contributor
timestamp: August 07, 2014, 05:07:26 pm
content: You can always compile to the corresponding CMx chip - which CoIDE supports and load up the right start-up file / CMSIS / libraries. This is effectively what CoIDE does for you automatically if the chip is supported.

author: photovore
author_rank: Newbie
timestamp: August 07, 2014, 08:35:45 pm
content: I recently did a project with the STM32F429 in CoIDE. I used the libraries from this pagehttp://mikrocontroller.bplaced.net/wordpress/?page_id=2736as a starting point. They all run perfectly in CoIDE, just make sure not to use the CoIDE repository if you have to import any new standard peripheral libraries as they are all for the STM32F4. You have to use the libraries for the 429 that you can download on the ST website. The file is named STM32F429I-Discovery_FW_V1.0.1.

author: QrackM
author_rank: Contributor
timestamp: August 15, 2014, 12:29:29 am
content: So, after a bit playing around, board works. For now I tried to use KEIL uVision 5 and CoIDE (which works without any problems...).Obviously, now I've got tons of libraries and other stuff, so have to clean it up and choose my tools&libs, but that will come with timeSo now only one thing is obscure to me, as I tested full speed (180MHz) and didCode:for(i=1000; i>0; i--){for(j=180000; j>0; j--);}loop in while(1) after toggling LED I get like ~7s delay. Using SysClockTick works like a charm, so won't bother about it much longer, but I'd like to know what causes this issue and should it be that way? (NOTE: problem appears both in CoIDE and KEIL)- my theory is latency (wait states).So, for now thanks for your answers, gave me a good start

author: dannyf
author_rank: Super Contributor
timestamp: August 15, 2014, 01:01:23 am
content: QuoteTough to answer without knowing what "this issue" is.

author: AndreasF
author_rank: Frequent Contributor
timestamp: August 15, 2014, 05:56:56 am
content: If you were hoping to get a 1 second interval with those nested loops, think about how many fundamental steps need to happen for each iteration of a loop. Each of those will take one (or more) processor cycles, so your total number cycles will be a lot more than 180000000.

author: QrackM
author_rank: Contributor
timestamp: August 15, 2014, 12:01:45 pm
content: @dannyf'this issue' meaning nested for's giving different delay time then expected. ButAndreasFalready gave the answer@AndreasFWell, expected just asm DJNZ's, but appears I should find output assembly file and check it outNow feel lame that I even asked, thing is so obvious...but it worked on 8051 so prettyEDIT://So, debugged, disassembled, now I see it

author: dannyf
author_rank: Super Contributor
timestamp: August 15, 2014, 12:32:04 pm
content: QuoteThen you will need to describe your expectation vs. the actual behavior the code gave.QuoteSoftware delays like that are actually much harder to code, in that their execution can be highly dependent on optimization settings of the compiler.

author: leppie
author_rank: Frequent Contributor
timestamp: August 15, 2014, 01:23:38 pm
content: It all depends on optimization levels of the compiler. But as you said, you found SysTick, and that is pretty much the way to go IMOThere are some assembly snippets for microsecond (or less) delay (which wont get optimized either way).

author: dannyf
author_rank: Super Contributor
timestamp: August 15, 2014, 02:05:41 pm
content: Systick has the added advantage of providing very fine timing resolution, even if systick itself is on larger intervals.

author: QrackM
author_rank: Contributor
timestamp: August 15, 2014, 04:48:39 pm
content: @leppieI noticed that it's strongly dependent on optimization. For start it took myforbased delay exactly 10 cycles, so when I expected to get 1 ms delay i got 10ms, pretty bang on. That was my main worry, I expected 2, maybe 3 cycles, not 10 :O But after some playing around 180 000forloop executions took arount 7ms...@dannyfThere's not much to explain, as just got surprised how many c cycles can emptyfortakeAs now I've got SysTick working, I'm going to give I2C a goOnce more, thanks for your help and explanations, jumping from AVR to STM32 with 2 weeks playing around with STM8 is funEDIT://updateSo, beware, I'll probably need some advice soonSetting up I2C is not as straigt-forward as expected, first problem I encountered is that start and stop are generated, but nothing in between. after sometweaking I get something on SDA, but SCL- zero, null, nada :O I'll link logic signals from Saleae

author: leppie
author_rank: Frequent Contributor
timestamp: August 18, 2014, 01:52:28 pm
content: Quote from: QrackM on August 15, 2014, 04:48:39 pmI know I2C on STM32Fxx was flaky a few years back, ST usually have a software driver for it in some board packages. Not sure if that is still the case. Check the errata.

author: Kjelt
author_rank: Super Contributor
timestamp: August 18, 2014, 02:20:52 pm
content: Yup: I2C for STM32 use the (CPAL) or (UM1029) library:seehttps://www.eevblog.com/forum/microcontrollers/atmel-arm-cortex/msg486593/#msg486593

author: QrackM
author_rank: Contributor
timestamp: August 18, 2014, 07:52:39 pm
content: @KjeltThere is an issue in F4's still it appears. Errata informs about different problem than I'm currently struggling with. In my case there is no SCL, which gives 'No ACK' and then constantly 'I2C busy', it desn't even generate STOPSince we started talking about I2C, I'm linking signal capture:This happens with sample code I retrieved from internetS(ommiting defines and includes...):Code:int main(void){// Init system to get 168MHz clock. PCLK is prescalled by 8, 42MHzSystemInit();SysTick_Init();GPIO_InitTypeDef GPIO_InitStructure;I2C_InitTypeDef I2C_InitStruct;RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_I2C1); //PB8 -> I2C1_SCLGPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_I2C1); //PB9 -> I2C1_SDAGPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; //GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;GPIO_Init(GPIOB, &GPIO_InitStructure);I2C_DeInit(I2C1);/* I2C DeInit *//* Enable the I2C peripheral */I2C_Cmd(I2C1, ENABLE);/* Set the I2C structure parameters */I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;I2C_InitStruct.I2C_OwnAddress1 = 0xFE; //Master addressI2C_InitStruct.I2C_Ack = I2C_Ack_Enable;I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; //7 bit address modeI2C_InitStruct.I2C_ClockSpeed = 30000; // speed = 30K/* Initialize the I2C peripheral w/ selected parameters */I2C_Init(I2C1, &I2C_InitStruct);while(1){while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY));I2C_GenerateSTART(I2C1,ENABLE);while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT));I2C_Send7bitAddress(I2C1, 0xAA, I2C_Direction_Transmitter); //random address for seeing bits changing on SDA// here I have ack failure (sr1) and busy, master (sr2) in SR. SR1 == 1024, SR2 = 3I2C_GenerateSTOP(I2C2, ENABLE);SysTick_DelayMs(50);}}Also got to condition when no data was sent, jus START and STOP bits (don't have capture)

author: AndreasF
author_rank: Frequent Contributor
timestamp: August 18, 2014, 08:56:31 pm
content: if you are sending a ...Quote..., why are you surprised that you will eventually get an acknowledge failure? If you don't have an I2C slave responding to that address this would be the expected behaviour, no?

author: AndreasF
author_rank: Frequent Contributor
timestamp: August 18, 2014, 09:06:21 pm
content: Here's the piece of I2C code I used with no problems on my STM32F407-Discovery board to talk to the onboard audio codec. Works like a charm. My I2C init structure looks virtually identical to yours (I use a higher speed).Code:void send_codec_ctrl(uint8_t controlBytes[], uint8_t numBytes){uint8_t bytesSent=0;while (I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BUSY)){//just wait until no longer busy}I2C_GenerateSTART(CODEC_I2C, ENABLE);while (!I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_SB)){//wait for generation of start condition}I2C_Send7bitAddress(CODEC_I2C, CODEC_I2C_ADDRESS, I2C_Direction_Transmitter);while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)){//wait for end of address transmission}while (bytesSent < numBytes){I2C_SendData(CODEC_I2C, controlBytes);bytesSent++;while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING)){//wait for transmission of byte}}while(!I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BTF)){//wait until it's finished sending before creating STOP}I2C_GenerateSTOP(CODEC_I2C, ENABLE);}

author: Kjelt
author_rank: Super Contributor
timestamp: August 18, 2014, 09:06:57 pm
content: Can,t help right now, no access to code.Check if you have proper pull up resistors and a slave device attached.Check the correct initialization of the GPIO pins. Read all docs you can and try to find a verified working example online of the correct initialization and verify with your code.EDIT see you have alread a helping hand with code

author: QrackM
author_rank: Contributor
timestamp: August 18, 2014, 09:57:41 pm
content: @AndreasFI don't expect to get ACK. I expect to get clock signal on SCL line, which just goes low and stays this way. And what I have to get my head around is why I don't get STOP. Didn't read datasheet yet, but engineers feeling would tell me that it should clear ACK failure and release bus...Thanks for the code though, gonna check it tomorrow (now got into other TTD's, and night is coming in Poland)@KjeltAs written between lines, I'm currently trying this I2C 'dry', without slave connected. Wouldn't it be same way as selecting wrong address? I mean, ACK wouldn't appear any way, bus should handle that...What I'm considering is that it need external pull-up's. Again, maybe I hope for too much, but since there's no load on bus, internal pull-up's should do... or not, just got enlightment that when used as Alternative Function they may be disconnected and it's just me hitting brick wall (there's even icon for that:). Would make myself look stupid again, but well.. sometimes you just go blind on basics...

author: Kjelt
author_rank: Super Contributor
timestamp: August 19, 2014, 08:11:41 am
content: Qrack have a look here:https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FI2C%20Configuration%20on%20STM32F2xx&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=1778more persons with your problem and solution.Probably a wrong remap of wrong pins icw ic peripheral. Double check everything. Check ifUsual pin config for i2c is gpioMode_Alternate,gpioModeOutputType_OD and gpioPull_Floating with external pullups.Also check I2C_Send7bitAddress implementation if it is not generating a start condition itself (then you have a conflict starting twice in periph.). Lots of possibilities unfortunately. Suggest to use CPAL library and example of ST to start afresh.Also the i2c event and error interrupts are they handled or do you use polling.

author: QrackM
author_rank: Contributor
timestamp: August 19, 2014, 02:26:12 pm
content: @KjeltThank's for the link, it's acctually one of many I visited, didn't help meBut, fortunatelly, our discussion did (to some extent) !As it's course took to pull-ups, I decided to make some art (I'm not at home this week, so I really used some MacGayver skills) and use external 10k's. Now I get SCL O0Still, I try it without Slave connected, so get ACK failure, but that's expected. Now I just have to figure why I don't get Stop...EDIT://Ok, call me an idiot. Now it was just me, looking for Stop generated on I2C2on I2C1interface...After this thread, I must admitt, I'm really happy to join this forum community. Hope I'll be able to rather-help-than-ask soon

author: Kjelt
author_rank: Super Contributor
timestamp: August 19, 2014, 03:02:41 pm
content: Quote from: QrackM on August 19, 2014, 02:26:12 pmDid you clear the AF flag in the SR before generating the stop?for cpal this looks like CPAL_I2C_DEVICE[(device)]->SR1 = ~I2C_SR1_AF

author: leppie
author_rank: Frequent Contributor
timestamp: August 19, 2014, 03:24:12 pm
content: Quote from: QrackM on August 19, 2014, 02:26:12 pmI was just going to say that!