Skip to content

Update SPI Device HAL to use new autogen interface#387

Open
ziuziakowska wants to merge 1 commit into
lowRISC:mainfrom
ziuziakowska:hal-autogen-rework-spi-device
Open

Update SPI Device HAL to use new autogen interface#387
ziuziakowska wants to merge 1 commit into
lowRISC:mainfrom
ziuziakowska:hal-autogen-rework-spi-device

Conversation

@ziuziakowska

@ziuziakowska ziuziakowska commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Split off from #299.

Depends on #579. Merged.

@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-spi-device branch from 1755b42 to 2cfbaa7 Compare April 9, 2026 15:34
@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-spi-device branch 2 times, most recently from f45de2f to 8b85c97 Compare April 30, 2026 15:17
@ziuziakowska ziuziakowska changed the title [WIP] Update SPI Device HAL to use new autogen interface Update SPI Device HAL to use new autogen interface Apr 30, 2026
@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-spi-device branch from 8b85c97 to 98fbdda Compare April 30, 2026 15:20
@ziuziakowska ziuziakowska marked this pull request as ready for review May 13, 2026 16:43
@ziuziakowska ziuziakowska requested a review from engdoreis May 13, 2026 16:44

@engdoreis engdoreis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the changes, I had a quick look and letf some comments.
I'm happy to give a more detailed review when it pass CI.

return true;
default:
uprintf(ctx->console, "\nUnsupported command: 0x%0x", cmd.opcode);
uprintf(ctx->console, "Unsupported command: 0x%x\n", cmd.opcode);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why remove the line break?

#include <stdint.h>

bool spi_device_interrupt_is_pending(spi_device_t spi_device, uint8_t intr_id)
enum : size_t {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These structs should not be inside the spi hal, you should create a flash header somewhere, then the app should call the hal to configure the spi.

@ziuziakowska ziuziakowska May 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just tried to translate the file into the new autogen interface and make some changes, but I do think this should stay here - the SPI Device is largely special purpose for emulating a SPI Flash device.

then the app should call the hal to configure the spi.

Programs still use the same HAL to configure the SPI Device, these enums are private to the C file as the SFDP table can be considered implementation details.

@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-spi-device branch 3 times, most recently from d54f157 to aa95279 Compare May 21, 2026 13:26
@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-spi-device branch 2 times, most recently from 372ea62 to 320c623 Compare June 24, 2026 16:44
@ziuziakowska ziuziakowska requested a review from engdoreis June 24, 2026 16:45
@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-spi-device branch from 320c623 to e90d51e Compare June 24, 2026 16:51
Comment thread sw/device/bootrom/bootrom.c Outdated
@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-spi-device branch 2 times, most recently from d9d839f to 68b17b9 Compare June 24, 2026 16:59
Signed-off-by: Alice Ziuziakowska <a.ziuziakowska@lowrisc.org>
@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-spi-device branch from 68b17b9 to 81451b2 Compare June 24, 2026 17:08
bool spi_device_flash_payload_buffer_read_byte(spi_device_t spi_device, size_t byte_index,
uint8_t *byte)
{
size_t word_index = byte_index >> 4u;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think you want:

size_t word_index = byte_index / 4u;

or:

size_t word_index = byte_index >> 2u;

{
// Wait for software-handled command
while (!spi_device_interrupt_is_pending(spi_device, SPI_DEVICE_INTR_UPLOAD_CMDFIFO_NOT_EMPTY)) {
size_t word_index = byte_index >> 4u;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
size_t word_index = byte_index >> 4u;
size_t word_index = byte_index >> 2u;

if (cmd.status != 0) {
spi_device_software_command command;
while (true) {
bool success = spi_device_software_command_get(spi_device, &command);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This function returns a enum, right?

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.

2 participants