Author Topic: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...  (Read 21702 times)

0 Members and 1 Guest are viewing this topic.

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #75 on: October 16, 2016, 05:54:18 pm »
Quote
I'm reluctant to recommend STM32 but only because its so much more complicated

That's because it is feature rich. Complexity is the price you pay for that.

I can easily replicate what I'm trying to do here with all register ops on TIM1, the most complicated timer on STM32.

Quote
and the standard peripheral library is a bit of a mess.

that statement would have a lot more credibility if it is backed up by facts.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #76 on: October 16, 2016, 08:22:08 pm »
to just show how not-difficult it is to replicate the same on TIM1 (advanced timer) on a STM32 (STM32F100RB in this particular case), here is the user code that does the same thing: blinking an led with variable duty cycle, from 0% to 100%:

Code: [Select]
//initialize the timer
tmr1_init(1000/2); //with a prescaler

//initialize oc1 to call a user handler
tmr1_setpr1(1000); //specify period
tmr1_act1(led_flp); //install user handler

//initialize oc2 to call a user handler
tmr1_setpr4(1000 * 1.01); //specify period
tmr1_act4(led_flp); //install user handler

it looks remarkably similar to the ones posted earlier.

The initialization code, implemented without any use of the ST standard peripheral library, is this:

Code: [Select]
//initialize tmr1 to use compare channels as timers
//16-bit prescaler. 32-bit used for compatability
void tmr1_init(uint32_t ps) {
//route the clock to timer
RCC->APB2ENR |= RCC_APB2ENR_TIMxEN;

//source from internal clock -> disable slave mode
TIMx->SMCR &=~TIM_SMCR_SMS; //clear sms->use internal clock

//stop the timer to configure it
TIMx->CR1 &=~TIM_CR1_CEN; //clear cen. 0=disable the timer, 1=enable the timer
TIMx->CR1 &=~TIM_CR1_CKD; //clear CKD0..1. 0b00->1x clock; 0b01->2:1 clock, 0b10->4:1 clk; 0b11->reserved
TIMx->CR1 &=~TIM_CR1_DIR; //clear DIR bit. 0=upcounter, 1=downcounter
TIMx->CR1 &=~TIM_CR1_OPM; //clear opm bit. 0=periodic timer, 1=one-shot timer
//or to simply zero the register
//TIMx->CR1 = 0; //much easier

//clear the status register bits for capture / compare flags
TIMx->SR &=~(TIM_SR_CC1IF | TIM_SR_CC2IF | TIM_SR_CC3IF | TIM_SR_CC4IF);
//disable the interrupt by clearing the enable bits
TIMx->DIER &=~(TIM_DIER_CC1IE | TIM_DIER_CC2IE | TIM_DIER_CC3IE | TIM_DIER_CC4IE);

//set the prescaler
TIMx->PSC = ps - 1; //set the prescaler
TIMx->RCR = 0; //repetition counter = 0 (=no repetition)
TIMx->ARR = -1; //auto reload register / period = 0; - need to change for downcounters
TIMx->CNT = 0; //reset the counter

//enable the timer.
TIMx->CR1 |= TIM_CR1_CEN; //enable the timer
}

the code to set the period:
Code: [Select]
//set tmr1_oc1 period
//pr is 16-bit. 32-bit used for compatability;
void tmr1_setpr1(uint32_t pr) {
//save the period value
_tmr_oc1 = pr - 1;
TIMx->CCR1 = _tmr_oc1;

//clear the flag
//TIMx->SR &=~TIM_SR_CC1IF; //clear the interrupt flag
//TIMx->DIER &=~TIM_DIER_CC1IE; //disable the isr
}


All the code requires is the standard header file, stm32f10x.h. you can make your life easier with CMSIS' NVIC management functions that even that can be optional.

The code can be easily replicated to cover TIM2/3/4/5, and with minor changes, other simpler timers as well.

As you can see, the code is only marginally more complicated than that for an AVR or a PIC. :)
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #77 on: October 16, 2016, 08:35:03 pm »
Quote
The code can be easily replicated to cover TIM2/3/4/5

Save you some trouble: with no change, the code compiles for TIM2 and runs flawlessly. So it should work also for TIM3/4/5 - that means you can make 4 "timers" out of each of those timers.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #78 on: October 24, 2016, 12:34:01 am »
In case someone is interested, I took the approach to a lpc2106 -> the superstar from 10+ years ago, :)

Code: [Select]
tmr0_init(0x12); //initialize the timer with a prescaler
tmr0_setpr0(0x5678); //set the prescaler
tmr0_act0(led_flp); //install user handler
ei(); //global interrupt enable

