Skip to content

Conversation

@desertsagebrush
Copy link
Contributor

@desertsagebrush desertsagebrush commented Nov 11, 2025

Detailed description

Adding/expanding support for Renesas RA6M5, RA4M1, and RA2E1 microcontrollers.

Todo:

  • Add ID codes and confirm probe support
  • Implement flashing for MF4/MF3 flash on the RA2E1 (RV40 flash for the RA6M5 is already supported)
  • Handle RA4 MF3/4 flash gracefully (different block size)
  • Possibly support the OCDREG control registers hanging off of AP1 (APB-AP)

Your checklist for this pull request

@dragonmux dragonmux added this to the v2.1 release milestone Nov 11, 2025
@dragonmux dragonmux added Enhancement General project improvement New Target New debug target labels Nov 11, 2025
@desertsagebrush
Copy link
Contributor Author

desertsagebrush commented Nov 24, 2025

Still todo:

  • Handle the different block size for RA4 flash
  • Update comments/etc to include the new RA family members
  • Handle the OCDREG AP?
  • Test more thoroughly
  • Possibly split the flash routines into their own files?
  • Possibly split the families into two feature flags to reduce the size burden?

Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

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

Done a review - very happy with the general direction you're managing to take this, there are only a few fairly small details we spotted that could do with being cleaned up/sorted.

Comment on lines 247 to 252
#define MF3_CF_BLOCK_SIZE (0x800U)
#define MF3_RA2A1_CF_BLOCK_SIZE (0x400U)
#define MF3_RA2A1_CF_BLOCK_SIZE (0x400U) // Contradicted by RA2A1 Ref Manual
#define MF3_DF_BLOCK_SIZE (0x400U)
#define MF3_CF_WRITE_SIZE (0x40U)
#define MF3_CF_WRITE_SIZE (0x8U)
#define MF3_RA2E1_CF_WRITE_SIZE (0x4U)
#define MF3_DF_WRITE_SIZE (0x1U)
Copy link
Member

Choose a reason for hiding this comment

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

We're aware this is, on your part, a "following the style set before", however the parens here are not doing anything useful and can (should) be dropped please. Their presence doesn't follow any of the rest of the code base.

/* See "Switching to Code Flash P/E Mode": §35.13.3.2 of the RA2E1 manual R01UH0852EJ0170. */
/* Set PE/READ mode. Note that this is very similar to the RV40 mode control,
* just with a different target register address. This probably ought to be
* deduplicated, but getting it working is more important first
Copy link
Member

Choose a reason for hiding this comment

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

Having this duplicated is fine - often de-dupe attempts result in more complex/spaghetti code, so this is more than fine with us.

* implementation (i.e. ignoring FMS2) as that is what I have to test on
* currently.
*
* Might also need a 5 us delay here (unlikely given the speed at which this
Copy link
Member

Choose a reason for hiding this comment

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

Please include a note of where exactly that 5µs delay might be needed as this may become relevant in the future. Otherwise, sound logic and reasoning 👍🏼


if (!(target_mem32_read8(target, MF3_FSTATR1) & MF3_FSTATR1_FRDY) ||
target_mem32_read16(target, MF3_FENTRYR) != 0) {
DEBUG_WARN("flash is not ready, may be hanging mid unfinished command due to something going wrong, "
Copy link
Member

Choose a reason for hiding this comment

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

'Flash not 'flash please; this is a serious enough thing that we might suggest making it DEBUG_ERROR or, if possible to get it back through GDB at this moment in the protocol, a gdb_outf() call so the user definitely gets to see this.

Comment on lines +1214 to +1215
target_mem32_write16(target, MF3_FSARL, (const uint16_t)(addr & 0xffffU));
target_mem32_write16(target, MF3_FSARH, (const uint16_t)((addr >> 16) & 0xffffU));
Copy link
Member

Choose a reason for hiding this comment

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

The const's in these casts do nothing and can (should) be dropped. Casting to uint16_t likewise has the same value effect as masking by 0xffffU so the mask can technically be dropped (though having that explicit is no bad thing).

/* Code flash or data flash operation */
const bool code_flash = addr < RENESAS_CF_END;

while (len) {
Copy link
Member

Choose a reason for hiding this comment

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

If it's possible to express this as a for loop over len, keeping len and addr constant, it would be better - the compiler's able to generate better code for this and prove to itself the correctness of the loop for optimisation purposes. Adding/tracking an offset turns out to be ~free due to instruction set things the compiler can take advantage of.

target_mem32_write16(target, MF3_FSARL, (const uint16_t)(dest & 0xffffU));
target_mem32_write16(target, MF3_FSARH, (const uint16_t)((dest >> 16) & 0xffffU));

while (len) {
Copy link
Member

Choose a reason for hiding this comment

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

Same query here, especially as src could be cast to a buffer pointer so you only have one cast to uint8_t to do and then everything else already uses the right pointer width for the remainder

Comment on lines +1292 to +1293
target_mem32_write16(target, MF3_FWBL0, *(const uint16_t *)src);
target_mem32_write16(target, MF3_FWBH0, *((const uint16_t *)src + 1U));
Copy link
Member

Choose a reason for hiding this comment

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

((const uint16_t *)src)[0]/((const uint16_t *)src)[1] would we think be clearer here what you're intending to do.

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

Labels

Enhancement General project improvement New Target New debug target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants