Prusa MINI Firmware overview
st25dv64k.c File Reference
#include "st25dv64k.h"
#include <string.h>
#include "cmsis_os.h"
#include "stm32f4xx_hal.h"

Macros

#define ST25DV64K_RTOS
 
#define REG_GPO   0x0000
 
#define REG_IT_TIME   0x0001
 
#define REG_EH_MODE   0x0002
 
#define REG_RF_MNGT   0x0003
 
#define REG_RFA1SS   0x0004
 
#define REG_ENDA1   0x0005
 
#define REG_RFA2SS   0x0006
 
#define REG_ENDA2   0x0007
 
#define REG_RFA3SS   0x0008
 
#define REG_ENDA3   0x0009
 
#define REG_RFA4SS   0x000A
 
#define REG_I2CSS   0x000B
 
#define REG_LOCK_CCFILE   0x000C
 
#define REG_MB_MODE   0x000D
 
#define REG_MB_WDG   0x000E
 
#define REG_LOCK_CFG   0x000F
 
#define ADDR_WRITE   0xA6
 
#define ADDR_READ   0xA7
 
#define ADDR_WRITE_SYS   0xAE
 
#define ADDR_READ_SYS   0xAF
 
#define BLOCK_DELAY   5
 
#define BLOCK_BYTES   4
 
#define DELAY   HAL_Delay
 
#define st25dv64k_delay   osDelay
 

Functions

static void st25dv64k_lock (void)
 
static void st25dv64k_unlock (void)
 
void st25dv64k_init (void)
 
uint8_t st25dv64k_user_read (uint16_t address)
 
void st25dv64k_user_write (uint16_t address, uint8_t data)
 
void st25dv64k_user_read_bytes (uint16_t address, void *pdata, uint8_t size)
 
void st25dv64k_user_write_bytes (uint16_t address, void *pdata, uint8_t size)
 
uint8_t st25dv64k_rd_cfg (uint16_t address)
 
void st25dv64k_wr_cfg (uint16_t address, uint8_t data)
 
void st25dv64k_present_pwd (uint8_t *pwd)
 

Variables

I2C_HandleTypeDef hi2c1
 
uint8_t st25dv64k_initialised = 0
 
osSemaphoreId st25dv64k_sema = 0
 

Macro Definition Documentation

◆ ST25DV64K_RTOS

#define ST25DV64K_RTOS

◆ REG_GPO

#define REG_GPO   0x0000

◆ REG_IT_TIME

#define REG_IT_TIME   0x0001

◆ REG_EH_MODE

#define REG_EH_MODE   0x0002

◆ REG_RF_MNGT

#define REG_RF_MNGT   0x0003

◆ REG_RFA1SS

#define REG_RFA1SS   0x0004

◆ REG_ENDA1

#define REG_ENDA1   0x0005

◆ REG_RFA2SS

#define REG_RFA2SS   0x0006

◆ REG_ENDA2

#define REG_ENDA2   0x0007

◆ REG_RFA3SS

#define REG_RFA3SS   0x0008

◆ REG_ENDA3

#define REG_ENDA3   0x0009

◆ REG_RFA4SS

#define REG_RFA4SS   0x000A

◆ REG_I2CSS

#define REG_I2CSS   0x000B

◆ REG_LOCK_CCFILE

#define REG_LOCK_CCFILE   0x000C

◆ REG_MB_MODE

#define REG_MB_MODE   0x000D

◆ REG_MB_WDG

#define REG_MB_WDG   0x000E

◆ REG_LOCK_CFG

#define REG_LOCK_CFG   0x000F

◆ ADDR_WRITE

#define ADDR_WRITE   0xA6

◆ ADDR_READ

#define ADDR_READ   0xA7

◆ ADDR_WRITE_SYS

#define ADDR_WRITE_SYS   0xAE

◆ ADDR_READ_SYS

#define ADDR_READ_SYS   0xAF

◆ BLOCK_DELAY

#define BLOCK_DELAY   5

◆ BLOCK_BYTES

#define BLOCK_BYTES   4

◆ DELAY

#define DELAY   HAL_Delay

◆ st25dv64k_delay

#define st25dv64k_delay   osDelay

Function Documentation

◆ st25dv64k_lock()