it runs TIMER0 at 0x12 prescaler, and then MR0 channel at a 0x5678 increment. The isr calls led_flp().

tmr0_init() initializes the module:
Code: [Select]
//reset tmr with a prescaler
void tmr0_init(uint32_t ps) {
//stop tmr0
CTx->TCR &=~(1<<0); //0=disable timer, 1=enable timer

//reset timer
CTx->TCR |= (1<<1); //1=reset timer on next pusitive edge of pclk, 0=timer can be started

CTx->CTCR &=~(0x03); //0b00->timer mode
CTx->TC = 0; //reset tc -> not needed if TCR is reset first
CTx->PR = ps - 1; //set prescaler

//enable timer
CTx->TCR &=~(1<<1); //1=reset timer on next pusitive edge of pclk, 0=timer can be started
CTx->TCR |= (1<<0); //0=disable timer, 1=enable timer

//now timer is running
}

tmr_setpr() sets the prescaler:
Code: [Select]
//set period register
void tmr0_setpr0(uint32_t pr) {
CTx->MR0 = _tmr_pr0 = pr - 1; //set pr

CTx->IR &=~(1<<0); //clear the flag
CTx->MCR = (CTx->MCR & ~(0x07 << (3*0))) | //clear the mcr bits
(0x00 << (3*0)); //interrupt not yet enabled
}

The whole thing was compiled on Keil uv3 / ADS compiler (really really old). No CMSIS, but the code was adopted from one that I wrote for LPC11xx so you can see the struct approach I took there - the stock lpc210x.h is not used.

As such, the code can be easily modified to run on newer LPC chips which has similar timer peripherals (CT16B0/1 and CT32B0/1).
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #79 on: October 24, 2016, 12:47:03 am »
Often times people ask "why do you use a commercial IDE?".

to me, it is service and reliability. here, i will show two pictures that I think make a great case for convenience.

The above code was debugged using uv3 - a great little ide - plus an old copy of ADS.

The first picture shows a screen shot when the user handler of led_flp() is being executed for the first time. Compare that vs. the code, and you will be surprised how much information can be captured with just a few numbers.

The 2nd one shows a virtual "logic analyzer" on the IOPIN register -> it reflects the status of the pins.

Once you have used a good IDE, it is hard to go back.

================================
https://dannyelectronics.wordpress.com/
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 18323
  • Country: nl
    • NCT Developments
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #80 on: October 24, 2016, 05:57:19 am »
As an IDE for typing & managing code Keil's uV 3&4 absolutely suck compared to Eclipse. The debugging seems nice to get a quick view of what peripherals do. Then again... how much time does the debugger take from the CPU? IOW how realtime is your software running?
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6140
  • Country: us
    • Personal site
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #81 on: October 24, 2016, 06:11:13 am »
IOW how realtime is your software running?
Debuggers on ARM are mostly non-intrusive, but they still do affect performance of the system a bit, especially if you use all those rich features like live variable tracking. But if this level of intrusion affects your system, then you probably have a bigger problem in the future anyway.

Debuggers can also cause a bit of havoc when you do live update of peripheral registers - some registers (like flags) are cleared on read, and if debugger get there first, your software will never know that flag was ever set.
Alex
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 18323
  • Country: nl
    • NCT Developments
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #82 on: October 24, 2016, 06:14:05 am »
IOW how realtime is your software running?
Debuggers on ARM are mostly non-intrusive, but they still do affect performance of the system a bit, especially if you use all those rich features like live variable tracking. But if this level of intrusion affects your system, then you probably have a bigger problem in the future anyway.
Not necessarily. In several of my projects I'm doing signal processing which can take 80% to 90% of the CPU time but that is all very well defined.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6140
  • Country: us
    • Personal site
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #83 on: October 24, 2016, 06:16:46 am »
Not necessarily. In several of my projects I'm doing signal processing which can take 80% to 90% of the CPU time but that is all very well defined.
Debuggers don't take CPU time. They do issue bus transactions, and whether this will be a problem depends on the bus architecture. Most high performance systems will have multilayer bus, so it would not be as big of a problem.

