Skip to content

Dproano/logging - #2

Open
jibbychohan wants to merge 16 commits into
mainfrom
dproano/logging
Open

jibbychohan wants to merge 16 commits into
mainfrom
dproano/logging

Conversation

@jibbychohan

Copy link
Copy Markdown

No description provided.

Comment thread firmware/lib/logging/logging.cpp Outdated
Comment thread firmware/src/ec_main.cpp
PT_TC_SPI_1.begin();
PT_TC_SPI_3.begin();

Flash::begin();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this down into the all_modules_ok section and check the return value - right now code silently continues if return is false!

@jacobh460
jacobh460 self-requested a review September 25, 2026 01:09
Comment thread firmware/lib/logging/flash.cpp Outdated
hqspi.Instance = QUADSPI;
hqspi.Init.ClockPrescaler = f_hclk / FREQ_MAX;
if (hqspi.Init.ClockPrescaler > 255)
hqspi.Init.ClockPrescaler = 255;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic has a bug!
If the division on line 330 has a remainder then the resulting clock frequency will exceed FREQ_MAX. You should increment the prescaler by one if the remainder is nonzero.


flash_error_t write_to_cache(uint32_t col_addr, uint8_t *data, size_t len);

flash_error_t program(uint32_t addr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming this parameter "addr" is misleading because I'm pretty sure it's really a row address. Need to confirm during testing because the datasheet isn't very specific.

Comment thread firmware/lib/logging/flash.cpp Outdated
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();

GPIO_InitTypeDef gpio_init{};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this gpio init can definitely be done dynamically rather than being hardcoded. I believe Arduino already has pin map. Check out void pinmap_pinout(PinName pin, const PinMap *map).

Comment thread firmware/lib/logging/flash.cpp Outdated
}

void init_qspi_gpio() {
__HAL_RCC_QSPI_CLK_ENABLE();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAL reference says (after enabling qspi clock in RCC):
Reset QuadSPI Peripheral with __HAL_RCC_QSPI_FORCE_RESET() and
__HAL_RCC_QSPI_RELEASE_RESET().

Comment thread firmware/lib/logging/flash.cpp Outdated
bool init_qspi_peripheral() {
init_qspi_gpio();

uint32_t f_hclk = HAL_RCC_GetHCLKFreq();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-check that the quadspi kernel clock is being sourced from HCLK. There are four different clocks that can be muxed to quadspi.

In the HAL reference for RCC:

"
Once the device started from reset, the user application has to:
...
Configure the clock kernel source(s) for peripherals which clocks are not derived from the System clock
through :RCC_D1CCIPR,RCC_D2CCIP1R,RCC_D2CCIP2R and RCC_D3CCIPR registers
" (p. 1296)
see HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig (RCC_PeriphCLKInitTypeDef * PeriphClkInit)

Comment thread firmware/lib/logging/flash.cpp Outdated
hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_NONE;
hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_8_CYCLE;
hqspi.Init.FlashSize = 23;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be set to 26 because our flash is 1Gb (2^27 bytes) and from the reference manual this should be set to FlashSize = (1 - log2(1GB)) = 26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants