Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions ulisp-stm32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const char LispLibrary[] PROGMEM = "";
// #define printgcs
// #define sdcardsupport
// #define lisplibrary

#define officialstm32
// Includes

// #include "LispLibrary.h"
Expand All @@ -25,6 +25,11 @@ const char LispLibrary[] PROGMEM = "";
#include <limits.h>
#include <EEPROM.h>

#if defined(officialstm32)
#define WiringPinMode uint32_t
#define FLASH_BASE_ADDRESS 0x801D800
#endif

#if defined(sdcardsupport)
#include <SD.h>
#define SDSIZE 172
Expand Down Expand Up @@ -380,22 +385,42 @@ void SDWriteInt (File file, int data) {
}
#else
void FlashSetup () {
#if defined(officialstm32)
for (uint16_t i=0; i<E2END; i++){
eeprom_buffered_write_byte(i, 0);
}
eeprom_buffer_flush();
//no way to check if erase failed through buffered API
#else
FLASH_Unlock();
uint16_t Status;
for (int page = Eeprom; page < 0x8020000; page = page + 0x400) {
Status = FLASH_ErasePage(page);
if (Status != FLASH_COMPLETE) error2(SAVEIMAGE, PSTR("flash erase failed"));
}
#endif
}

#if defined(officialstm32)
void FlashWriteByte (unsigned int *addr, uint8_t data) {
eeprom_buffered_write_byte((uint32_t) *addr, data);
(*addr)++;
}
#else
void FlashWrite16 (unsigned int *addr, uint16_t data) {
uint16_t Status = FLASH_ProgramHalfWord((*addr) + Eeprom, data);
if (Status != FLASH_COMPLETE) error2(SAVEIMAGE, PSTR("flash write failed"));
(*addr) = (*addr) + 2;
}
#endif

void FlashWriteInt (unsigned int *addr, int data) {
#if defined(officialstm32)
FlashWriteByte(addr, data & 0xFF); FlashWriteByte(addr, data>>8 & 0xFF);
FlashWriteByte(addr, data>>16 & 0xFF); FlashWriteByte(addr, data>>24 & 0xFF);
#else
FlashWrite16(addr, data & 0xFFFF); FlashWrite16(addr, data>>16 & 0xFFFF);
#endif
}
#endif

Expand Down Expand Up @@ -442,13 +467,20 @@ int saveimage (object *arg) {
FlashWriteInt(&addr, (uintptr_t)GCStack);
#if SYMBOLTABLESIZE > BUFFERSIZE
FlashWriteInt(&addr, (uintptr_t)SymbolTop);
#if defined(officialstm32)
for (int i=0; i<SYMBOLTABLESIZE; i++) FlashWriteByte(&addr, SymbolTable[i]);
#else
for (int i=0; i<SYMBOLTABLESIZE; i=i+2) FlashWrite16(&addr, SymbolTable[i] | SymbolTable[i+1]<<8);
#endif
#endif
for (unsigned int i=0; i<imagesize; i++) {
object *obj = &Workspace[i];
FlashWriteInt(&addr, (uintptr_t)car(obj));
FlashWriteInt(&addr, (uintptr_t)cdr(obj));
}
#if defined(officialstm32)
eeprom_buffer_flush();
#endif
return imagesize;
}
#endif
Expand All @@ -460,16 +492,29 @@ int SDReadInt (File file) {
return b0 | b1<<8 | b2<<16 | b3<<24;
}
#else
#if defined(officialstm32)
uint8_t FlashReadByte (unsigned int *addr) {
uint8_t data = eeprom_buffered_read_byte((uint32_t) *addr);
(*addr)++;
return data;
}
#else
uint16_t FlashRead16 (unsigned int *addr) {
uint16_t data = (*(__IO uint16*)((*addr) + Eeprom));
(*addr) = (*addr) + 2;
return data;
}

#endif
int FlashReadInt (unsigned int *addr) {
#if defined(officialstm32)
uint8_t b0 = FlashReadByte(addr); uint8_t b1 = FlashReadByte(addr);
uint8_t b2 = FlashReadByte(addr); uint8_t b3 = FlashReadByte(addr);
return b0 | b1<<8 | b2<<16 | b3<<24;
#else
uint16_t b0 = FlashRead16(addr);
uint16_t b1 = FlashRead16(addr);
return b0 | b1<<16;
#endif
}
#endif

Expand Down Expand Up @@ -498,6 +543,13 @@ int loadimage (object *arg) {
gc(NULL, NULL);
return imagesize;
#else
#if defined(officialstm32)
//clear and fill the buffer
for (uint16_t i=0; i<E2END; i++){
eeprom_buffered_write_byte(i, 0);
}
eeprom_buffer_fill();
#endif
unsigned int addr = 0;
FlashReadInt(&addr); // Skip eval address
int imagesize = FlashReadInt(&addr);
Expand All @@ -506,11 +558,15 @@ int loadimage (object *arg) {
GCStack = (object *)FlashReadInt(&addr);
#if SYMBOLTABLESIZE > BUFFERSIZE
SymbolTop = (char *)FlashReadInt(&addr);
#if defined(officialstm32)
for (int i=0; i<SYMBOLTABLESIZE; i++) SymbolTable[i] = FlashReadByte(&addr);
#else
for (int i=0; i<SYMBOLTABLESIZE; i=i+2) {
uint16_t bytes = FlashRead16(&addr);
SymbolTable[i] = bytes & 0xFF;
SymbolTable[i+1] = bytes>>8 & 0xFF;
}
#endif
#endif
for (int i=0; i<imagesize; i++) {
object *obj = &Workspace[i];
Expand Down