Skip to content

Commit ff8640f

Browse files
committed
examples(ADC internal): disable ICACHE if enabled
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 <[email protected]>
1 parent b875d3a commit ff8640f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

examples/Peripherals/ADC/Internal_channels/Internal_channels.ino

+19
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ static int32_t readVoltage(int32_t VRef, uint32_t pin)
9393

9494
// The loop routine runs over and over again forever:
9595
void loop() {
96+
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
97+
bool icache_enabled = false;
98+
if (HAL_ICACHE_IsEnabled() == 1) {
99+
icache_enabled = true;
100+
/* Disable instruction cache prior to internal cacheable memory update */
101+
if (HAL_ICACHE_Disable() != HAL_OK) {
102+
Error_Handler();
103+
}
104+
}
105+
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
96106
// Print out the value read
97107
int32_t VRef = readVref();
98108
Serial.printf("VRef(mv)= %i", VRef);
@@ -104,4 +114,13 @@ void loop() {
104114
#endif
105115
Serial.printf("\tA0(mv)= %i\n", readVoltage(VRef, A0));
106116
delay(200);
117+
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
118+
if (icache_enabled)
119+
{
120+
/* Re-enable instruction cache */
121+
if (HAL_ICACHE_Enable() != HAL_OK) {
122+
Error_Handler();
123+
}
124+
}
125+
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
107126
}

0 commit comments

Comments
 (0)