Skip to content

Commit

Permalink
examples(ADC internal): disable ICACHE if enabled
Browse files Browse the repository at this point in the history
For some series, calibration values are stored in FLASH
read-only area and required to disable ICACHE before
access them.

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
  • Loading branch information
fpistm committed May 24, 2023
1 parent b875d3a commit ff8640f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples/Peripherals/ADC/Internal_channels/Internal_channels.ino
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ static int32_t readVoltage(int32_t VRef, uint32_t pin)

// The loop routine runs over and over again forever:
void loop() {
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
bool icache_enabled = false;
if (HAL_ICACHE_IsEnabled() == 1) {
icache_enabled = true;
/* Disable instruction cache prior to internal cacheable memory update */
if (HAL_ICACHE_Disable() != HAL_OK) {
Error_Handler();
}
}
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
// Print out the value read
int32_t VRef = readVref();
Serial.printf("VRef(mv)= %i", VRef);
Expand All @@ -104,4 +114,13 @@ void loop() {
#endif
Serial.printf("\tA0(mv)= %i\n", readVoltage(VRef, A0));
delay(200);
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
if (icache_enabled)
{
/* Re-enable instruction cache */
if (HAL_ICACHE_Enable() != HAL_OK) {
Error_Handler();
}
}
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
}

0 comments on commit ff8640f

Please sign in to comment.