Author Topic: STM32, ghetto style  (Read 149381 times)

0 Members and 2 Guests are viewing this topic.

Offline Koepi

  • Regular Contributor
  • *
  • Posts: 64
  • Country: de
Re: STM32, ghetto style
« Reply #275 on: October 25, 2014, 03:08:07 pm »
I'm playing around a little with LDOs and switching regulators. Now the power supply for the stm32f030-boards can be done ghetto-style as well (just look how bad my soldering skills are :D ).

The first three pictures show how to build up a PAM3101 LDO; I used a MiniUSB-connector for power input via USB. I added more Vout/GND pins so peripherals can be powered with it, too. It copes with a 4 digit 7-segment display as well. It has no issues with little load around 10-40mA (up to Imax, around 250mA), this is something cheap LDOs have issues with (like AMS1117).

The last picture shows a smaller footprint RT9166 LDO "breakout" board. It delivers power for my soft-PWM-dimming LED sample f030 board, also down to 5mA with no issues (Imax around 300mA). Both work stable, and from the amount of connections and solder points the RT9166 version is the preferred one to put it for example directly on a TSSOP20-2-DIP board with F030 µC.

The RT9166 costs around 10 cents each (at Aliexpress 30 pieces for 3 bucks including shipping around the globe). It delivers great, low noise, very low dropout current. I'll test a few more ICs soon, as MCP1700 promise even less quiescent current draw.

I'm looking out for NCP 1402SN 33/50; with those, I can use a single mignon alkaline cell to provide power for a circuit. With quite amazing efficiency. Those are around 40cents per IC though.
« Last Edit: October 25, 2014, 03:17:51 pm by Koepi »
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #276 on: October 25, 2014, 07:38:45 pm »
1117s (both knock-offs and ld1117) are my favorite low-current regulator. I buy them in the hundreds and they are cheaper than discrete transistors.

Would love to try RT9166 when I get a chance. Used MCP1700 a few times and didn't find a compelling reason to use them.
================================
https://dannyelectronics.wordpress.com/
 

Offline Koepi

  • Regular Contributor
  • *
  • Posts: 64
  • Country: de
Re: STM32, ghetto style
« Reply #277 on: October 25, 2014, 09:31:18 pm »
I'm just checking if I manage to see a difference between all those LDOs and power supply mechanisms in practice, thus I ordered plenty different ICs.
Those RT9166 are quite cheap as well:
http://www.aliexpress.com/snapshot/6256602707.html
Of course, you get 100+ AMS1117 for that price tag. But they're less precise and effective and have a significant higher dropout voltage. Relevant only if you thin about using 3 AA batteries or LiIon as power source, of course. :) What bothers me most with 1117 is the minimum load of 5-10mA.
« Last Edit: October 25, 2014, 09:38:37 pm by Koepi »
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: STM32, ghetto style
« Reply #278 on: October 25, 2014, 10:22:58 pm »
What bothers me most with 1117 is the minimum load of 5-10mA.
Lets be clear here (for my understanding at least).
Looking at the datasheet of the quiescent current of a LD1117 (link below) that is 5 to 10mA.
The minimum load however is typ. 2mA.
So you probably mean that the quiescent losses are 5 to 10mA which bothers you, not the minimum output current?

http://www.farnell.com/datasheets/1776449.pdf
 

Offline Koepi

  • Regular Contributor
  • *
  • Posts: 64
  • Country: de
Re: STM32, ghetto style
« Reply #279 on: October 25, 2014, 10:49:06 pm »
You're looking at a different datasheet. Talking about the 3-cents AMS1117:
http://www.advanced-monolithic.com/pdf/ds1117.pdf

Minimum load 5-10mA, quiescent current the same range. The more expensive "original" IC has a little better data but still is not as good as for example a RT9166.

