Skip to content

Instantly share code, notes, and snippets.

@RickKimball
Created March 19, 2012 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickKimball/2114737 to your computer and use it in GitHub Desktop.
Save RickKimball/2114737 to your computer and use it in GitHub Desktop.
msp430 with minimized low level init code
/*
* main.cpp
*
* Created on: Mar 15, 2012
* Author: kimballr
*/
#include <msp430.h>
#define GREEN_LED_PIN BIT6
#define RED_LED_PIN BIT0
#define OUTPUT_SMCLK_PIN BIT4
static void init() {
P1OUT = RED_LED_PIN; // start with the red led lit
P1DIR = GREEN_LED_PIN | RED_LED_PIN | OUTPUT_SMCLK_PIN;
P1SEL |= OUTPUT_SMCLK_PIN;
}
static void loop() {
do {
P1OUT ^= GREEN_LED_PIN | RED_LED_PIN;
__delay_cycles(128000);
} while(1);
}
int main(void) {
init();
do {
loop();
} while(1);
}
#ifdef __cplusplus
extern "C" {
#endif
/**
* override the lowlevel initialization
*/
__attribute__((naked,section(".init2"))) void __init_stack(void) {
asm("mov #__stack, r1\n");
}
/**
* __low_level_init() - simple replacement routine just do a WDT stop
*
*/
__attribute__((naked,section(".init3"))) void __low_level_init(void) {
WDTCTL = WDTHOLD + WDTPW;
}
/**
* __do_copy_data() - empty replacement when no data
*/
__attribute__((naked,section(".init3"))) void __do_copy_data(void) {
; // nothing
}
/**
* __do_copy_bss() - empty replacement when no bss
*/
__attribute__((naked,section(".init3"))) void __do_clear_bss(void) {
; // nothing
}
#ifdef __cplusplus
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment