Skip to content

Instantly share code, notes, and snippets.

@spirilis
Created September 1, 2014 14:51
Show Gist options
  • Save spirilis/b16d311655794a4951a5 to your computer and use it in GitHub Desktop.
Save spirilis/b16d311655794a4951a5 to your computer and use it in GitHub Desktop.
MSP430F5xxx infomem flash example
#include <msp430.h>
#include <stdint.h>
#include "flash.h"
#define SEG_INFOB __attribute__((section(".infob")))
#define DMX_PASSWORD_VALID ((uint16_t) 0xFEF5)
uint16_t SEG_INFOB _dmx_password = 0x0505;
uint16_t SEG_INFOB _dmx_red = 0x00FF;
uint16_t SEG_INFOB _dmx_green = 0x0050;
uint16_t SEG_INFOB _dmx_blue = 0x0080;
volatile uint16_t flash_erase_err, flash_unlock_err;
int dmx512_flash_load(uint8_t startcode)
{
if (startcode != DMX512_STARTCODE)
return -1;
if (_dmx_password != DMX_PASSWORD_VALID)
return -1;
dmx512_buffer[0] = (uint8_t) _dmx_red;
dmx512_buffer[1] = (uint8_t) _dmx_green;
dmx512_buffer[2] = (uint8_t) _dmx_blue;
dmx512_update_commit(startcode); // this sets WS2811 LEDs to the values in dmx512_buffer[]
return 0;
}
volatile uint16_t flash_erase_err, flash_unlock_err;
void dmx512_flash_commit(uint8_t startcode)
{
if (startcode != DMX512_STARTCODE)
return;
if (!flash_erase_info((void *)&_dmx_password)) {
if (!flash_write_unlock()) {
flash_write_word((void *)&_dmx_password, DMX_PASSWORD_VALID);
flash_write_word((void *)&_dmx_red, (uint16_t)dmx512_buffer[0]);
flash_write_word((void *)&_dmx_green, (uint16_t)dmx512_buffer[1]);
flash_write_word((void *)&_dmx_blue, (uint16_t)dmx512_buffer[2]);
flash_write_lock();
return;
} else {
flash_unlock_err++;
}
} else {
flash_erase_err++;
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment