Skip to content

Commit

Permalink
Merge pull request #26 from Ralim/Fix-s60p-flash-size
Browse files Browse the repository at this point in the history
Fix S60P flash size
  • Loading branch information
discip authored Apr 10, 2024
2 parents 87a9996 + 7ab0a57 commit 6d88f82
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 37 deletions.
47 changes: 29 additions & 18 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@
#define ENABLE_DFU_UPLOAD
#define ENABLE_WATCHDOG 26

#if VECTOR_TABLE_OFFSET != 0
#define SHOW_HASH
#define HASH_REGION_START FLASH_BASE_ADDR
#define HASH_REGION_END (FLASH_BASE_ADDR + (1024 * FLASH_BOOTLDR_SIZE_KB))
#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR)
#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024))
#define RUNTIME_MODE
#else
#define BOOTLOADER_MODE
#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024))
#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_PAYLOAD_SIZE_KB * 1024))
// In DFU mode, we use button to enter

#define ENABLE_GPIO_DFU_BOOT

#endif

/* Commands sent with wBlockNum == 0 as per ST implementation. */
#define CMD_SETADDR 0x21
#define CMD_ERASE 0x41
Expand All @@ -36,7 +19,8 @@
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 16
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 112
#elif MODEL_S60 || MODEL_S60P

#elif MODEL_S60
#define GPIO_DFU_BOOT_PORT GPIOB
#define GPIO_DFU_BOOT_PIN 0
#define GPIO_DP_PULLUP_PORT GPIOA
Expand All @@ -45,6 +29,15 @@
#define FLASH_BOOTLDR_SIZE_KB 17
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 111

#elif MODEL_S60P
#define GPIO_DFU_BOOT_PORT GPIOB
#define GPIO_DFU_BOOT_PIN 0
#define GPIO_DP_PULLUP_PORT GPIOA
#define GPIO_DP_PULLUP_PIN 8
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 20
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 108

#elif MODEL_TS80 || MODEL_TS80P
#define GPIO_DFU_BOOT_PORT GPIOB
#define GPIO_DFU_BOOT_PIN 1
Expand Down Expand Up @@ -73,4 +66,22 @@
#define SDA_Pin 7
#define SDA_GPIO_Port GPIOB

// Setup defines for other code so we protect writing OOB

#if VECTOR_TABLE_OFFSET != 0
#define SHOW_HASH
#define HASH_REGION_START FLASH_BASE_ADDR
#define HASH_REGION_END (FLASH_BASE_ADDR + (1024 * FLASH_BOOTLDR_SIZE_KB))
#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR)
#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024))
#define RUNTIME_MODE
#else
#define BOOTLOADER_MODE
#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024))
#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_PAYLOAD_SIZE_KB * 1024))
// In DFU mode, we use button to enter

#define ENABLE_GPIO_DFU_BOOT