static void st25dv64k_lock ( void  )
static
49  {
50  if (st25dv64k_sema == 0) {
51  osSemaphoreDef(st25dv64kSema);
52  st25dv64k_sema = osSemaphoreCreate(osSemaphore(st25dv64kSema), 1);
53  }
55 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st25dv64k_unlock()

static void st25dv64k_unlock ( void  )
static
57  {
59 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st25dv64k_init()

void st25dv64k_init ( void  )
73  {
74  uint8_t pwd[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
75  if (!st25dv64k_initialised) {
76  if ((st25dv64k_rd_cfg(REG_ENDA1) != 0x7f)
77  && (st25dv64k_rd_cfg(REG_ENDA2) != 0xff)
78  && (st25dv64k_rd_cfg(REG_ENDA3) != 0xff)) {
84 
88  }
90  }
91 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st25dv64k_user_read()

uint8_t st25dv64k_user_read ( uint16_t  address)
93  {
94  uint8_t _out[2] = { address >> 8, address & 0xff };
95  uint8_t data;
100  return data;
101 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st25dv64k_user_write()

void st25dv64k_user_write ( uint16_t  address,
uint8_t  data 
)
103  {
104  uint8_t _out[3] = { address >> 8, address & 0xff, data };
105  st25dv64k_lock();
108  st25dv64k_unlock(); // unlock must be here because other threads cannot access eeprom while writing/waiting
109 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st25dv64k_user_read_bytes()

void st25dv64k_user_read_bytes ( uint16_t  address,
void pdata,
uint8_t  size 
)
111  {
112  uint8_t _out[2] = { address >> 8, address & 0xff };
113  st25dv64k_lock();
117 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st25dv64k_user_write_bytes()

void st25dv64k_user_write_bytes ( uint16_t  address,
void pdata,
uint8_t  size 
)
119  {
120  uint8_t *p = (uint8_t *)pdata;
121  uint8_t _out[6];
122  uint8_t block_size;
123  st25dv64k_lock();
124  while (size) {
125  block_size = BLOCK_BYTES - (address % BLOCK_BYTES);
126  if (block_size > size)
127  block_size = size;
128  _out[0] = address >> 8;
129  _out[1] = address & 0xff;
130  memcpy(_out + 2, p, block_size);
131  HAL_I2C_Master_Transmit(&hi2c1, ADDR_WRITE, _out, 2 + block_size, HAL_MAX_DELAY);
133  size -= block_size;
134  address += block_size;
135  p += block_size;
136  }
137  st25dv64k_unlock(); // unlock must be here because other threads cannot access eeprom while writing/waiting
138 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st25dv64k_rd_cfg()

uint8_t st25dv64k_rd_cfg ( uint16_t  address)
140  {
141  uint8_t _out[2] = { address >> 8, address & 0xff };
142  uint8_t data;
143  st25dv64k_lock();
147  return data;
148 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st25dv64k_wr_cfg()

void st25dv64k_wr_cfg ( uint16_t  address,
uint8_t  data 
)
150  {
151  uint8_t _out[3] = { address >> 8, address & 0xff, data };
152  st25dv64k_lock();
155  st25dv64k_unlock(); // unlock must be here because other threads cannot access eeprom while writing/waiting
156 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st25dv64k_present_pwd()

void st25dv64k_present_pwd ( uint8_t pwd)
158  {
159  uint8_t _out[19] = { 0x09, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0x09, 0, 0, 0, 0, 0, 0, 0, 0 };
160  if (pwd) {
161  memcpy(_out + 2, pwd, 8);
162  memcpy(_out + 11, pwd, 8);
163  }
164  st25dv64k_lock();
167 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ hi2c1

◆ st25dv64k_initialised

uint8_t st25dv64k_initialised = 0

◆ st25dv64k_sema

osSemaphoreId st25dv64k_sema = 0
osSemaphore
#define osSemaphore(name)
Definition: cmsis_os.h:709
osSemaphoreWait
int32_t osSemaphoreWait(osSemaphoreId semaphore_id, uint32_t millisec)
Wait until a Semaphore token becomes available.
Definition: cmsis_os.c:822
ADDR_READ
#define ADDR_READ
Definition: st25dv64k.c:31
BLOCK_DELAY
#define BLOCK_DELAY
Definition: st25dv64k.c:35
st25dv64k_rd_cfg
uint8_t st25dv64k_rd_cfg(uint16_t address)
Definition: st25dv64k.c:140
DELAY
#define DELAY
Definition: st25dv64k.c:38
data
uint8_t data[8]
Definition: masstorage.h:49
st25dv64k_wr_cfg
void st25dv64k_wr_cfg(uint16_t address, uint8_t data)
Definition: st25dv64k.c:150
osSemaphoreCreate
osSemaphoreId osSemaphoreCreate(const osSemaphoreDef_t *semaphore_def, int32_t count)
Create and Initialize a Semaphore object used for managing resources.
Definition: cmsis_os.c:755
REG_ENDA3
#define REG_ENDA3
Definition: st25dv64k.c:21
osSemaphoreDef
#define osSemaphoreDef(name)
Definition: cmsis_os.h:700
st25dv64k_present_pwd
void st25dv64k_present_pwd(uint8_t *pwd)
Definition: st25dv64k.c:158
auto_build.pwd
pwd
Definition: auto_build.py:78
st25dv64k_unlock
static void st25dv64k_unlock(void)
Definition: st25dv64k.c:57
REG_ENDA1
#define REG_ENDA1
Definition: st25dv64k.c:17
st25dv64k_sema
osSemaphoreId st25dv64k_sema
Definition: st25dv64k.c:47
st25dv64k_lock
static void st25dv64k_lock(void)
Definition: st25dv64k.c:49
osWaitForever
#define osWaitForever
wait forever timeout value
Definition: cmsis_os.h:230
ADDR_READ_SYS
#define ADDR_READ_SYS
Definition: st25dv64k.c:33
uint8_t
const uint8_t[]
Definition: 404_html.c:3
address
UsbDeviceAddress address
Definition: address.h:202
HAL_I2C_Master_Transmit
HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
st25dv64k_initialised
uint8_t st25dv64k_initialised
Definition: st25dv64k.c:42
hi2c1
I2C_HandleTypeDef hi2c1
Definition: main.c:77
BLOCK_BYTES
#define BLOCK_BYTES
Definition: st25dv64k.c:36
ADDR_WRITE_SYS
#define ADDR_WRITE_SYS
Definition: st25dv64k.c:32
HAL_I2C_Master_Receive
HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
REG_ENDA2
#define REG_ENDA2
Definition: st25dv64k.c:19
HAL_MAX_DELAY
#define HAL_MAX_DELAY
Definition: stm32f4xx_hal_def.h:76
osSemaphoreRelease
osStatus osSemaphoreRelease(osSemaphoreId semaphore_id)
Release a Semaphore token.
Definition: cmsis_os.c:862
ADDR_WRITE
#define ADDR_WRITE
Definition: st25dv64k.c:30
size
static png_bytep size_t size
Definition: pngwrite.c:2170