From 6ff9a532f88cea1dfa9883c7e6b865ce5e0eed4c Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sun, 12 Jun 2022 17:35:38 -0400 Subject: [PATCH] Fix #335: [un]signed cleanup Catena_Mx25v8035f::begin() --- src/lib/stm32/Catena_Mx25v8035f.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/stm32/Catena_Mx25v8035f.cpp b/src/lib/stm32/Catena_Mx25v8035f.cpp index 9b4f90b..b52e2ea 100644 --- a/src/lib/stm32/Catena_Mx25v8035f.cpp +++ b/src/lib/stm32/Catena_Mx25v8035f.cpp @@ -116,8 +116,9 @@ bool Catena_Mx25v8035f::begin( return false; } - if (ChipSelectPin == -1 && this->m_CS == -1) + if (ChipSelectPin == -1 && this->m_CS == UINT8_MAX) { + // [1] prevent us from proceeding if both ChipSelectPin and m_CS are "not specified" gLog.printf(cLog::kError, "flash pin not set\n"); return false; } @@ -129,8 +130,12 @@ bool Catena_Mx25v8035f::begin( this->m_pSpi = pSpi; if (ChipSelectPin != -1) + // [2] make sure m_CS has a value. this->m_CS = ChipSelectPin; + // at this point, m_CS is valid by [1] and [2] above. + + // start the operation. pSpi->beginTransaction(this->m_CS, SpiSettings); /* force to put stand-by mode, just in case */