#endif
#endif
2 changes: 1 addition & 1 deletion src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ void display_show_version(void) {
void display_splash(void) {
// Print the splash screen directly to the OLED
oled_clearScreen();
oled_DrawArea(0, 0, 96, 16, logo_buffer);
oled_DrawArea(OLED_AREA_X, OLED_AREA_Y, 96, 16, logo_buffer);
oled_Refresh();
}
9 changes: 6 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
#include "watchdog.h"

// Payload/app comes inmediately after Bootloader
#define APP_ADDRESS (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB)*1024)
#define APP_ADDRESS (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB) * 1024)
#ifndef VECTOR_TABLE_OFFSET
#error MUST set VTOR
#endif

#ifdef ENABLE_PINRST_DFU_BOOT
static inline int reset_due_to_pin() { return (RCC_CSR & RCC_CSR_PINRSTF) && !(RCC_CSR & (RCC_CSR_LPWRRSTF | RCC_CSR_WWDGRSTF | RCC_CSR_IWDGRSTF | RCC_CSR_SFTRSTF | RCC_CSR_PORRSTF)); }
Expand All @@ -38,9 +41,9 @@ int main(void) {
* asked to reboot into DFU mode. This should make the CPU to
* boot into DFU if the user app has been erased. */

// Setup vector table to use out offset whatever it is
// Setup vector table to use our offset whatever it is
volatile uint32_t *_csb_vtor = (uint32_t *)0xE000ED08U;
*_csb_vtor = 0;
*_csb_vtor = VECTOR_TABLE_OFFSET;

#ifdef ENABLE_WATCHDOG
// Enable the watchdog
Expand Down
15 changes: 7 additions & 8 deletions src/oled.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,11 @@ void oled_DrawArea(uint8_t x, uint8_t y, uint8_t wide, uint8_t height, const uin
// Y is the height value (affects the bits)
// Y is either 0 or 8, we dont do smaller bit blatting
uint8_t lines = height / 8;
// We draw the 1 or two stripes seperately
for (uint8_t i = 0; i < (wide * lines); i++) {
uint8_t xp = x + (i % wide);
uint8_t yoffset = i < wide ? 0 : OLED_WIDTH;
if (y == 8)
yoffset = OLED_WIDTH;
// We draw the 1 or two stripes separately
for (uint16_t i = 0; i < (wide * lines); i++) {
uint16_t xp = x + (i % wide);

uint16_t yoffset = ((i / wide) + (y / 8)) * OLED_WIDTH;

displayBuffer[xp + yoffset] = ptr[i];
}
Expand All @@ -166,7 +165,7 @@ void oled_DrawArea(uint8_t x, uint8_t y, uint8_t wide, uint8_t height, const uin
Function:Clear_Screen
Description:Clear the entire screen to off (black)
*******************************************************************************/
void oled_clearScreen(void) { memset(displayBuffer, 0, 96 * 2); }
void oled_clearScreen(void) { memset(displayBuffer, 0, OLED_WIDTH * (OLED_HEIGHT / 8)); }

/*
* Draws a string onto the screen starting at the left
Expand Down Expand Up @@ -202,5 +201,5 @@ void OLED_DrawChar(char c, uint8_t x, const uint8_t row) {
offset *= (FONT_WIDTH * (FONT_HEIGHT / 8));
ptr += offset;

oled_DrawArea(x, row * 8, FONT_WIDTH, FONT_HEIGHT, (uint8_t *)ptr);
oled_DrawArea(OLED_AREA_X + x, OLED_AREA_Y + (row * 8), FONT_WIDTH, FONT_HEIGHT, (uint8_t *)ptr);
}
19 changes: 12 additions & 7 deletions src/oled.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@
#define DEVICEADDR_OLED (0x3c << 1)

#if MODEL_S60 || MODEL_S60P
// TODO; for now just cropping in on the screen from 128x32 to 96x16
#define OLED_WIDTH 96
#define OLED_HEIGHT 16
#define OLED_GRAM_START 0x10 // Should be 0x00 when we have full width
#define OLED_GRAM_END 0x6F // Should be 0x7F when we have full width
#define OLED_AREA_X 16
#define OLED_AREA_Y 8
#define OLED_WIDTH 128
#define OLED_HEIGHT 32
#define OLED_GRAM_START 0x00
#define OLED_GRAM_END 0x7F
#define OLED_VCOM_LAYOUT 0x12
#define OLED_SEGMENT_MAP 0xA1
#else

#define OLED_AREA_X 0
#define OLED_AREA_Y 0
#define OLED_WIDTH 96
#define OLED_HEIGHT 16
#define OLED_VCOM_LAYOUT 0x02

#ifdef OLED_FLIP
#define OLED_GRAM_START 0 // Should be 0x00 when we have full width
#define OLED_GRAM_START 0 // Aligned to top left of buffer
#define OLED_GRAM_END 95
#define OLED_SEGMENT_MAP 0xA1
#else
#define OLED_GRAM_START 0x20 // Should be 0x00 when we have full width
#define OLED_GRAM_START 0x20 // Align to bottom right of buffer
#define OLED_GRAM_END 0x7F
#define OLED_SEGMENT_MAP 0xA0
#endif

#endif

#define FRAMEBUFFER_START 17

// Run OLED init
Expand Down

0 comments on commit 6d88f82

Please sign in to comment.