Driving a circuit in mobile conditions (=on battery power) which uses 2.6mA like for example the 4-digit 7-segment LED clock I built, that is way to much wasted energy and even out of specs when using a 1117.
I took an ATmega328 in Arduino Pro Mini format, as it has a wide input voltage range from 1.8-5V and thus can be fed directly with a LiIon battery. With an efficient LDO/boost/whatever power supply, I could do this with a cheap F030 and one or two AA batteries.
« Last Edit: October 25, 2014, 10:54:14 pm by Koepi »
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: STM32, ghetto style
« Reply #280 on: October 25, 2014, 10:53:32 pm »
Ok I thought you said 1117 as in any 1117 LDO VR.
 

Offline Koepi

  • Regular Contributor
  • *
  • Posts: 64
  • Country: de
Re: STM32, ghetto style
« Reply #281 on: October 25, 2014, 10:55:18 pm »
I did in the last sentence. I thought they all behave the same, but there are obviously tiny differences. Not really much, not enough to change usability significantly.
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #282 on: October 26, 2014, 11:43:40 am »
I did a quick testing of a couple LD1117/3.3v regulators (to220) I have.

3.28 - 3.30v output, no load attached. Rock solid output;

5.0 - 5.2ma idle current.

I don't have much complaints about 1117 regulators in general, given their low low prices. However, my application is mostly desktop so idle current isn't a concern. I can understand that for a battery powered application, 5ma maybe a little on the high side.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #283 on: October 26, 2014, 11:45:19 am »
At some point, a regulator shoot-out may be interesting to see. We can pick a few easy to measure attributes and we can go through our own parts box and find some interesting regulators to test.
================================
https://dannyelectronics.wordpress.com/
 

Offline Koepi

  • Regular Contributor
  • *
  • Posts: 64
  • Country: de
Re: STM32, ghetto style
« Reply #284 on: October 27, 2014, 09:56:55 pm »
Huh, there was trash on TV tonight (which my wife wanted to watch), so I took the chance to build up the three different LDOs I have flying around as single ICs and do first measurements. A bit OT, but as it fits into the discussion and dannyf suggested it ...  ;D

I used only X7R ceramic capacitors; the GND "plane" is done with fat solder blob or fat wire. Other wiring is done with 0.1mm enameled copper wire.

LDOVout *1Current *2
PAM31013.292V59,8µA
RT91663.285V6.3µA
MCP1825S3.335V44.1µA
*1 Output voltage with STM32F030 attached doing software PWM with 100kHz+,  load between 20-40mA
*2 Without any load attached.


The PAM3101 really sucks to build up - you need three capacitors and puzzle that together in very little space.
On the photo from left to right: MCP1825S, RT9166 and PAM3101.
« Last Edit: October 28, 2014, 05:42:24 am by Koepi »
 

Offline Ribster

  • Frequent Contributor
  • **
  • Posts: 250
  • Country: be
  • Electronics prototyper. Design. Prototype. Consult
    • Ash Labs
Re: STM32, ghetto style
« Reply #285 on: November 01, 2014, 01:16:39 pm »
Set up HSIxPLL:
...
That's 64 million reasons to get this little bugger, :)

Hey guys,
I'm trying the STM32F051C8T6.
For a while i'm trying to get the HSI as clock source, but it doesn't work to get it going.
I've used this piece of code directly inside my system_stm32f0xx.c file:
Code: [Select]
RCC_DeInit(); //reset rcc
RCC_PLLCmd(DISABLE); //disable PLL
RCC_HSICmd(ENABLE); //enable hsi;
RCC_HCLKConfig(RCC_SYSCLK_Div1); //set sysclk divider
RCC_PLLConfig(RCC_CFGR_PLLSRC_HSI_Div2, RCC_PLLMul_12); //configure pll / divider. _x=[2..16]
RCC_PLLCmd(ENABLE); //enable pll
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) continue; //wait for pll to be ready
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //set pll as sysclk
while (RCC_GetSYSCLKSource() != RCC_CFGR_SWS_PLL/*0x08*/) continue; //wait for PLL to be ready

SystemCoreClockUpdate(); //update SystemCoreClock

When i let an LED come on before the "while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) continue;   //wait for pll to be ready", it lights up, but flickers.
So i guess it resets on the watchdog because the while loop goes on forever.
Now my question: why can't i select my HSI as PLL clocksource. Am i doing something wrong ?
This chip is good for 48MHz, so multiplier of 12 should be okay. I've tried multiplier of 6, but same result..

Greetings
www.ashlabs.be
Design and manufacturing of embedded hard- and software
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #286 on: November 01, 2014, 02:19:10 pm »
I think that's my code for stm32f030f -> but they are in the same family so it should work - it doesn't check for wait state and that's something you may want to address.

I don't change system files, like system_stm32f0xx.c. Instead, in user main(), I put a routine that sets up the mcu, including the clock.

You should try that and see if it works. The way to check is to step through the pll set up section of your code and see if SystemCoreClock has the right value.

Hope it helps.
================================
https://dannyelectronics.wordpress.com/
 

Offline Ribster

  • Frequent Contributor
  • **
  • Posts: 250
  • Country: be
  • Electronics prototyper. Design. Prototype. Consult
    • Ash Labs
Re: STM32, ghetto style
« Reply #287 on: November 01, 2014, 02:27:56 pm »
Yeah, he keeps hanging on the wating for PLL getting ready.
I wish there was some kind of good tutorial about this.
All the documentation for STM32 is quite extensive, which makes it a bit hard to search for what you exactly want.
The small simple things are documented on other peoples blogs, but this stuff is mostly left out.. Which is a shame..
I'll look further and post a solution once i found one.

Greetings
www.ashlabs.be
Design and manufacturing of embedded hard- and software
 

Offline Koepi

  • Regular Contributor
  • *
  • Posts: 64
  • Country: de
Re: STM32, ghetto style
« Reply #288 on: November 01, 2014, 02:45:17 pm »
What happens if you try this code snippet?


Code: [Select]
// ---- Setup PLL for 48 MHz :) ----
RCC_DeInit();
RCC_PLLCmd(DISABLE);
RCC_PLLConfig(RCC_PLLSource_HSI, RCC_PLLMul_12);
// Flash: 1 WaitState for 24MHz < SysCLK < 48 MHz
FLASH_SetLatency(FLASH_Latency_1);
FLASH_PrefetchBufferCmd(ENABLE);
// Set ADC clock to internal HSI 14MHz
RCC_ADCCLKConfig(RCC_ADCCLK_HSI14);
// and turn the PLL back on again
RCC_PLLCmd(ENABLE);
// set PLL as system clock source
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
// ---- End of Setup PLL for 48 MHz :) ----

This sets clock to HSI and the PLL.
 

Offline Ribster

  • Frequent Contributor
  • **
  • Posts: 250
  • Country: be
  • Electronics prototyper. Design. Prototype. Consult
    • Ash Labs
Re: STM32, ghetto style
« Reply #289 on: November 01, 2014, 08:08:43 pm »
I've tried it, with the same result.
My leds keep flashing, so the MCU keeps crashing and restarting.
After programming the MCU also disconnects from programmer, picture added.

The only problem that i had, was that i couldn't use the flash functions.
I've added #include "stm32f0xx_flash.h", with no result. My compiler does not find the routines in the corresponding .c file.
Which is very weird. I know eclipse has it's quirks, but this one i don't understand.
Thanks for the help, i'll continue my search..
www.ashlabs.be
Design and manufacturing of embedded hard- and software
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #290 on: November 01, 2014, 08:30:04 pm »
Quote
My leds keep flashing, so the MCU keeps crashing and restarting.

Not sure how your code works so not much can be read from the fact that "the led keep flashing"

Quote
After programming the MCU also disconnects from programmer, picture added.

Typically from the swd pins being used by the code.