And if you don't use live watch of variables or registers and only use breakpoints, then debugger is completely transparent.
Alex
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3265
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #84 on: October 24, 2016, 08:22:36 am »
Quote
I have yet to figure out why I want constructors and destructors with a serial port.
The Serial "objects" in the arduino library are statically allocated, not "constructed" (causing some concern on chips with several serial ports but not much RAM.)  AFAIK, nearly all of the arduino libraries (even from 3rd parties) follow the same model, avoid dynamic allocation, and are based on static creation and "begin" methods rather than constructors.  They seem to take the "don't use malloc on embedded systems" thing petty seriously, AND there's a big problem with using even static constructors of any complexity on AVR, because the constructor code gets called before peripheral initialization.  (when I say they don't use constructors, I mean that they don't use constructors that generate actual code.)

(Sigh.  Except for Strings.  Which are widely avoided due to problems, and/or perceived problems.)
Arduino relied on compiler optimization to remove unused static allocations, so if you only used 1 out of 4 instances of the UART object, only one of them will be present in the final compiled code.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #85 on: October 28, 2016, 02:37:04 pm »
simulating the use of the PWM0 module on a lpc2148 as 7 independent timers: all done in software, without any actual hardware.

the idea is like from 10 years ago.

can your command line do this?

;)
================================
https://dannyelectronics.wordpress.com/
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 18323
  • Country: nl
    • NCT Developments
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #86 on: October 28, 2016, 03:01:11 pm »
Why would you want to do that? Also there are some less well documented features (like setting or resetting the match pins from software IIRC) in those timers so I wonder how the simulator handles those.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 1993
  • Country: 00
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #87 on: October 28, 2016, 03:10:12 pm »
Keil is really much better than those eclipse shit, people that like eclipse are mac users windows user didn't
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6140
  • Country: us
    • Personal site
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #88 on: October 28, 2016, 03:16:08 pm »
Keil is really much better than those eclipse shit
It is also ~$5000  more expensive.
Alex
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #89 on: October 28, 2016, 03:39:48 pm »
Quote
Keil is really much better than those eclipse shit,

I think so too.

however, the later versions (4.x) got a little too fancy - but still usable. I tried to like 5.x multiple times and never succeeded in convincing myself to use it. the concept of RTE is good and even noble. but not sure if it is practical.

on the plus side, IAR still remains utilitarian. But a little bloated.
================================
https://dannyelectronics.wordpress.com/
 

Offline newbrain

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: se
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #90 on: October 29, 2016, 02:17:33 pm »
The timers (TIMER A) on msp430 are well thought out and well thought of.
[...8<...]
Wish others, especially ST, had modelled their timers after the TI's.

Though I tend to prefer STM32s to the MSP432 (maybe due to some sort of imprinting), I have to agree here.
HAL or not HAL it's an arcane art to master STM32 Timers while the TimerA model is clean, simple and effective enough.
May like NXP's timers in their LPC ARM chips over the ones in the MSP430/MSP432 ?  :box:
Totally missed this post...or we can pretend to live 6-7 light-days apart!
The answer is: I don't know yet.
Together with a PSoC kit, I also got a 43S67 LPCxpresso board (some people here like to collect DMM or scopes, I go for cheap development kits... ^-^) and I just started the bedtime reading of datasheets.
At first glance, they seem to be easy to use, clearly described and all 32bits to boost!
PWM peripheral does not look much simpler than ST's, though.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #91 on: October 29, 2016, 02:26:00 pm »
Quote
I just started the bedtime reading of datasheets.

Pay very close attention to if the peripherals can be halted in debug.

You will thank me for  that.
================================
https://dannyelectronics.wordpress.com/
 
The following users thanked this post: newbrain

Offline BurnedResistor

  • Regular Contributor
  • *
  • Posts: 168
  • Country: at
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #92 on: November 01, 2016, 11:33:59 pm »
Having started programming on 8bit pics, 32 bit pics and 32bit arm cores (stm nearly exclusively) I would recommend the STM line as a starting point.

The simplisity of setup of PICs MPLAB is very nearly approached by the free version of Keil. If one should outgrow KEIL, the free gcc toolchain is available.

But the main advantage of programming for arm is that there are many more exmaples and explainations. This is only logical as there aer many more arm cores in use, and they share stricking similarities. I personally struggeled with Microchip documentation a lot!
 

Offline ez24

  • Super Contributor
  • ***
  • Posts: 3092
  • Country: us
  • L.D.A.
Re: Where to begin? STM32F0 vs PIC32mx vs MSP432 vs ...
« Reply #93 on: November 01, 2016, 11:42:33 pm »
Pay very close attention to if the peripherals can be halted in debug.

You will thank me for  that.

What do you mean?
YouTube and Website Electronic Resources ------>  https://www.eevblog.com/forum/other-blog-specific/a/msg1341166/#msg1341166
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf