Prusa MINI Firmware overview
|
#include "sys.h"
#include "shared_config.h"
#include "stm32f4xx_hal.h"
#include "st25dv64k.h"
#include "new_eeprom.h"
#include "dbg.h"
◆ __attribute__()
◆ sys_reset()
21 uint32_t aircr = SCB->AIRCR & 0x0000ffff;
22 if (__get_PRIMASK() & 1)
◆ sys_dfu_boot()
◆ sys_calc_flash_latency()
int sys_calc_flash_latency |
( |
int |
freq | ) |
|
◆ sys_pll_is_enabled()
int sys_pll_is_enabled |
( |
void |
| ) |
|
◆ sys_pll_disable()
58 int irq = __get_PRIMASK() & 1;
◆ sys_pll_enable()
79 int irq = __get_PRIMASK() & 1;
◆ sys_sscg_is_enabled()
int sys_sscg_is_enabled |
( |
void |
| ) |
|
122 return (RCC->SSCGR & RCC_SSCGR_SSCGEN_Msk) ? 1 : 0;
◆ sys_sscg_disable()
126 uint32_t sscgr = RCC->SSCGR;
128 if ((sscgr & RCC_SSCGR_SSCGEN_Msk) == 0)
130 sscgr &= ~((1 << RCC_SSCGR_SSCGEN_Pos) & RCC_SSCGR_SSCGEN_Msk);
134 _dbg0(
"written SSCGR = 0x%08lx (%lu)", sscgr, sscgr);
136 _dbg0(
"readback SSCGR = 0x%08lx (%lu)", sscgr, sscgr);
◆ sys_sscg_enable()
141 uint32_t sscgr = RCC->SSCGR;
142 uint32_t modper = ((sscgr & RCC_SSCGR_MODPER_Msk) >> RCC_SSCGR_MODPER_Pos);
143 uint32_t incstep = ((sscgr & RCC_SSCGR_INCSTEP_Msk) >> RCC_SSCGR_INCSTEP_Pos);
148 sscgr |= (1 << RCC_SSCGR_SSCGEN_Pos) & RCC_SSCGR_SSCGEN_Msk;
153 _dbg0(
"written SSCGR = 0x%08lx (%lu)", sscgr, sscgr);
155 _dbg0(
"readback SSCGR = 0x%08lx (%lu)", sscgr, sscgr);
◆ sys_sscg_set_config()
void sys_sscg_set_config |
( |
int |
freq, |
|
|
int |
depth |
|
) |
| |
163 uint32_t sscgr = RCC->SSCGR;
164 uint32_t modper = ((sscgr & RCC_SSCGR_MODPER_Msk) >> RCC_SSCGR_MODPER_Pos);
165 uint32_t incstep = ((sscgr & RCC_SSCGR_INCSTEP_Msk) >> RCC_SSCGR_INCSTEP_Pos);
166 uint32_t spreadsel = ((sscgr & RCC_SSCGR_SPREADSEL_Msk) >> RCC_SSCGR_SPREADSEL_Pos);
167 uint32_t sscgen = ((sscgr & RCC_SSCGR_SSCGEN_Msk) >> RCC_SSCGR_SSCGEN_Pos);
168 _dbg0(
"SSCGR = 0x%08lx (%lu)", sscgr, sscgr);
169 _dbg0(
" MODPER = 0x%08lx (%lu)", modper, modper);
170 _dbg0(
" INCSTEP = 0x%08lx (%lu)", incstep, incstep);
171 _dbg0(
" SPREADSEL = 0x%08lx (%lu)", spreadsel, spreadsel);
172 _dbg0(
" SSCGEN = 0x%08lx (%lu)", sscgen, sscgen);
174 plln = RCC_OscInitStruct.
PLL.
PLLN;
177 modper = (uint32_t)(((
float)fpll / (4 * freq)) + 0.5F);
180 incstep = (uint32_t)((((
float)214 * depth * plln) / (100 * 5 * modper)) + 0.5F);
184 sscgr |= (modper << RCC_SSCGR_MODPER_Pos) & RCC_SSCGR_MODPER_Msk;
185 sscgr |= (incstep << RCC_SSCGR_INCSTEP_Pos) & RCC_SSCGR_INCSTEP_Msk;
186 sscgr |= (spreadsel << RCC_SSCGR_SPREADSEL_Pos) & RCC_SSCGR_SPREADSEL_Msk;
187 sscgr |= (sscgen << RCC_SSCGR_SSCGEN_Pos) & RCC_SSCGR_SSCGEN_Msk;
191 _dbg0(
"written SSCGR = 0x%08lx (%lu)", sscgr, sscgr);
193 modper = ((sscgr & RCC_SSCGR_MODPER_Msk) >> RCC_SSCGR_MODPER_Pos);
194 incstep = ((sscgr & RCC_SSCGR_INCSTEP_Msk) >> RCC_SSCGR_INCSTEP_Pos);
195 spreadsel = ((sscgr & RCC_SSCGR_SPREADSEL_Msk) >> RCC_SSCGR_SPREADSEL_Pos);
196 sscgen = ((sscgr & RCC_SSCGR_SSCGEN_Msk) >> RCC_SSCGR_SSCGEN_Pos);
197 _dbg0(
"readback SSCGR = 0x%08lx (%lu)", sscgr, sscgr);
198 _dbg0(
" MODPER = 0x%08lx (%lu)", modper, modper);
199 _dbg0(
" INCSTEP = 0x%08lx (%lu)", incstep, incstep);
200 _dbg0(
" SPREADSEL = 0x%08lx (%lu)", spreadsel, spreadsel);
201 _dbg0(
" SSCGEN = 0x%08lx (%lu)", sscgen, sscgen);
◆ sys_sscg_get_config()
int sys_sscg_get_config |
( |
float * |
pfreq, |
|
|
float * |
pdepth |
|
) |
| |
◆ _spi_prescaler()
uint32_t _spi_prescaler |
( |
int |
prescaler_num | ) |
|
209 switch (prescaler_num) {
◆ sys_spi_set_prescaler()
void sys_spi_set_prescaler |
( |
int |
prescaler_num | ) |
|
231 int irq = __get_PRIMASK() & 1;
◆ sys_fw_update_is_enabled()
int sys_fw_update_is_enabled |
( |
void |
| ) |
|
◆ sys_fw_update_enable()
◆ sys_fw_update_disable()
◆ sys_fw_update_on_restart_is_enabled()
int sys_fw_update_on_restart_is_enabled |
( |
void |
| ) |
|
◆ sys_fw_update_on_restart_enable()
void sys_fw_update_on_restart_enable |
( |
void |
| ) |
|
◆ sys_fw_update_on_restart_disable()
void sys_fw_update_on_restart_disable |
( |
void |
| ) |
|
◆ sys_fw_is_valid()
int sys_fw_is_valid |
( |
void |
| ) |
|
◆ sys_fw_invalidate()
int sys_fw_invalidate |
( |
void |
| ) |
|
◆ sys_fw_validate()
int sys_fw_validate |
( |
void |
| ) |
|
◆ sys_flash_is_empty()
int sys_flash_is_empty |
( |
void * |
ptr, |
|
|
int |
size |
|
) |
| |
◆ sys_flash_write()
int sys_flash_write |
( |
void * |
dst, |
|
|
void * |
src, |
|
|
int |
size |
|
) |
| |
◆ sys_flash_erase_sector()
int sys_flash_erase_sector |
( |
unsigned int |
sector | ) |
|
325 if ((sector < FLASH_SECTOR_0) || (sector > FLASH_SECTOR_11))
◆ hspi2
◆ sys_pll_freq
int sys_pll_freq = 168000000 |
◆ boot_version
◆ psys_fw_valid
#define SPI_BAUDRATEPRESCALER_2
Definition: stm32f4xx_hal_spi.h:236
Definition: stm32f4xx_hal_def.h:57
RCC System, AHB and APB busses clock configuration structure definition.
Definition: stm32f4xx_hal_rcc.h:93
#define SPI_BAUDRATEPRESCALER_16
Definition: stm32f4xx_hal_spi.h:239
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
uint32_t SYSCLKSource
Definition: stm32f4xx_hal_rcc.h:98
#define SPI_BAUDRATEPRESCALER_256
Definition: stm32f4xx_hal_spi.h:243
#define HSE_VALUE
Adjust the value of External High Speed oscillator (HSE) used in your application....
Definition: stm32f4xx_hal_conf.h:108
#define FLASH_FLAG_EOP
Definition: stm32f4xx_hal_flash.h:132
#define VOLTAGE_RANGE_3
Definition: stm32_hal_legacy.h:317
HAL_StatusTypeDef HAL_FLASH_Unlock(void)
#define _dbg0
Definition: dbg.h:31
#define pd
Definition: screen_filebrowser.cpp:39
volatile data_exchange_t ram_data_exchange
SPI_HandleTypeDef hspi2
Definition: main.c:81
uint8_t i
Definition: screen_test_graph.c:72
#define SPI_BAUDRATEPRESCALER_32
Definition: stm32f4xx_hal_spi.h:240
void st25dv64k_user_write(uint16_t address, uint8_t data)
Definition: st25dv64k.c:103
volatile uint8_t * psys_fw_valid
Definition: sys.cpp:18
#define FLASH_TYPEPROGRAM_BYTE
Definition: stm32f4xx_hal_flash.h:120
#define RCC_SYSCLKSOURCE_HSE
Definition: stm32f4xx_hal_rcc.h:220
#define FLASH_FLAG_PGSERR
Definition: stm32f4xx_hal_flash.h:137
HAL_StatusTypeDef
HAL Status structures definition.
Definition: stm32f4xx_hal_def.h:55
#define RCC_PLL_ON
Definition: stm32f4xx_hal_rcc.h:178
int sys_flash_write(void *dst, void *src, int size)
Definition: sys.cpp:293
void sys_pll_enable(void)
Definition: sys.cpp:78
#define FLASH_FLAG_BSY
Definition: stm32f4xx_hal_flash.h:141
HAL_StatusTypeDef HAL_FLASH_Lock(void)
#define SPI_BAUDRATEPRESCALER_4
Definition: stm32f4xx_hal_spi.h:237
#define SPI_BAUDRATEPRESCALER_64
Definition: stm32f4xx_hal_spi.h:241
RCC_PLLInitTypeDef PLL
Definition: stm32f4xx_hal_rcc.h:87
#define SPI_BAUDRATEPRESCALER_128
Definition: stm32f4xx_hal_spi.h:242
#define FLASH_FLAG_PGAERR
Definition: stm32f4xx_hal_flash.h:135
#define RCC_PLL_OFF
Definition: stm32f4xx_hal_rcc.h:177
HAL_StatusTypeDef HAL_SPI_DeInit(SPI_HandleTypeDef *hspi)
uint32_t PLLState
Definition: stm32f4xx_hal_rcc_ex.h:65
void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange)
#define FW_UPDATE_ENABLE
Definition: shared_config.h:11
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi)
#define __HAL_FLASH_CLEAR_FLAG(__FLAG__)
Clear the specified FLASH flags.
Definition: stm32f4xx_hal_flash.h:307
#define FLASH_FLAG_PGPERR
Definition: stm32f4xx_hal_flash.h:136
int sys_flash_is_empty(void *ptr, int size)
Definition: sys.cpp:285
void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
const uint8_t[]
Definition: 404_html.c:3
uint32_t _spi_prescaler(int prescaler_num)
Definition: sys.cpp:208
#define FLASH_FLAG_OPERR
Definition: stm32f4xx_hal_flash.h:133
SPI_InitTypeDef Init
Definition: stm32f4xx_hal_spi.h:124
void sys_pll_disable(void)
Definition: sys.cpp:57
int sys_calc_flash_latency(int freq)
Definition: sys.cpp:34
int sys_flash_erase_sector(unsigned int sector)
Definition: sys.cpp:323
static status_t status
Definition: filament_sensor.c:37
uint8_t fw_update_flag
Definition: shared_config.h:20
#define RCC_SYSCLKSOURCE_PLLCLK
Definition: stm32f4xx_hal_rcc.h:221
uint32_t BaudRatePrescaler
Definition: stm32f4xx_hal_spi.h:84
HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
#define FW_UPDATE_FLAG_ADDRESS
Definition: new_eeprom.h:20
RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition.
Definition: stm32f4xx_hal_rcc.h:67
#define SPI_BAUDRATEPRESCALER_8
Definition: stm32f4xx_hal_spi.h:238
uint8_t st25dv64k_user_read(uint16_t address)
Definition: st25dv64k.c:93
uint32_t PLLN
Definition: stm32f4xx_hal_rcc_ex.h:74
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
#define FLASH_FLAG_WRPERR
Definition: stm32f4xx_hal_flash.h:134
int sys_pll_freq
Definition: sys.cpp:12
#define FW_UPDATE_DISABLE
Definition: shared_config.h:12
static png_bytep size_t size
Definition: pngwrite.c:2170