MSP430 Workshop Series 4d of 12 - System Initialization

We conclude this chapter by looking at some of the other initialisation topics. So here's a list six things that you may need to initialise at the beginning of your program. The first one we point out is initializing the stack pointer, and this also would include the heap pointer if you're using dynamic memory.
This is a required action, but there's really nothing we need to do, because this is handled by the compiler. And were assuming that we're using C code, so we don't discuss this really in any detail anywhere. You can look at the compiler user's guide if you want to know more about how that is done.
Number two is initializing the watchdog timer. We've talked about this. We're responsible for it, we have to do something about it. It's a required action, and it's covered coming up next.
Setting up the power manager and supervisors, this is not required. These are things that can help us manage the power going to the CPU and let us know if it's getting out of range, but it's not required. And we'll cover that here in just a couple minutes.
Configuring the I/O pins, the GPIO pins. This is not something that's required, although most of your applications will probably need that. We discussed that in the last chapter.
Configuring the clocks, that doesn't necessarily need to be done, because there are default values which we looked at a little bit earlier on. So that's covered here in this chapter. But you most likely will want to change those clocks.
And finally, you don't have to configure all the other peripherals that are on the device, but that's something that you most likely will want to do. And we cover that in later chapters.
Let's start by taking a look at the watchdog timer. So the watchdog timer provides a good system failsafe. If it is not reset occasionally by your program, it will reset your system, that's basically the idea.
You can see that over on the right-hand side is the watchdog timer, the WDT. That timer is clocked by one of our system clocks.
In your code, to reset the timer, all you have to do is call in the 5529 and the FR5969. If you call WDT_restTimer, that will reset the timer back to its reset or startup state and will start counting down.
If the watchdog timer gets to the end of its counter and you haven't reset it, it will reset the CPU, or it will reset your program back to the start. If you remember at the beginning of this chapter, that's going to be a puck reset.
So there are some slight variations amongst the various watchdog timers. The one on the 5xx and the FR5xx devices, the WDT_A timer. And it's just a little fancier, it has a few more time intervals. It also allows the VLO to be its input. The WDT+ is the one that's on the G2553 device.
You can use the watchdog timer in three ways. You can turn it off, this is what we do for most of our common debugging when we're trying to get a program up and running. That's what we'll do in Lab A of this chapter. You could also use it as a watchdog. And we will try that out if you do the optional Lab B. And then finally, later on in the workshop, we'll use the watchdog timer as just a standard old interval timer.
Finally, as we said earlier, if you want to use the watchdog as a watchdog, usually you want the slowest clock and set up the longest intervals. The watchdog's source clock, the one that feeds the watchdog counter cannot be turned off even if you turn on a low-power mode or go into a low-power mode that would normally that clock off. It keeps that running. So that's a failsafe that's built into the system.
Next, let's look at some of the power management features. Many of our devices have a load dropout voltage regulator. This allows us to convert voltage coming on to the device into the core voltage that's needed by the CPU.
When this exists on the high side of the regulator, that's the unregulated voltage. We call the regulated voltage the low side.
Many devices have supply voltage supervisors. These supervisors can let us know when either the high side or the low side are coming close to being out of range.
So the supply voltage monitor will generate an interrupt when those supply voltages are getting close to being out of range. This doesn't mean that they're failing yet, it just means we're getting closer to failing. And we can use these events either on the high side and/or the low side as a way to generate an interrupt to the CPU to warn it that we may be getting close to going out of voltage, or maybe there's something that the program can do to mitigate or respond to this type of event.
If things get a little worse, then the supply voltage supervisor, not the monitor in this case, but the supervisor, comes into play to reset the processor. It says, we've gone too far, the voltage is out of spec, and we get a reset. Once again, we have one of these on the high side, and we have one of these on the low side.
Not all devices have supply voltage supervision. It's a nice feature to have. Oftentimes, people will put it outside of the processor chip when they don't exist on chip. But we save money by having this integrated on chip.
The last item in this power management module would be something we've already looked at, and that's the brownout reset. It's always on, the supervisors and the monitors, supply voltage supervisor and monitors can be turned off, save just a little bit of power if we do that. But the brownout reset cannot be turned off. And the brownout reset is found all MOSP430 devices, unlike the supply voltage supervisors and monitors, which are only found on some of the devices.
Another item to cover, the 5xx devices and also the F6xx devices have different operating ranges. This allows us to set the voltage used by the CPU to different rates. And we would pick the lowest rate that would support the frequency that we want to run at. It just gives us flexibility so that we don't have to be running the CPU with peak power when it's not really needed.
So for example, you can see, we've circled-- if we wanted to be running anywhere from 8 to 12 megahertz, we should have the power management set to a core voltage of 1. And then down lower in the page, we can see how PMM_setVCore equal to PMM_CORE_LEVEL_1.
On the F5xx devices, you can program the flash at any of the voltage levels. This is not the case for all of the MOSP430 devices, such as the F2xx devices or the G2553, which is one of the devices we've been looking at. Those, you have to be over a certain voltage in order to use the flash in-circuit programming.
To summarize the power management, here's a chart looking at the three devices we've been examining so far in this class. You can see that they all run in the same input voltage range. The value line devices do not have low dropout voltage regulators, but the 5529 and the FR5969 devices do.
The 5529 has those four power voltage levels that we just talked about. Those types of things exist on the FR5969, but that's done intelligently. We don't have to manually change the power settings ourselves.
You can see that the speed is affected by the voltage. So I can run up to 8 megahertz on the 5529 at one 1.8 volts. We don't have those limitations though, on the 5969. I can run it at any speed at any voltage within the given voltage range.
You can also see the flash and FRAM programming. We don't need to have a specific voltage in order to program the flash on the 5529 or the FRAM on the 5969.
They all have a brownout reset. The 5529 and 5969 both have the supply voltage supervisor and the power monitor, the supply voltage monitor. The G2553 does not have either of those.
Finally, we talked in the last chapter about the LOCK LPM5. That exists on the M 29 but it's not a default state. And it is something that we still have to deal with on the 5969.
Our final initialization summary. This is very simplistic to kind of drive home the concept that, at the beginning of main, there are some things we need to set up. We need to initialize our watchdog. We need to initialize our GPIO. We need to initialize our clocks. Now, there are a number of other peripherals you might need to set up as well.