Quote
The only problem that i had, was that i couldn't use the flash functions.
I've added #include "stm32f0xx_flash.h", with no result. My compiler does not find the routines in the corresponding .c file.

Include the .c files in your project and have the .h files in the include path.

If I were you, I would post a minimalist but complete piece of code so that others know what you are talking about.

As to wait state, I ran a stm32f030f up to 50+Mhz on 0 wait state so it is fairly tolerant.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #291 on: November 02, 2014, 02:06:36 pm »
Thanks for the help, i'll continue my search..

Liked the sublime style. Did you do it in eclipse or just used sublime as the external editor in eclipse?
================================
https://dannyelectronics.wordpress.com/
 

Offline Koepi

  • Regular Contributor
  • *
  • Posts: 64
  • Country: de
Re: STM32, ghetto style
« Reply #292 on: November 02, 2014, 02:46:47 pm »
Continued the test, built up a MCP1700 today. This one is amazing!

LDOVout *1Current *2
PAM31013.292V59,8µA
RT91663.285V6.3µA
MCP1825S3.335V44.1µA
MCP17003.283V1.3µA
*1 Output voltage with STM32F030 attached doing software PWM with 100kHz+,  load between 20-40mA
*2 Without any load attached.


It's the second part from the left on the attached photo.
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #293 on: November 02, 2014, 03:26:36 pm »
1.3ua is pretty impressive, especially in ghetto style, :)

Drop out voltage of 150-180mv is pretty good too.
================================
https://dannyelectronics.wordpress.com/
 

Offline Ribster

  • Frequent Contributor
  • **
  • Posts: 250
  • Country: be
  • Electronics prototyper. Design. Prototype. Consult
    • Ash Labs
Re: STM32, ghetto style
« Reply #294 on: November 02, 2014, 09:58:58 pm »
Thanks for the help, i'll continue my search..

Liked the sublime style. Did you do it in eclipse or just used sublime as the external editor in eclipse?

Nope, fully in Eclipse. The sublime text theme is quite nice. Although i have had some issues with the background for popups.
Personally, its the best syntax coloring for an IDE that i can think of.

EDIT: found the resource link ;) -   Eclipse Color Theme   0.13.1.201405041302   com.github.eclipsecolortheme.feature.feature.group   GitHub
« Last Edit: November 02, 2014, 10:10:13 pm by Ribster »
www.ashlabs.be
Design and manufacturing of embedded hard- and software
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #295 on: November 02, 2014, 10:23:58 pm »
Sublime has the best visual.

I wish you could invoke such a theme in Source Insight.
================================
https://dannyelectronics.wordpress.com/
 

Offline Ribster

  • Frequent Contributor
  • **
  • Posts: 250
  • Country: be
  • Electronics prototyper. Design. Prototype. Consult
    • Ash Labs
Re: STM32, ghetto style
« Reply #296 on: November 02, 2014, 10:29:16 pm »
Quote
My leds keep flashing, so the MCU keeps crashing and restarting.

Not sure how your code works so not much can be read from the fact that "the led keep flashing"

Quote
After programming the MCU also disconnects from programmer, picture added.

Typically from the swd pins being used by the code.

Quote
The only problem that i had, was that i couldn't use the flash functions.
I've added #include "stm32f0xx_flash.h", with no result. My compiler does not find the routines in the corresponding .c file.

Include the .c files in your project and have the .h files in the include path.

If I were you, I would post a minimalist but complete piece of code so that others know what you are talking about.

As to wait state, I ran a stm32f030f up to 50+Mhz on 0 wait state so it is fairly tolerant.

Okay, have had a busy weekend with another project. Sorry for the late feedback.
Code for main.cpp that i used:
Code: [Select]
#include <stdio.h>
#include "stm32f0xx.h"
#include "stm32f0xx_flash.h"

void delay(long int delaytime){
for(long int i=0; i<(delaytime*10000000);i++){

}
}

int
main(int argc, char* argv[])
{

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitTypeDef gis;
gis.GPIO_Mode = GPIO_Mode_OUT;
gis.GPIO_OType = GPIO_OType_PP;
gis.GPIO_Pin = GPIO_Pin_12;
gis.GPIO_PuPd = GPIO_PuPd_NOPULL;
gis.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&gis);


// ---- Setup PLL for 48 MHz :) ----
RCC_DeInit();
RCC_PLLCmd(DISABLE);
RCC_PLLConfig(RCC_PLLSource_HSI, RCC_PLLMul_2);
// Flash: 1 WaitState for 24MHz < SysCLK < 48 MHz
//FLASH_SetLatency(FLASH_Latency_1);
//FLASH_PrefetchBufferCmd(ENABLE);
// Set ADC clock to internal HSI 14MHz
RCC_ADCCLKConfig(RCC_ADCCLK_HSI14);
// and turn the PLL back on again
RCC_PLLCmd(ENABLE);
// set PLL as system clock source
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
// ---- End of Setup PLL for 48 MHz :) ----


  // Infinite loop
  while (1)
    {
  delay(100);
  GPIOA->BSRR = GPIO_Pin_12;
  delay(100);
  GPIOA->BRR = GPIO_Pin_12;
    }

  return 0;
}

So my IDE is eclipse with gcc-arm-none-eabi-4_8-2014q2.
I'm using the eclipse wizard that sets up a project in C++ with all the necessary includes and .c-files.
Reference:   GNU ARM C/C++ STM32Fx Project Templates   2.1.1.201404240550   ilg.gnuarmeclipse.templates.stm.feature.group   Liviu Ionescu
I've stripped everything from the code and just using the linked main.cpp file as above.
The chip is the STM32F051C8T6 on a custom board, its the LQFP48 board.
I'm using the HSE pins for something else, assuming i can get the HSI to work.. (That was the plan though..)
Connected via GDB and the STLINK utility from texane (yep, on OS X).
Have had other projects running without any problem, but since i made this custom board with HSI, these problems.
STLink V2 genuine from ST, so no fake. Genuine STM32F0's ordered from mouser. (So i'm using no fake, hate fake in the development fase.)

I've stepped through my code and find that this gives me the error:
Code: [Select]
void RCC_PLLCmd(FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_FUNCTIONAL_STATE(NewState));
 
  if (NewState != DISABLE)
  {
    RCC->CR |= RCC_CR_PLLON;
  }
  else
  {
    RCC->CR &= ~RCC_CR_PLLON;
  }
}
I step through my code, everything goes well, until my PLL-bit gets set and then i lose everything. ->>RCC->CR |= RCC_CR_PLLON;
When i was talking about the led, i let an LED light up right before the PLL configuration, and the led flashes very dim.
What i think that happens is that it just resets and goes into an infinite loop..
I'm having the necessary decoupling caps on the bottom side of the PCB right below the pins with via's.
0402 caps with 1 tantalum as per datasheet. (did my research).
I'm really scratching my head on this one.
When i'm going into the system_stm32f0xx.c file, i see that the SetSysClock routine sets the HSE bit on, waits for the HSE to get ready and then bails out.
I've found adjusted SetSysClock routines that incorporate compiler directives to adjust for the HSI in the first go, but i guess doing this in main() does the same thing..

I hope this is enough info..
www.ashlabs.be
Design and manufacturing of embedded hard- and software
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #297 on: November 02, 2014, 11:23:27 pm »
I am running CoIDE/gcc. I didn't do it but the code should yield the same results on keil / iar.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #298 on: November 02, 2014, 11:35:42 pm »
Koepi's code also worked, in case you are wondering.
================================
https://dannyelectronics.wordpress.com/
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4208
  • Country: us
Re: STM32, ghetto style
« Reply #299 on: November 02, 2014, 11:40:23 pm »
Quote
built up a MCP1700 today. This one is amazing!
Available in TO92, too!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf