Skip to content

Commit 93c6c9e

Browse files
committed
Further toolchain build tests/debugging
- revert back to standard toolchain - Fix USB deadlock - Fix CS timing problem on SPI flash
1 parent fa75511 commit 93c6c9e

File tree

7 files changed

+41
-29
lines changed

7 files changed

+41
-29
lines changed

.github/workflows/Build.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches:
66
- main
7-
- siglent
7+
- build_FW_test
88
pull_request:
99
branches:
1010
- main
@@ -207,13 +207,7 @@ jobs:
207207
- name: Install toolchain
208208
run: |
209209
sudo apt-get update
210-
sudo apt install -y build-essential binutils-arm-none-eabi
211-
212-
# Ubuntu 24.04 comes with version 10.3 of the ARM GCC toolchain. For some reason builds with that version result in buggy file reading/writing and unstable USB connections.
213-
# Manually install older version of the toolchain which does not have the problem
214-
wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2
215-
tar -xvjf gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 -C /opt
216-
210+
sudo apt install -y build-essential gcc-arm-none-eabi binutils-arm-none-eabi
217211
sudo git clone https://github.com/raspberrypi/pico-sdk.git /opt/pico-sdk
218212
sudo git -C /opt/pico-sdk checkout 2.1.1
219213
sudo git -C /opt/pico-sdk submodule update --init
@@ -236,7 +230,6 @@ jobs:
236230
- name: Build application
237231
run: |
238232
export PICO_SDK_PATH=/opt/pico-sdk
239-
export PATH=/opt/gcc-arm-none-eabi-9-2020-q2-update/bin:$PATH
240233
cd Software/LibreCAL
241234
mkdir build && cd build
242235
cmake ..

Software/LibreCAL/src/Flash.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
#include "FreeRTOS.h"
44
#include "task.h"
55
#include <cstring>
6+
#include "pico/time.h"
67

78
#include <stdio.h>
89

9-
#define LOG_DEBUG(s, ...) //printf(s, __VA_ARGS__)
10-
#define LOG_INFO(s...) //printf(s)
11-
#define LOG_ERR(s...) //printf(s)
12-
//#define LOG_ERR(s, ...) printf(s, __VA_ARGS__)
13-
//#define LOG_ERR(s, ...) printf(s, __VA_ARGS__)
14-
//#define LOG_ERR(s, ...) printf(s, __VA_ARGS__)
10+
#define LOG_LEVEL LOG_LEVEL_INFO
11+
#define LOG_MODULE "Flash"
12+
#include "Log.h"
1513

1614
bool Flash::isPresent() {
1715
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
@@ -50,16 +48,16 @@ void Flash::read(uint32_t address, uint16_t length, void *dest) {
5048
xSemaphoreGiveRecursive(mutex);
5149
}
5250

53-
bool Flash::write(uint32_t address, uint16_t length, const void *src) {
51+
bool Flash::write(uint32_t address, uint16_t length, const uint8_t *src) {
5452
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
5553
if(address % PageSize != 0 || length%PageSize != 0) {
5654
// only writes to complete pages allowed
57-
LOG_ERR("Invalid write address/size: %lu/%u", address, length);
55+
LOG_ERR("Invalid write address/size: 0x%08x/%u", address, length);
5856
xSemaphoreGiveRecursive(mutex);
5957
return false;
6058
}
6159
address &= 0x00FFFFFF;
62-
LOG_DEBUG("Writing %u bytes to address %lu", length, address);
60+
LOG_DEBUG("Writing %u bytes to address 0x%08x", length, address);
6361
while(length > 0) {
6462
EnableWrite();
6563
CS(false);
@@ -101,6 +99,7 @@ void Flash::EnableWrite() {
10199
uint8_t wel = 0x06;
102100
spi_write_blocking(spi, &wel, 1);
103101
CS(true);
102+
sleep_us(1);
104103
}
105104

106105
bool Flash::eraseChip() {
@@ -111,14 +110,15 @@ bool Flash::eraseChip() {
111110
uint8_t chip_erase = 0x60;
112111
spi_write_blocking(spi, &chip_erase, 1);
113112
CS(true);
113+
sleep_us(1);
114114
return WaitBusy(25000);
115115
}
116116

117117
bool Flash::eraseSector(uint32_t address) {
118118
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
119119
// align address with sector address
120120
address -= address % SectorSize;
121-
LOG_INFO("Erasing sector at %lu", address);
121+
LOG_INFO("Erasing sector at 0x%08x", address);
122122
EnableWrite();
123123
CS(false);
124124
uint8_t cmd[4] = {
@@ -129,6 +129,7 @@ bool Flash::eraseSector(uint32_t address) {
129129
};
130130
spi_write_blocking(spi, cmd, 4);
131131
CS(true);
132+
sleep_us(1);
132133
bool ret = WaitBusy(25000);
133134
xSemaphoreGiveRecursive(mutex);
134135
return ret;
@@ -138,7 +139,7 @@ bool Flash::erase32Block(uint32_t address) {
138139
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
139140
// align address with block address
140141
address -= address % Block32Size;
141-
LOG_INFO("Erasing 32kB block at %lu", address);
142+
LOG_INFO("Erasing 32kB block at 0x%08x", address);
142143
EnableWrite();
143144
CS(false);
144145
uint8_t cmd[4] = {
@@ -149,6 +150,7 @@ bool Flash::erase32Block(uint32_t address) {
149150
};
150151
spi_write_blocking(spi, cmd, 4);
151152
CS(true);
153+
sleep_us(1);
152154
bool ret = WaitBusy(25000);
153155
xSemaphoreGiveRecursive(mutex);
154156
return ret;
@@ -158,7 +160,7 @@ bool Flash::erase64Block(uint32_t address) {
158160
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
159161
// align address with block address
160162
address -= address % Block64Size;
161-
LOG_INFO("Erasing 64kB block at %lu", address);
163+
LOG_INFO("Erasing 64kB block at 0x%08x", address);
162164
EnableWrite();
163165
CS(false);
164166
uint8_t cmd[4] = {

Software/LibreCAL/src/Flash.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Flash {
2424

2525
bool isPresent();
2626
void read(uint32_t address, uint16_t length, void *dest);
27-
bool write(uint32_t address, uint16_t length, const void *src);
27+
bool write(uint32_t address, uint16_t length, const uint8_t *src);
2828
bool eraseChip();
2929
bool eraseSector(uint32_t address);
3030
bool erase32Block(uint32_t address);

Software/LibreCAL/src/Touchstone.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <cstdio>
77
#include <cstring>
88

9+
#define LOG_LEVEL LOG_LEVEL_INFO
10+
#define LOG_MODULE "Touchstone"
11+
#include "Log.h"
12+
913
static FIL writeFile;
1014
static bool writeFileOpen = false;
1115

@@ -324,6 +328,7 @@ extern FATFS fs1;
324328

325329
bool Touchstone::clearFactory() {
326330
if(!writeFactory) {
331+
LOG_ERR("Factory deletion not allowed");
327332
return false;
328333
}
329334

@@ -335,16 +340,21 @@ bool Touchstone::clearFactory() {
335340

336341
// format the factory drive
337342
BYTE work[FF_MAX_SS];
338-
if(f_mkfs("1:", 0, work, sizeof(work)) != FR_OK) {
343+
FRESULT status;
344+
if((status = f_mkfs("1:", 0, work, sizeof(work))) != FR_OK) {
345+
LOG_ERR("mkfs failed: %d", status);
339346
return false;
340347
}
341-
if(f_setlabel("1:LibreCAL_R") != FR_OK) {
348+
if((status = f_mount(&fs1, "1:", 1)) != FR_OK) {
349+
LOG_ERR("mount failed: %d", status);
342350
return false;
343351
}
344-
if(f_mount(&fs1, "1:", 1) != FR_OK) {
352+
if((status = f_setlabel("1:LibreCAL_R")) != FR_OK) {
353+
LOG_ERR("set label failed: %d", status);
345354
return false;
346355
}
347356

357+
348358
// needs to recreate the information file
349359
return createInfoFile();
350360
}

Software/LibreCAL/src/USB/usb.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ static void tinyUSB_task(void* ptr) {
108108
}
109109
}
110110

111+
static TaskHandle_t usb_task;
112+
111113
void usb_init(usbd_recv_callback_t receive_callback) {
112114
callback = receive_callback;
113115
tud_init(0);
114-
xTaskCreate(tinyUSB_task, "TinyUSB", 1024, NULL, 1, NULL);
116+
xTaskCreate(tinyUSB_task, "TinyUSB", 1024, NULL, 3, &usb_task);
115117
}
116118
bool usb_transmit(const uint8_t *data, uint16_t length, uint8_t i) {
117119
if(i == USB_INTERFACE_CDC) {

Software/LibreCAL/src/freertos.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33

44
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );
55

6-
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName);
6+
void vApplicationStackOverflowHook(xTaskHandle xTask, char *pcTaskName);
77

8-
__attribute__((weak)) void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName)
8+
__attribute__((weak)) void vApplicationStackOverflowHook(xTaskHandle xTask, char *pcTaskName)
99
{
1010
/* Run time stack overflow checking is performed if
1111
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
1212
called if a stack overflow is detected. */
13+
while(1) {
14+
15+
}
1316
}
1417

1518
static StaticTask_t xIdleTaskTCBBuffer;

Software/LibreCAL/src/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ static void defaultTask(void* ptr) {
166166
}
167167
}
168168

169+
static TaskHandle_t main_task;
170+
169171
int main(void) {
170172
#ifdef ENABLE_UART
171173
Log_Init();
@@ -209,7 +211,7 @@ int main(void) {
209211
Heater::SetTarget(35);
210212
SCPI::Init(usb_transmit);
211213

212-
xTaskCreate(defaultTask, "defaultTask", 16384, NULL, 3, NULL);
214+
xTaskCreate(defaultTask, "defaultTask", 16384, NULL, 3, &main_task);
213215

214216
vTaskStartScheduler();
215217
return 0;

0 commit comments

Comments
 (0)