tutorials:microcontroller_programming_tips
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
tutorials:microcontroller_programming_tips [2024/10/29 20:30] – ibchadmin | tutorials:microcontroller_programming_tips [2024/10/29 20:32] (current) – ibchadmin | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Microcontroller Programming Tips ====== | ====== Microcontroller Programming Tips ====== | ||
- | When programming microcontrollers, | + | When programming microcontrollers, |
**Registers: | **Registers: | ||
Line 22: | Line 22: | ||
**Memory:** The MSP430s typically used have very little RAM (usually 2Kb). This means that the usual games you play on your laptop have to change. For one, we generally do not use dynamic memory allocation — no malloc, calloc, realloc, free, new. Everything is static. The reason is that with so little memory, having a heap that grows dynamically at runtime makes things really hard to debug. Your stack grows from one end of that 2KB. Your globals go on the other end. If your stack ever grows too large, it will start overwriting the globals (or the heap, if you have one). | **Memory:** The MSP430s typically used have very little RAM (usually 2Kb). This means that the usual games you play on your laptop have to change. For one, we generally do not use dynamic memory allocation — no malloc, calloc, realloc, free, new. Everything is static. The reason is that with so little memory, having a heap that grows dynamically at runtime makes things really hard to debug. Your stack grows from one end of that 2KB. Your globals go on the other end. If your stack ever grows too large, it will start overwriting the globals (or the heap, if you have one). | ||
Note, that recursion, deep function call graphs, and passing large arrays or structs as parameters are similarly dangerous. You want to keep your stack small, so it doesn’t run over your globals. | Note, that recursion, deep function call graphs, and passing large arrays or structs as parameters are similarly dangerous. You want to keep your stack small, so it doesn’t run over your globals. | ||
+ | |||
+ | **FRAM:** RAM may be tight, but you do have FRAM to use. FRAM is like Flash memory (it’s nonvolatile) but faster and less complicated to use. On the MSP430s, your code is stored in FRAM, and the remaining FRAM is available for data that you want to keep around even if your device reboots. | ||
tutorials/microcontroller_programming_tips.1730233845.txt.gz · Last modified: 2024/10/29 20:30 by ibchadmin